Ejemplo n.º 1
0
        private void pnlDisplayBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (currentScene == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left && transitionDelegate == null)
            {
                // matrix
                Matrix mat = matrixOfEmulator();

                // set flag that mouse is pressed and store position
                MousePressed = true;
                MouseDownPos = new PointF(e.X, e.Y);

                // target item
                TActor selectedActor = currentScene.actorAtPosition(mat, e.Location, true);
                if (selectedActor != null)
                {
                    // fire touch event
                    MouseDownActor = selectedActor;
                    MouseDownActor.fireEvent(Program.DEFAULT_EVENT_TOUCH, false);

                    // fire drag event
                    if (MouseDownActor.draggable || MouseDownActor.puzzle)
                    {
                        MouseDownActor.createBackup();
                    }
                }

                // redraw workspace
                this.pnlDisplayBox.Refresh();
            }
        }
Ejemplo n.º 2
0
        private void pnlWorkspace_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.document.currentScene() == null)
            {
                return;
            }

            FrmMainContainer mainForm = (FrmMainContainer)this.MdiParent;

            if (e.Button == MouseButtons.Left)
            {
                // set flag that mouse is pressed and store position
                MousePressed  = true;
                MouseDownPos  = new PointF(e.X, e.Y);
                MouseDownTool = this.document.activeTool();

                if (MouseDownTool == TDocument.TOOL_SELECT || MouseDownTool == TDocument.TOOL_BOUNDING || MouseDownTool == TDocument.TOOL_PUZZLE)
                {
                    // if no current selection, create new selection
                    if (!this.document.haveSelection())
                    {
                        // target item
                        TActor target = this.document.actorAtPosition(e.X, e.Y, (MouseDownTool == TDocument.TOOL_BOUNDING));
                        if (target != null && (MouseDownTool != TDocument.TOOL_PUZZLE || target.puzzle))
                        {
                            // add target item to selection stack
                            this.document.toggleSelectedItem(target);

                            if (target.locked)
                            {
                                MousePressed  = false;
                                MouseDownTool = TDocument.TOOL_NONE;
                                MouseDownPart = -1;
                                SelectRegion  = RectangleF.Empty;
                            }
                            else
                            {
                                // record modify action
                                modifyActorAction = new ModifyActorAction(document, target);

                                // calc which part of selection is mouse position
                                MouseDownPart = 0;
                                target.createBackup(); // when moving actor, need the original state before moving
                                this.Cursor = Cursors.SizeAll;
                            }
                        }
                        else
                        {
//                            this.SelectRegion = new RectangleF(e.X, e.Y, 0, 0);
                        }
                    }
                    else
                    {
                        // calc which part of selection is mouse position
                        int cursor;
                        MouseDownPart = this.document.partOfSelection(e.X, e.Y, out cursor);

                        if (MouseDownPart == -1)   // if click at outside of selection bound, deselect current selection.

                        // clear selection stack
                        {
                            this.document.clearSelectedItems();

                            // clear modify action
                            modifyActorAction = null;

                            // target item
                            TActor target = this.document.actorAtPosition(e.X, e.Y, MouseDownTool == TDocument.TOOL_BOUNDING);
                            if (target != null)
                            {
                                // add target item to selection stack
                                this.document.toggleSelectedItem(target);

                                if (target.locked)
                                {
                                    MousePressed  = false;
                                    MouseDownTool = TDocument.TOOL_NONE;
                                    MouseDownPart = -1;
                                    SelectRegion  = RectangleF.Empty;
                                }
                                else
                                {
                                    // record modify action
                                    modifyActorAction = new ModifyActorAction(document, target);

                                    MouseDownPart = 0;
                                    this.Cursor   = Cursors.SizeAll;
                                }
                            }
                            else
                            {
                                //                                this.SelectRegion = new RectangleF(e.X, e.Y, 0, 0);
                            }
                        }
                        else
                        {
                            if (this.document.selectedActor().locked)
                            {
                                MousePressed  = false;
                                MouseDownTool = TDocument.TOOL_NONE;
                                MouseDownPart = -1;
                                SelectRegion  = RectangleF.Empty;
                            }
                            else
                            {
                                if (MouseDownPart == 0)
                                {
                                    // record modify action
                                    modifyActorAction = new ModifyActorAction(document, this.document.selectedActor());
                                }
                            }
                        }

                        if (MouseDownPart != -1)
                        {
                            foreach (TActor actor in this.document.selectedItems)
                            {
                                actor.createBackup();
                            }
                        }
                    }

                    // redraw workspace
                    this.pnlWorkspace.Refresh();

                    // fire mainform's selected item changed event
                    mainForm.selectedItemChanged();
                }
                else if (MouseDownTool == TDocument.TOOL_TEXT || MouseDownTool == TDocument.TOOL_AVATAR)
                {
                    // if no current selection, create new selection
                    if (!this.document.haveSelection())
                    {
                        // start selection
                        this.SelectRegion = new RectangleF(e.X, e.Y, 0, 0);
                    }
                    else
                    {
                        // calc which part of selection is mouse position
                        int cursor;
                        MouseDownPart = this.document.partOfSelection(e.X, e.Y, out cursor);

                        if (MouseDownPart == -1 || MouseDownPart == 9 || MouseDownTool == TDocument.TOOL_AVATAR)   // if click at outside of selection bound, deselect current selection.
                        // start selection
                        {
                            this.SelectRegion = new RectangleF(e.X, e.Y, 0, 0);
                            MouseDownPart     = -1;
                        }
                    }

                    // redraw workspace
                    this.pnlWorkspace.Refresh();
                }
            }

            // for moving by space key, set focus the control in the workspace form
            lblFocusTarget.Focus();
        }