Inheritance: GDIPlus_ColorConverter
Esempio n. 1
0
        void comboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            int colorRectangleWidth = e.Bounds.Height * 3 / 2;

            // Draw the background of the item.
            e.DrawBackground();

            if (e.Index < 0)
            {
                return;
            }

            ColorAndText colorAndText = (ColorAndText)comboBox.Items[e.Index];

            if (colorAndText.Color != null)
            {
                // Create a rectangle filled with the color.
                Rectangle rectangle = new Rectangle(2, e.Bounds.Top + 2, colorRectangleWidth, e.Bounds.Height - 4);
                e.Graphics.FillRectangle(new SolidBrush(SwopColorConverter.CmykToRgbColor(colorAndText.Color)), rectangle);
            }

            // Draw each string in the array, using a different size, color,
            // and font for each item.
            e.Graphics.DrawString(colorAndText.Text, e.Font, SystemBrushes.ControlText,
                                  new RectangleF(e.Bounds.X + colorRectangleWidth + 4, e.Bounds.Y, e.Bounds.Width - (colorRectangleWidth + 4), e.Bounds.Height));

            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }
        public LinePropertiesDialog(string dialogTitle, string usageText, string helpTopic, CmykColor purpleColor, CourseAppearance appearance)
        {
            InitializeComponent();
            this.appearance = appearance;

            if (!appearance.useDefaultPurple)
            {
                purpleColor = CmykColor.FromCmyk(appearance.purpleC, appearance.purpleM, appearance.purpleY, appearance.purpleK);
            }

            this.purpleColor           = SwopColorConverter.CmykToRgbColor(purpleColor);
            colorChooser               = new SpecialColorChooser(comboBoxColor, buttonChangeColor, purpleColor);
            colorChooser.ColorChanged += colorChooser_ColorChanged;
            LineKind        = PurplePen.LineKind.Single;
            this.Text       = dialogTitle;
            this.HelpTopic  = helpTopic;
            usageLabel.Text = usageText;
        }
Esempio n. 3
0
        private void pictureBoxPreview_Paint(object sender, PaintEventArgs e)
        {
            string expandedText = textExpander(this.UserText);
            float  emHeight     = pictureBoxPreview.Height * 0.7F;
            Color  textColor    = SwopColorConverter.CmykToRgbColor(colorChooser.CmykColor);

            if (!checkBoxAutoFontSize.Checked)
            {
                emHeight = GetEmHeight(e.Graphics, this.FontName, this.FontStyle, (float)upDownFontSize.Value);
            }

            StringFormat stringFormat = new StringFormat(StringFormat.GenericDefault);

            stringFormat.LineAlignment = StringAlignment.Center;
            stringFormat.FormatFlags  |= StringFormatFlags.NoWrap;
            using (Font font = new Font(this.FontName, emHeight, this.FontStyle, GraphicsUnit.Pixel))
                using (Brush brush = new SolidBrush(textColor)) {
                    e.Graphics.DrawString(expandedText, font, brush, pictureBoxPreview.ClientRectangle, stringFormat);
                }
        }
Esempio n. 4
0
 private void pictureBoxPreview_Paint(object sender, PaintEventArgs e)
 {
     e.Graphics.Clear(SwopColorConverter.CmykToRgbColor(Color));
 }
        private void pictureBoxPreview_Paint(object sender, PaintEventArgs e)
        {
            // Get the graphics, size to 10 mm high.
            float    scale = 10.0F / pictureBoxPreview.ClientSize.Height;
            Graphics g     = e.Graphics;

            g.ScaleTransform(1 / scale, 1 / scale);
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            // Get sizes and colors and so forth.
            float controlLineWidth        = NormalCourseAppearance.lineThickness * appearance.lineWidth;
            float controlCircleDiameter   = appearance.ControlCircleOutsideDiameter;        // outside diameter
            float controlDotDiameter      = appearance.centerDotDiameter;
            float controlCircleDrawRadius = (controlCircleDiameter - controlLineWidth) / 2; // radius to pen center

            SpecialColor lineSpecialColor = this.Color;
            Color        lineColor;

            if (lineSpecialColor.Kind == SpecialColor.ColorKind.Black)
            {
                lineColor = System.Drawing.Color.Black;
            }
            else if (lineSpecialColor.Kind == SpecialColor.ColorKind.Purple)
            {
                lineColor = purpleColor;
            }
            else
            {
                lineColor = SwopColorConverter.CmykToRgbColor(lineSpecialColor.CustomColor);
            }

            using (Brush purpleBrush = new SolidBrush(purpleColor))
                using (Pen purplePen = new Pen(purpleColor, controlLineWidth))
                    using (Pen linePen = new Pen(lineColor, this.LineWidth))
                    {
                        // Create the pen to be correct for the style and so forth.
                        LineKind lineKind = this.LineKind;
                        linePen.StartCap = linePen.EndCap = System.Drawing.Drawing2D.LineCap.Flat;
                        if (lineKind == PurplePen.LineKind.Double)
                        {
                            linePen.Width = this.LineWidth * 2 + this.GapSize;
                            float widthFract = this.LineWidth / linePen.Width;
                            float gapFract   = this.GapSize / linePen.Width;
                            linePen.CompoundArray = new float[4] {
                                0, widthFract, widthFract + gapFract, 1
                            };
                        }
                        else if (lineKind == PurplePen.LineKind.Dashed && this.DashSize > 0 && this.GapSize > 0)
                        {
                            linePen.DashCap     = System.Drawing.Drawing2D.DashCap.Flat;
                            linePen.DashOffset  = 0;
                            linePen.DashPattern = new float[2] {
                                this.DashSize / this.LineWidth, this.GapSize / this.LineWidth
                            };
                        }

                        // Draw control circle
                        PointF centerCircle = new PointF(5, 5);
                        g.DrawEllipse(purplePen, RectangleF.FromLTRB(centerCircle.X - controlCircleDrawRadius, centerCircle.Y - controlCircleDrawRadius, centerCircle.X + controlCircleDrawRadius, centerCircle.Y + controlCircleDrawRadius));

                        // Draw center dot.
                        if (controlDotDiameter > 0.0F)
                        {
                            g.FillEllipse(purpleBrush, RectangleF.FromLTRB(centerCircle.X - controlDotDiameter / 2, centerCircle.Y - controlDotDiameter / 2, centerCircle.X + controlDotDiameter / 2, centerCircle.Y + controlDotDiameter / 2));
                        }

                        // Draw legs
                        double angle = (Math.PI * 1.4);
                        g.DrawLine(purplePen, (float)(centerCircle.X + Math.Cos(angle) * 15), (float)(centerCircle.Y + Math.Sin(angle) * 15),
                                   (float)(centerCircle.X + Math.Cos(angle) * controlCircleDrawRadius), (float)(centerCircle.Y + Math.Sin(angle) * controlCircleDrawRadius));
                        angle = (Math.PI * 0.8);
                        g.DrawLine(purplePen, (float)(centerCircle.X + Math.Cos(angle) * 15), (float)(centerCircle.Y + Math.Sin(angle) * 15),
                                   (float)(centerCircle.X + Math.Cos(angle) * controlCircleDrawRadius), (float)(centerCircle.Y + Math.Sin(angle) * controlCircleDrawRadius));

                        // Draw line
                        PointF lineStart = new PointF(12, -5), lineCorner = new PointF(12, 5), lineEnd = new PointF(100, 5);
                        using (GraphicsPath path = new GraphicsPath()) {
                            if (!this.showRadius)
                            {
                                // Line, not rectangle. Just show line.
                                path.AddLine(lineCorner, lineEnd);
                            }
                            else if (this.CornerRadius > 0)
                            {
                                const float kappa = 0.5522847498F; // constant used to create near-circle with a bezier.

                                PointF roundStart = new PointF(lineCorner.X, lineCorner.Y - CornerRadius);
                                PointF roundEnd   = new PointF(lineCorner.X + CornerRadius, lineCorner.Y);
                                PointF control1   = new PointF(lineCorner.X, lineCorner.Y - (1 - kappa) * CornerRadius);
                                PointF control2   = new PointF(lineCorner.X + (1 - kappa) * CornerRadius, lineCorner.Y);
                                path.AddLine(lineStart, roundStart);
                                path.AddBezier(roundStart, control1, control2, roundEnd);
                                path.AddLine(roundEnd, lineEnd);
                            }
                            else
                            {
                                // No corner radius.
                                path.AddLine(lineStart, lineCorner);
                                path.AddLine(lineCorner, lineEnd);
                            }
                            try {
                                g.DrawPath(linePen, path);
                            }
                            catch (Exception) {
                                // Do nothing. Very occasionally, GDI+ given an overflow exception or ExternalException or OutOfMemory exception.
                                // Just ignore it; there's nothing else to do. See bug #1997301.
                            }
                        }
                    }
        }