- Signature fixes
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ControlPaint.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25 //
26 // $Log: ControlPaint.cs,v $
27 // Revision 1.3  2004/08/11 22:20:59  pbartok
28 // - Signature fixes
29 //
30 // Revision 1.2  2004/07/26 17:42:03  jordi
31 // Theme support
32 //
33 // Revision 1.1  2004/07/09 05:21:25  pbartok
34 // - Initial check-in
35 //
36 //
37
38 // NOT COMPLETE
39
40 using System.Drawing;
41 using System.Drawing.Drawing2D;
42 using System.Drawing.Imaging;
43
44 namespace System.Windows.Forms {
45         public sealed class ControlPaint {
46                 #region Local Variables
47                 static int              RGBMax=255;
48                 static int              HLSMax=255;
49                 #endregion      // Local Variables
50
51                 #region Private Enumerations
52
53
54                 #region Constructor
55                 // Prevent a public constructor from being created
56                 private ControlPaint() {
57                 }
58                 #endregion      // Constructor
59
60
61                 #endregion      // Private Enumerations
62
63                 #region Helpers
64                 private static Color Win32ToColor(int Win32Color) {
65                         return(Color.FromArgb(
66                                 (int)(Win32Color) & 0xff0000 >> 16,             // blue
67                                 (int)(Win32Color) & 0xff00 >> 8,                // green
68                                 (int)(Win32Color) & 0xff                        // red
69                         ));
70                 }
71
72                 internal static void Color2HBS(Color color, out int h, out int l, out int s) {
73                         int     r;
74                         int     g;
75                         int     b;
76                         int     cMax;
77                         int     cMin;
78                         int     rDelta;
79                         int     gDelta;
80                         int     bDelta;
81
82                         r=color.R;
83                         g=color.G;
84                         b=color.B;
85
86                         cMax = Math.Max(Math.Max(r, g), b);
87                         cMin = Math.Min(Math.Min(r, g), b);
88
89                         l = (((cMax+cMin)*HLSMax)+RGBMax)/(2*RGBMax);
90
91                         if (cMax==cMin) {               // Achromatic
92                                 h=0;                                    // h undefined
93                                 s=0;
94                                 l=r;
95                                 return;
96                         }
97
98                         /* saturation */
99                         if (l<=(HLSMax/2)) {
100                                 s=(((cMax-cMin)*HLSMax)+((cMax+cMin)/2))/(cMax+cMin);
101                         } else {
102                                 s=(((cMax-cMin)*HLSMax)+((2*RGBMax-cMax-cMin)/2))/(2*RGBMax-cMax-cMin);
103                         }
104
105                         /* hue */
106                         rDelta=(((cMax-r)*(HLSMax/6))+((cMax-cMin)/2))/(cMax-cMin);
107                         gDelta=(((cMax-g)*(HLSMax/6))+((cMax-cMin)/2))/(cMax-cMin);
108                         bDelta=(((cMax-b)*(HLSMax/6))+((cMax-cMin)/2))/(cMax-cMin);
109
110                         if (r == cMax) {
111                                 h=bDelta - gDelta;
112                         } else if (g == cMax) {
113                                 h=(HLSMax/3) + rDelta - bDelta;
114                         } else { /* B == cMax */
115                                 h=((2*HLSMax)/3) + gDelta - rDelta;
116                         }
117
118                         if (h<0) {
119                                 h+=HLSMax;
120                         }
121
122                         if (h>HLSMax) {
123                                 h-=HLSMax;
124                         }
125                 }
126
127                 private static int HueToRGB(int n1, int n2, int hue) {
128                         if (hue<0) {
129                                 hue+=HLSMax;
130                         }
131
132                         if (hue>HLSMax) {
133                                 hue -= HLSMax;
134                         }
135
136                         /* return r,g, or b value from this tridrant */
137                         if (hue<(HLSMax/6)) {
138                                 return(n1+(((n2-n1)*hue+(HLSMax/12))/(HLSMax/6)));
139                         }
140
141                         if (hue<(HLSMax/2)) {
142                                 return(n2);
143                         }
144
145                         if (hue<((HLSMax*2)/3)) {
146                                 return(n1+(((n2-n1)*(((HLSMax*2)/3)-hue)+(HLSMax/12))/(HLSMax/6)));
147                         } else {
148                                 return(n1);
149                         }
150                 }
151
152                 internal static Color HBS2Color(int hue, int lum, int sat) {
153                         int     R;
154                         int     G;
155                         int     B;
156                         int     Magic1;
157                         int     Magic2;
158
159                         if (sat == 0) {            /* Achromatic */
160                                 R=G=B=(lum*RGBMax)/HLSMax;
161                                 // FIXME : Should throw exception if hue!=0
162                         } else {
163                                 if (lum<=(HLSMax/2)) {
164                                         Magic2=(lum*(HLSMax+sat)+(HLSMax/2))/HLSMax;
165                                 } else {
166                                         Magic2=sat+lum-((sat*lum)+(HLSMax/2))/HLSMax;
167                                 }
168                                 Magic1=2*lum-Magic2;
169
170                                 R = Math.Min(255, (HueToRGB(Magic1,Magic2,hue+(HLSMax/3))*RGBMax+(HLSMax/2))/HLSMax);
171                                 G = Math.Min(255, (HueToRGB(Magic1,Magic2,hue)*RGBMax+(HLSMax/2))/HLSMax);
172                                 B = Math.Min(255, (HueToRGB(Magic1,Magic2,hue-(HLSMax/3))*RGBMax+(HLSMax/2))/HLSMax);
173                         }
174                         return(Color.FromArgb(R, G, B));
175                 }
176                 #endregion      // Helpers
177
178                 #region Public Static Properties
179                 public static Color ContrastControlDark {
180                         get { return(SystemColors.ControlDark); }
181                 }
182                 #endregion      // Public Static Properties
183
184                 #region Public Static Methods
185                 public static IntPtr CreateHBitmap16Bit(Bitmap bitmap, Color background){
186                         throw new NotImplementedException ();
187                 }
188
189                 public static IntPtr CreateHBitmapColorMask(Bitmap bitmap, IntPtr monochromeMask){
190                         throw new NotImplementedException ();
191                 }
192
193                 public static IntPtr CreateHBitmapTransparencyMask(Bitmap bitmap){
194                         throw new NotImplementedException ();
195                 }
196
197                 public static Color Light(Color baseColor) {
198                         return Light( baseColor, 10.0f);
199                 }
200
201                 public static Color Light(Color baseColor,float percOfLightLight) {
202                         int H, I, S;
203
204                         ControlPaint.Color2HBS(baseColor, out H, out I, out S);
205                         int NewIntensity = Math.Min( 255, I + ((255*(int)percOfLightLight)/100));
206                         return ControlPaint.HBS2Color(H, NewIntensity, S);
207                 }
208
209                 public static Color LightLight(Color baseColor) {
210                         return Light( baseColor, 20.0f);
211                 }
212
213                 public static Color Dark(Color baseColor) {
214                         return Dark(baseColor, 10.0f);
215                 }
216
217                 public static Color Dark(Color baseColor,float percOfDarkDark) {
218                         int H, I, S;
219                         ControlPaint.Color2HBS(baseColor, out H, out I, out S);
220                         int NewIntensity = Math.Max(0, I - ((255*(int)percOfDarkDark) / 100));
221                         return ControlPaint.HBS2Color(H, NewIntensity, S);
222                 }
223
224                 public static Color DarkDark(Color baseColor) {
225                         return Dark(baseColor, 20.0f);
226                 }
227
228                 public static void DrawBorder(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style) {
229                         DrawBorder(graphics, bounds, color, 1, style, color, 1, style, color, 1, style, color, 1, style);
230                 }
231
232                 public static void DrawBorder( Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
233                         ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
234                         Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor, int bottomWidth,
235                         ButtonBorderStyle bottomStyle) {
236
237                         ThemeEngine.Current.DrawBorder (graphics, bounds, leftColor, leftWidth,
238                                 leftStyle, topColor, topWidth, topStyle, rightColor, rightWidth, rightStyle,
239                                 bottomColor, bottomWidth, bottomStyle);
240                 }
241
242
243                 public static void DrawBorder3D(Graphics graphics, Rectangle rectangle) {
244                         DrawBorder3D(graphics, rectangle, Border3DStyle.Etched, Border3DSide.All);
245                 }
246
247                 public static void DrawBorder3D(Graphics graphics, Rectangle rectangle, Border3DStyle style) {
248                         DrawBorder3D(graphics, rectangle, style, Border3DSide.All);
249                 }
250
251                 public static void DrawBorder3D(Graphics graphics, int x, int y, int width, int height) {
252                         DrawBorder3D(graphics, new Rectangle(x, y, width, height), Border3DStyle.Etched, Border3DSide.All);
253                 }
254
255                 public static void DrawBorder3D(Graphics graphics, int x, int y, int width, int height, Border3DStyle style) {
256                         DrawBorder3D(graphics, new Rectangle(x, y, width, height), style, Border3DSide.All);
257                 }
258
259                 public static void DrawBorder3D( Graphics graphics, int x, int y, int width, int height, Border3DStyle style,Border3DSide sides) {
260                         DrawBorder3D( graphics, new Rectangle(x, y, width, height), style, sides);
261                 }
262
263                 public static void DrawBorder3D( Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
264
265                         ThemeEngine.Current.DrawBorder3D (graphics, rectangle, style, sides);
266                 }
267
268                 public static void DrawButton( Graphics graphics, int x, int y, int width, int height, ButtonState state) {
269                         DrawButton(graphics, new Rectangle(x, y, width, height), state);
270                 }
271
272                 public static void DrawButton( Graphics graphics, Rectangle rectangle, ButtonState state) {
273
274                         ThemeEngine.Current.DrawButton (graphics, rectangle, state);
275                 }
276
277
278                 public static void DrawCaptionButton(Graphics graphics, int x, int y, int width, int height, CaptionButton button, ButtonState state) {
279                         DrawCaptionButton(graphics, new Rectangle(x, y, width, height), button, state);
280                 }
281
282                 public static void DrawCaptionButton(Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
283
284                         ThemeEngine.Current.DrawCaptionButton (graphics, rectangle, button, state);
285                 }
286
287                 public static void DrawCheckBox(Graphics graphics, int x, int y, int width, int height, ButtonState state) {
288                         DrawCheckBox(graphics, new Rectangle(x, y, width, height), state);
289                 }
290
291                 public static void DrawCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state) {
292
293                         ThemeEngine.Current.DrawCheckBox (graphics, rectangle, state);
294                 }
295
296                 public static void DrawComboButton(Graphics graphics, Rectangle rectangle, ButtonState state) {
297
298                         ThemeEngine.Current.DrawComboButton (graphics, rectangle,  state);
299                 }
300
301                 public static void DrawComboButton(Graphics graphics, int x, int y, int width, int height, ButtonState state) {
302                         DrawComboButton(graphics, new Rectangle(x, y, width, height), state);
303                 }
304
305                 public static void DrawContainerGrabHandle(Graphics graphics, Rectangle bounds) {
306
307                         ThemeEngine.Current.DrawContainerGrabHandle (graphics, bounds);
308                 }
309
310                 public static void DrawFocusRectangle( Graphics graphics, Rectangle rectangle) {
311                         DrawFocusRectangle(graphics, rectangle, Color.White, Color.Black);
312                 }
313
314                 public static void DrawFocusRectangle( Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) {
315
316                         ThemeEngine.Current.DrawFocusRectangle (graphics, rectangle, foreColor, backColor);
317                 }
318
319                 public static void DrawGrabHandle(Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
320
321                         ThemeEngine.Current.DrawGrabHandle (graphics, rectangle, primary, enabled);
322                 }
323
324                 public static void DrawGrid(Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
325
326                         ThemeEngine.Current.DrawGrid (graphics, area, pixelsBetweenDots, backColor);
327                 }
328
329                 public static void DrawImageDisabled(Graphics graphics, Image image, int x, int y, Color background) {
330
331                         ThemeEngine.Current.DrawImageDisabled (graphics, image, x, y, background);
332                 }
333
334                 public static void DrawLockedFrame(Graphics graphics, Rectangle rectangle, bool primary) {
335
336                         ThemeEngine.Current.DrawLockedFrame (graphics, rectangle, primary);
337                 }
338
339                 public static void DrawMenuGlyph(Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
340
341                         ThemeEngine.Current.DrawMenuGlyph (graphics, rectangle, glyph);
342                 }
343
344                 public static void DrawMenuGlyph(Graphics graphics, int x, int y, int width, int height, MenuGlyph glyph) {
345                         DrawMenuGlyph(graphics, new Rectangle(x, y, width, height), glyph);
346                 }
347
348                 public static void DrawMixedCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state) {
349                         DrawCheckBox(graphics, rectangle, state);
350                 }
351
352                 public static void DrawMixedCheckBox(Graphics graphics, int x, int y, int width, int height, ButtonState state) {
353                         DrawMixedCheckBox(graphics, new Rectangle(x, y, width, height), state);
354                 }
355
356
357                 public static void DrawRadioButton(Graphics graphics, int x, int y, int width, int height, ButtonState state) {
358                         DrawRadioButton(graphics, new Rectangle(x, y, width, height), state);
359                 }
360
361                 public static void DrawRadioButton(Graphics graphics, Rectangle rectangle, ButtonState state) {
362
363                         ThemeEngine.Current.DrawRadioButton (graphics, rectangle, state);
364                 }
365
366                 [MonoTODO("Figure out a good System.Drawing way for XOR drawing")]
367                 public static void DrawReversibleFrame(Rectangle rectangle, Color backColor, FrameStyle style) {
368                         throw new NotImplementedException();
369                 }
370
371                 [MonoTODO("Figure out a good System.Drawing way for XOR drawing")]
372                 public static void DrawReversibleLine(Point start, Point end, Color backColor) {
373                         throw new NotImplementedException();
374                 }
375
376                 [MonoTODO("Figure out a good System.Drawing way for XOR drawing")]
377                 public static void FillReversibleRectangle(Rectangle rectangle, Color backColor) {
378                         throw new NotImplementedException();
379                 }
380
381
382                 public static void DrawScrollButton (Graphics graphics, int x, int y, int width, int height, ScrollButton button, ButtonState state) {
383                         ThemeEngine.Current.DrawScrollButton (graphics, new Rectangle(x, y, width, height), button, state);
384                 }
385
386                 public static void DrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state) {
387                         ThemeEngine.Current.DrawScrollButton (graphics, rectangle, button, state);
388                 }
389
390                 [MonoTODO]
391                 public static void DrawSelectionFrame(Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect, Color backColor) {
392                         throw new NotImplementedException();
393                 }
394
395                 public static void DrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds)
396                 {
397                         ThemeEngine.Current.DrawSizeGrip (graphics,  backColor,  bounds);
398                 }
399
400                 public static void DrawSizeGrip(Graphics graphics, Color backColor, int x, int y, int width, int height) {
401                         DrawSizeGrip(graphics, backColor, new Rectangle(x, y, width, height));
402                 }
403
404                 public static void DrawStringDisabled(Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format) {
405
406                         ThemeEngine.Current.DrawStringDisabled (graphics, s, font, color, layoutRectangle, format);
407                 }
408                 #endregion      // Public Static Methods
409         }
410 }