Exemplo n.º 1
0
 /// <summary>
 /// Shows where a player can possibly play by anchoring his counter where he can actually play
 /// otherwise shows his counter nearly visible when mouse is on board
 /// </summary>
 /// <param name="sender">sender object</param>
 /// <param name="e">mouse event</param>
 private void BoardHover(object sender, MouseEventArgs e)
 {
     //If game has started
     if (isPlaying)
     {
         rectHover.Name = "hoverRect";
         //Getting board canvas dimensions
         double canvasHeight = canBoard.ActualHeight;
         double dH           = canvasHeight / 8.0;
         double canvasWidth  = canBoard.ActualWidth;
         double dW           = canvasWidth / 8.0;
         //Getting mouse positions
         double mouseX = e.GetPosition(canBoard).X;
         double mouseY = e.GetPosition(canBoard).Y;
         //Setting counter dimensions
         rectHover.Width  = dW;
         rectHover.Height = dH;
         //Setting counter positions
         int squareIdI = (int)(mouseX / dW);
         int squareIdJ = (int)(mouseY / dH);
         //Setting counter skin based on player turn
         if (turnToWhite)
         {
             rectHover.Fill = skinPlayer1.Clone();
         }
         else
         {
             rectHover.Fill = skinPlayer2.Clone();
         }
         //Anchoring counter if possible play
         if (board.IsPlayable(squareIdI, squareIdJ, turnToWhite))
         {
             Canvas.SetTop(rectHover, (squareIdJ * dH));
             Canvas.SetLeft(rectHover, (squareIdI * dW));
             rectHover.Fill.Opacity = 0.6;
         }
         else
         {
             Canvas.SetTop(rectHover, mouseY - dH / 2);
             Canvas.SetLeft(rectHover, mouseX - dW / 2);
             rectHover.Fill.Opacity = 0.2;
         }
         rectHover.InvalidateVisual();
         //Counter only if on board
         if (canBoard.Children.Contains(rectHover))
         {
             if (mouseX > canvasWidth || mouseX > canvasHeight || mouseX < 0 || mouseY < 0)
             {
                 canBoard.Children.Remove(rectHover);
             }
         }
         else
         {
             canBoard.Children.Add(rectHover);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Load all and instanciate all brush
        /// </summary>
        private void LoadAssets()
        {
            brushWhite = ImageManager.GetBrushHeroes(imageCoinType[0]);
            brushBlack = ImageManager.GetBrushHeroes(imageCoinType[1]);

            brushWhitePlayable         = brushWhite.Clone();
            brushWhitePlayable.Opacity = 0.3;
            brushBlackPlayable         = brushBlack.Clone();
            brushBlackPlayable.Opacity = 0.3;

            brushMarvel         = ImageManager.GetBrushImage("marvel_logo.png");
            brushMarvel.Opacity = 0.3;
            brushDC             = ImageManager.GetBrushImage("dc_logo.png");
            brushDC.Opacity     = 0.3;

            brushMarvelDC         = ImageManager.GetBrushImage("marvel_dc_logo.png");
            brushMarvelDC.Opacity = 0.3;

            BtnWhitePlayer.Background = brushWhite;
            BtnBlackPlayer.Background = brushBlack;

            brushWallpaper         = ImageManager.GetBrushImage("marvel_logo_1.jpg");
            brushWallpaper.Stretch = Stretch.UniformToFill;
            brushWallpaper.Opacity = 0.1;
            root.Background        = Brushes.WhiteSmoke;
        }
Exemplo n.º 3
0
        //---------------------------------------------------------------------------

        /**
         * @fn		internal void SetImage(WriteableBitmap wb, Stretch stretch = Stretch.None)
         * @brief	WriteableBitmap Type을 Align Control에 Set.
         * @return	void
         * @param	WriteableBitmap wb      : Source Image.
         * @param	Stretch         stretch : Stretch Option.
         * @remark
         * - Stretch Option을 Fill로 할 경우, 배율이 맞지 않을 수 있음.
         * - 배율 조정 + Fit을 원하면 GetFitScale을 사용하여 수동으로 화면 Scale 조정 할 것.
         * @author	선경규(Kyeong Kyu - Seon)
         * @date	2020/3/9  16:40
         */
        public void SetImage(WriteableBitmap wb, Stretch stretch = Stretch.None, bool bUpdateOrg = true)
        {
            if (wb == null)
            {
                return;
            }

            m_ImgBrs = new ImageBrush(wb);

            m_ImgBrs.Stretch = stretch;
            if (m_ImgBrs != null && bUpdateOrg)
            {
                m_ImgBrsOrg = m_ImgBrs.Clone();
            }

            m_nWidth   = wb.PixelWidth;
            m_nHeight  = wb.PixelHeight;
            m_nChannel = (int)(wb.Format.BitsPerPixel / 8.0);
            if (m_ImgBrs.Stretch == Stretch.None)
            {
                lib_Canvas.Width  = m_nWidth;
                lib_Canvas.Height = m_nHeight;
            }
            lib_Canvas.Background = m_ImgBrs;
            m_dScale = myScaleTransform.ScaleX;
        }
Exemplo n.º 4
0
        private Resource()
        {
            Uri         u  = new Uri("Pack://application:,,,/rs/brid.png");
            BitmapImage bi = new BitmapImage(u);

            Background         = new ImageBrush(bi);
            Background.Viewbox = new Rect(0, 0, 0.61987f, 1f);
            Brid             = new ImageBrush[3];
            Brid[0]          = Background.Clone();
            Brid[0].Viewbox  = new Rect(0.6587473f, 0.919921f, 0.0734341f, 0.046875f);
            Brid[1]          = Background.Clone();
            Brid[1].Viewbox  = new Rect(0.7796976f, 0.919921f, 0.0734341f, 0.046875f);
            Brid[2]          = Background.Clone();
            Brid[2].Viewbox  = new Rect(0.9006479f, 0.919921f, 0.0734341f, 0.046875f);
            PipeUp           = Background.Clone();
            PipeUp.Viewbox   = new Rect(0.697264f, 0.02539f, 0.112311f, 0.625f);
            PipeDown         = Background.Clone();
            PipeDown.Viewbox = new Rect(0.8185745f, 0.02539f, 0.112311f, 0.625f);
        }
Exemplo n.º 5
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //1、这种写法,会同时更新两个按钮的背景,因为画刷资源继承自Freezable类,自带跟踪变化的机制
            //ImageBrush brush = (ImageBrush)this.Resources["brushTitle"];
            //brush.Viewport = new Rect(0, 0, 100, 100);

            //2、
            ImageBrush brush    = (ImageBrush)this.Resources["brushTitle"];
            ImageBrush newBrush = brush.Clone();

            newBrush.Viewport            = new Rect(0, 0, 100, 100);
            this.Resources["brushTitle"] = newBrush;//此处虽然修改了全局资源,但是,静态资源只查找一次,所以不受影响
        }
Exemplo n.º 6
0
        /// <summary>
        /// Load design elements.
        /// </summary>
        private void LoadPictures()
        {
            whiteBrush = CreateImageBrushFromFile("fig1.png");
            blackBrush = CreateImageBrushFromFile("fig2.png");

            mainWindow.BtnWhitePlayer.Background = whiteBrush;
            mainWindow.BtnBlackPlayer.Background = blackBrush;

            whiteBrushCanPlay         = whiteBrush.Clone();
            whiteBrushCanPlay.Opacity = 0.3;
            blackBrushCanPlay         = blackBrush.Clone();
            blackBrushCanPlay.Opacity = 0.3;
        }
Exemplo n.º 7
0
        //---------------------------------------------------------------------------

        /**
         * @fn		public void SetImage(BitmapImage bmpimg, Stretch stretch = Stretch.None)
         * @brief	WriteableBitmap Type을 Align Control에 Set.
         * @return	void
         * @param	BitmapImage     bmpimg  : Source Image.
         * @param	Stretch         stretch : Stretch Option.
         * @remark
         * - Stretch Option을 Fill로 할 경우, 배율이 맞지 않을 수 있음.
         * - 배율 조정 + Fit을 원하면 GetFitScale을 사용하여 수동으로 화면 Scale 조정 할 것.
         * @author	선경규(Kyeong Kyu - Seon)
         * @date	2020/3/9  16:40
         */
        public void SetImage(BitmapImage bmpimg, Stretch stretch = Stretch.None)
        {
            WriteableBitmap wbm = null;

            FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();

            // BitmapSource objects like FormatConvertedBitmap can only have their properties
            // changed within a BeginInit/EndInit block.
            newFormatedBitmapSource.BeginInit();

            // Use the BitmapSource object defined above as the source for this new
            // BitmapSource (chain the BitmapSource objects together).
            newFormatedBitmapSource.Source = bmpimg;

            // Set the new format to Gray32Float (grayscale).
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Bgr24;
            newFormatedBitmapSource.EndInit();

            wbm = new WriteableBitmap(newFormatedBitmapSource);

            m_ImgBrs         = new ImageBrush(wbm);
            m_ImgBrs.Stretch = stretch;
            if (m_ImgBrs != null)
            {
                m_ImgBrsOrg = m_ImgBrs.Clone();
            }
            if (m_ImgBrs.Stretch == Stretch.None)
            {
                lib_Canvas.Width  = m_ImgBrs.ImageSource.Width;
                lib_Canvas.Height = m_ImgBrs.ImageSource.Height;
            }

            m_nWidth   = (int)m_ImgBrs.ImageSource.Width;
            m_nHeight  = (int)m_ImgBrs.ImageSource.Height;
            m_nChannel = (int)(wbm.Format.BitsPerPixel / 8.0);

            lib_Canvas.Background = new ImageBrush(wbm);
            m_dScale = myScaleTransform.ScaleX;
        }
Exemplo n.º 8
0
        public void OpenImage()
        {
            /// <summary>
            /// Paints selected image file to the window panes.
            /// </summary>

            string directory = FromFile();

            if (directory != "")
            {
                Bitmap left = LoadRecolor(directory);

                ImageBrush iBrush = new ImageBrush(ToImageSource(left));

                _Owner.Image1Border.Background = _Owner.Image1 = iBrush;
                _Owner.Image2Border.Background = _Owner.Image2 = iBrush.Clone();

                _Owner.FromBox.IsEnabled = true;
                _Owner.ToBox.IsEnabled   = true;

                _Owner.IsOpen = true;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Update the score of both player and change the background
        /// </summary>
        private void UpdateScore()
        {
            whitePlayer.Score = board.GetWhiteScore();
            blackPlayer.Score = board.GetBlackScore();
            Brush brush;

            if (this.whitePlayer.Score > this.blackPlayer.Score)
            {
                brush         = whiteBrushCanPlay.Clone();
                brush.Opacity = 0.15;
            }
            else if (this.whitePlayer.Score < this.blackPlayer.Score)
            {
                brush         = blackBrushCanPlay.Clone();
                brush.Opacity = 0.15;
            }
            else
            {
                brush = System.Windows.Media.Brushes.Black;
            }
            if (!mainWindow.gameGrid.Background.Equals(brush))
            {
                try
                {
                    animation.From = mainWindow.gameGrid.Background;
                    animation.To   = brush;
                    Storyboard.SetTarget(animation, mainWindow.gameGrid);
                    Storyboard.SetTargetProperty(animation, new PropertyPath("Background"));

                    var sb = new Storyboard();
                    sb.Children.Add(animation);
                    sb.Begin();
                }
                catch { }
            }
        }
Exemplo n.º 10
0
        //---------------------------------------------------------------------------

        /**
         * @fn		public void OpenImage(string strPath)
         * @brief	Align Control에 string path로 이미지 Open.
         * @return
         * @param
         * @remark
         * -
         * @author	선경규(Kyeong Kyu - Seon)
         * @date	2020/3/9  16:39
         */
        public void OpenImage(string strPath)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
            {
                try
                {
                    if (!File.Exists(strPath))
                    {
                        m_ImgBrs              = null;
                        m_ImgBrsOrg           = null;
                        lib_Canvas.Background = Brushes.Transparent;
                        return;
                    }
                    FileInfo fi       = new FileInfo(strPath);
                    m_strPath         = strPath;
                    m_strFileName     = strPath.Substring(strPath.LastIndexOf('\\') + 1);
                    m_strExtension    = fi.Extension;
                    m_strCreationTime = fi.CreationTime.ToString("yyyy.MM.dd HH:mm:ss");

                    BitmapImage bmpImg = new BitmapImage();
                    FileStream source  = File.OpenRead(strPath);
                    //bmpImg.Format = PixelFormats.Bgr32;
                    bmpImg.BeginInit();
                    bmpImg.CacheOption  = BitmapCacheOption.OnLoad;
                    bmpImg.StreamSource = source;
                    bmpImg.EndInit();

                    WriteableBitmap wbm = null;
                    FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();

                    // BitmapSource objects like FormatConvertedBitmap can only have their properties
                    // changed within a BeginInit/EndInit block.
                    newFormatedBitmapSource.BeginInit();

                    // Use the BitmapSource object defined above as the source for this new
                    // BitmapSource (chain the BitmapSource objects together).
                    newFormatedBitmapSource.Source = bmpImg;

                    // Set the new format to Gray32Float (grayscale).
                    newFormatedBitmapSource.DestinationFormat = PixelFormats.Bgr24;
                    newFormatedBitmapSource.EndInit();

                    wbm = new WriteableBitmap(newFormatedBitmapSource);

                    m_ImgBrs              = new ImageBrush(wbm);
                    m_ImgBrs.Stretch      = Stretch.None;
                    lib_Canvas.Width      = m_ImgBrs.ImageSource.Width;
                    lib_Canvas.Height     = m_ImgBrs.ImageSource.Height;
                    lib_Canvas.Background = m_ImgBrs;
                    m_nWidth              = wbm.PixelWidth;
                    m_nHeight             = wbm.PixelHeight;
                    m_nChannel            = (int)(wbm.Format.BitsPerPixel / 8.0);
                    m_nStride             = (m_nWidth * m_nChannel + 3) & ~3;
                    m_dDpiX = wbm.DpiX;
                    m_dDpiY = wbm.DpiY;

                    m_ImgBrsOrg = m_ImgBrs.Clone();

                    m_dScale = myScaleTransform.ScaleX;
                }
                catch (Exception)
                {
                }
            }));
        }