Beispiel #1
0
        public override bool Equals(object obj)
        {
            ToolInfo rhs = obj as ToolInfo;

            if (rhs == null)
            {
                return(false);
            }

            return((this.name == rhs.name) &&
                   (this.helpText == rhs.helpText) &&
                   (this.hotKey == rhs.hotKey) &&
                   (this.skipIfActiveOnHotKey == rhs.skipIfActiveOnHotKey) &&
                   (this.toolType == rhs.toolType));
        }
Beispiel #2
0
        // NOTE: Your constructor must be able to run successfully with a documentWorkspace
        //       of null. This is sent in while the DocumentControl static constructor
        //       class is building a list of ToolInfo instances, so that it may construct
        //       the list without having to also construct a DocumentControl.
        public Tool(DocumentWorkspace documentWorkspace,
                    ImageResource toolBarImage,
                    string name,
                    string helpText,
                    char hotKey,
                    bool skipIfActiveOnHotKey,
                    ToolBarConfigItems toolBarConfigItems)
        {
            this.documentWorkspace = documentWorkspace;
            this.toolBarImage      = toolBarImage;
            this.toolInfo          = new ToolInfo(name, helpText, toolBarImage, hotKey, skipIfActiveOnHotKey, toolBarConfigItems, this.GetType());

            if (this.documentWorkspace != null)
            {
                this.documentWorkspace.UpdateStatusBarToToolHelpText(this);
            }
        }
Beispiel #3
0
        /// <summary>
        /// This method is called when the tool is active and a keyboard key is pressed
        /// and released. If you respond to the keyboard key, set e.Handled to true.
        /// </summary>
        protected virtual void OnKeyPress(KeyPressEventArgs e)
        {
            if (!e.Handled && DocumentWorkspace.Focused)
            {
                int wsIndex = Array.IndexOf <char>(wildShortcuts, e.KeyChar);

                if (wsIndex != -1)
                {
                    e.Handled = OnWildShortcutKey(wsIndex);
                }
                else if (e.KeyChar == swapColorsShortcut)
                {
                    AppWorkspace.Widgets.ColorsForm.SwapUserColors();
                    e.Handled = true;
                }
                else if (e.KeyChar == decPenSizeShortcut)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(-1.0f);
                    e.Handled = true;
                }
                else if (e.KeyChar == decPenSizeBy5Shortcut && (ModifierKeys & Keys.Control) != 0)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(-5.0f);
                    e.Handled = true;
                }
                else if (e.KeyChar == incPenSizeShortcut)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(+1.0f);
                    e.Handled = true;
                }
                else if (e.KeyChar == incPenSizeBy5Shortcut && (ModifierKeys & Keys.Control) != 0)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(+5.0f);
                    e.Handled = true;
                }
                else
                {
                    ToolInfo[] toolInfos       = DocumentWorkspace.ToolInfos;
                    Type       currentToolType = DocumentWorkspace.GetToolType();
                    int        currentTool     = 0;

                    if (0 != (ModifierKeys & Keys.Shift))
                    {
                        Array.Reverse(toolInfos);
                    }

                    if (char.ToLower(this.HotKey) != char.ToLower(e.KeyChar) ||
                        (DateTime.Now - lastToolSwitch) > toolSwitchReset)
                    {
                        // If it's been a short time since they pressed a tool switching hotkey,
                        // we will start from the beginning of this list. This helps to enable two things:
                        // 1) If multiple tools have the same hotkey, the user may press that hotkey
                        //    to cycle through them
                        // 2) After a period of time, pressing the hotkey will revert to always
                        //    choosing the first tool in that list of tools which have the same hotkey.
                        currentTool = -1;
                    }
                    else
                    {
                        for (int t = 0; t < toolInfos.Length; ++t)
                        {
                            if (toolInfos[t].ToolType == currentToolType)
                            {
                                currentTool = t;
                                break;
                            }
                        }
                    }

                    for (int t = 0; t < toolInfos.Length; ++t)
                    {
                        int      newTool       = (t + currentTool + 1) % toolInfos.Length;
                        ToolInfo localToolInfo = toolInfos[newTool];

                        if (localToolInfo.ToolType == DocumentWorkspace.GetToolType() &&
                            localToolInfo.SkipIfActiveOnHotKey)
                        {
                            continue;
                        }

                        if (char.ToLower(localToolInfo.HotKey) == char.ToLower(e.KeyChar))
                        {
                            if (!this.IsMouseDown)
                            {
                                AppWorkspace.Widgets.ToolsControl.SelectTool(localToolInfo.ToolType);
                            }

                            e.Handled      = true;
                            lastToolSwitch = DateTime.Now;
                            break;
                        }
                    }

                    // If the keypress is still not handled ...
                    if (!e.Handled)
                    {
                        switch (e.KeyChar)
                        {
                        // By default, Esc/Enter clear the current selection if there is any
                        case (char)13:     // Enter
                        case (char)27:     // Escape
                            if (this.mouseDown == 0 && !Selection.IsEmpty)
                            {
                                e.Handled = true;
                                DocumentWorkspace.ExecuteFunction(new DeselectFunction());
                            }

                            break;
                        }
                    }
                }
            }
        }