Esempio n. 1
0
 private void ExecuteSelection()
 {
     if (SelectedItem is OpenDesignerItem)
     {
         if (styleSetProvider is Project)
         {
             // Try to find the main window (the application's first opened window)
             Form parentForm = (Application.OpenForms.Count > 0) ? Application.OpenForms[0] : null;
             // Show dialog with parent form or otherwise it will show in background
             DesignEditorDialog dlg = new DesignEditorDialog((Project)styleSetProvider, styleCategory);
             if (parentForm == null)
             {
                 dlg.Show();
             }
             else
             {
                 dlg.Show(parentForm);
             }
         }
         SelectedItem = preselectedStyle;
     }
     if (editorService != null)
     {
         editorService.CloseDropDown();
     }
     else
     {
         // Notify ToolCache about changed styles only if no EditorService is set.
         // Otherwise the ToolCache re-creates the associated brush, pen, etc
         // each time the user selects a style for a shape in the property grid.
         if (SelectedStyle is CapStyle || SelectedStyle is LineStyle)
         {
             ToolCache.NotifyStyleChanged(SelectedStyle);
         }
     }
 }
Esempio n. 2
0
        /// <override></override>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (maxItemTextWidth < 0)
            {
                UpdateMaxItemWidth(e.Graphics);
            }
            const int txtMargin = 4;

            itemBounds.X      = e.Bounds.X + 3;
            itemBounds.Y      = e.Bounds.Y + 1;
            itemBounds.Width  = (e.Bounds.Right - 3) - (e.Bounds.X + 3);
            itemBounds.Height = (e.Bounds.Bottom - 1) - (e.Bounds.Y + 1);

            previewRect.X      = itemBounds.X + margin;
            previewRect.Y      = itemBounds.Y + margin;
            previewRect.Width  = itemBounds.Width - Math.Max(maxItemTextWidth, itemBounds.Width / 4) - (2 * margin) - (2 * txtMargin);
            previewRect.Height = (itemBounds.Bottom - margin) - (itemBounds.Y + margin);

            labelLayoutRect.X      = previewRect.Right + txtMargin;
            labelLayoutRect.Y      = previewRect.Y;
            labelLayoutRect.Width  = maxItemTextWidth;
            labelLayoutRect.Height = previewRect.Height;

            // Draw Item Background and Border
            e.Graphics.FillRectangle(ItemBackgroundBrush, itemBounds);
            if (itemBorderColor != Color.Transparent)
            {
                e.Graphics.DrawRectangle(ItemBorderPen, itemBounds);
            }

            // Draw Selection and/or Focus markers
            if ((e.State & DrawItemState.Selected) != 0)
            {
                e.Graphics.FillRectangle(ItemSelectedBrush, itemBounds);
            }
            if ((e.State & DrawItemState.Focus) != 0)
            {
                if (itemFocusedColor != Color.Transparent)
                {
                    e.Graphics.FillRectangle(ItemFocusedBrush, itemBounds);
                }
                if (FocusBorderColor != Color.Transparent)
                {
                    e.Graphics.DrawRectangle(FocusBorderPen, itemBounds);
                }
            }
            else if (HighlightItems && (e.State & DrawItemState.HotLight) != 0)
            {
                if (ItemHighlightedColor != Color.Transparent)
                {
                    e.Graphics.FillRectangle(ItemHighlightedBrush, itemBounds);
                }
            }

            e.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
            e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            if (Items.Count > 0 && e.Index >= 0)
            {
                if (Items[e.Index] is IStyle)
                {
                    switch (StyleCategory)
                    {
                    case StyleCategory.CapStyle:
                        DrawCapStyleItem((CapStyle)Items[e.Index], e);
                        break;

                    case StyleCategory.ColorStyle:
                        ColorStyle colorStyle = (ColorStyle)Items[e.Index];
                        Brush      colorBrush = ToolCache.GetBrush(colorStyle);
                        e.Graphics.FillRectangle(colorBrush, previewRect);
                        e.Graphics.DrawRectangle(ItemBorderPen, previewRect);
                        e.Graphics.DrawRectangle(Pens.Black, previewRect);
                        e.Graphics.DrawString(colorStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.FillStyle:
                        DrawFillStyleItem((FillStyle)Items[e.Index], e);
                        break;

                    case StyleCategory.CharacterStyle:
                        CharacterStyle charStyle = (CharacterStyle)Items[e.Index];
                        Font           font      = ToolCache.GetFont(charStyle);
                        Brush          fontBrush = ToolCache.GetBrush(charStyle.ColorStyle);
                        e.Graphics.DrawString(string.Format("{0} {1} pt", font.FontFamily.Name, font.SizeInPoints), font, fontBrush, previewRect, styleItemFormatter);
                        e.Graphics.DrawString(charStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.LineStyle:
                        LineStyle lineStyle = (LineStyle)Items[e.Index];
                        Pen       linePen   = ToolCache.GetPen(lineStyle, null, null);
                        e.Graphics.DrawLine(linePen, previewRect.X, previewRect.Y + (previewRect.Height / 2), previewRect.Right, previewRect.Y + (previewRect.Height / 2));
                        e.Graphics.DrawString(lineStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.ParagraphStyle:
                        ParagraphStyle paragraphStyle = (ParagraphStyle)Items[e.Index];
                        StringFormat   stringFormat   = ToolCache.GetStringFormat(paragraphStyle);
                        Rectangle      r = Rectangle.Empty;
                        r.X      = previewRect.Left + paragraphStyle.Padding.Left;
                        r.Y      = previewRect.Top + paragraphStyle.Padding.Top;
                        r.Width  = previewRect.Width - (paragraphStyle.Padding.Left + paragraphStyle.Padding.Right);
                        r.Height = previewRect.Height - (paragraphStyle.Padding.Top + paragraphStyle.Padding.Bottom);
                        e.Graphics.DrawString(previewText, e.Font, TextBrush, r, stringFormat);
                        e.Graphics.DrawRectangle(Pens.Black, previewRect);
                        e.Graphics.DrawString(paragraphStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    default:
                        throw new NShapeException(string.Format("Unexpected enum value '{0}'.", styleCategory));
                    }
                }
                else
                {
                    e.Graphics.DrawString(Items[e.Index].ToString().Trim(), e.Font, TextBrush, e.Bounds, specialItemFormatter);
                }
            }
        }
Esempio n. 3
0
 private void repository_StyleDeleted(object sender, RepositoryStyleEventArgs e)
 {
     ToolCache.NotifyStyleChanged(e.Style);
 }
Esempio n. 4
0
        public override void Draw(Graphics graphics)
        {
            Pen pen = ToolCache.GetPen(LineStyle, null, null);

            DrawOutline(graphics, pen);
        }
 private void Start()
 {
     _currentTool = ToolCache.GetOrCreateTool <TargetTool>();
     _currentTool.OnToolHeld(this);
 }
 private void Start()
 {
     _currentTool        = ToolCache.GetOrCreateTool <TargetTool>();
     _currentTool.IsHeld = true;
 }
Esempio n. 7
0
        private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, IColorStyle colorStyle)
        {
            Brush brush = ToolCache.GetBrush(colorStyle);

            gfx.FillRectangle(brush, previewBounds);
        }