コード例 #1
0
        private void Editor_MouseUp(object sender, MouseEventArgs e)
        {
            if (selectedTool != tools_t.TOOL_NONE)
            {
                // use current tool drawing
                applyTool(selectedTool, 2, e.Location);
            }
            this.selectedTool = tools_t.TOOL_NONE;

            // end tile selection mode when "finished" left-clicking
            if (e.Button == MouseButtons.Left && TileMode == true)
            {
                // set to read tiles from map
                TileMode = false;
                this.Invalidate();
            }
            this.mouseDown    = false;
            this.drawDragRect = false;
        }
コード例 #2
0
        private void Editor_MouseDown(object sender, MouseEventArgs e)
        {
            // reset selected tool
            selectedTool = tools_t.TOOL_NONE;

            if (e.Button == MouseButtons.Left)
            {
                if (TileMode)
                {
                    applySelection(0, e.Location);
                }
                else
                {
                    if (Control.ModifierKeys == Keys.Control)
                    {
                        // Ctrl: set lift/read tool
                        selectedTool = tools_t.TOOL_READ;
                    }
                    else
                    {
                        // Normal: set selected tool
                        selectedTool = CurrentTool;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                // set to read tiles from map
                if (TileMode == false)
                {
                    TileMode = true;
                    this.Invalidate();
                }
            }

            if (selectedTool != tools_t.TOOL_NONE)
            {
                // use current tool drawing
                applyTool(selectedTool, 0, e.Location);
            }
            this.mouseDown = true;
        }
コード例 #3
0
        public Editor()
        {
            // default graph properties
            GraphGridColor   = Color.DarkOliveGreen;
            GraphGridOpacity = 0.5f;                    // default 10% visible

            graphOffset = new PointF(0.0f, 0.0f);       // panning offset
            graphZoom   = 1.2f;
            tileOffset  = new PointF(0.0f, 0.0f);
            tileZoom    = 1.2f;
            GridSize    = 16;

            CurrentTool = tools_t.TOOL_NONE;
            selection   = new Selection(1, 0);
            // initialize private stuff
            mapfile       = new MapFile();
            SelectedLayer = 0;
            ShowGrid      = true;
            TileMode      = false;
            TileDrawing   = true;
            LayersAbove   = true;

            // designer auto-generated initialization procedure
            InitializeComponent();

            // add mousewheel function to event trigger list
            SizeChanged += Editor_SizeChanged;
            Paint       += Editor_Paint;

            MouseWheel += Editor_MouseWheel;
            MouseDown  += Editor_MouseDown;
            MouseMove  += Editor_MouseMove;
            MouseUp    += Editor_MouseUp;

            // make sure only we can paint, and double-buffered
            this.SetStyle(ControlStyles.AllPaintingInWmPaint
                          | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }
コード例 #4
0
        private void applyTool(tools_t tool, int state, Point e)
        {
            // ignore empty maps
            if (mapfile.layers.Count == 0)
            {
                return;
            }

            PointF p = new PointF(e.X, e.Y);

            // transformed relative mouse position
            p    = transformPoint(p);
            p.X -= GraphOffset.X;
            p.Y -= GraphOffset.Y;
            // get current point & tile
            Layer L  = getCurrentLayer();
            Point tp = L.toTileCoord(p.X, p.Y);
            Tile  t  = L.getTile(tp);

            // outside of area (most likely)
            if (t == null)
            {
                return;
            }

            if (state == 0)
            {
                // set mousedown tilepoint
                originalTilePoint = tp;
            }

            if (tool == tools_t.TOOL_RECT)
            {
                dragRect         = toTileRect(originalTilePoint, tp);
                dragRect.X      *= tileset.size;
                dragRect.Y      *= tileset.size;
                dragRect.Width  *= tileset.size;
                dragRect.Height *= tileset.size;
                // invalidate to draw the rectangle
                this.drawDragRect = true;
                this.Invalidate();
            }
            else if (tool == tools_t.TOOL_READ)
            {
                selectionRect         = toTileRect(originalTilePoint, tp);
                selectionRect.X      *= tileset.size;
                selectionRect.Y      *= tileset.size;
                selectionRect.Width  *= tileset.size;
                selectionRect.Height *= tileset.size;
                // invalidate to draw the rectangle
                this.drawSelectionRect  = true;
                this.selectionFromTiles = false;
                this.Invalidate();
            }

            switch (tool)
            {
            case tools_t.TOOL_READ:
                if (state == 2)
                {
                    selection = new Selection(L, originalTilePoint, tp);
                }
                // lifting a tile didn't change map, so just exit
                return;

            case tools_t.TOOL_DRAW:
                // signal that changes are about to be made to @layer
                if (state == 0)
                {
                    aboutToMakeChanges(SelectedLayer);
                }
                if (state != 2) // not mouse up
                {
                    // get drawing deltas
                    Tile cur = selection.delta(originalTilePoint, tp);
                    // draw at tile position
                    drawTile(L, tp.X, tp.Y, cur);
                }
                this.Invalidate();
                break;

            case tools_t.TOOL_RECT:
                if (state == 2)
                {
                    // now that we're here, before doing anything
                    // signal that changes are about to be made to @layer
                    aboutToMakeChanges(SelectedLayer);
                    Rectangle TR = toTileRect(originalTilePoint, tp);

                    for (int y = 0; y < TR.Height; y++)
                    {
                        for (int x = 0; x < TR.Width; x++)
                        {
                            int tx = TR.X + x;
                            int ty = TR.Y + y;
                            if (L.inRange(tx, ty))
                            {
                                Tile cur = selection.get(x, y);
                                drawTile(L, tx, ty, cur);
                            }
                        }
                    }
                    // mouse up event, map has changed
                    break;
                }
                else
                {
                    return;
                }

            case tools_t.TOOL_FILL:
                // signal that changes are about to be made to @layer
                if (state == 0)
                {
                    aboutToMakeChanges(SelectedLayer);
                }
                {
                    // get drawing deltas
                    Tile cur = selection.delta(originalTilePoint, tp);
                    // fill at tile position
                    L.fill(tp.X, tp.Y, t.getTX(), t.getTY(), cur.getTX(), cur.getTY());
                }
                L.invalidate(this.tileset);
                this.Invalidate();
                break;

            case tools_t.TOOL_REPLACE:
                // signal that changes are about to be made to @layer
                if (state == 0)
                {
                    aboutToMakeChanges(SelectedLayer);
                }
                {
                    // get drawing deltas
                    Tile cur = selection.delta(originalTilePoint, tp);
                    // replace at tile position
                    L.replace(t.getTX(), t.getTY(), cur);
                }
                L.invalidate(this.tileset);
                this.Invalidate();
                break;

            case tools_t.TOOL_ROTATE:
                // signal that changes are about to be made to @layer
                if (state == 0)
                {
                    aboutToMakeChanges(SelectedLayer);
                }
                if (state != 2) // not mouse up
                {
                    // use original tile
                    Tile cur = t;
                    t.setRot((t.getRot() + 1) % 4);
                    // draw at tile position
                    drawTile(L, tp.X, tp.Y, cur, false);
                }
                this.Invalidate();
                break;

            default:
                // unimplemented tools can't change the map, just exit
                return;
            }
            // changes were potentially made
            changesWereMade();
        }