예제 #1
0
 /// <summary>
 /// Color a grid element based on an id
 /// </summary>
 /// <param name="element">Grid element to paint</param>
 /// <param name="id">ID to paint from</param>
 public void ColorGridElementBasedOnID(GridElement element, int id)
 {
     if (id == -1)
     {
         DeColorGridElement(element);
     }
     else
     {
         element.m_Image.Opacity = 1;
         element.m_Visible       = true;
         element.m_ID            = id;
         element.m_Image.Source  = m_TilesetManager.GetTileSetElementFromID(id).m_CroppedImage;
     }
 }
예제 #2
0
        /// <summary>
        /// Tries to color 4 grid element sides of a grid element
        /// </summary>
        /// <param name="element">Grid element to look from</param>
        private void RecursiveDeColorSideGridElements(GridElement element)
        {
            //Up grid element
            GridElement upElement = m_GridManager.GetGridElementInDirectionFromGridElement(element, Direction.Up);

            if (upElement != null)
            {
                if (upElement.m_ID != -1)
                {
                    RecursiveDeColorGridElement(upElement);
                }
            }

            //Right grid element
            GridElement rightElement = m_GridManager.GetGridElementInDirectionFromGridElement(element, Direction.Right);

            if (rightElement != null)
            {
                if (rightElement.m_ID != -1)
                {
                    RecursiveDeColorGridElement(rightElement);
                }
            }

            //Down grid element
            GridElement downElement = m_GridManager.GetGridElementInDirectionFromGridElement(element, Direction.Down);

            if (downElement != null)
            {
                if (downElement.m_ID != -1)
                {
                    RecursiveDeColorGridElement(downElement);
                }
            }

            //Left grid element
            GridElement leftElement = m_GridManager.GetGridElementInDirectionFromGridElement(element, Direction.Left);

            if (leftElement != null)
            {
                if (leftElement.m_ID != -1)
                {
                    RecursiveDeColorGridElement(leftElement);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Grid element mouse over function
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Mouse event arguements</param>
        public void GridElementMouseOver(object sender, MouseEventArgs e)
        {
            ///If mouse is down
            bool mouseIsDown = System.Windows.Input.Mouse.LeftButton == MouseButtonState.Pressed;

            if (mouseIsDown)
            {
                ///Get Grid Element in correct layer from location
                Image  img = (Image)sender;
                double x   = Canvas.GetLeft(img);
                double y   = Canvas.GetTop(img);

                GridElement element = m_GridManager.GetGridElementOnPositionFromLayer(m_GridManager.m_LayerIndex, x, y);

                //Based on the active paint mode,
                //paint grid elements differently
                if (img != null)
                {
                    if (m_PaintMode == PaintMode.Erase)
                    {
                        DeColorGridElement(element);
                    }
                    else if (m_PaintMode == PaintMode.Paint)
                    {
                        ColorGridElement(element);
                    }
                    else if (m_PaintMode == PaintMode.Fill)
                    {
                        RecursiveColorGridElement(element);
                    }
                    else if (m_PaintMode == PaintMode.DeleteFill)
                    {
                        RecursiveDeColorGridElement(element);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Adds layer to Grid canvas
        /// </summary>
        public void AddLayer()
        {
            m_LayerIndex++;

            ///Creating layer
            GridLayer layer = new GridLayer("Layer " + m_LayerIndex.ToString());

            AddGridLayer(layer);

            double widthHeight = m_GridCanvas.Width / m_GridWidth;

            //Loop indexes
            int xStep = -1;
            int yStep = 0;

            int size = m_GridWidth * m_GridHeight;

            for (int i = 0; i < size; i++)
            {
                //Creation of grid elememnt
                GridElement element = new GridElement();

                //Setting of various grid element variables
                element.m_GridID    = i;
                element.m_ID        = -1;
                element.m_GridLayer = m_LayerIndex;

                element.m_Image             = new Image();
                element.m_Image.Stretch     = Stretch.Fill;
                element.m_Image.Width       = widthHeight;
                element.m_Image.Height      = widthHeight;
                element.m_Image.MouseEnter += new MouseEventHandler(m_PaintManager.GridElementMouseOver);
                element.m_Image.MouseDown  += new MouseButtonEventHandler(m_PaintManager.GridElementMouseOver);

                xStep++;

                //Handling of correct spacing of loop indexes
                if (xStep > m_GridWidth - 1)
                {
                    xStep = 0;
                    yStep++;
                }

                //Setting image position in grid canvas
                Canvas.SetLeft(element.m_Image, 0 + (widthHeight * xStep));
                Canvas.SetTop(element.m_Image, 0 + (widthHeight * yStep));

                m_GridCanvas.Children.Add(element.m_Image);

                //Grid element position
                element.m_PositionX = Canvas.GetLeft(element.m_Image);
                element.m_PositionY = Canvas.GetTop(element.m_Image);

                AddGridElement(element);
            }

            //Setting up stack panel
            StackPanel sp = new StackPanel();

            sp.Orientation         = Orientation.Horizontal;
            sp.HorizontalAlignment = HorizontalAlignment.Stretch;
            sp.MouseDown          += new MouseButtonEventHandler(ButtonLayerSelect);
            m_LayerSelectStackPanels.Add(sp);

            //Setting up layer label
            Label layerButton = new Label();

            layerButton.Content = layer.m_Name;

            //Setting up layer visibility image
            Image       layerVisibleImage  = new Image();
            BitmapImage layerVisibleBitmap = new BitmapImage(new Uri("pack://application:,,,/Resources/LayerVisible.png", UriKind.Absolute));

            layerVisibleImage.Width      = 15;
            layerVisibleImage.Height     = 15;
            layerVisibleImage.Source     = layerVisibleBitmap;
            layerVisibleImage.Stretch    = Stretch.Fill;
            layerVisibleImage.MouseDown += new MouseButtonEventHandler(ButtonLayerVisibilityClick);
            m_LayerVisibilityImages.Add(layerVisibleImage);

            //Adding to stackpanel
            sp.Children.Add(layerButton);
            sp.Children.Add(layerVisibleImage);
            m_GridLayerStackPanel.Children.Add(sp);

            VisuallyActivateGridLayer(m_LayerIndex);
        }
예제 #5
0
 /// <summary>
 /// Adds Grid Element to active layer
 /// </summary>
 /// <param name="element">Grid Element to add</param>
 /// <returns></returns>
 public GridElement AddGridElement(GridElement element)
 {
     m_GridLayers[m_LayerIndex].m_GridElements.Add(element);
     return(element);
 }
예제 #6
0
 /// <summary>
 /// Recursive de-coloring of grid element
 /// </summary>
 /// <param name="element">Grid element to recursively de-color</param>
 private void RecursiveDeColorGridElement(GridElement element)
 {
     DeColorGridElement(element);
     RecursiveDeColorSideGridElements(element);
 }