1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Windows.Forms;
|
---|
5 | using System.Drawing.Drawing2D;
|
---|
6 | using System.Drawing;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Calendar
|
---|
9 | {
|
---|
10 | public abstract class AbstractRenderer : IDisposable
|
---|
11 | {
|
---|
12 | ~AbstractRenderer()
|
---|
13 | {
|
---|
14 | Dispose(false);
|
---|
15 | }
|
---|
16 |
|
---|
17 | public void Dispose()
|
---|
18 | {
|
---|
19 | Dispose(true);
|
---|
20 | GC.SuppressFinalize(this);
|
---|
21 | }
|
---|
22 |
|
---|
23 | protected virtual void Dispose(bool mainThread)
|
---|
24 | {
|
---|
25 | if (hourFont != null)
|
---|
26 | hourFont.Dispose();
|
---|
27 |
|
---|
28 | if (minuteFont != null)
|
---|
29 | minuteFont.Dispose();
|
---|
30 | }
|
---|
31 |
|
---|
32 | public virtual Color AllDayEventsBackColor
|
---|
33 | {
|
---|
34 | get
|
---|
35 | {
|
---|
36 | return InterpolateColors(this.BackColor, Color.Black, 0.5f);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public virtual Font BaseFont
|
---|
41 | {
|
---|
42 | get
|
---|
43 | {
|
---|
44 | return Control.DefaultFont;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public virtual Color HourSeperatorColor
|
---|
49 | {
|
---|
50 | get
|
---|
51 | {
|
---|
52 | return System.Drawing.Color.FromArgb(234, 208, 152);
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public virtual Color HalfHourSeperatorColor
|
---|
57 | {
|
---|
58 | get
|
---|
59 | {
|
---|
60 | return System.Drawing.Color.FromArgb(243, 228, 177);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public virtual Color HourColor
|
---|
65 | {
|
---|
66 | get
|
---|
67 | {
|
---|
68 | return System.Drawing.Color.FromArgb(255, 244, 188);
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | public virtual Color WorkingHourColor
|
---|
73 | {
|
---|
74 | get
|
---|
75 | {
|
---|
76 | return System.Drawing.Color.FromArgb(255, 255, 213);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public virtual Color BackColor
|
---|
81 | {
|
---|
82 | get
|
---|
83 | {
|
---|
84 | return SystemColors.Control;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | public virtual Color SelectionColor
|
---|
89 | {
|
---|
90 | get
|
---|
91 | {
|
---|
92 | return SystemColors.Highlight;
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | private Font hourFont;
|
---|
97 |
|
---|
98 | public virtual Font HourFont
|
---|
99 | {
|
---|
100 | get
|
---|
101 | {
|
---|
102 | if (hourFont == null)
|
---|
103 | {
|
---|
104 | hourFont = new Font(BaseFont.FontFamily, 14, FontStyle.Regular);
|
---|
105 | }
|
---|
106 |
|
---|
107 | return hourFont;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | private Font minuteFont;
|
---|
112 |
|
---|
113 | public virtual Font MinuteFont
|
---|
114 | {
|
---|
115 | get
|
---|
116 | {
|
---|
117 | if (minuteFont == null)
|
---|
118 | {
|
---|
119 | minuteFont = new Font(BaseFont.FontFamily, 8, FontStyle.Regular);
|
---|
120 | }
|
---|
121 |
|
---|
122 | return minuteFont;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | public abstract void DrawHourLabel(Graphics g, Rectangle rect, int hour, bool ampm);
|
---|
127 |
|
---|
128 | public abstract void DrawHourLabel(Graphics g, Rectangle rect, int hour, bool ampm, bool timeindicator);
|
---|
129 |
|
---|
130 | public abstract void DrawDayHeader(Graphics g, Rectangle rect, DateTime date);
|
---|
131 |
|
---|
132 | public abstract void DrawDayBackground(Graphics g, Rectangle rect);
|
---|
133 |
|
---|
134 | public virtual void DrawHourRange(Graphics g, Rectangle rect, bool drawBorder, bool hilight)
|
---|
135 | {
|
---|
136 | if (g == null)
|
---|
137 | throw new ArgumentNullException("g");
|
---|
138 |
|
---|
139 | using (SolidBrush brush = new SolidBrush(hilight ? this.SelectionColor : this.WorkingHourColor))
|
---|
140 | {
|
---|
141 | g.FillRectangle(brush, rect);
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (drawBorder)
|
---|
145 | g.DrawRectangle(SystemPens.WindowFrame, rect);
|
---|
146 | }
|
---|
147 |
|
---|
148 | public virtual void DrawDayGripper(Graphics g, Rectangle rect, int gripWidth)
|
---|
149 | {
|
---|
150 | if (g == null)
|
---|
151 | throw new ArgumentNullException("g");
|
---|
152 |
|
---|
153 | using (Brush m_Brush = new SolidBrush(Color.White))
|
---|
154 | g.FillRectangle(m_Brush, rect.Left, rect.Top - 1, gripWidth, rect.Height);
|
---|
155 |
|
---|
156 | using (Pen m_Pen = new Pen(Color.Black))
|
---|
157 | g.DrawRectangle(m_Pen, rect.Left, rect.Top - 1, gripWidth, rect.Height);
|
---|
158 | }
|
---|
159 |
|
---|
160 | public abstract void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect);
|
---|
161 |
|
---|
162 | public abstract void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners);
|
---|
163 |
|
---|
164 | public void DrawAllDayBackground(Graphics g, Rectangle rect)
|
---|
165 | {
|
---|
166 | if (g == null)
|
---|
167 | throw new ArgumentNullException("g");
|
---|
168 |
|
---|
169 | using (Brush brush = new SolidBrush(InterpolateColors(this.BackColor, Color.Black, 0.5f)))
|
---|
170 | g.FillRectangle(brush, rect);
|
---|
171 | }
|
---|
172 |
|
---|
173 | public static Color InterpolateColors(Color color1, Color color2, float percentage)
|
---|
174 | {
|
---|
175 | int num1 = ((int)color1.R);
|
---|
176 | int num2 = ((int)color1.G);
|
---|
177 | int num3 = ((int)color1.B);
|
---|
178 | int num4 = ((int)color2.R);
|
---|
179 | int num5 = ((int)color2.G);
|
---|
180 | int num6 = ((int)color2.B);
|
---|
181 | byte num7 = Convert.ToByte(((float)(((float)num1) + (((float)(num4 - num1)) * percentage))));
|
---|
182 | byte num8 = Convert.ToByte(((float)(((float)num2) + (((float)(num5 - num2)) * percentage))));
|
---|
183 | byte num9 = Convert.ToByte(((float)(((float)num3) + (((float)(num6 - num3)) * percentage))));
|
---|
184 | return Color.FromArgb(num7, num8, num9);
|
---|
185 | }
|
---|
186 |
|
---|
187 | public static GraphicsPath CreateRoundRectangle(Rectangle rectangle)
|
---|
188 | {
|
---|
189 | int radius = 8;
|
---|
190 |
|
---|
191 | GraphicsPath path = new GraphicsPath();
|
---|
192 | int l = rectangle.Left;
|
---|
193 | int t = rectangle.Top;
|
---|
194 | int w = rectangle.Width;
|
---|
195 | int h = rectangle.Height;
|
---|
196 | int d = radius << 1;
|
---|
197 | path.AddArc(l, t, d, d, 180, 90); // topleft
|
---|
198 | path.AddLine(l + radius, t, l + w - radius, t); // top
|
---|
199 | path.AddArc(l + w - d, t, d, d, 270, 90); // topright
|
---|
200 | path.AddLine(l + w, t + radius, l + w, t + h - radius); // right
|
---|
201 | path.AddArc(l + w - d, t + h - d, d, d, 0, 90); // bottomright
|
---|
202 | path.AddLine(l + w - radius, t + h, l + radius, t + h); // bottom
|
---|
203 | path.AddArc(l, t + h - d, d, d, 90, 90); // bottomleft
|
---|
204 | path.AddLine(l, t + h - radius, l, t + radius); // left
|
---|
205 | path.CloseFigure();
|
---|
206 | return path;
|
---|
207 | }
|
---|
208 |
|
---|
209 | public static GraphicsPath CreateGripRectangle(Rectangle rectangle)
|
---|
210 | {
|
---|
211 | int radius = rectangle.Width;
|
---|
212 |
|
---|
213 | GraphicsPath path = new GraphicsPath();
|
---|
214 | int l = rectangle.Left;
|
---|
215 | int t = rectangle.Top;
|
---|
216 | int w = rectangle.Width;
|
---|
217 | int h = rectangle.Height;
|
---|
218 | int d = radius << 1;
|
---|
219 | path.AddArc(l, t, d, d, 180, 90); // topleft
|
---|
220 | path.AddLine(l + w, t + radius, l + w, t + h - radius); // right
|
---|
221 | path.AddArc(l, t + h - d, d, d, 90, 90); // bottomleft
|
---|
222 | path.AddLine(l, t + h - radius, l, t + radius); // left
|
---|
223 | path.CloseFigure();
|
---|
224 | return path;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|