Пример #1
0
        //---------------------------------------------------------------------------

        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (m_IsDrag)
            {
                m_Drag = new Point(e.GetPosition(Root).X - m_Click.X, e.GetPosition(Root).Y - m_Click.Y);
                switch (m_Mode)
                {
                case EResizeMode.Left:
                    m_Size = new SelectionPoint(Math.Min(MapWidth - MapMinWidth, (int)m_Drag.X / PxTileWidth), (int)m_Drag.Y / PxTileHeight);
                    UpdateLeftBorderMargin(m_Size.X);
                    break;

                case EResizeMode.Right:
                    m_Size = new SelectionPoint(Math.Max(MapMinWidth - MapWidth, (int)m_Drag.X / PxTileWidth), (int)m_Drag.Y / PxTileHeight);
                    UpdateRightBorderMargin(m_Size.X);
                    break;

                case EResizeMode.Top:
                    m_Size = new SelectionPoint((int)m_Drag.X / PxTileWidth, Math.Min(MapHeight - MapMinHeight, (int)m_Drag.Y / PxTileHeight));
                    UpdateTopBorderMargin(m_Size.Y);
                    break;

                case EResizeMode.Bottom:
                    m_Size = new SelectionPoint((int)m_Drag.X / PxTileWidth, Math.Max(MapMinHeight - MapHeight, (int)m_Drag.Y / PxTileHeight));
                    UpdateBottomBorderMargin(m_Size.Y);
                    break;
                }
            }
        }
Пример #2
0
        //---------------------------------------------------------------------------

        private void FloodFill(ELayerMode mode, SelectionPoint center, SelectionPoint fill)
        {
            if (IsMatch(mode, center.X, center.Y, fill.X, fill.Y))
            {
                return;
            }

            Layer layer = m_Map[mode, center.X, center.Y];

            if (layer != null)
            {
                SelectionPoint         expected = new SelectionPoint(layer.TargetX, layer.TargetY);
                Queue <SelectionPoint> q        = new Queue <SelectionPoint>();
                q.Enqueue(center);
                while (q.Count > 0)
                {
                    SelectionPoint n = q.Dequeue();
                    if (!IsMatch(mode, n.X, n.Y, expected.X, expected.Y))
                    {
                        continue;
                    }
                    SelectionPoint w = n, e = new SelectionPoint(n.X + 1, n.Y);
                    while ((w.X >= 0) && IsMatch(mode, w.X, w.Y, expected.X, expected.Y))
                    {
                        if (m_Map.SetTile(mode, w.X, w.Y, fill.X, fill.Y))
                        {
                            ContainsChanges = true;
                            m_Control?.SetTile(mode, w.X, w.Y, fill.X, fill.Y);
                        }
                        if ((w.Y > 0) && IsMatch(mode, w.X, w.Y - 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(w.X, w.Y - 1));
                        }
                        if ((w.Y < m_Map.Height - 1) && IsMatch(mode, w.X, w.Y + 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(w.X, w.Y + 1));
                        }
                        w.X--;
                    }
                    while ((e.X <= m_Map.Width - 1) && IsMatch(mode, e.X, e.Y, expected.X, expected.Y))
                    {
                        if (m_Map.SetTile(mode, e.X, e.Y, fill.X, fill.Y))
                        {
                            ContainsChanges = true;
                            m_Control?.SetTile(mode, e.X, e.Y, fill.X, fill.Y);
                        }
                        if ((e.Y > 0) && IsMatch(mode, e.X, e.Y - 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(e.X, e.Y - 1));
                        }
                        if ((e.Y < m_Map.Height - 1) && IsMatch(mode, e.X, e.Y + 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(e.X, e.Y + 1));
                        }
                        e.X++;
                    }
                }
            }
        }
Пример #3
0
        //---------------------------------------------------------------------------

        public ResizeControl()
        {
            InitializeComponent();
            DataContext = this;

            m_Size = new SelectionPoint();
            m_Mode = EResizeMode.None;

            m_ModeMapping = new Dictionary <FrameworkElement, EResizeMode>()
            {
                { LeftBorder, EResizeMode.Left },
                { RightBorder, EResizeMode.Right },
                { TopBorder, EResizeMode.Top },
                { BottomBorder, EResizeMode.Bottom }
            };

            UpdateLeftBorderMargin(0);
            UpdateRightBorderMargin(0);
            UpdateTopBorderMargin(0);
            UpdateBottomBorderMargin(0);
        }