Beispiel #1
0
        /// <summary>
        /// Get properties from selected objects and fill GraphicsProperties instance
        /// </summary>
        /// <returns></returns>
        private GraphicsProperties GetProperties()
        {
            GraphicsProperties properties = new GraphicsProperties();

            bool bFirst = true;

            int firstColor    = 0;
            int firstPenWidth = 1;

            bool allColorsAreEqual = true;
            bool allWidthAreEqual  = true;

            foreach (DrawObject o in Selection)
            {
                if (bFirst)
                {
                    firstColor    = o.Color.ToArgb();
                    firstPenWidth = o.PenWidth;
                    bFirst        = false;
                }
                else
                {
                    if (o.Color.ToArgb() != firstColor)
                    {
                        allColorsAreEqual = false;
                    }

                    if (o.PenWidth != firstPenWidth)
                    {
                        allWidthAreEqual = false;
                    }
                }
            }


            if (allColorsAreEqual)
            {
                properties.Color = Color.FromArgb(firstColor);
            }

            if (allWidthAreEqual)
            {
                properties.PenWidth = firstPenWidth;
            }

            return(properties);
        }
Beispiel #2
0
        /// <summary>
        /// Get properties from selected objects and fill GraphicsProperties instance
        /// </summary>
        /// <returns></returns>
        private GraphicsProperties GetProperties()
        {
            GraphicsProperties properties = new GraphicsProperties();

            int n = SelectionCount;

            if (n < 1)
            {
                return(properties);
            }

            DrawObject o = GetSelectedObject(0);

            int firstColor    = o.Color.ToArgb();
            int firstPenWidth = o.PenWidth;

            bool allColorsAreEqual = true;
            bool allWidthAreEqual  = true;

            for (int i = 1; i < n; i++)
            {
                if (GetSelectedObject(i).Color.ToArgb() != firstColor)
                {
                    allColorsAreEqual = false;
                }

                if (GetSelectedObject(i).PenWidth != firstPenWidth)
                {
                    allWidthAreEqual = false;
                }
            }

            if (allColorsAreEqual)
            {
                properties.ColorDefined = true;
                properties.Color        = Color.FromArgb(firstColor);
            }

            if (allWidthAreEqual)
            {
                properties.PenWidthDefined = true;
                properties.PenWidth        = firstPenWidth;
            }

            return(properties);
        }
Beispiel #3
0
        public MainForm()
        {
            InitializeComponent();

            g = this.CreateGraphics();

            DocManagerData data = new DocManagerData();
            data.FormOwner = this;
            data.UpdateTitle = true;
            data.FileDialogFilter = "DrawTools files (*.dtl)|*.dtl|All Files (*.*)|*.*";
            data.NewDocName = "Untitled.dtl";

            docManager = new DocManager(data);
            docManager.RegisterFileType("dtl", "dtlfile", "DrawTools File");

            this.Cursor = Cursors.Cross;

            drawArea.Location = new System.Drawing.Point(0, 0);
            drawArea.Size = new System.Drawing.Size(200, 200);
            drawArea.Owner = this;
            drawArea.Visible = false;
            drawArea.Initialize(this, docManager);

            GraphicsProperties graphicProperties = drawArea.GraphicsList.GetProperties();
            this.myColorPicker.SelectedColor = DrawSettings.LastUsedColor;
            this.myColorPicker.PenWidth = graphicProperties.PenWidth;
            this.drawArea.ToolTextBox.ForeColor = DrawSettings.LastUsedColor;

            this.myColorPicker.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                GraphicsProperties p = new GraphicsProperties();
                p.Color = e.Color;
                p.PenWidth = e.Width;
                this.drawArea.ToolTextBox.ForeColor = e.Color.Value;
                this.drawArea.ToolTextBox.Font = new System.Drawing.Font("Arial Narrow", e.TextSize);

                if (drawArea.GraphicsList.ShowColorPickerPanel(drawArea, p))
                {
                    drawArea.SetDirty();
                    drawArea.Refresh();
                }
            };
        }
Beispiel #4
0
        /// <summary>
        /// Apply properties for all selected objects
        /// </summary>
        private void ApplyProperties(GraphicsProperties properties)
        {
            foreach (DrawObject o in graphicsList)
            {
                if (o.Selected)
                {
                    if (properties.ColorDefined)
                    {
                        o.Color = properties.Color;
                        DrawObject.LastUsedColor = properties.Color;
                    }

                    if (properties.PenWidthDefined)
                    {
                        o.PenWidth = properties.PenWidth;
                        DrawObject.LastUsedPenWidth = properties.PenWidth;
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Show Properties dialog. Return true if list is changed
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public bool ShowPropertiesDialog(IWin32Window parent)
        {
            if (SelectionCount < 1)
            {
                return(false);
            }

            GraphicsProperties properties = GetProperties();
            PropertiesDialog   dlg        = new PropertiesDialog();

            dlg.Properties = properties;

            if (dlg.ShowDialog(parent) != DialogResult.OK)
            {
                return(false);
            }

            ApplyProperties(properties);

            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Get properties from selected objects and fill GraphicsProperties instance
        /// </summary>
        /// <returns></returns>
        private GraphicsProperties GetProperties()
        {
            GraphicsProperties properties = new GraphicsProperties();

            //int n = SelectionCount;

            //if (n < 1)
            //    return properties;

            //DrawObject o = GetSelectedObject(0);

            //int firstColor = o.Color.ToArgb();
            //int firstPenWidth = o.PenWidth;

            //bool allColorsAreEqual = true;
            //bool allWidthAreEqual = true;

            //for (int i = 1; i < n; i++)
            //{
            //    if (GetSelectedObject(i).Color.ToArgb() != firstColor)
            //        allColorsAreEqual = false;

            //    if (GetSelectedObject(i).PenWidth != firstPenWidth)
            //        allWidthAreEqual = false;
            //}

            //if (allColorsAreEqual)
            //{
            //    properties.ColorDefined = true;
            //    properties.Color = Color.FromArgb(firstColor);
            //}

            //if (allWidthAreEqual)
            //{
            //    properties.PenWidthDefined = true;
            //    properties.PenWidth = firstPenWidth;
            //}

            return(properties);
        }
        /// <summary>
        /// Get properties from selected objects and fill GraphicsProperties instance
        /// </summary>
        /// <returns></returns>
        private GraphicsProperties GetProperties()
        {
            GraphicsProperties properties = new GraphicsProperties();

            bool bFirst = true;

            int firstColor = 0;
            int firstPenWidth = 1;

            bool allColorsAreEqual = true;
            bool allWidthAreEqual = true;

            foreach (DrawObject o in Selection)
            {
                if (bFirst)
                {
                    firstColor = o.Color.ToArgb();
                    firstPenWidth = o.PenWidth;
                    bFirst = false;
                }
                else
                {
                    if (o.Color.ToArgb() != firstColor)
                        allColorsAreEqual = false;

                    if (o.PenWidth != firstPenWidth)
                        allWidthAreEqual = false;
                }
            }

            if (allColorsAreEqual)
            {
                properties.Color = Color.FromArgb(firstColor);
            }

            if (allWidthAreEqual)
            {
                properties.PenWidth = firstPenWidth;
            }

            return properties;
        }
        /// <summary>
        /// Apply properties for all selected objects.
        /// Returns TRue if at least one property is changed.
        /// </summary>
        private bool ApplyProperties(GraphicsProperties properties)
        {
            bool changed = false;

            foreach (DrawObject o in graphicsList)
            {
                if (o.Selected)
                {
                    if (properties.Color.HasValue)
                    {
                        if (o.Color != properties.Color.Value)
                        {
                            o.Color = properties.Color.Value;
                            DrawObject.LastUsedColor = properties.Color.Value;
                            changed = true;
                        }
                    }

                    if (properties.PenWidth.HasValue)
                    {
                        if (o.PenWidth != properties.PenWidth.Value)
                        {
                            o.PenWidth = properties.PenWidth.Value;
                            DrawObject.LastUsedPenWidth = properties.PenWidth.Value;
                            changed = true;
                        }
                    }
                }
            }

            return changed;
        }