Simply3DScan
ButtonRenderer.cs
Go to the documentation of this file.
1 using System.Drawing;
2 using System.Drawing.Drawing2D;
3 using System.Windows.Forms;
4 using Configuration;
5 using SharedObjects;
6 using Syncfusion.Windows.Forms.Tools;
7 using Translator;
8 
9 namespace Simple3DScan.UI
10 {
14  public class ButtonRenderer : IToggleButtonRenderer
15  {
28  [LogException]
29  public void DrawButton(PaintEventArgs e, ToggleButtonState toggleState, DisplayType displayMode, Font font, ActiveStateCollection activeState, InactiveStateCollection inactiveState, RightToLeft righttoLeft, bool isMouseHover, ToggleButton toggleButton)
30  {
31  string displayText = Singleton<Translate>.Instance.GetString(toggleState == ToggleButtonState.Active ? activeState.Text : inactiveState.Text, Singleton<Config>.Instance.Information.Language);
32  SizeF textSize = e.Graphics.MeasureString(displayText, font);
33  Rectangle controlRect = new Rectangle(e.ClipRectangle.X + 1, e.ClipRectangle.Y + 1, e.ClipRectangle.Width - 4, e.ClipRectangle.Height - 4);
34  e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
35  GraphicsPath gp = new GraphicsPath();
36 
37  if (controlRect.Height > 1)
38  {
39  gp.AddArc(controlRect.X, controlRect.Y, controlRect.Height, controlRect.Height, 180, 90);
40  gp.AddArc(controlRect.X + controlRect.Width - controlRect.Height, controlRect.Y, controlRect.Height,
41  controlRect.Height, 270, 90);
42  gp.AddArc(controlRect.X + controlRect.Width - controlRect.Height,
43  controlRect.Y + controlRect.Height - controlRect.Height, controlRect.Height, controlRect.Height, 0,
44  90);
45  gp.AddArc(controlRect.X, controlRect.Y + controlRect.Height - controlRect.Height, controlRect.Height,
46  controlRect.Height, 90, 90);
47  gp.CloseFigure();
48  e.Graphics.DrawPath(new Pen(Color.Tan, 2), gp);
49  }
50  GraphicsPath gp1 = new GraphicsPath();
51  using (LinearGradientBrush br = new LinearGradientBrush(e.ClipRectangle, Color.Tan, Color.PapayaWhip, LinearGradientMode.Vertical))
52  {
53  if (controlRect.Height > 1)
54  {
55  gp1.AddArc(controlRect.X, controlRect.Y + 1, controlRect.Height + 2, controlRect.Height, 180, 90);
56  gp1.AddArc(controlRect.X + controlRect.Width - controlRect.Height, controlRect.Y, controlRect.Height, controlRect.Height, 270, 90);
57  gp1.AddArc(controlRect.X + 1 + controlRect.Width - controlRect.Height, controlRect.Y + controlRect.Height - controlRect.Height, controlRect.Height, controlRect.Height, 0, 90);
58  gp1.AddArc(controlRect.X, controlRect.Y + controlRect.Height - controlRect.Height, controlRect.Height, controlRect.Height, 90, 90);
59  gp1.CloseFigure();
60  e.Graphics.FillPath(br, gp1);
61  gp1.Dispose();
62  }
63  }
64  if (isMouseHover)
65  using (SolidBrush br = new SolidBrush(Color.PapayaWhip))
66  {
67  e.Graphics.FillPath(br, gp);
68  }
69  PointF pt1 = new PointF(e.ClipRectangle.X + e.ClipRectangle.Width / 2 - textSize.Width / 2, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 - textSize.Height / 2);
70  using (SolidBrush br = new SolidBrush(Color.Black))
71  {
72  if (displayMode == DisplayType.Text)
73  e.Graphics.DrawString(displayText, font, br, pt1);
74  }
75  gp.Dispose();
76  }
77 
89  [LogException]
90  public void DrawSlider(PaintEventArgs e, Point p, ToggleButtonState toggleState, SliderCollection slider, Font font, RightToLeft righttoLeft, bool isMouseMove, bool isMouseHover)
91  {
92  e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
93  Rectangle sliderRectangle;
94  if (!isMouseMove)
95  {
96  sliderRectangle = toggleState == ToggleButtonState.Inactive ? new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Height - 1, e.ClipRectangle.Height - 1) : new Rectangle(e.ClipRectangle.X + e.ClipRectangle.Width - e.ClipRectangle.Height, e.ClipRectangle.Y, e.ClipRectangle.Height - 1, e.ClipRectangle.Height - 1);
97  }
98  else
99  sliderRectangle = new Rectangle(p.X, e.ClipRectangle.Y, e.ClipRectangle.Height - 1, e.ClipRectangle.Height - 1);
100  if (isMouseHover)
101  {
102  using (SolidBrush br = new SolidBrush(slider.BackColor))
103  {
104  e.Graphics.FillEllipse(br, sliderRectangle);
105  using (Pen pn = new Pen(Color.Gray, 2))
106  e.Graphics.DrawEllipse(pn, sliderRectangle);
107  }
108  }
109  else
110  {
111  using (SolidBrush br = new SolidBrush(slider.BackColor))
112  {
113  e.Graphics.FillEllipse(br, sliderRectangle);
114  e.Graphics.DrawEllipse(Pens.Gray, sliderRectangle);
115  }
116  }
117  }
118  }
119 }
void DrawSlider(PaintEventArgs e, Point p, ToggleButtonState toggleState, SliderCollection slider, Font font, RightToLeft righttoLeft, bool isMouseMove, bool isMouseHover)
Method for Drawing the Slider in ToggleButton
void DrawButton(PaintEventArgs e, ToggleButtonState toggleState, DisplayType displayMode, Font font, ActiveStateCollection activeState, InactiveStateCollection inactiveState, RightToLeft righttoLeft, bool isMouseHover, ToggleButton toggleButton)
Method for Drawing the Button Frame for ToggleButton
Class for creating a singleton for a generic class
Definition: Singleton.cs:9
Just a class for a special style of the toogle buttons
static T Instance
Gets the instance.
Definition: Singleton.cs:27