PageRenderTime 47ms CodeModel.GetById 19ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdipluscolor.d

http://github.com/wilkie/djehuty
D | 307 lines | 231 code | 37 blank | 39 comment | 0 complexity | 975185ea9adae65b01449bf4a804de3d MD5 | raw file
  1/*
  2 * gdicolorplus.d
  3 *
  4 * This module binds GdiPlusColor.h to D. The original copyright notice
  5 * is preserved below.
  6 *
  7 * Author: Dave Wilkinson
  8 * Originated: November 25th, 2009
  9 *
 10 */
 11
 12module binding.win32.gdicolorplus;
 13
 14import binding.win32.windef;
 15import binding.win32.winbase;
 16import binding.win32.winnt;
 17import binding.win32.wingdi;
 18
 19import binding.win32.gdiplustypes;
 20import binding.win32.gdipluspixelformats;
 21
 22/**************************************************************************\
 23*
 24* Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
 25*
 26* Module Name:
 27*
 28*   GdiplusColor.h
 29*
 30* Abstract:
 31*
 32*   GDI+ Color Object
 33*
 34\**************************************************************************/
 35
 36extern(System):
 37
 38//----------------------------------------------------------------------------
 39// Color mode
 40//----------------------------------------------------------------------------
 41
 42enum ColorMode {
 43    ColorModeARGB32 = 0,
 44    ColorModeARGB64 = 1
 45}
 46
 47//----------------------------------------------------------------------------
 48// Color Channel flags
 49//----------------------------------------------------------------------------
 50
 51enum ColorChannelFlags {
 52    ColorChannelFlagsC = 0,
 53    ColorChannelFlagsM,
 54    ColorChannelFlagsY,
 55    ColorChannelFlagsK,
 56    ColorChannelFlagsLast
 57}
 58
 59//----------------------------------------------------------------------------
 60// Color
 61//----------------------------------------------------------------------------
 62
 63class Color {
 64
 65    // Construct an opaque Color object with
 66    // the specified Red, Green, Blue values.
 67    //
 68    // Color values are not premultiplied.
 69
 70	this() {
 71	}
 72
 73    this(in BYTE r, in BYTE g, in BYTE b) {
 74        this(MakeARGB(255, r, g, b));
 75    }
 76
 77    this(in BYTE a, in BYTE r, in BYTE g, in BYTE b) {
 78        this(MakeARGB(a, r, g, b));
 79    }
 80
 81    this(in ARGB argb) {
 82        Argb = argb;        
 83    }
 84
 85    BYTE GetAlpha() {
 86        return cast(BYTE) (Argb >> AlphaShift);
 87    }
 88
 89    BYTE GetA() {
 90        return GetAlpha();
 91    }
 92
 93    BYTE GetRed() {
 94        return cast(BYTE) (Argb >> RedShift);
 95    }
 96
 97    BYTE GetR() {
 98        return GetRed();
 99    }
100
101    BYTE GetGreen() {
102        return cast(BYTE) (Argb >> GreenShift);
103    }
104
105    BYTE GetG() {
106        return GetGreen();
107    }
108
109    BYTE GetBlue() {
110        return cast(BYTE) (Argb >> BlueShift);
111    }
112
113    BYTE GetB() {
114        return GetBlue();
115    }
116
117    ARGB GetValue() {
118        return Argb;
119    }
120
121    VOID SetValue(in ARGB argb) {
122        Argb = argb;
123    }
124
125    VOID SetFromCOLORREF(in COLORREF rgb) {
126        Argb = MakeARGB(255, GetRValue(rgb), GetGValue(rgb), GetBValue(rgb));
127    }
128
129    COLORREF ToCOLORREF() {
130    	return (cast(COLORREF)((cast(BYTE)(GetRed())|(cast(WORD)(cast(BYTE)(GetGreen()))<<8))|((cast(DWORD)cast(BYTE)(GetBlue()))<<16)));
131    }
132
133    // Common color constants
134
135    enum : ARGB {
136        AliceBlue            = 0xFFF0F8FF,
137        AntiqueWhite         = 0xFFFAEBD7,
138        Aqua                 = 0xFF00FFFF,
139        Aquamarine           = 0xFF7FFFD4,
140        Azure                = 0xFFF0FFFF,
141        Beige                = 0xFFF5F5DC,
142        Bisque               = 0xFFFFE4C4,
143        Black                = 0xFF000000,
144        BlanchedAlmond       = 0xFFFFEBCD,
145        Blue                 = 0xFF0000FF,
146        BlueViolet           = 0xFF8A2BE2,
147        Brown                = 0xFFA52A2A,
148        BurlyWood            = 0xFFDEB887,
149        CadetBlue            = 0xFF5F9EA0,
150        Chartreuse           = 0xFF7FFF00,
151        Chocolate            = 0xFFD2691E,
152        Coral                = 0xFFFF7F50,
153        CornflowerBlue       = 0xFF6495ED,
154        Cornsilk             = 0xFFFFF8DC,
155        Crimson              = 0xFFDC143C,
156        Cyan                 = 0xFF00FFFF,
157        DarkBlue             = 0xFF00008B,
158        DarkCyan             = 0xFF008B8B,
159        DarkGoldenrod        = 0xFFB8860B,
160        DarkGray             = 0xFFA9A9A9,
161        DarkGreen            = 0xFF006400,
162        DarkKhaki            = 0xFFBDB76B,
163        DarkMagenta          = 0xFF8B008B,
164        DarkOliveGreen       = 0xFF556B2F,
165        DarkOrange           = 0xFFFF8C00,
166        DarkOrchid           = 0xFF9932CC,
167        DarkRed              = 0xFF8B0000,
168        DarkSalmon           = 0xFFE9967A,
169        DarkSeaGreen         = 0xFF8FBC8B,
170        DarkSlateBlue        = 0xFF483D8B,
171        DarkSlateGray        = 0xFF2F4F4F,
172        DarkTurquoise        = 0xFF00CED1,
173        DarkViolet           = 0xFF9400D3,
174        DeepPink             = 0xFFFF1493,
175        DeepSkyBlue          = 0xFF00BFFF,
176        DimGray              = 0xFF696969,
177        DodgerBlue           = 0xFF1E90FF,
178        Firebrick            = 0xFFB22222,
179        FloralWhite          = 0xFFFFFAF0,
180        ForestGreen          = 0xFF228B22,
181        Fuchsia              = 0xFFFF00FF,
182        Gainsboro            = 0xFFDCDCDC,
183        GhostWhite           = 0xFFF8F8FF,
184        Gold                 = 0xFFFFD700,
185        Goldenrod            = 0xFFDAA520,
186        Gray                 = 0xFF808080,
187        Green                = 0xFF008000,
188        GreenYellow          = 0xFFADFF2F,
189        Honeydew             = 0xFFF0FFF0,
190        HotPink              = 0xFFFF69B4,
191        IndianRed            = 0xFFCD5C5C,
192        Indigo               = 0xFF4B0082,
193        Ivory                = 0xFFFFFFF0,
194        Khaki                = 0xFFF0E68C,
195        Lavender             = 0xFFE6E6FA,
196        LavenderBlush        = 0xFFFFF0F5,
197        LawnGreen            = 0xFF7CFC00,
198        LemonChiffon         = 0xFFFFFACD,
199        LightBlue            = 0xFFADD8E6,
200        LightCoral           = 0xFFF08080,
201        LightCyan            = 0xFFE0FFFF,
202        LightGoldenrodYellow = 0xFFFAFAD2,
203        LightGray            = 0xFFD3D3D3,
204        LightGreen           = 0xFF90EE90,
205        LightPink            = 0xFFFFB6C1,
206        LightSalmon          = 0xFFFFA07A,
207        LightSeaGreen        = 0xFF20B2AA,
208        LightSkyBlue         = 0xFF87CEFA,
209        LightSlateGray       = 0xFF778899,
210        LightSteelBlue       = 0xFFB0C4DE,
211        LightYellow          = 0xFFFFFFE0,
212        Lime                 = 0xFF00FF00,
213        LimeGreen            = 0xFF32CD32,
214        Linen                = 0xFFFAF0E6,
215        Magenta              = 0xFFFF00FF,
216        Maroon               = 0xFF800000,
217        MediumAquamarine     = 0xFF66CDAA,
218        MediumBlue           = 0xFF0000CD,
219        MediumOrchid         = 0xFFBA55D3,
220        MediumPurple         = 0xFF9370DB,
221        MediumSeaGreen       = 0xFF3CB371,
222        MediumSlateBlue      = 0xFF7B68EE,
223        MediumSpringGreen    = 0xFF00FA9A,
224        MediumTurquoise      = 0xFF48D1CC,
225        MediumVioletRed      = 0xFFC71585,
226        MidnightBlue         = 0xFF191970,
227        MintCream            = 0xFFF5FFFA,
228        MistyRose            = 0xFFFFE4E1,
229        Moccasin             = 0xFFFFE4B5,
230        NavajoWhite          = 0xFFFFDEAD,
231        Navy                 = 0xFF000080,
232        OldLace              = 0xFFFDF5E6,
233        Olive                = 0xFF808000,
234        OliveDrab            = 0xFF6B8E23,
235        Orange               = 0xFFFFA500,
236        OrangeRed            = 0xFFFF4500,
237        Orchid               = 0xFFDA70D6,
238        PaleGoldenrod        = 0xFFEEE8AA,
239        PaleGreen            = 0xFF98FB98,
240        PaleTurquoise        = 0xFFAFEEEE,
241        PaleVioletRed        = 0xFFDB7093,
242        PapayaWhip           = 0xFFFFEFD5,
243        PeachPuff            = 0xFFFFDAB9,
244        Peru                 = 0xFFCD853F,
245        Pink                 = 0xFFFFC0CB,
246        Plum                 = 0xFFDDA0DD,
247        PowderBlue           = 0xFFB0E0E6,
248        Purple               = 0xFF800080,
249        Red                  = 0xFFFF0000,
250        RosyBrown            = 0xFFBC8F8F,
251        RoyalBlue            = 0xFF4169E1,
252        SaddleBrown          = 0xFF8B4513,
253        Salmon               = 0xFFFA8072,
254        SandyBrown           = 0xFFF4A460,
255        SeaGreen             = 0xFF2E8B57,
256        SeaShell             = 0xFFFFF5EE,
257        Sienna               = 0xFFA0522D,
258        Silver               = 0xFFC0C0C0,
259        SkyBlue              = 0xFF87CEEB,
260        SlateBlue            = 0xFF6A5ACD,
261        SlateGray            = 0xFF708090,
262        Snow                 = 0xFFFFFAFA,
263        SpringGreen          = 0xFF00FF7F,
264        SteelBlue            = 0xFF4682B4,
265        Tan                  = 0xFFD2B48C,
266        Teal                 = 0xFF008080,
267        Thistle              = 0xFFD8BFD8,
268        Tomato               = 0xFFFF6347,
269        Transparent          = 0x00FFFFFF,
270        Turquoise            = 0xFF40E0D0,
271        Violet               = 0xFFEE82EE,
272        Wheat                = 0xFFF5DEB3,
273        White                = 0xFFFFFFFF,
274        WhiteSmoke           = 0xFFF5F5F5,
275        Yellow               = 0xFFFFFF00,
276        YellowGreen          = 0xFF9ACD32
277    }
278
279    // Shift count and bit mask for A, R, G, B components
280
281    enum {
282        AlphaShift  = 24,
283        RedShift    = 16,
284        GreenShift  = 8,
285        BlueShift   = 0
286    }
287
288    enum {
289        AlphaMask   = 0xff000000,
290        RedMask     = 0x00ff0000,
291        GreenMask   = 0x0000ff00,
292        BlueMask    = 0x000000ff
293    }
294
295    // Assemble A, R, G, B values into a 32-bit integer
296
297    static ARGB MakeARGB(in BYTE a, in BYTE r, in BYTE g, in BYTE b) {
298        return ((cast(ARGB) (b) <<  BlueShift) |
299                (cast(ARGB) (g) << GreenShift) |
300                (cast(ARGB) (r) <<   RedShift) |
301                (cast(ARGB) (a) << AlphaShift));
302    }
303
304protected:
305
306    ARGB Argb = Black;
307}