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