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