Exemplo n.º 1
0
        // метод обработки действия от канвы при режиме перемещения точки.
        private void resolveCanvasAction_movePoint(CanvasAction action, Point point)
        {
            switch (action)
            {
            //если действие - кнопка мыши опустилась
            case CanvasAction.DOWN:
                // и если она была достаточно рядом к одной из точек (задается this.MOUSE_SENSITIVITY)
                int movingPivotIndex = this.bezierCurve.getPivotIndex(point, this.MOUSE_SENSITIVITY);
                if (movingPivotIndex >= 0)
                {
                    //то сохраняем индекс этой точки и включаем режим ее перемещения
                    this.movingPivotIndex = movingPivotIndex;
                    this.DDMode           = DropDownMode.MOVE;
                }
                break;

            //если действие перемещение мышки и включен режим перемещения
            case CanvasAction.MOVE_TO:
                if (this.DDMode == DropDownMode.MOVE)
                {
                    //то меняем состояние точки в хранилище и отрисовываем его.
                    this.bezierCurve.setPivot(this.movingPivotIndex, point);
                    this.renderBezier.render(this.bezierCurve);
                }
                break;

            //если действие - поднялась кнопка мыши то отключаем режим перемещения точки.
            case CanvasAction.UP:
                this.DDMode = DropDownMode.PREPAREDNESS;
                break;
            }
        }
Exemplo n.º 2
0
        public void Stroke()
        {
            float halfWidth = this.LineWidth * .5f;

            this.stack.Insert(0, new CanvasAction(0, Vector2.Zero));

            for (int i = 1; i < this.stack.Count; i++)
            {
                CanvasAction prev = this.stack[i - 1];
                CanvasAction curr = this.stack[i];
                switch (curr.Action)
                {
                case 0:
                    if (prev.Action == 1)
                    {
                        this.FillCircle(prev.Position, halfWidth, this.StrokeColor);
                    }
                    break;

                case 1:
                    this.StrokeLine(prev.Position, curr.Position);
                    //if (i > 1 && i < this.stack.Count) // TODO: not if 90 angle
                    this.FillCircle(prev.Position, halfWidth, this.StrokeColor);
                    break;
                }
            }
            this.stack.RemoveAt(0);

            Vector2 last = this.stack[this.stack.Count - 1].Position;

            if (this.stack[0].Position != last)
            {
                this.FillCircle(last, halfWidth, this.StrokeColor);
            }
        }
Exemplo n.º 3
0
 // метод обработки действия от канвы при режиме добавления точки.
 private void resolveCanvasAction_addPoint(CanvasAction action, Point point)
 {
     //если действи - опустиласль кнопка мыши то
     // добавляем новую опорную точку в хранилище с места клика и отрисовываем его
     if (action == CanvasAction.DOWN)
     {
         this.bezierCurve.addPivot(point);
         this.renderBezier.render(this.bezierCurve);
     }
 }
Exemplo n.º 4
0
 // метод обработки действия от канвы при режиме удаления точки.
 private void resolveCanvasAction_removePoint(CanvasAction action, Point point)
 {
     //если действи - опустиласль кнопка мыши то
     if (action == CanvasAction.DOWN)
     {
         // и если она была достаточно рядом к одной из точек(задается this.MOUSE_SENSITIVITY)
         int removingPivotIndex = this.bezierCurve.getPivotIndex(point, this.MOUSE_SENSITIVITY);
         if (removingPivotIndex >= 0)
         {
             //то удаляем точку из хранилища в хранилище и отрисовываем его.
             this.bezierCurve.removePivotIndex(removingPivotIndex);
             this.renderBezier.render(this.bezierCurve);
         }
     }
 }
Exemplo n.º 5
0
        /************************************************************************************
        *  методы обрабатывающие дейтвия от канвы в зависимости от
        *  режима работы приложения
        ************************************************************************************/
        //в зависимости от режима работы приложения вызывает нужный метод
        private void resolveCanvasAction(CanvasAction action, Point data)
        {
            switch (this.appMode)
            {
            case OperationMode.ADD_POINT:
                this.resolveCanvasAction_addPoint(action, data);
                break;

            case OperationMode.MOVE_POINT:
                this.resolveCanvasAction_movePoint(action, data);
                break;

            case OperationMode.REMOVE_POINT:
                this.resolveCanvasAction_removePoint(action, data);
                break;
            }
        }
Exemplo n.º 6
0
        public void FillGradient(Vector2 startPosition, Vector2 endPosition, Color startColor, Color endColor)
        {
            List <Vector2> poly = new List <Vector2>();

            this.stack.Insert(0, new CanvasAction(0, Vector2.Zero));

            for (int i = 1; i < this.stack.Count; i++)
            {
                CanvasAction prev = this.stack[i - 1];
                CanvasAction curr = this.stack[i];
                switch (curr.Action)
                {
                case 0:
                    if (poly.Count != 0)
                    {
                        FillPolygonGradient(poly, startPosition, endPosition, startColor, endColor);
                    }
                    poly.Clear();
                    break;

                case 1:
                    if (prev.Action == 0)
                    {
                        poly.Add(prev.Position);
                    }
                    poly.Add(curr.Position);
                    break;
                }
            }
            if (poly.Count != 0)
            {
                FillPolygonGradient(poly, startPosition, endPosition, startColor, endColor);
            }

            this.stack.RemoveAt(0);
        }
Exemplo n.º 7
0
        public void FillFourPointGradient(Vector2 topLeftPosition, Vector2 bottomRightPosition, Color topLeft, Color topRight, Color bottomLeft, Color bottomRight)
        {
            List <Vector2> poly = new List <Vector2>();

            this.stack.Insert(0, new CanvasAction(0, Vector2.Zero));

            for (int i = 1; i < this.stack.Count; i++)
            {
                CanvasAction prev = this.stack[i - 1];
                CanvasAction curr = this.stack[i];
                switch (curr.Action)
                {
                case 0:
                    if (poly.Count != 0)
                    {
                        FillPolygonFourPointGradient(poly, topLeftPosition, bottomRightPosition, topLeft, topRight, bottomLeft, bottomRight);
                    }
                    poly.Clear();
                    break;

                case 1:
                    if (prev.Action == 0)
                    {
                        poly.Add(prev.Position);
                    }
                    poly.Add(curr.Position);
                    break;
                }
            }
            if (poly.Count != 0)
            {
                FillPolygonFourPointGradient(poly, topLeftPosition, bottomRightPosition, topLeft, topRight, bottomLeft, bottomRight);
            }

            this.stack.RemoveAt(0);
        }
Exemplo n.º 8
0
 private void pbCanvas_MouseUp(object sender, MouseEventArgs e)
 {
     currentCanvasAction = CanvasAction.none;
 }
Exemplo n.º 9
0
        private void pbCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (currentTilemap == null) return;
            if (!clTilemaps.CheckedItems.Contains(currentTilemap)) return;

            int tx = e.X / 32;
            int ty = e.Y / 32;
            slCoordinates.Text = tx + "," + ty;
            slTileId.Text = currentTilemap.getTileAt(tx, ty).ToString();
            if (currentCanvasAction == CanvasAction.drawingTiles) {
                if (ModifierKeys == Keys.Shift) {
                    currentTilemap.setTileAt(tx, ty, 0);
                } else {
                    currentTilemap.setTileAt(tx, ty, currentTileId);
                }
                pbCanvas.Invalidate(new Rectangle(tx * 32, ty * 32, 32, 32));
            }
            if (currentCanvasAction == CanvasAction.selecting) {
                currentSelection.Width = tx - currentSelection.X + 1;
                currentSelection.Height = ty - currentSelection.Y + 1;
                pbCanvas.Invalidate();
            }
            if (currentCanvasAction == CanvasAction.movingFloatingTilemap) {
                int dx = tx - (canvasActionStart.X / 32);
                int dy = ty - (canvasActionStart.Y / 32);
                currentFloatingTilemapPos.Offset(dx, dy);
                canvasActionStart.X = e.X;
                canvasActionStart.Y = e.Y;
                pbCanvas.Invalidate();
            }
            if (currentCanvasAction == CanvasAction.movingObject) {
                if (ModifierKeys == Keys.Shift) {
                    currentSector.gameObjects.Remove(currentGameObject);
                    pbCanvas.Invalidate();
                    currentCanvasAction = CanvasAction.none;
                } else {
                    int dx = e.X - canvasActionStart.X;
                    int dy = e.Y - canvasActionStart.Y;
                    currentGameObject.X += dx;
                    currentGameObject.Y += dy;
                    canvasActionStart.X = e.X;
                    canvasActionStart.Y = e.Y;
                    pbCanvas.Invalidate();
                }
            }
            if (currentCanvasAction == CanvasAction.drawingBrush) {
                if (ModifierKeys == Keys.Shift) {
                    if (currentBrush != null) currentBrush.erase(currentTilemap, tx, ty);
                } else if (ModifierKeys == Keys.Control) {
                    if (currentBrush != null) {
                        currentBrush.learn(currentTilemap, tx, ty);
                        laBrushSize.Text = currentBrush.Length + " Patterns";
                    }
                } else if (ModifierKeys == (Keys.Control | Keys.Shift)) {
                    if (currentBrush != null) {
                        currentBrush.forget(currentTilemap, tx, ty);
                        laBrushSize.Text = currentBrush.Length + " Patterns";
                    }
                } else {
                    if (currentBrush != null) currentBrush.draw(currentTilemap, tx, ty);
                }
                pbCanvas.Invalidate(new Rectangle((tx - 1) * 32, (ty - 1) * 32, 32 * 3, 32 * 3));
            }
        }
Exemplo n.º 10
0
        private void pbCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            int tx = e.X / 32;
            int ty = e.Y / 32;

            if (currentSector == null) return;

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTiles)) {
                currentCanvasAction = CanvasAction.drawingTiles;
            }

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTileManip)) {
                if ((currentFloatingTilemap != null) && (currentFloatingTilemapPos.Contains(tx,ty))) {
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                } else
                if (currentSelection.Contains(tx, ty)) {
                    createFloatingTilemapFromSelection(true);
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                    pbCanvas.Invalidate();
                } else {
                    anchorFloatingTilemap();
                    pbCanvas.Invalidate();
                    currentCanvasAction = CanvasAction.selecting;
                    currentSelection = new Rectangle(tx, ty, 0, 0);
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpObjects)) {
                GameObject selectedObject = (GameObject)lbGameObjects.SelectedItem;
                if ((selectedObject != null) && (selectedObject is SpatialGameObject)) {
                    SpatialGameObject spatialGameObject = (SpatialGameObject)selectedObject.Clone();
                    spatialGameObject.X = e.X;
                    spatialGameObject.Y = e.Y;
                    currentSector.gameObjects.Add(spatialGameObject);
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpGameObjectManip)) {
                currentGameObject = getNearestGameObject(e.X, e.Y, 32);
                if (currentGameObject != null) {
                    currentCanvasAction = CanvasAction.movingObject;
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpBrushes)) {
                currentCanvasAction = CanvasAction.drawingBrush;
            }

            canvasActionStart.X = e.X;
            canvasActionStart.Y = e.Y;
            pbCanvas_MouseMove(sender, e);
        }
Exemplo n.º 11
0
 private void pbCanvas_MouseUp(object sender, MouseEventArgs e)
 {
     currentCanvasAction = CanvasAction.none;
 }
Exemplo n.º 12
0
        private void pbCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (currentTilemap == null)
            {
                return;
            }
            if (!clTilemaps.CheckedItems.Contains(currentTilemap))
            {
                return;
            }

            int tx = e.X / 32;
            int ty = e.Y / 32;

            slCoordinates.Text = tx + "," + ty;
            slTileId.Text      = currentTilemap.getTileAt(tx, ty).ToString();
            if (currentCanvasAction == CanvasAction.drawingTiles)
            {
                if (ModifierKeys == Keys.Shift)
                {
                    currentTilemap.setTileAt(tx, ty, 0);
                }
                else
                {
                    currentTilemap.setTileAt(tx, ty, currentTileId);
                }
                pbCanvas.Invalidate(new Rectangle(tx * 32, ty * 32, 32, 32));
            }
            if (currentCanvasAction == CanvasAction.selecting)
            {
                currentSelection.Width  = tx - currentSelection.X + 1;
                currentSelection.Height = ty - currentSelection.Y + 1;
                pbCanvas.Invalidate();
            }
            if (currentCanvasAction == CanvasAction.movingFloatingTilemap)
            {
                int dx = tx - (canvasActionStart.X / 32);
                int dy = ty - (canvasActionStart.Y / 32);
                currentFloatingTilemapPos.Offset(dx, dy);
                canvasActionStart.X = e.X;
                canvasActionStart.Y = e.Y;
                pbCanvas.Invalidate();
            }
            if (currentCanvasAction == CanvasAction.movingObject)
            {
                if (ModifierKeys == Keys.Shift)
                {
                    currentSector.gameObjects.Remove(currentGameObject);
                    pbCanvas.Invalidate();
                    currentCanvasAction = CanvasAction.none;
                }
                else
                {
                    int dx = e.X - canvasActionStart.X;
                    int dy = e.Y - canvasActionStart.Y;
                    currentGameObject.X += dx;
                    currentGameObject.Y += dy;
                    canvasActionStart.X  = e.X;
                    canvasActionStart.Y  = e.Y;
                    pbCanvas.Invalidate();
                }
            }
            if (currentCanvasAction == CanvasAction.drawingBrush)
            {
                if (ModifierKeys == Keys.Shift)
                {
                    if (currentBrush != null)
                    {
                        currentBrush.erase(currentTilemap, tx, ty);
                    }
                }
                else if (ModifierKeys == Keys.Control)
                {
                    if (currentBrush != null)
                    {
                        currentBrush.learn(currentTilemap, tx, ty);
                        laBrushSize.Text = currentBrush.Length + " Patterns";
                    }
                }
                else if (ModifierKeys == (Keys.Control | Keys.Shift))
                {
                    if (currentBrush != null)
                    {
                        currentBrush.forget(currentTilemap, tx, ty);
                        laBrushSize.Text = currentBrush.Length + " Patterns";
                    }
                }
                else
                {
                    if (currentBrush != null)
                    {
                        currentBrush.draw(currentTilemap, tx, ty);
                    }
                }
                pbCanvas.Invalidate(new Rectangle((tx - 1) * 32, (ty - 1) * 32, 32 * 3, 32 * 3));
            }
        }
Exemplo n.º 13
0
        private void pbCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            int tx = e.X / 32;
            int ty = e.Y / 32;

            if (currentSector == null)
            {
                return;
            }

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTiles))
            {
                currentCanvasAction = CanvasAction.drawingTiles;
            }

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTileManip))
            {
                if ((currentFloatingTilemap != null) && (currentFloatingTilemapPos.Contains(tx, ty)))
                {
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                }
                else
                if (currentSelection.Contains(tx, ty))
                {
                    createFloatingTilemapFromSelection(true);
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                    pbCanvas.Invalidate();
                }
                else
                {
                    anchorFloatingTilemap();
                    pbCanvas.Invalidate();
                    currentCanvasAction = CanvasAction.selecting;
                    currentSelection    = new Rectangle(tx, ty, 0, 0);
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpObjects))
            {
                GameObject selectedObject = (GameObject)lbGameObjects.SelectedItem;
                if ((selectedObject != null) && (selectedObject is SpatialGameObject))
                {
                    SpatialGameObject spatialGameObject = (SpatialGameObject)selectedObject.Clone();
                    spatialGameObject.X = e.X;
                    spatialGameObject.Y = e.Y;
                    currentSector.gameObjects.Add(spatialGameObject);
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpGameObjectManip))
            {
                currentGameObject = getNearestGameObject(e.X, e.Y, 32);
                if (currentGameObject != null)
                {
                    currentCanvasAction = CanvasAction.movingObject;
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpBrushes))
            {
                currentCanvasAction = CanvasAction.drawingBrush;
            }


            canvasActionStart.X = e.X;
            canvasActionStart.Y = e.Y;
            pbCanvas_MouseMove(sender, e);
        }