Esempio n. 1
0
        public void SetTools(ToolInfo[] toolInfos)
        {
            if (this.toolStripEx != null)
            {
                this.toolStripEx.Items.Clear();
            }

            this.imageList = new ImageList();
            this.imageList.ColorDepth = ColorDepth.Depth32Bit;
            this.imageList.TransparentColor = Utility.TransparentKey;

            this.toolStripEx.ImageList = this.imageList;

            ToolStripItem[] buttons = new ToolStripItem[toolInfos.Length];
            string toolTipFormat = PdnResources.GetString("ToolsControl.ToolToolTip.Format");

            for (int i = 0; i < toolInfos.Length; ++i)
            {
                ToolInfo toolInfo = toolInfos[i];
                ToolStripButton button = new ToolStripButton();

                int imageIndex = imageList.Images.Add(
                    toolInfo.Image.Reference,
                    imageList.TransparentColor);

                button.ImageIndex = imageIndex;
                button.Tag = toolInfo.ToolType;
                button.ToolTipText = string.Format(toolTipFormat, toolInfo.Name, char.ToUpperInvariant(toolInfo.HotKey).ToString());
                buttons[i] = button;
            }

            this.toolStripEx.Items.AddRange(buttons);
        }
Esempio n. 2
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));
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
 public void SetTools(ToolInfo[] newToolInfos)
 {
     this.toolInfos = newToolInfos;
     SetToolButtonLabel();
 }
Esempio n. 6
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 == swapPrimarySecondaryChoice)
                {
                    AppWorkspace.Widgets.ColorsForm.ToggleWhichUserColor();
                    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;
                        }
                    }
                }
            }
        }