1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Drawing.Drawing2D;
|
---|
4 | namespace Netron.Diagramming.Core {
|
---|
5 | /// <summary>
|
---|
6 | /// The art pallet consists of the often used colors, brushes, font etc. used by the painting methods.
|
---|
7 | /// You can set the pallet at starup of the diagram control
|
---|
8 | /// </summary>
|
---|
9 | public static class ArtPalette {
|
---|
10 |
|
---|
11 | #region Fields
|
---|
12 | private static Font mTitleFont = new Font("Arial", 20F, FontStyle.Bold);
|
---|
13 |
|
---|
14 | // ------------------------------------------------------------------
|
---|
15 | /// <summary>
|
---|
16 | /// The default color for new pages.
|
---|
17 | /// </summary>
|
---|
18 | // ------------------------------------------------------------------
|
---|
19 | static Color mDefaultPageColor = Color.White;
|
---|
20 |
|
---|
21 | // ------------------------------------------------------------------
|
---|
22 | /// <summary>
|
---|
23 | /// The default color for the page background.
|
---|
24 | /// </summary>
|
---|
25 | // ------------------------------------------------------------------
|
---|
26 | static Color mDefaultPageBackgroundColor = Color.DarkGray;
|
---|
27 |
|
---|
28 | // ------------------------------------------------------------------
|
---|
29 | /// <summary>
|
---|
30 | /// whether shadows of entities are painted
|
---|
31 | /// </summary>
|
---|
32 | // ------------------------------------------------------------------
|
---|
33 | private static bool mEnableShadows = true;
|
---|
34 |
|
---|
35 | // ------------------------------------------------------------------
|
---|
36 | /// <summary>
|
---|
37 | /// the font for the marks on the rulers
|
---|
38 | /// </summary>
|
---|
39 | // ------------------------------------------------------------------
|
---|
40 | private static Font mRulerFont = new Font(
|
---|
41 | "Arial", 7.0F, FontStyle.Regular);
|
---|
42 |
|
---|
43 | // ------------------------------------------------------------------
|
---|
44 | /// <summary>
|
---|
45 | /// the ruler pen
|
---|
46 | /// </summary>
|
---|
47 | // ------------------------------------------------------------------
|
---|
48 | private static Pen mRulerPen = Pens.Black;
|
---|
49 |
|
---|
50 | // ------------------------------------------------------------------
|
---|
51 | /// <summary>
|
---|
52 | /// the background of the rulers
|
---|
53 | /// </summary>
|
---|
54 | // ------------------------------------------------------------------
|
---|
55 | private static Brush mRulerFillBrush = Brushes.White;
|
---|
56 | /// <summary>
|
---|
57 | /// the brush with which to paint the ghosts
|
---|
58 | /// </summary>
|
---|
59 | private static Brush mGhostBrush = new SolidBrush(Color.FromArgb(120, Color.LightYellow));
|
---|
60 | /// <summary>
|
---|
61 | /// the ghost pen
|
---|
62 | /// </summary>
|
---|
63 | private static Pen mGhostPen = new Pen(Color.Green, 1.5f);
|
---|
64 | /// <summary>
|
---|
65 | /// the pen to draw the interconnecting folder lines
|
---|
66 | /// </summary>
|
---|
67 | private static Pen mFolderLinesPen = new Pen(Color.Gray, 1.0F);
|
---|
68 | /// <summary>
|
---|
69 | /// the pen used for drawing the tracker
|
---|
70 | /// </summary>
|
---|
71 | private static Pen mTrackerPen = new Pen(Color.DimGray, 1.5F);
|
---|
72 | /// <summary>
|
---|
73 | /// the brush used to paint the grips
|
---|
74 | /// </summary>
|
---|
75 | private static Brush mGripBrush = Brushes.WhiteSmoke;
|
---|
76 | /// <summary>
|
---|
77 | /// Default font for drawing text
|
---|
78 | /// </summary>
|
---|
79 | private static Font mDefaultFont = new Font("Tahoma", 8.5F);
|
---|
80 | /// <summary>
|
---|
81 | /// the font used to draw bold text
|
---|
82 | /// </summary>
|
---|
83 | private static Font mDefaultBoldFont = new Font("Tahoma", 8.5F, FontStyle.Bold);
|
---|
84 | /// <summary>
|
---|
85 | /// randomizer for generating random colors of a certain style
|
---|
86 | /// </summary>
|
---|
87 | private static Random rnd = new Random();
|
---|
88 | /// <summary>
|
---|
89 | /// Default black pen
|
---|
90 | /// </summary>
|
---|
91 | private static Pen mBlackPen = new Pen(Brushes.Black, 1F);
|
---|
92 | /// <summary>
|
---|
93 | /// the global shadow brush
|
---|
94 | /// </summary>
|
---|
95 | private static Brush mShadowBrush = new SolidBrush(Color.FromArgb(30, Color.Black));
|
---|
96 | /// <summary>
|
---|
97 | /// Default red pen
|
---|
98 | /// </summary>
|
---|
99 | private static Pen mHighlightPen = new Pen(Brushes.OrangeRed, 1.7F);
|
---|
100 | /// <summary>
|
---|
101 | /// the global shadow pen
|
---|
102 | /// </summary>
|
---|
103 | private static Pen mShadowPen = new Pen(Color.FromArgb(30, Color.Black), 1F);
|
---|
104 | /// <summary>
|
---|
105 | /// the pen used to paint the connections
|
---|
106 | /// </summary>
|
---|
107 | private static Pen mConnectionPen = new Pen(Color.Silver, 1F);
|
---|
108 | /// <summary>
|
---|
109 | /// the pen used to paint the highlighted connection
|
---|
110 | /// </summary>
|
---|
111 | private static Pen mConnectionHighlightPen = new Pen(Color.Red, 2.5F);
|
---|
112 |
|
---|
113 | private static IPaintStyle mTransparentPaintStyle = new SolidPaintStyle(Color.Transparent);
|
---|
114 | #endregion
|
---|
115 |
|
---|
116 | #region Properties
|
---|
117 |
|
---|
118 | // ------------------------------------------------------------------
|
---|
119 | /// <summary>
|
---|
120 | /// Gets or sets the default color for new pages.
|
---|
121 | /// </summary>
|
---|
122 | // ------------------------------------------------------------------
|
---|
123 | public static Color DefaultPageColor {
|
---|
124 | get {
|
---|
125 | return mDefaultPageColor;
|
---|
126 | }
|
---|
127 | set {
|
---|
128 | mDefaultPageColor = value;
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | // ------------------------------------------------------------------
|
---|
133 | /// <summary>
|
---|
134 | /// Gets or sets the default color for the background of new pages.
|
---|
135 | /// </summary>
|
---|
136 | // ------------------------------------------------------------------
|
---|
137 | public static Color DefaultPageBackgroundColor {
|
---|
138 | get {
|
---|
139 | return mDefaultPageBackgroundColor;
|
---|
140 | }
|
---|
141 | set {
|
---|
142 | mDefaultPageBackgroundColor = value;
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | /// <summary>
|
---|
147 | /// Gets or sets the title font used on the canvas to display the title of the current page.
|
---|
148 | /// </summary>
|
---|
149 | /// <value>The title font.</value>
|
---|
150 | public static Font TitleFont {
|
---|
151 | get { return mTitleFont; }
|
---|
152 | set { mTitleFont = value; }
|
---|
153 | }
|
---|
154 | /// <summary>
|
---|
155 | /// Gets or sets the global value indicating whether to enable entities shadows.
|
---|
156 | /// </summary>
|
---|
157 | /// <value><c>true</c> to enable shadows; otherwise, <c>false</c>.</value>
|
---|
158 | public static bool EnableShadows {
|
---|
159 | get { return mEnableShadows; }
|
---|
160 | set { mEnableShadows = value; }
|
---|
161 | }
|
---|
162 | /// <summary>
|
---|
163 | /// Gets the ruler font.
|
---|
164 | /// </summary>
|
---|
165 | /// <value>The ruler font.</value>
|
---|
166 | public static Font RulerFont {
|
---|
167 | get { return mRulerFont; }
|
---|
168 | }
|
---|
169 | /// <summary>
|
---|
170 | /// Gets the pen with which the ruler is drawn.
|
---|
171 | /// </summary>
|
---|
172 | /// <value>The ruler pen.</value>
|
---|
173 | public static Pen RulerPen {
|
---|
174 | get { return mRulerPen; }
|
---|
175 | }
|
---|
176 |
|
---|
177 | /// <summary>
|
---|
178 | /// Gets the ruller fill brush.
|
---|
179 | /// </summary>
|
---|
180 | /// <value>The ruller fill brush.</value>
|
---|
181 | public static Brush RullerFillBrush {
|
---|
182 | get {
|
---|
183 | return mRulerFillBrush;
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | /// <summary>
|
---|
188 | /// Gets the brush with which the ghosts are painted.
|
---|
189 | /// </summary>
|
---|
190 | /// <value>The ghost brush.</value>
|
---|
191 | public static Brush GhostBrush {
|
---|
192 | get {
|
---|
193 | return mGhostBrush;
|
---|
194 | }
|
---|
195 | }
|
---|
196 | /// <summary>
|
---|
197 | /// Gets the pen to draw the multi-point ghost lines.
|
---|
198 | /// </summary>
|
---|
199 | /// <value>The ghost pen.</value>
|
---|
200 | public static Pen GhostPen {
|
---|
201 | get {
|
---|
202 | return mGhostPen;
|
---|
203 | }
|
---|
204 | }
|
---|
205 | /// <summary>
|
---|
206 | /// Gets the pen used to draw the dashed line between <see cref="FolderMaterial"/> nodes.
|
---|
207 | /// </summary>
|
---|
208 | /// <value>The folder lines pen.</value>
|
---|
209 | public static Pen FolderLinesPen {
|
---|
210 | get {
|
---|
211 |
|
---|
212 | return mFolderLinesPen;
|
---|
213 | }
|
---|
214 | }
|
---|
215 | /// <summary>
|
---|
216 | /// Gets or sets the connection pen.
|
---|
217 | /// </summary>
|
---|
218 | /// <value>The connection pen.</value>
|
---|
219 | public static Pen ConnectionPen {
|
---|
220 | get {
|
---|
221 | return mConnectionPen;
|
---|
222 | }
|
---|
223 | set {
|
---|
224 | mConnectionPen = value;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | /// <summary>
|
---|
228 | /// Gets or sets the pen used to paint the highlighted connection.
|
---|
229 | /// </summary>
|
---|
230 | /// <value>The connection highlight pen.</value>
|
---|
231 | public static Pen ConnectionHighlightPen {
|
---|
232 | get {
|
---|
233 | return mConnectionHighlightPen;
|
---|
234 | }
|
---|
235 | set {
|
---|
236 | mConnectionHighlightPen = value;
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | /// <summary>
|
---|
241 | /// Gets or sets the grip brush.
|
---|
242 | /// </summary>
|
---|
243 | /// <value>The grip brush.</value>
|
---|
244 | public static Brush GripBrush {
|
---|
245 | get { return mGripBrush; }
|
---|
246 | set { mGripBrush = value; }
|
---|
247 | }
|
---|
248 |
|
---|
249 | #endregion
|
---|
250 |
|
---|
251 | #region Methods
|
---|
252 | /// <summary>
|
---|
253 | /// Inits the static instance.
|
---|
254 | /// </summary>
|
---|
255 | public static void Init() {
|
---|
256 | mTrackerPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
---|
257 | mBlackPen.LineJoin = LineJoin.Round;
|
---|
258 |
|
---|
259 | //AdjustableArrowCap ccap = new AdjustableArrowCap(5, 7, true);
|
---|
260 | //mConnectionPen.EndCap = LineCap.Custom;
|
---|
261 | //mConnectionPen.CustomEndCap = ccap;
|
---|
262 |
|
---|
263 | //mConnectionHighlightPen.EndCap = LineCap.Custom;
|
---|
264 | //mConnectionHighlightPen.CustomEndCap = ccap;
|
---|
265 |
|
---|
266 | mFolderLinesPen.DashStyle = DashStyle.Dot;
|
---|
267 | }
|
---|
268 | /// <summary>
|
---|
269 | /// Gets or sets the default font to render text on the canvas.
|
---|
270 | /// </summary>
|
---|
271 | /// <value>The font.</value>
|
---|
272 | public static Font DefaultFont {
|
---|
273 | get {
|
---|
274 | return ArtPalette.mDefaultFont;
|
---|
275 | }
|
---|
276 | set {
|
---|
277 | ArtPalette.mDefaultFont = value;
|
---|
278 | }
|
---|
279 | }
|
---|
280 | /// <summary>
|
---|
281 | /// Gets or sets the default bold font to render text on the canvas.
|
---|
282 | /// </summary>
|
---|
283 | /// <value>The font.</value>
|
---|
284 | public static Font DefaultBoldFont {
|
---|
285 | get {
|
---|
286 | return ArtPalette.mDefaultBoldFont;
|
---|
287 | }
|
---|
288 | set {
|
---|
289 | ArtPalette.mDefaultBoldFont = value;
|
---|
290 | }
|
---|
291 | }
|
---|
292 | /// <summary>
|
---|
293 | /// Gets the black pen.
|
---|
294 | /// </summary>
|
---|
295 | /// <value>The black pen.</value>
|
---|
296 | public static Pen BlackPen {
|
---|
297 | get {
|
---|
298 | return ArtPalette.mBlackPen;
|
---|
299 | }
|
---|
300 | set {
|
---|
301 | ArtPalette.mBlackPen = value;
|
---|
302 | }
|
---|
303 | }
|
---|
304 | /// <summary>
|
---|
305 | /// Gets the tracker pen.
|
---|
306 | /// </summary>
|
---|
307 | /// <value>The red pen.</value>
|
---|
308 | public static Pen TrackerPen {
|
---|
309 | get {
|
---|
310 | return ArtPalette.mTrackerPen;
|
---|
311 | }
|
---|
312 | set { ArtPalette.mTrackerPen = value; }
|
---|
313 | }
|
---|
314 | /// <summary>
|
---|
315 | /// Gets the red pen.
|
---|
316 | /// </summary>
|
---|
317 | /// <value>The red pen.</value>
|
---|
318 | public static Pen HighlightPen {
|
---|
319 | get {
|
---|
320 | return ArtPalette.mHighlightPen;
|
---|
321 | }
|
---|
322 | set {
|
---|
323 | ArtPalette.mHighlightPen = value;
|
---|
324 | }
|
---|
325 | }
|
---|
326 | /// <summary>
|
---|
327 | /// Gets the shadow brush.
|
---|
328 | /// </summary>
|
---|
329 | /// <value>The shadow brush.</value>
|
---|
330 | public static Brush ShadowBrush {
|
---|
331 | get {
|
---|
332 | return ArtPalette.mShadowBrush;
|
---|
333 | }
|
---|
334 | set {
|
---|
335 | ArtPalette.mShadowBrush = value;
|
---|
336 | }
|
---|
337 | }
|
---|
338 | /// <summary>
|
---|
339 | /// Gets the shadow pen to paint the shadow of the connections.
|
---|
340 | /// </summary>
|
---|
341 | /// <value>The shadow pen.</value>
|
---|
342 | public static Pen ConnectionShadow {
|
---|
343 | get {
|
---|
344 | return ArtPalette.mShadowPen;
|
---|
345 | }
|
---|
346 | set {
|
---|
347 | ArtPalette.mShadowPen = value;
|
---|
348 | }
|
---|
349 | }
|
---|
350 | /// <summary>
|
---|
351 | /// Gets a random color from the whole available color spectrum.
|
---|
352 | /// </summary>
|
---|
353 | /// <value>The random color.</value>
|
---|
354 | ///<example file="ArtPallet.RandomColor.xml">
|
---|
355 | ///
|
---|
356 | ///
|
---|
357 | /// wdfgsdfgsdfs
|
---|
358 | ///</example>
|
---|
359 | public static Color RandomColor {
|
---|
360 | get {
|
---|
361 | return Color.FromArgb(rnd.Next(10, 250), rnd.Next(10, 250), rnd.Next(10, 250));
|
---|
362 | }
|
---|
363 | }
|
---|
364 | /// <summary>
|
---|
365 | /// Gets a random blue color.
|
---|
366 | /// <remarks>You can generate any variation of a certain color range by specifying the HSV range and a utility function will convert it to
|
---|
367 | /// an RGB value (<see cref="Utils.HSL2RGB"/>).
|
---|
368 | /// </remarks>
|
---|
369 | /// </summary>
|
---|
370 | /// <value>The random blues.</value>
|
---|
371 | public static Color RandomBlues {
|
---|
372 | get {
|
---|
373 | return (Color)Utils.HSL2RGB(
|
---|
374 | (rnd.NextDouble() * 20D + 150D) / 255D,
|
---|
375 | (rnd.NextDouble() * 150D + 100D) / 255D,
|
---|
376 | (rnd.NextDouble() * 50D + 150D) / 255D);
|
---|
377 | }
|
---|
378 | }
|
---|
379 | /// <summary>
|
---|
380 | /// Gets a random low saturation color.
|
---|
381 | /// </summary>
|
---|
382 | /// <value>The random color.</value>
|
---|
383 | public static Color RandomLowSaturationColor {
|
---|
384 | get {
|
---|
385 | return (Color)Utils.HSL2RGB(
|
---|
386 | (rnd.NextDouble() * 255D) / 255D,
|
---|
387 | (rnd.NextDouble() * 20D + 30D) / 255D,
|
---|
388 | (rnd.NextDouble() * 20D + 130D) / 255D);
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | /// <summary>
|
---|
393 | /// Gets the solid brush.
|
---|
394 | /// </summary>
|
---|
395 | /// <param name="color">The color.</param>
|
---|
396 | /// <param name="alpha">The alpha.</param>
|
---|
397 | /// <returns></returns>
|
---|
398 | public static Brush GetSolidBrush(Color color, int alpha) {
|
---|
399 | return new SolidBrush(Color.FromArgb(alpha, color));
|
---|
400 | }
|
---|
401 |
|
---|
402 | /// <summary>
|
---|
403 | /// Gets the gradient brush.
|
---|
404 | /// </summary>
|
---|
405 | /// <param name="startColor">The start color.</param>
|
---|
406 | /// <param name="endColor">The end color.</param>
|
---|
407 | /// <param name="rectangle">The rectangle.</param>
|
---|
408 | /// <param name="angle">The angle.</param>
|
---|
409 | /// <returns></returns>
|
---|
410 | public static Brush GetGradientBrush(Color startColor, Color endColor, Rectangle rectangle, float angle) {
|
---|
411 | return new LinearGradientBrush(rectangle, startColor, endColor, angle);
|
---|
412 | }
|
---|
413 |
|
---|
414 | /// <summary>
|
---|
415 | /// Gets the default solid <see cref="IPaintStyle"/>.
|
---|
416 | /// </summary>
|
---|
417 | /// <returns></returns>
|
---|
418 | public static IPaintStyle GetDefaultSolidPaintStyle() {
|
---|
419 | return new SolidPaintStyle(ArtPalette.RandomLowSaturationColor);
|
---|
420 | }
|
---|
421 | /// <summary>
|
---|
422 | /// Gets the default gradient <see cref="IPaintStyle"/>.
|
---|
423 | /// </summary>
|
---|
424 | /// <returns></returns>
|
---|
425 | public static IPaintStyle GetDefaultGradientPaintStyle() {
|
---|
426 | return new GradientPaintStyle();
|
---|
427 | }
|
---|
428 | /// <summary>
|
---|
429 | /// Gets the transparent <see cref="IPaintStyle"/>.
|
---|
430 | /// </summary>
|
---|
431 | /// <returns></returns>
|
---|
432 | public static IPaintStyle GetTransparentPaintStyle() {
|
---|
433 | return mTransparentPaintStyle;
|
---|
434 | }
|
---|
435 |
|
---|
436 | /// <summary>
|
---|
437 | /// Returns the default paint style for the whole control.
|
---|
438 | /// </summary>
|
---|
439 | /// <returns></returns>
|
---|
440 | public static IPaintStyle GetDefaultPaintStyle() {
|
---|
441 | return GetDefaultGradientPaintStyle();
|
---|
442 | }
|
---|
443 |
|
---|
444 | /// <summary>
|
---|
445 | /// Gets the default <see cref="IPenStyle"/>.
|
---|
446 | /// </summary>
|
---|
447 | /// <returns></returns>
|
---|
448 | public static IPenStyle GetDefaultPenStyle() {
|
---|
449 | return new PenStyle(); //this returns a black, standard pen.
|
---|
450 | }
|
---|
451 |
|
---|
452 | /// <summary>
|
---|
453 | /// The <see cref="IPenStyle"/> used when the ConnectorStyle is
|
---|
454 | /// 'Simple'.
|
---|
455 | /// </summary>
|
---|
456 | /// <returns></returns>
|
---|
457 | public static IPenStyle GetSimpleConnectorPenStyle() {
|
---|
458 | LinePenStyle penStyle = new LinePenStyle();
|
---|
459 | penStyle.DashStyle = DashStyle.Solid;
|
---|
460 | penStyle.Color = Color.Blue;
|
---|
461 | return penStyle;
|
---|
462 | }
|
---|
463 |
|
---|
464 | /// <summary>
|
---|
465 | /// Returns the <see cref="IPaintStyle"/> used when the
|
---|
466 | /// ConnectorStyle is 'Simple'.
|
---|
467 | /// </summary>
|
---|
468 | /// <returns></returns>
|
---|
469 | public static IPaintStyle GetSimpleConnectorPaintStyle() {
|
---|
470 | return new SolidPaintStyle(Color.Transparent);
|
---|
471 | }
|
---|
472 |
|
---|
473 | #endregion
|
---|
474 |
|
---|
475 | }
|
---|
476 |
|
---|
477 | }
|
---|