Beispiel #1
0
 public void Apply(LinearGradientColorTable table)
 {
     if (table == null)
     {
         this.Color1 = Color.Empty;
         this.Color2 = Color.Empty;
     }
     else
     {
         this.Color1 = table.Start;
         this.Color2 = table.End;
     }
 }
Beispiel #2
0
 public ShapeBorder(LinearGradientColorTable table, int width)
 {
     this.Color1 = table.Start;
     this.Color2 = table.End;
     this.Width = width;
 }
Beispiel #3
0
        protected override void PaintClose(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled)
        {
            SmoothingMode sm = g.SmoothingMode;
            g.SmoothingMode = SmoothingMode.Default;

            Size s = new Size(11, 9);
            Rectangle rm = GetSignRect(r, s);

            Rectangle r1 = rm;
            r1.Inflate(-1, 0);
            r1.Height--;

            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddLine(r1.X + 1, r1.Y, r1.X + 3, r1.Y);
                path.AddLine(r1.X + 3, r1.Y, r1.X + 5, r1.Y + 2);
                path.AddLine(r1.X + 5, r1.Y + 2, r1.X + 7, r1.Y);
                path.AddLine(r1.X + 7, r1.Y, r1.X + 9, r1.Y);
                path.AddLine(r1.X + 10, r1.Y + 1, r1.X + 7, r1.Y + 4);
                path.AddLine(r1.X + 7, r1.Y + 4, r1.X + 10, r1.Y + 7);
                path.AddLine(r1.X + 10, r1.Y + 7, r1.X + 9, r1.Y + 8);
                path.AddLine(r1.X + 9, r1.Y + 8, r1.X + 7, r1.Y + 8);
                path.AddLine(r1.X + 7, r1.Y + 8, r1.X + 5, r1.Y + 6);
                path.AddLine(r1.X + 5, r1.Y + 6, r1.X + 3, r1.Y + 8);
                path.AddLine(r1.X + 3, r1.Y + 8, r1.X + 1, r1.Y + 8);
                path.AddLine(r1.X, r1.Y + 7, r1.X + 3, r1.Y + 4);
                path.AddLine(r1.X + 3, r1.Y + 4, r1.X, r1.Y + 1);

                if (isEnabled)
                {
                    DisplayHelp.FillPath(g, path, ct.Foreground);
                    if (!ct.DarkShade.IsEmpty)
                    {
                        using (Pen pen = new Pen(ct.DarkShade))
                        {
                            g.DrawPath(pen, path);
                        }
                    }
                    else
                    {
                        using (Pen pen = new Pen(ct.Foreground.Start))
                        {
                            g.DrawPath(pen, path);
                        }
                    }
                }
                else
                {
                    LinearGradientColorTable lg = new LinearGradientColorTable(ct.Foreground.Start.IsEmpty ? ct.Foreground.Start : Color.FromArgb(128, ct.Foreground.Start),
                        ct.Foreground.End.IsEmpty ? ct.Foreground.End : Color.FromArgb(128, ct.Foreground.End),
                        ct.Foreground.GradientAngle);
                    DisplayHelp.FillPath(g, path, lg);
                    DisplayHelp.DrawGradientPathBorder(g, path, lg, 1);
                }
            }

            g.SmoothingMode = sm;
        }
Beispiel #4
0
 public ShapeFill(LinearGradientColorTable table)
 {
     this.Color1 = table.Start;
     this.Color2 = table.End;
 }
Beispiel #5
0
        public override void Paint(SwitchButtonRenderEventArgs e)
        {
            SwitchButtonItem switchButton = e.SwitchButtonItem;
            bool enabled = switchButton.Enabled;
            SwitchButtonColorTable colorTable = enabled ? this.ColorTable.SwitchButton.Default : this.ColorTable.SwitchButton.Disabled;
            if (colorTable == null) colorTable = new SwitchButtonColorTable();
            
            Rectangle bounds = switchButton.Bounds;
            if (e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is AdvTree.AdvTree)
            {
                if (switchButton.ItemAlignment == eItemAlignment.Far)
                    bounds.X = bounds.Right - switchButton.Margin.Right - switchButton.ButtonWidth;
                else if (switchButton.ItemAlignment == eItemAlignment.Center)
                    bounds.X += (bounds.Width - switchButton.ButtonWidth) / 2;
            }
            else
                bounds.X = bounds.Right - switchButton.Margin.Right - switchButton.ButtonWidth;
            bounds.Width = switchButton.ButtonWidth;
            bounds.Y += switchButton.Margin.Top + (bounds.Height - switchButton.Margin.Vertical - switchButton.ButtonHeight) / 2;
            bounds.Height = switchButton.ButtonHeight;
            switchButton.ButtonBounds = bounds;
            bool rendersOnGlass = (e.ItemPaintArgs != null && e.ItemPaintArgs.GlassEnabled && (switchButton.Parent is CaptionItemContainer && !(e.ItemPaintArgs.ContainerControl is QatToolbar) || (switchButton.Parent is RibbonTabItemContainer && switchButton.EffectiveStyle == eDotNetBarStyle.Office2010)));
            Graphics g = e.Graphics;
            if (switchButton.TextVisible && !string.IsNullOrEmpty(switchButton.Text))
            {
                Rectangle textRect = switchButton.Bounds;
                textRect.Width -= switchButton.ButtonWidth + switchButton.Margin.Right;
                textRect.Y += switchButton.TextPadding.Top;
                textRect.Height -= switchButton.TextPadding.Vertical;
                bool rtl = e.RightToLeft;
                Color textColor = (switchButton.TextColor.IsEmpty || !enabled) ? colorTable.TextColor : switchButton.TextColor;
                Font textFont = e.Font;
                eTextFormat tf = eTextFormat.Left | eTextFormat.VerticalCenter;
                if (switchButton.TextMarkupBody != null)
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, textFont, textColor, rtl);
                    d.HotKeyPrefixVisible = !((tf & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    if ((tf & eTextFormat.VerticalCenter) == eTextFormat.VerticalCenter)
                        textRect.Y = switchButton.TopInternal + (switchButton.Bounds.Height - switchButton.TextMarkupBody.Bounds.Height) / 2;
                    else if ((tf & eTextFormat.Bottom) == eTextFormat.Bottom)
                        textRect.Y += (switchButton.TextMarkupBody.Bounds.Height - textRect.Height) + 1;
                    textRect.Height = switchButton.TextMarkupBody.Bounds.Height;
                    switchButton.TextMarkupBody.Bounds = textRect;
                    switchButton.TextMarkupBody.Render(d);
                }
                else
                {
#if FRAMEWORK20
                    if(rendersOnGlass)
                    {
                        if (!e.ItemPaintArgs.CachedPaint)
                            Office2007RibbonControlPainter.PaintTextOnGlass(g, switchButton.Text, textFont, textRect, TextDrawing.GetTextFormat(tf));
                    }
                    else
#endif
                        TextDrawing.DrawString(g, switchButton.Text, textFont, textColor, textRect, tf);
                }
            }


            bool switchState = switchButton.Value;
            string offText = switchButton.OffText;
            string onText = switchButton.OnText;
            Font font = (switchButton.SwitchFont == null) ? new Font(e.Font, FontStyle.Bold) : switchButton.SwitchFont;
            Color textOffColor = (switchButton.OffTextColor.IsEmpty || !enabled) ? colorTable.OffTextColor : switchButton.OffTextColor;
            Color textOnColor = (switchButton.OnTextColor.IsEmpty || !enabled) ? colorTable.OnTextColor : switchButton.OnTextColor;

            int switchWidth = switchButton.SwitchWidth;
            int switchX = Math.Min(bounds.X + switchButton.SwitchOffset, bounds.Right);
            if (switchState)
            {
                switchX = Math.Max(bounds.Right - switchWidth - switchButton.SwitchOffset, bounds.X);
            }

            Color borderColor = (switchButton.BorderColor.IsEmpty || !enabled) ? colorTable.BorderColor : switchButton.BorderColor;
            Color offBackgroundColor = (switchButton.OffBackColor.IsEmpty || !enabled) ? colorTable.OffBackColor : switchButton.OffBackColor;
            Color onBackgroundColor = (switchButton.OnBackColor.IsEmpty || !enabled) ? colorTable.OnBackColor : switchButton.OnBackColor;

            // Set clip
            Rectangle innerBoundsClip = bounds;
            innerBoundsClip.Inflate(-1, -1);
            GraphicsPath innerClipPath = DisplayHelp.GetRoundedRectanglePath(innerBoundsClip, SwitchCornerSize - 1);
            Region oldClip = g.Clip;
            g.SetClip(innerClipPath, System.Drawing.Drawing2D.CombineMode.Intersect);
            innerClipPath.Dispose();
            
            // Draw On Background, it is to the left of the switch
            Rectangle onBounds = new Rectangle(switchX - (bounds.Width - switchWidth), bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
            switchButton.OnPartBounds = onBounds;
            DisplayHelp.FillRoundedRectangle(g, onBounds, SwitchCornerSize - 1, onBackgroundColor);
            DisplayHelp.FillRoundedRectangle(g, onBounds, SwitchCornerSize - 1, Color.FromArgb(onBackgroundColor.GetBrightness() > .90f ? 8 : 24, Color.Black), Color.FromArgb(32, Color.White));
            // Draw On Text
            if(rendersOnGlass && BarUtilities.UseTextRenderer)
                TextDrawing.DrawStringLegacy(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
            else
                TextDrawing.DrawString(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);

            // Draw Off Background, it is on the right of the switch 
            Rectangle offBounds = new Rectangle(switchX + switchWidth - 2, bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
            switchButton.OffPartBounds = offBounds;
            DisplayHelp.FillRoundedRectangle(g, offBounds, SwitchCornerSize, offBackgroundColor);
            DisplayHelp.FillRoundedRectangle(g, offBounds, SwitchCornerSize, Color.FromArgb(offBackgroundColor.GetBrightness() > .90f ? 12 : 32, Color.Black), Color.FromArgb(64, Color.White));
            // Draw Off Text
            if (rendersOnGlass && BarUtilities.UseTextRenderer)
                TextDrawing.DrawStringLegacy(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
            else
                TextDrawing.DrawString(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);

            // Restore old clip
            g.Clip = oldClip;
            oldClip.Dispose();

            // Main control border
            DisplayHelp.DrawRoundedRectangle(g, borderColor, bounds, SwitchCornerSize);

            LinearGradientColorTable innerOverlay = new LinearGradientColorTable(Color.FromArgb(96, Color.DarkGray), Color.Transparent, 90);
            Rectangle overlayBounds = bounds;
            overlayBounds.Inflate(-SwitchCornerSize / 2, -1);
            DisplayHelp.DrawLine(g, overlayBounds.X, overlayBounds.Y, overlayBounds.Right, overlayBounds.Y, Color.FromArgb(24, Color.Black), 1);
            overlayBounds.Y++;
            DisplayHelp.DrawLine(g, overlayBounds.X, overlayBounds.Y, overlayBounds.Right, overlayBounds.Y, Color.FromArgb(8, Color.Black), 1);

            // Draw Switch on top
            Rectangle switchBounds = new Rectangle(switchX, bounds.Y, switchWidth, bounds.Height);
            switchButton.SwitchBounds = switchBounds;
            Color switchBorderColor = (switchButton.SwitchBorderColor.IsEmpty || !enabled) ? colorTable.SwitchBorderColor : switchButton.SwitchBorderColor;
            Color switchFillColor = (switchButton.SwitchBackColor.IsEmpty || !enabled) ? colorTable.SwitchBackColor : switchButton.SwitchBackColor;

            if (switchBounds.Right + 2 < bounds.Right)
            {
                DisplayHelp.DrawLine(g, switchBounds.Right, switchBounds.Y + 3, switchBounds.Right, switchBounds.Bottom - 2, Color.FromArgb(24, Color.Black), 1);
                DisplayHelp.DrawLine(g, switchBounds.Right + 1, switchBounds.Y + 3, switchBounds.Right + 1, switchBounds.Bottom - 2, Color.FromArgb(8, Color.Black), 1);
            }

            DisplayHelp.DrawRoundedRectangle(g, switchBorderColor, switchFillColor, switchBounds, SwitchCornerSize);
            DisplayHelp.FillRoundedRectangle(g, switchBounds, SwitchCornerSize, Color.FromArgb(switchFillColor.GetBrightness() > .90f ? 42 : 72, Color.Black), Color.FromArgb(64, Color.White));
            DisplayHelp.DrawLine(g, switchBounds.X + 2, switchBounds.Y + 1, switchBounds.Right - 3, switchBounds.Y + 1, Color.FromArgb(164, Color.White), 1);

            if (switchButton.IsReadOnly && switchButton.ShowReadOnlyMarker)
            {
                Color markerColor=switchButton.ReadOnlyMarkerColor;
                Rectangle marker = new Rectangle(switchBounds.X + (switchBounds.Width - 7) / 2, switchBounds.Y + (switchBounds.Height - 10) / 2, 7, 10);
                SmoothingMode sm = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.None;
                using (SolidBrush brush = new SolidBrush(markerColor))
                {
                    g.FillRectangle(brush, new Rectangle(marker.X, marker.Y + 4, marker.Width, marker.Height - 4));
                    g.FillRectangle(Brushes.White, new Rectangle(marker.X + 3, marker.Y + 5, 1, 2));
                }
                using (Pen pen = new Pen(markerColor, 1))
                {
                    g.DrawLine(pen, marker.X + 2, marker.Y + 0, marker.X + 4, marker.Y + 0);
                    g.DrawLine(pen, marker.X + 1, marker.Y + 1, marker.X + 1, marker.Y + 3);
                    g.DrawLine(pen, marker.X + 5, marker.Y + 1, marker.X + 5, marker.Y + 3);
                }
                g.SmoothingMode = sm;
            }
        }
Beispiel #6
0
        private void DrawHighlight(Graphics g, LinearGradientColorTable c, Rectangle r, PointF centerPoint)
        {
            Rectangle ellipse = new Rectangle(r.X, r.Y, r.Width, r.Height * 2);
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(ellipse);
            PathGradientBrush brush = new PathGradientBrush(path);
            brush.CenterColor = c.Start;
            brush.SurroundColors = new Color[] { c.End };
            brush.CenterPoint = centerPoint;
            Blend blend = new Blend();
            blend.Factors = new float[] { 0f, .5f, 1f };
            blend.Positions = new float[] { .0f, .4f, 1f };
            brush.Blend = blend;

            g.FillRectangle(brush, r);
            brush.Dispose();
            path.Dispose();
        }