1 | ' Classes/System/Drawing/Color.ab
|
---|
2 |
|
---|
3 | #ifndef __SYSTEM_DRAWING_COLOR_AB__
|
---|
4 | #define __SYSTEM_DRAWING_COLOR_AB__
|
---|
5 |
|
---|
6 | #include <GdiplusTypes.ab>
|
---|
7 | #include <Classes/System/Math.ab>
|
---|
8 | #include <Classes/System/Drawing/Imaging/misc.ab>
|
---|
9 |
|
---|
10 | Namespace System
|
---|
11 | Namespace Drawing
|
---|
12 |
|
---|
13 | Class Color
|
---|
14 | Public
|
---|
15 | Sub Color()
|
---|
16 | argb = MakeARGB(255, 0, 0, 0) 'Black
|
---|
17 | End Sub
|
---|
18 |
|
---|
19 | Sub Color(r As Byte, g As Byte, b As Byte)
|
---|
20 | argb = MakeARGB(255, r, g, b)
|
---|
21 | End Sub
|
---|
22 |
|
---|
23 | Sub Color(a As Byte, r As Byte, g As Byte, b As Byte)
|
---|
24 | argb = MakeARGB(a, r, g, b)
|
---|
25 | End Sub
|
---|
26 |
|
---|
27 | Sub Color(newArgb As Gdiplus.ARGB)
|
---|
28 | argb = newArgb
|
---|
29 | End Sub
|
---|
30 |
|
---|
31 | Function Operator ==(c As Color) As Boolean
|
---|
32 | Return Equals(c)
|
---|
33 | End Function
|
---|
34 |
|
---|
35 | Function Operator <>(c As Color) As Boolean
|
---|
36 | Return Not Equals(c)
|
---|
37 | End Function
|
---|
38 |
|
---|
39 | Function A() As Byte
|
---|
40 | Return (argb >> ALPHA_SHIFT) As Byte
|
---|
41 | End Function
|
---|
42 |
|
---|
43 | Function R() As Byte
|
---|
44 | Return (argb >> RED_SHIFT) As Byte
|
---|
45 | End Function
|
---|
46 |
|
---|
47 | Function G() As Byte
|
---|
48 | Return (argb >> GREEN_SHIFT) As Byte
|
---|
49 | End Function
|
---|
50 |
|
---|
51 | Function B() As Byte
|
---|
52 | Return (argb >> BLUE_SHIFT) As Byte
|
---|
53 | End Function
|
---|
54 |
|
---|
55 | Function Value() As Gdiplus.ARGB
|
---|
56 | Return argb
|
---|
57 | End Function
|
---|
58 |
|
---|
59 | Sub Value(value As Gdiplus.ARGB)
|
---|
60 | argb = value
|
---|
61 | End Sub
|
---|
62 |
|
---|
63 | Sub SetFromCOLORREF(rgb As COLORREF)
|
---|
64 | If (rgb And &hff000000) = &h01000000 Then
|
---|
65 | Exit Sub ' パレットインデックス指定は無効
|
---|
66 | Else
|
---|
67 | argb = Color_MakeARGB(255, GetRValue(rgb), GetGValue(rgb), GetBValue(rgb))
|
---|
68 | End If
|
---|
69 | End Sub
|
---|
70 |
|
---|
71 | Function ToCOLORREF() As COLORREF
|
---|
72 | ToCOLORREF = RGB(R, G, B)
|
---|
73 | End Function
|
---|
74 |
|
---|
75 | Function ToArgb() As Gdiplus.ARGB
|
---|
76 | Return argb
|
---|
77 | End Function
|
---|
78 |
|
---|
79 | Static Function FromArgb(argb As Gdiplus.ARGB) As Color
|
---|
80 | Dim c As Color(argb)
|
---|
81 | Rteurn c
|
---|
82 | End Function
|
---|
83 |
|
---|
84 | Static Function FromArgb(a As Byte, base As Color) As Color
|
---|
85 | Dim c As Color(a, base.R, base.G, base.B)
|
---|
86 | Return c
|
---|
87 | End Function
|
---|
88 |
|
---|
89 | Static Function FromArgb(r As Byte, g As Byte, b As Byte) As Color
|
---|
90 | Dim c As Color(r, g, b)
|
---|
91 | Return c
|
---|
92 | End Function
|
---|
93 |
|
---|
94 | Static Function FromArgb(a As Byte, r As Byte, g As Byte, b As Byte) As Color
|
---|
95 | Dim c As Color(a, r, g, b)
|
---|
96 | Return c
|
---|
97 | End Function
|
---|
98 |
|
---|
99 | Override Function GetHashCode() As Long
|
---|
100 | Return argb As Long
|
---|
101 | End Function
|
---|
102 |
|
---|
103 | Function Equals(c As Color) As Boolean
|
---|
104 | Return argb = c.argb
|
---|
105 | End Function
|
---|
106 |
|
---|
107 | ' HSBを求める式はhttp://ofo.jp/osakana/cgtips/hsb.phtmlを参考にしました。
|
---|
108 | Function GetHue() As Single
|
---|
109 | Dim max As Long, min As Long, d As Long
|
---|
110 | max = Math.Max(Math.Max(r, g), b)
|
---|
111 | min = Math.Min(Math.Min(r, g), b)
|
---|
112 | d = max - min
|
---|
113 | If g = max Then
|
---|
114 | Return (b - r) As Double / d * 60 + 120
|
---|
115 | ElseIf b = max Then
|
---|
116 | Return (r - g) As Double / d * 60 + 240
|
---|
117 | ElseIf g < b Then
|
---|
118 | Return (g - b) As Double / d * 60 + 360
|
---|
119 | Else
|
---|
120 | Return (g - b) As Double / d * 60
|
---|
121 | EndIf
|
---|
122 | End Function
|
---|
123 |
|
---|
124 | Function GetSaturation() As Single
|
---|
125 | Dim max As Long, min As Long
|
---|
126 | max = Math.Max(Math.Max(r, g), b)
|
---|
127 | min = Math.Min(Math.Min(r, g), b)
|
---|
128 | Return (max - min) / max
|
---|
129 | End Function
|
---|
130 |
|
---|
131 | Function GetBrightness() As Single
|
---|
132 | Dim max As Long
|
---|
133 | max = Math.Max(Math.Max(r, g), b)
|
---|
134 | Return max * (1 / 255)
|
---|
135 | End Function
|
---|
136 |
|
---|
137 | /*
|
---|
138 | ' Common color constants
|
---|
139 | Const Enum
|
---|
140 | AliceBlue = &hFFF0F8FF
|
---|
141 | AntiqueWhite = &hFFFAEBD7
|
---|
142 | Aqua = &hFF00FFFF
|
---|
143 | Aquamarine = &hFF7FFFD4
|
---|
144 | Azure = &hFFF0FFFF
|
---|
145 | Beige = &hFFF5F5DC
|
---|
146 | Bisque = &hFFFFE4C4
|
---|
147 | Black = &hFF000000
|
---|
148 | BlanchedAlmond = &hFFFFEBCD
|
---|
149 | Blue = &hFF0000FF
|
---|
150 | BlueViolet = &hFF8A2BE2
|
---|
151 | Brown = &hFFA52A2A
|
---|
152 | BurlyWood = &hFFDEB887
|
---|
153 | CadetBlue = &hFF5F9EA0
|
---|
154 | Chartreuse = &hFF7FFF00
|
---|
155 | Chocolate = &hFFD2691E
|
---|
156 | Coral = &hFFFF7F50
|
---|
157 | CornflowerBlue = &hFF6495ED
|
---|
158 | Cornsilk = &hFFFFF8DC
|
---|
159 | Crimson = &hFFDC143C
|
---|
160 | Cyan = &hFF00FFFF
|
---|
161 | DarkBlue = &hFF00008B
|
---|
162 | DarkCyan = &hFF008B8B
|
---|
163 | DarkGoldenrod = &hFFB8860B
|
---|
164 | DarkGray = &hFFA9A9A9
|
---|
165 | DarkGreen = &hFF006400
|
---|
166 | DarkKhaki = &hFFBDB76B
|
---|
167 | DarkMagenta = &hFF8B008B
|
---|
168 | DarkOliveGreen = &hFF556B2F
|
---|
169 | DarkOrange = &hFFFF8C00
|
---|
170 | DarkOrchid = &hFF9932CC
|
---|
171 | DarkRed = &hFF8B0000
|
---|
172 | DarkSalmon = &hFFE9967A
|
---|
173 | DarkSeaGreen = &hFF8FBC8B
|
---|
174 | DarkSlateBlue = &hFF483D8B
|
---|
175 | DarkSlateGray = &hFF2F4F4F
|
---|
176 | DarkTurquoise = &hFF00CED1
|
---|
177 | DarkViolet = &hFF9400D3
|
---|
178 | DeepPink = &hFFFF1493
|
---|
179 | DeepSkyBlue = &hFF00BFFF
|
---|
180 | DimGray = &hFF696969
|
---|
181 | DodgerBlue = &hFF1E90FF
|
---|
182 | Firebrick = &hFFB22222
|
---|
183 | FloralWhite = &hFFFFFAF0
|
---|
184 | ForestGreen = &hFF228B22
|
---|
185 | Fuchsia = &hFFFF00FF
|
---|
186 | Gainsboro = &hFFDCDCDC
|
---|
187 | GhostWhite = &hFFF8F8FF
|
---|
188 | Gold = &hFFFFD700
|
---|
189 | Goldenrod = &hFFDAA520
|
---|
190 | Gray = &hFF808080
|
---|
191 | Green = &hFF008000
|
---|
192 | GreenYellow = &hFFADFF2F
|
---|
193 | Honeydew = &hFFF0FFF0
|
---|
194 | HotPink = &hFFFF69B4
|
---|
195 | IndianRed = &hFFCD5C5C
|
---|
196 | Indigo = &hFF4B0082
|
---|
197 | Ivory = &hFFFFFFF0
|
---|
198 | Khaki = &hFFF0E68C
|
---|
199 | Lavender = &hFFE6E6FA
|
---|
200 | LavenderBlush = &hFFFFF0F5
|
---|
201 | LawnGreen = &hFF7CFC00
|
---|
202 | LemonChiffon = &hFFFFFACD
|
---|
203 | LightBlue = &hFFADD8E6
|
---|
204 | LightCoral = &hFFF08080
|
---|
205 | LightCyan = &hFFE0FFFF
|
---|
206 | LightGoldenrodYellow = &hFFFAFAD2
|
---|
207 | LightGray = &hFFD3D3D3
|
---|
208 | LightGreen = &hFF90EE90
|
---|
209 | LightPink = &hFFFFB6C1
|
---|
210 | LightSalmon = &hFFFFA07A
|
---|
211 | LightSeaGreen = &hFF20B2AA
|
---|
212 | LightSkyBlue = &hFF87CEFA
|
---|
213 | LightSlateGray = &hFF778899
|
---|
214 | LightSteelBlue = &hFFB0C4DE
|
---|
215 | LightYellow = &hFFFFFFE0
|
---|
216 | Lime = &hFF00FF00
|
---|
217 | LimeGreen = &hFF32CD32
|
---|
218 | Linen = &hFFFAF0E6
|
---|
219 | Magenta = &hFFFF00FF
|
---|
220 | Maroon = &hFF800000
|
---|
221 | MediumAquamarine = &hFF66CDAA
|
---|
222 | MediumBlue = &hFF0000CD
|
---|
223 | MediumOrchid = &hFFBA55D3
|
---|
224 | MediumPurple = &hFF9370DB
|
---|
225 | MediumSeaGreen = &hFF3CB371
|
---|
226 | MediumSlateBlue = &hFF7B68EE
|
---|
227 | MediumSpringGreen = &hFF00FA9A
|
---|
228 | MediumTurquoise = &hFF48D1CC
|
---|
229 | MediumVioletRed = &hFFC71585
|
---|
230 | MidnightBlue = &hFF191970
|
---|
231 | MintCream = &hFFF5FFFA
|
---|
232 | MistyRose = &hFFFFE4E1
|
---|
233 | Moccasin = &hFFFFE4B5
|
---|
234 | NavajoWhite = &hFFFFDEAD
|
---|
235 | Navy = &hFF000080
|
---|
236 | OldLace = &hFFFDF5E6
|
---|
237 | Olive = &hFF808000
|
---|
238 | OliveDrab = &hFF6B8E23
|
---|
239 | Orange = &hFFFFA500
|
---|
240 | OrangeRed = &hFFFF4500
|
---|
241 | Orchid = &hFFDA70D6
|
---|
242 | PaleGoldenrod = &hFFEEE8AA
|
---|
243 | PaleGreen = &hFF98FB98
|
---|
244 | PaleTurquoise = &hFFAFEEEE
|
---|
245 | PaleVioletRed = &hFFDB7093
|
---|
246 | PapayaWhip = &hFFFFEFD5
|
---|
247 | PeachPuff = &hFFFFDAB9
|
---|
248 | Peru = &hFFCD853F
|
---|
249 | Pink = &hFFFFC0CB
|
---|
250 | Plum = &hFFDDA0DD
|
---|
251 | PowderBlue = &hFFB0E0E6
|
---|
252 | Purple = &hFF800080
|
---|
253 | Red = &hFFFF0000
|
---|
254 | RosyBrown = &hFFBC8F8F
|
---|
255 | RoyalBlue = &hFF4169E1
|
---|
256 | SaddleBrown = &hFF8B4513
|
---|
257 | Salmon = &hFFFA8072
|
---|
258 | SandyBrown = &hFFF4A460
|
---|
259 | SeaGreen = &hFF2E8B57
|
---|
260 | SeaShell = &hFFFFF5EE
|
---|
261 | Sienna = &hFFA0522D
|
---|
262 | Silver = &hFFC0C0C0
|
---|
263 | SkyBlue = &hFF87CEEB
|
---|
264 | SlateBlue = &hFF6A5ACD
|
---|
265 | SlateGray = &hFF708090
|
---|
266 | Snow = &hFFFFFAFA
|
---|
267 | SpringGreen = &hFF00FF7F
|
---|
268 | SteelBlue = &hFF4682B4
|
---|
269 | Tan = &hFFD2B48C
|
---|
270 | Teal = &hFF008080
|
---|
271 | Thistle = &hFFD8BFD8
|
---|
272 | Tomato = &hFFFF6347
|
---|
273 | Transparent = &h00FFFFFF
|
---|
274 | Turquoise = &hFF40E0D0
|
---|
275 | Violet = &hFFEE82EE
|
---|
276 | Wheat = &hFFF5DEB3
|
---|
277 | White = &hFFFFFFFF
|
---|
278 | WhiteSmoke = &hFFF5F5F5
|
---|
279 | Yellow = &hFFFFFF00
|
---|
280 | YellowGreen = &hFF9ACD32
|
---|
281 | End Enum
|
---|
282 |
|
---|
283 | ' Shift count and bit mask for A, R, G, B components
|
---|
284 |
|
---|
285 | Const Enum
|
---|
286 | AlphaShift = 24
|
---|
287 | RedShift = 16
|
---|
288 | GreenShift = 8
|
---|
289 | BlueShift = 0
|
---|
290 | End Enum
|
---|
291 |
|
---|
292 | Const Enum
|
---|
293 | AlphaMask = &hff000000
|
---|
294 | RedMask = &h00ff0000
|
---|
295 | GreenMask = &h0000ff00
|
---|
296 | BlueMask = &h000000ff
|
---|
297 | End Enum
|
---|
298 | */
|
---|
299 | Static Function MakeARGB(a As Byte, r As Byte, g As Byte, b As Byte) As Gdiplus.ARGB
|
---|
300 | MakeARGB = (((b As Gdiplus.ARGB) << Gdiplus.BLUE_SHIFT) Or _
|
---|
301 | ((g As Gdiplus.ARGB) << Gdiplus.GREEN_SHIFT) Or _
|
---|
302 | ((r As Gdiplus.ARGB) << Gdiplus.RED_SHIFT) Or _
|
---|
303 | ((a As Gdiplus.ARGB) << Gdiplus.ALPHA_SHIFT))
|
---|
304 | End Function
|
---|
305 |
|
---|
306 | Protected
|
---|
307 | argb As Gdiplus.ARGB
|
---|
308 | End Class
|
---|
309 |
|
---|
310 | End Namespace 'Drawing
|
---|
311 | End Namespace 'System
|
---|
312 |
|
---|
313 | #endif '__SYSTEM_DRAWING_COLOR_AB__
|
---|