コード例 #1
0
    private void OnButtonPress(object o, ButtonPressEventArgs args)
    {
        if (args.Event.Button == 1)
        {
            if (tilegroup == null)
            {
                return;
            }

            Vector MousePos = new Vector((float)args.Event.X,
                                         (float)args.Event.Y);
            int tile = PosToTile(MousePos);
            if (tile < 0)
            {
                return;
            }

            selection.Resize(1, 1, 0);
            selection[0, 0] = tilegroup.Tiles[tile];
            selection.FireChangedEvent();
            QueueDraw();
        }

        if (args.Event.Button == 3)
        {
            if (tilegroup == null)
            {
                return;
            }
            StartPos = new Vector((float)args.Event.X,
                                  (float)args.Event.Y);
            application.PrintStatus("selecting...");
            multiselectInProgress = true;
        }
    }
コード例 #2
0
    public void OnMouseButtonPress(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null)
        {
            return;
        }

        UpdateMouseTilePos(mousePos);
        LastDrawPos = MouseTilePos;

        if (button == 3)
        {
            if (state == State.DRAWING)                 //both buttons => cancel drawing
            {
                state = State.NONE;
                application.CurrentTilemap.RestoreState(tilemapBackup);
            }
            else
            {
                if (MouseTilePos.X < 0 || MouseTilePos.Y < 0 ||
                    MouseTilePos.X >= application.CurrentTilemap.Width ||
                    MouseTilePos.Y >= application.CurrentTilemap.Height)
                {
                    return;
                }

                SelectStartPos = MouseTilePos;
                state          = State.SELECTING;
                UpdateSelection();
            }
        }
        else if (button == 1)
        {
            if (state == State.DRAWING)                 //both buttons => cancel selection
            {
                state = State.NONE;
                selection.Resize(0, 0, 0);
                selection.FireChangedEvent();
            }
            else
            {
                // save backup of Tilemap
                tilemapBackup = application.CurrentTilemap.SaveState();

                if ((Modifiers & ModifierType.ShiftMask) != 0)
                {
                    if (MouseTilePos.X < 0 || MouseTilePos.Y < 0 ||
                        MouseTilePos.X >= application.CurrentTilemap.Width ||
                        MouseTilePos.Y >= application.CurrentTilemap.Height)
                    {
                        return;
                    }

                    SelectStartPos = MouseTilePos;
                    state          = State.FILLING;
                    UpdateSelection();
                }
                else
                {
                    PerformActionBetweenPoints(LastDrawPos, MouseTilePos, Modifiers);

                    state = State.DRAWING;
                }
            }
        }
        Redraw();
    }