' ########################################################################################
' Microsoft Windows
' File: GdiplusColor.inc
' Contents: GDI+ Color constants and class
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_GdiPlusColor_PBI)
#DEFINE PBX_GdiPlusColor_PBI
%EQUATE `GDIPLUSCOLOR_INC = 1
' // Size = 4 bytes
TYPE GDIPCOLOR_BGRA_STRUCT BYTE
 blue AS BYTE
 green AS BYTE
 red AS BYTE
 alpha AS BYTE
END TYPE
' // Size = 4 bytes
UNION GDIPCOLOR_BGRA_UNION
 color AS DWORD
 GDIPCOLOR_BGRA_STRUCT
END UNION
'//----------------------------------------------------------------------------
'// Color mode
'//----------------------------------------------------------------------------
' enum ColorMode
%EQUATE `ColorModeARGB32 = 0
%EQUATE `ColorModeARGB64 = 1
'//----------------------------------------------------------------------------
'// Color Channel flags
'//----------------------------------------------------------------------------
' enum ColorChannelFlags
%EQUATE `ColorChannelFlagsC = 0
%EQUATE `ColorChannelFlagsM = 1
%EQUATE `ColorChannelFlagsY = 2
%EQUATE `ColorChannelFlagsK = 3
%EQUATE `ColorChannelFlagsLast = 4
'//----------------------------------------------------------------------------
'// Color
'//----------------------------------------------------------------------------
%EQUATE `ARGB_AliceBlue = &HFFF0F8FF
%EQUATE `ARGB_AntiqueWhite = &HFFFAEBD7
%EQUATE `ARGB_Aqua = &HFF00FFFF
%EQUATE `ARGB_Aquamarine = &HFF7FFFD4
%EQUATE `ARGB_Azure = &HFFF0FFFF
%EQUATE `ARGB_Beige = &HFFF5F5DC
%EQUATE `ARGB_Bisque = &HFFFFE4C4
%EQUATE `ARGB_Black = &HFF000000
%EQUATE `ARGB_BlanchedAlmond = &HFFFFEBCD
%EQUATE `ARGB_Blue = &HFF0000FF
%EQUATE `ARGB_BlueViolet = &HFF8A2BE2
%EQUATE `ARGB_Brown = &HFFA52A2A
%EQUATE `ARGB_BurlyWood = &HFFDEB887
%EQUATE `ARGB_CadetBlue = &HFF5F9EA0
%EQUATE `ARGB_Chartreuse = &HFF7FFF00
%EQUATE `ARGB_Chocolate = &HFFD2691E
%EQUATE `ARGB_Coral = &HFFFF7F50
%EQUATE `ARGB_CornflowerBlue = &HFF6495ED
%EQUATE `ARGB_Cornsilk = &HFFFFF8DC
%EQUATE `ARGB_Crimson = &HFFDC143C
%EQUATE `ARGB_Cyan = &HFF00FFFF
%EQUATE `ARGB_DarkBlue = &HFF00008B
%EQUATE `ARGB_DarkCyan = &HFF008B8B
%EQUATE `ARGB_DarkGoldenrod = &HFFB8860B
%EQUATE `ARGB_DarkGray = &HFFA9A9A9
%EQUATE `ARGB_DarkGreen = &HFF006400
%EQUATE `ARGB_DarkKhaki = &HFFBDB76B
%EQUATE `ARGB_DarkMagenta = &HFF8B008B
%EQUATE `ARGB_DarkOliveGreen = &HFF556B2F
%EQUATE `ARGB_DarkOrange = &HFFFF8C00
%EQUATE `ARGB_DarkOrchid = &HFF9932CC
%EQUATE `ARGB_DarkRed = &HFF8B0000
%EQUATE `ARGB_DarkSalmon = &HFFE9967A
%EQUATE `ARGB_DarkSeaGreen = &HFF8FBC8B
%EQUATE `ARGB_DarkSlateBlue = &HFF483D8B
%EQUATE `ARGB_DarkSlateGray = &HFF2F4F4F
%EQUATE `ARGB_DarkTurquoise = &HFF00CED1
%EQUATE `ARGB_DarkViolet = &HFF9400D3
%EQUATE `ARGB_DeepPink = &HFFFF1493
%EQUATE `ARGB_DeepSkyBlue = &HFF00BFFF
%EQUATE `ARGB_DimGray = &HFF696969
%EQUATE `ARGB_DodgerBlue = &HFF1E90FF
%EQUATE `ARGB_Firebrick = &HFFB22222
%EQUATE `ARGB_FloralWhite = &HFFFFFAF0
%EQUATE `ARGB_ForestGreen = &HFF228B22
%EQUATE `ARGB_Fuchsia = &HFFFF00FF
%EQUATE `ARGB_Gainsboro = &HFFDCDCDC
%EQUATE `ARGB_GhostWhite = &HFFF8F8FF
%EQUATE `ARGB_Gold = &HFFFFD700
%EQUATE `ARGB_Goldenrod = &HFFDAA520
%EQUATE `ARGB_Gray = &HFF808080
%EQUATE `ARGB_Green = &HFF008000
%EQUATE `ARGB_GreenYellow = &HFFADFF2F
%EQUATE `ARGB_Honeydew = &HFFF0FFF0
%EQUATE `ARGB_HotPink = &HFFFF69B4
%EQUATE `ARGB_IndianRed = &HFFCD5C5C
%EQUATE `ARGB_Indigo = &HFF4B0082
%EQUATE `ARGB_Ivory = &HFFFFFFF0
%EQUATE `ARGB_Khaki = &HFFF0E68C
%EQUATE `ARGB_Lavender = &HFFE6E6FA
%EQUATE `ARGB_LavenderBlush = &HFFFFF0F5
%EQUATE `ARGB_LawnGreen = &HFF7CFC00
%EQUATE `ARGB_LemonChiffon = &HFFFFFACD
%EQUATE `ARGB_LightBlue = &HFFADD8E6
%EQUATE `ARGB_LightCoral = &HFFF08080
%EQUATE `ARGB_LightCyan = &HFFE0FFFF
%EQUATE `ARGB_LightGoldenrodYellow = &HFFFAFAD2
%EQUATE `ARGB_LightGray = &HFFD3D3D3
%EQUATE `ARGB_LightGreen = &HFF90EE90
%EQUATE `ARGB_LightPink = &HFFFFB6C1
%EQUATE `ARGB_LightSalmon = &HFFFFA07A
%EQUATE `ARGB_LightSeaGreen = &HFF20B2AA
%EQUATE `ARGB_LightSkyBlue = &HFF87CEFA
%EQUATE `ARGB_LightSlateGray = &HFF778899
%EQUATE `ARGB_LightSteelBlue = &HFFB0C4DE
%EQUATE `ARGB_LightYellow = &HFFFFFFE0
%EQUATE `ARGB_Lime = &HFF00FF00
%EQUATE `ARGB_LimeGreen = &HFF32CD32
%EQUATE `ARGB_Linen = &HFFFAF0E6
%EQUATE `ARGB_Magenta = &HFFFF00FF
%EQUATE `ARGB_Maroon = &HFF800000
%EQUATE `ARGB_MediumAquamarine = &HFF66CDAA
%EQUATE `ARGB_MediumBlue = &HFF0000CD
%EQUATE `ARGB_MediumOrchid = &HFFBA55D3
%EQUATE `ARGB_MediumPurple = &HFF9370DB
%EQUATE `ARGB_MediumSeaGreen = &HFF3CB371
%EQUATE `ARGB_MediumSlateBlue = &HFF7B68EE
%EQUATE `ARGB_MediumSpringGreen = &HFF00FA9A
%EQUATE `ARGB_MediumTurquoise = &HFF48D1CC
%EQUATE `ARGB_MediumVioletRed = &HFFC71585
%EQUATE `ARGB_MidnightBlue = &HFF191970
%EQUATE `ARGB_MintCream = &HFFF5FFFA
%EQUATE `ARGB_MistyRose = &HFFFFE4E1
%EQUATE `ARGB_Moccasin = &HFFFFE4B5
%EQUATE `ARGB_NavajoWhite = &HFFFFDEAD
%EQUATE `ARGB_Navy = &HFF000080
%EQUATE `ARGB_OldLace = &HFFFDF5E6
%EQUATE `ARGB_Olive = &HFF808000
%EQUATE `ARGB_OliveDrab = &HFF6B8E23
%EQUATE `ARGB_Orange = &HFFFFA500
%EQUATE `ARGB_OrangeRed = &HFFFF4500
%EQUATE `ARGB_Orchid = &HFFDA70D6
%EQUATE `ARGB_PaleGoldenrod = &HFFEEE8AA
%EQUATE `ARGB_PaleGreen = &HFF98FB98
%EQUATE `ARGB_PaleTurquoise = &HFFAFEEEE
%EQUATE `ARGB_PaleVioletRed = &HFFDB7093
%EQUATE `ARGB_PapayaWhip = &HFFFFEFD5
%EQUATE `ARGB_PeachPuff = &HFFFFDAB9
%EQUATE `ARGB_Peru = &HFFCD853F
%EQUATE `ARGB_Pink = &HFFFFC0CB
%EQUATE `ARGB_Plum = &HFFDDA0DD
%EQUATE `ARGB_PowderBlue = &HFFB0E0E6
%EQUATE `ARGB_Purple = &HFF800080
%EQUATE `ARGB_Red = &HFFFF0000
%EQUATE `ARGB_RosyBrown = &HFFBC8F8F
%EQUATE `ARGB_RoyalBlue = &HFF4169E1
%EQUATE `ARGB_SaddleBrown = &HFF8B4513
%EQUATE `ARGB_Salmon = &HFFFA8072
%EQUATE `ARGB_SandyBrown = &HFFF4A460
%EQUATE `ARGB_SeaGreen = &HFF2E8B57
%EQUATE `ARGB_SeaShell = &HFFFFF5EE
%EQUATE `ARGB_Sienna = &HFFA0522D
%EQUATE `ARGB_Silver = &HFFC0C0C0
%EQUATE `ARGB_SkyBlue = &HFF87CEEB
%EQUATE `ARGB_SlateBlue = &HFF6A5ACD
%EQUATE `ARGB_SlateGray = &HFF708090
%EQUATE `ARGB_Snow = &HFFFFFAFA
%EQUATE `ARGB_SpringGreen = &HFF00FF7F
%EQUATE `ARGB_SteelBlue = &HFF4682B4
%EQUATE `ARGB_Tan = &HFFD2B48C
%EQUATE `ARGB_Teal = &HFF008080
%EQUATE `ARGB_Thistle = &HFFD8BFD8
%EQUATE `ARGB_Tomato = &HFFFF6347
%EQUATE `ARGB_Transparent = &H00FFFFFF
%EQUATE `ARGB_Turquoise = &HFF40E0D0
%EQUATE `ARGB_Violet = &HFFEE82EE
%EQUATE `ARGB_Wheat = &HFFF5DEB3
%EQUATE `ARGB_White = &HFFFFFFFF
%EQUATE `ARGB_WhiteSmoke = &HFFF5F5F5
%EQUATE `ARGB_Yellow = &HFFFFFF00
%EQUATE `ARGB_YellowGreen = &HFF9ACD32
%EQUATE `AlphaShift = 24
%EQUATE `RedShift = 16
%EQUATE `GreenShift = 8
%EQUATE `BlueShift = 0
%EQUATE `AlphaMask = &HFF000000
%EQUATE `RedMask = &HFF0000
%EQUATE `GreenMask = &HFF00
%EQUATE `BlueMask = &HFF
' ########################################################################################
' A Color object stores a 32-bit value that represents a color. The color value contains
' four, 8-bit components: alpha, red, green, and blue. The first 8 bits (the most significant)
' contain the alpha component, the next 8 bits contain the red component, the next 8 bits
' contain the green component, and the next 8 bits (the least significant) contain the
' blue component. The 32-bit value is stored in a variable of type ARGB.
' ########################################################################################
CLASS CGdipColor
 INSTANCE m_Argb AS DWORD
 INTERFACE IGdipColor : INHERIT IAutomation
 ' =====================================================================================
 ' Creates a Color object by using an ARGB value. The default value is opaque black.
 ' =====================================================================================
 METHOD Color (OPTIONAL argbColor AS DWORD) THREADSAFE
 IF argbColor = 0 THEN m_Argb = %ARGB_Black ELSE m_Argb = argbColor
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Creates a Color object by using specified values for the red, green, and blue
 ' components. This constructor sets the alpha component to 255 (opaque).
 ' =====================================================================================
 METHOD ColorRGB (BYVAL r AS BYTE, BYVAL g AS BYTE, BYVAL b AS BYTE) THREADSAFE
 m_Argb = ME.MakeARGB(255, r, g, b)
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Creates a Color object by using specified values for the alpha, red, green, and blue components.
 ' =====================================================================================
 METHOD ColorARGB (BYVAL a AS BYTE, BYVAL r AS BYTE, BYVAL g AS BYTE, BYVAL b AS BYTE) THREADSAFE
 m_Argb = ME.MakeARGB(a, r, g, b)
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Gets the alpha component of this Color object.
 ' =====================================================================================
 METHOD GetAlpha () THREADSAFE AS BYTE
 LOCAL clr AS GDIPCOLOR_BGRA_UNION
 clr.color = m_Argb
 METHOD = clr.alpha
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 METHOD GetA () THREADSAFE AS BYTE
 METHOD = ME.GetAlpha
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Gets the red component of this Color object.
 ' =====================================================================================
 METHOD GetRed () THREADSAFE AS BYTE
 LOCAL clr AS GDIPCOLOR_BGRA_UNION
 clr.color = m_Argb
 METHOD = clr.Red
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 METHOD GetR () THREADSAFE AS BYTE
 METHOD = ME.GetRed
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Gets the green component of this Color object.
 ' =====================================================================================
 METHOD GetGreen () THREADSAFE AS BYTE
 LOCAL clr AS GDIPCOLOR_BGRA_UNION
 clr.color = m_Argb
 METHOD = clr.green
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 METHOD GetG () THREADSAFE AS BYTE
 METHOD = ME.GetGreen
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Gets the blue component of this Color object.
 ' =====================================================================================
 METHOD GetBlue () THREADSAFE AS BYTE
 LOCAL clr AS GDIPCOLOR_BGRA_UNION
 clr.color = m_Argb
 METHOD = clr.blue
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 METHOD GetB () THREADSAFE AS BYTE
 METHOD = ME.GetBlue
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Gets the ARGB value of this Color object.
 ' =====================================================================================
 METHOD GetValue () THREADSAFE AS DWORD
 METHOD = m_Argb
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Sets the color of this Color object.
 ' =====================================================================================
 METHOD SetValue (BYVAL argbColor AS DWORD) THREADSAFE
 m_Argb = argbColor
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Uses a Windows Graphics Device Interface (GDI)COLORREF value to set the ARGB value of
 ' this Color object.
 ' =====================================================================================
 METHOD SetFromCOLORREF(BYVAL rgbColor AS DWORD) THREADSAFE
 m_Argb = ME.MakeARGB(255, LO(BYTE, rgbColor), LO(BYTE, rgbColor \ 256), LO(BYTE, rgbColor \ 65536))
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Converts this Color object's ARGB value to a Windows Graphics Device Interface (GDI)COLORREF value.
 ' =====================================================================================
 METHOD ToCOLORREF () THREADSAFE AS DWORD
 METHOD = RGB(ME.GetRed, ME.GetGreen, ME.GetBlue)
 END METHOD
 ' =====================================================================================
 ' =====================================================================================
 ' Creates a 32-bit value that consolidates the specified alpha, red, green, and blue components.
 ' =====================================================================================
 METHOD MakeARGB(BYVAL a AS BYTE, BYVAL r AS BYTE, BYVAL g AS BYTE, BYVAL b AS BYTE) THREADSAFE AS DWORD
 SHIFT LEFT b, %BlueShift
 SHIFT LEFT g, %GreenShift
 SHIFT LEFT r, %RedShift
 SHIFT LEFT a, %AlphaShift
 METHOD = b OR g OR r OR a
 END METHOD
 ' =====================================================================================
 END INTERFACE
END CLASS
' ########################################################################################
' ########################################################################################
' Creates new Color objects.
' ########################################################################################
FUNCTION NewGdipColor (OPTIONAL BYVAL argbColor AS DWORD) THREADSAFE AS IGdipColor
 LOCAL pGdipColor AS IGdipColor
 pGdipColor = CLASS "CGdipColor"
 IF ISNOTHING(pGdipColor) THEN EXIT FUNCTION
 pGdipColor.Color(argbColor)
 FUNCTION = pGdipColor
END FUNCTION
' ========================================================================================
FUNCTION NewGdipColorRGB (BYVAL r AS BYTE, BYVAL g AS BYTE, BYVAL b AS BYTE) THREADSAFE AS IGdipColor
 LOCAL pGdipColor AS IGdipColor
 pGdipColor = CLASS "CGdipColor"
 IF ISNOTHING(pGdipColor) THEN EXIT FUNCTION
 pGdipColor.ColorRGB(r, g, b)
 FUNCTION = pGdipColor
END FUNCTION
' ========================================================================================
FUNCTION NewGdipColorARGB (BYVAL a AS BYTE, BYVAL r AS BYTE, BYVAL g AS BYTE, BYVAL b AS BYTE) THREADSAFE AS IGdipColor
 LOCAL pGdipColor AS IGdipColor
 pGdipColor = CLASS "CGdipColor"
 IF ISNOTHING(pGdipColor) THEN EXIT FUNCTION
 pGdipColor.ColorARGB(a, r, g, b)
 FUNCTION = pGdipColor
END FUNCTION
' ########################################################################################
#ENDIF
