Пример #1
0
 public FormToolPresets(AbstractDrawingTool _preselect)
 {
     m_Preselect = _preselect;
     InitializeComponent();
     LocalizeForm();
     LoadPresets(true);
 }
Пример #2
0
        public void AddToolButtonGroup(AbstractDrawingTool[] tools, int selectedIndex, EventHandler handler)
        {
            // Each menu item will act as a button, and the master button will take the icon of the selected menu.
            ToolStripButtonWithDropDown button = new ToolStripButtonWithDropDown();

            button.AutoSize     = false;
            button.DisplayStyle = ToolStripItemDisplayStyle.Image;
            button.ImageScaling = ToolStripItemImageScaling.None;
            button.Size         = new Size(25, 25);
            button.AutoToolTip  = false;

            for (int i = tools.Length - 1; i >= 0; i--)
            {
                AbstractDrawingTool tool = tools[i];
                ToolStripMenuItem   item = new ToolStripMenuItem();
                item.Image = tool.Icon;
                item.Text  = tool.DisplayName;
                item.Tag   = tool;
                int indexClosure = tools.Length - 1 - i;
                item.Click += (s, e) =>
                {
                    button.SelectedIndex = indexClosure;
                    handler(s, e);
                };

                button.DropDownItems.Add(item);
            }

            button.SelectedIndex = tools.Length - 1 - selectedIndex;

            view.Items.Add(button);
        }
Пример #3
0
        private void ImportDrawingTool(List <AbstractDrawingTool> list, XmlNode node)
        {
            XmlAttribute nameAttribute = node.Attributes["name"];

            if (nameAttribute == null)
            {
                return;
            }

            string toolName = nameAttribute.Value;

            if (toolName == "%CustomTools%")
            {
                foreach (AbstractDrawingTool customTool in GenericPostureManager.Tools)
                {
                    list.Add(customTool);
                }

                return;
            }

            if (ToolManager.Tools.ContainsKey(toolName))
            {
                AbstractDrawingTool tool = ToolManager.Tools[toolName];
                list.Add(tool);
            }
            else
            {
                log.ErrorFormat("Cannot find {0}.", toolName);
            }
        }
Пример #4
0
 public void AfterToolUse()
 {
     if (!activeTool.KeepTool)
     {
         activeTool       = handTool;
         invalidateCursor = true;
     }
 }
Пример #5
0
 public void AfterFrameChanged()
 {
     if (!activeTool.KeepToolFrameChanged)
     {
         activeTool       = handTool;
         invalidateCursor = true;
     }
 }
Пример #6
0
        private void LstPresetsSelectedIndexChanged(object sender, EventArgs e)
        {
            AbstractDrawingTool preset = lstPresets.SelectedItem as AbstractDrawingTool;

            if (preset != null)
            {
                LoadPreset(preset);
            }
        }
Пример #7
0
        private void DrawingTool_Click(object sender, EventArgs e)
        {
            // Disable magnifier.
            // TODO: when we have a user control for the whole strip, it should directly
            // pass the tool as sender.
            AbstractDrawingTool tool = ((ToolStripItem)sender).Tag as AbstractDrawingTool;

            screenToolManager.SetActiveTool(tool);
            // Update cursor
            // refresh for cursor.
        }
Пример #8
0
        public void AddToolButton(AbstractDrawingTool tool, EventHandler handler)
        {
            ToolStripButton button = CreateToolButton();

            button.Image       = tool.Icon;
            button.Tag         = tool;
            button.Click      += handler;
            button.ToolTipText = tool.DisplayName;

            view.Items.Add(button);
        }
        private static Cursor GetCursorIcon(AbstractDrawingTool tool)
        {
            if (tool.Icon == null)
            {
                return(Cursors.Cross);
            }

            Bitmap   b = new Bitmap(tool.Icon.Width, tool.Icon.Height);
            Graphics g = Graphics.FromImage(b);

            g.DrawImage(tool.Icon, 0, 0);

            return(new Cursor(b.GetHicon()));
        }
Пример #10
0
        private void lvPresets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvPresets.SelectedItems.Count != 1)
            {
                return;
            }

            AbstractDrawingTool preset = lvPresets.SelectedItems[0].Tag as AbstractDrawingTool;

            if (preset == null)
            {
                return;
            }

            LoadPreset(preset);
        }
        private static void ImportExternalTools()
        {
            if (!Directory.Exists(Software.StandardToolsDirectory))
            {
                return;
            }

            foreach (string file in Directory.GetFiles(Software.StandardToolsDirectory))
            {
                AbstractDrawingTool tool = DrawingTool.CreateFromFile(file);
                if (tool != null && !tools.ContainsKey(tool.Name))
                {
                    tools.Add(tool.Name, tool);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Get the cursor from the tool's icon.
        /// </summary>
        private Cursor GetCursorIcon(AbstractDrawingTool tool)
        {
            if (tool.Icon == null)
            {
                return(Cursors.Cross);
            }

            if (bitmap.Width != tool.Icon.Width || bitmap.Height != tool.Icon.Height)
            {
                bitmap = new Bitmap(tool.Icon.Width, tool.Icon.Height);
            }

            Graphics g = Graphics.FromImage(bitmap);

            g.DrawImage(tool.Icon, 0, 0);

            return(CursorFromBitmap(bitmap));
        }
Пример #13
0
        public void RefreshUICulture()
        {
            // TODO: Move to view.
            foreach (ToolStripItem tsi in view.Items)
            {
                if (tsi is ToolStripSeparator)
                {
                    continue;
                }

                if (tsi is ToolStripButtonWithDropDown)
                {
                    foreach (ToolStripItem subItem in ((ToolStripButtonWithDropDown)tsi).DropDownItems)
                    {
                        if (!(subItem is ToolStripMenuItem))
                        {
                            continue;
                        }

                        AbstractDrawingTool tool = subItem.Tag as AbstractDrawingTool;
                        if (tool != null)
                        {
                            subItem.Text        = tool.DisplayName;
                            subItem.ToolTipText = tool.DisplayName;
                        }
                    }

                    ((ToolStripButtonWithDropDown)tsi).UpdateToolTip();
                }
                else if (tsi is ToolStripButton)
                {
                    AbstractDrawingTool tool = tsi.Tag as AbstractDrawingTool;
                    if (tool != null)
                    {
                        tsi.ToolTipText = tool.DisplayName;
                    }
                }
            }
        }
Пример #14
0
 public void AfterToolUse()
 {
     activeTool = activeTool.KeepTool ? activeTool : handTool;
 }
Пример #15
0
 public void SetActiveTool(AbstractDrawingTool tool)
 {
     activeTool = tool ?? handTool;
 }
Пример #16
0
 public ScreenToolManager()
 {
     handTool   = new DrawingToolPointer();
     activeTool = handTool;
 }
Пример #17
0
        /// <summary>
        /// Get the cursor for the passed tool.
        /// This must be called every time the active tool changes or the image scale changes.
        /// </summary>
        public Cursor GetToolCursor(AbstractDrawingTool tool, double stretchFactor)
        {
            if (tool is DrawingToolPointer)
            {
                return(((DrawingToolPointer)tool).GetCursor());
            }

            // Custom cursors.
            // The general guideline is that
            // - We try to use custom cursor where it make sense like for pencil.
            // - Otherwise we fallback to either precision cross or the tool icon.
            // - Drawings that splat themselves at once on the canvas (no dragging a second leg), should use the icon,
            // - Drawings that are created in several steps should use the precision cross.

            if (tool is DrawingToolGenericPosture || tool is DrawingToolAutoNumbers)
            {
                // Many of the GenericPosture tools have a color style element that doesn't really serve any purpose,
                // as the lines making the drawing can have their own color defined in the XML.
                // They are also drawn at once on the canvas like a stamp.
                // So for these we reuse the drawing tool icon as a cursor.
                return(GetCursorIcon(tool));
            }
            else if (tool is DrawingTool)
            {
                // These are the standard tool but defined in XML.
                // For these we try to use a precision cursor or a semantic one.
                DrawingStyle style = ToolManager.GetStylePreset(tool.Name);

                if (tool.Name == "Pencil")
                {
                    return(GetCursorPencil(style, stretchFactor));
                }
                else if (tool.Name == "CrossMark")
                {
                    return(GetCursorCrossMark(style));
                }
                else if (tool.Name == "Grid" ||
                         tool.Name == "Plane" ||
                         tool.Name == "DistortionGrid" ||
                         tool.Name == "Label")
                {
                    // These are stamp-like.
                    return(GetCursorIcon(tool));
                }
                else
                {
                    return(GetCursorPrecision(style, false));
                }
            }
            else if (tool is DrawingToolCoordinateSystem ||
                     tool is DrawingToolMagnifier ||
                     tool is DrawingToolSpotlight ||
                     tool is DrawingToolTestGrid)
            {
                // Special internal tools.
                // Still nice to use a precision cursor with them, but the color might not make sense.
                DrawingStyle style = ToolManager.GetStylePreset(tool.Name);
                return(GetCursorPrecision(style, false));
            }
            else
            {
                return(null);
            }
        }
Пример #18
0
 public FormToolPresets(AbstractDrawingTool preselect)
 {
     this.preselect = preselect;
     InitializeComponent();
     LocalizeForm();
 }
Пример #19
0
        private void LoadPreset(AbstractDrawingTool preset)
        {
            // Load a single preset

            // Tool title and icon
            btnToolIcon.BackColor = Color.Transparent;
            btnToolIcon.Image     = preset.Icon;
            lblToolName.Text      = preset.DisplayName;

            // Clean up
            styleElements.Clear();
            grpConfig.Controls.Clear();
            Graphics helper = grpConfig.CreateGraphics();

            Size editorSize = new Size(60, 20);

            int minimalWidth = btnApply.Width + btnCancel.Width + 10;

            editorsLeft = minimalWidth - 20 - editorSize.Width;

            int mimimalHeight    = grpConfig.Height;
            int lastEditorBottom = 10;

            foreach (KeyValuePair <string, AbstractStyleElement> pair in preset.StylePreset.Elements)
            {
                AbstractStyleElement styleElement = pair.Value;
                styleElements.Add(styleElement);

                Button btn = new Button();
                btn.Image     = styleElement.Icon;
                btn.Size      = new Size(20, 20);
                btn.Location  = new Point(10, lastEditorBottom + 15);
                btn.FlatStyle = FlatStyle.Flat;
                btn.FlatAppearance.BorderSize = 0;
                btn.BackColor = Color.Transparent;

                Label lbl = new Label();
                lbl.Text     = styleElement.DisplayName;
                lbl.AutoSize = true;
                lbl.Location = new Point(btn.Right + 10, lastEditorBottom + 20);

                SizeF labelSize = helper.MeasureString(lbl.Text, lbl.Font);

                if (lbl.Left + labelSize.Width + 25 > editorsLeft)
                {
                    editorsLeft = (int)(lbl.Left + labelSize.Width + 25);
                }

                Control miniEditor = styleElement.GetEditor();
                miniEditor.Size     = editorSize;
                miniEditor.Location = new Point(editorsLeft, btn.Top);

                lastEditorBottom = miniEditor.Bottom;

                grpConfig.Controls.Add(btn);
                grpConfig.Controls.Add(lbl);
                grpConfig.Controls.Add(miniEditor);
            }

            helper.Dispose();

            // Recheck all mini editors to realign them on the leftmost.
            foreach (Control c in grpConfig.Controls)
            {
                if (!(c is Label) && !(c is Button))
                {
                    if (c.Left < editorsLeft)
                    {
                        c.Left = editorsLeft;
                    }
                }
            }
        }
Пример #20
0
 public void AfterFrameChanged()
 {
     activeTool = activeTool.KeepToolFrameChanged ? activeTool : handTool;
 }
Пример #21
0
 public void SetActiveTool(AbstractDrawingTool tool)
 {
     activeTool       = tool ?? handTool;
     invalidateCursor = true;
 }
Пример #22
0
        private void LoadPreset(AbstractDrawingTool _preset)
        {
            // Load a single preset
            // The layout is dynamic. The groupbox and the whole form is resized when needed on a "GrowOnly" basis.

            // Tool title and icon
            btnToolIcon.BackColor = Color.Transparent;
            btnToolIcon.Image     = _preset.Icon;
            lblToolName.Text      = _preset.DisplayName;

            // Clean up
            m_Elements.Clear();
            grpConfig.Controls.Clear();
            Graphics helper = grpConfig.CreateGraphics();

            Size editorSize = new Size(60, 20);

            // Initialize the horizontal layout with a minimal value,
            // it will be fixed later if some of the entries have long text.
            int minimalWidth = btnApply.Width + btnCancel.Width + 10;

            //m_iEditorsLeft = Math.Max(minimalWidth - 20 - editorSize.Width, m_iEditorsLeft);
            m_iEditorsLeft = minimalWidth - 20 - editorSize.Width;

            int mimimalHeight    = grpConfig.Height;
            int lastEditorBottom = 10;

            foreach (KeyValuePair <string, AbstractStyleElement> pair in _preset.StylePreset.Elements)
            {
                AbstractStyleElement styleElement = pair.Value;
                m_Elements.Add(styleElement);

                //styleElement.ValueChanged += element_ValueChanged;

                Button btn = new Button();
                btn.Image     = styleElement.Icon;
                btn.Size      = new Size(20, 20);
                btn.Location  = new Point(10, lastEditorBottom + 15);
                btn.FlatStyle = FlatStyle.Flat;
                btn.FlatAppearance.BorderSize = 0;
                btn.BackColor = Color.Transparent;

                Label lbl = new Label();
                lbl.Text     = styleElement.DisplayName;
                lbl.AutoSize = true;
                lbl.Location = new Point(btn.Right + 10, lastEditorBottom + 20);

                SizeF labelSize = helper.MeasureString(lbl.Text, lbl.Font);

                if (lbl.Left + labelSize.Width + 25 > m_iEditorsLeft)
                {
                    // dynamic horizontal layout for high dpi and verbose languages.
                    m_iEditorsLeft = (int)(lbl.Left + labelSize.Width + 25);
                }

                Control miniEditor = styleElement.GetEditor();
                miniEditor.Size     = editorSize;
                miniEditor.Location = new Point(m_iEditorsLeft, btn.Top);

                lastEditorBottom = miniEditor.Bottom;

                grpConfig.Controls.Add(btn);
                grpConfig.Controls.Add(lbl);
                grpConfig.Controls.Add(miniEditor);
            }

            helper.Dispose();

            // Recheck all mini editors for the left positionning.
            foreach (Control c in grpConfig.Controls)
            {
                if (!(c is Label) && !(c is Button))
                {
                    if (c.Left < m_iEditorsLeft)
                    {
                        c.Left = m_iEditorsLeft;
                    }
                }
            }

            //grpConfig.Height = Math.Max(lastEditorBottom + 20, grpConfig.Height);
            //grpConfig.Width = Math.Max(m_iEditorsLeft + editorSize.Width + 20, grpConfig.Width);
            grpConfig.Height  = Math.Max(lastEditorBottom + 20, 110);
            grpConfig.Width   = m_iEditorsLeft + editorSize.Width + 20;
            lstPresets.Height = grpConfig.Bottom - lstPresets.Top;

            btnApply.Top   = grpConfig.Bottom + 10;
            btnApply.Left  = grpConfig.Right - (btnCancel.Width + 10 + btnApply.Width);
            btnCancel.Top  = btnApply.Top;
            btnCancel.Left = btnApply.Right + 10;

            int borderLeft = this.Width - this.ClientRectangle.Width;

            this.Width = borderLeft + btnCancel.Right + 10;

            int borderTop = this.Height - this.ClientRectangle.Height;

            this.Height = borderTop + btnApply.Bottom + 10;
        }