File: n_svc_color.sru
Size: 15711
Date: Mon, 07 Apr 2008 21:31:46 +0200
$PBExportHeader$n_svc_color.sru
$PBExportComments$Color service
forward
global type n_svc_color from n_svc_base
end type
end forward

global type n_svc_color from n_svc_base
end type
global n_svc_color n_svc_color

type prototypes
Function Boolean GradientRect( ULong hdc, TRIVERTEX pVert[], ULong numVert, GRADIENT_RECT pMesh [], ULong numMesh, ULong dMode ) Library 'msimg32' Alias For 'GradientFill;Ansi'
//Function Boolean GradientTriangle( Long hdc, TRIVERTEX pVert[], ULong numVert, GRADIENT_TRIANGLE pMesh [], ULong numMesh, ULong dMode ) Library 'msimg32' Alias For 'GradientFill'
end prototypes

type variables
Public:
CONSTANT integer CTLMSGBOX         = 0
CONSTANT integer CTLEDIT           = 1
CONSTANT integer CTLLISTBOX        = 2
CONSTANT integer CTLBTN            = 3
CONSTANT integer CTLDLG            = 4
CONSTANT integer CTLSCROLLBAR      = 5
CONSTANT integer CTLSTATIC         = 6
CONSTANT integer CTLMAX            = 7
CONSTANT integer SCROLLBAR         = 0
CONSTANT integer BACKGROUND        = 1
CONSTANT integer ACTIVECAPTION     = 2
CONSTANT integer INACTIVECAPTION   = 3
CONSTANT integer MENU              = 4
CONSTANT integer WINDOW            = 5
CONSTANT integer WINDOWFRAME       = 6
CONSTANT integer MENUTEXT          = 7
CONSTANT integer WINDOWTEXT        = 8
CONSTANT integer CAPTIONTEXT       = 9
CONSTANT integer ACTIVEBORDER      = 10
CONSTANT integer INACTIVEBORDER    = 11
CONSTANT integer APPWORKSPACE      = 12
CONSTANT integer HIGHLIGHT         = 13
CONSTANT integer HIGHLIGHTTEXT     = 14
CONSTANT integer BTNFACE           = 15
CONSTANT integer BTNSHADOW         = 16
CONSTANT integer GRAYTEXT          = 17
CONSTANT integer BTNTEXT           = 18
CONSTANT integer INACTIVECAPTIONTEXT = 19
CONSTANT integer BTNHIGHLIGHT      = 20
CONSTANT integer COLOR_3DDKSHADOW        = 21
CONSTANT integer COLOR_3DLIGHT           = 22
CONSTANT integer INFOTEXT          = 23
CONSTANT integer INFOBK            = 24
CONSTANT integer HOTLIGHT          = 26
CONSTANT integer GRADIENTACTIVECAPTION = 27
CONSTANT integer GRADIENTINACTIVECAPTION = 28
CONSTANT integer MENUHILIGHT       = 29
CONSTANT integer MENUBAR           = 30
CONSTANT integer DESKTOP           = BACKGROUND
CONSTANT integer COLOR_3DFACE            = BTNFACE
CONSTANT integer COLOR_3DSHADOW          = BTNSHADOW
CONSTANT integer COLOR_3DHIGHLIGHT       = BTNHIGHLIGHT
CONSTANT integer COLOR_3DHILIGHT         = BTNHIGHLIGHT
CONSTANT integer BTNHILIGHT        = BTNHIGHLIGHT

Protected:

CONSTANT uLong GRADIENT_FILL_RECT_H = 0, &
               GRADIENT_FILL_RECT_V = 1, &
               GRADIENT_FILL_TRIANGLE = 2, &
               GRADIENT_FILL_OP_FLAG = 255
               
String   is_ColorNames[] = { "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", &
                         "Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", &
                        "Brown", "BurlyWood", "CadetBlue", "Chartreuse", "Chocolate", &
                        "Coral", "CornflowerBlue", "Cornsilk", "Crimson", "Cyan", &
                        "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGray", "DarkGreen", &
                        "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange", &
                        "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue", &
                        "DarkSlateGray", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue",&
                        "DimGray", "DodgerBlue" , "FireBrick", "FloralWhite", "ForestGreen", &
                        "Fuchsia", "Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Gray", "Green", &
                        "GreenYellow", "Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", &
                        "Khaki", "Lavender", "LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", &
                        "LightCoral", "LightCyan", "LightGoldenrodYellow", "LightGreen", "LightGrey", &
                        "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGray", &
                        "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta", &
                        "Maroon", "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumPurple", &
                        "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", &
                        "MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin", &
                        "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed", &
                        "Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed", &
                        "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple", &
                        "Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", &
                        "SeaGreen", "Seashell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGray", &
                        "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal", "Thistle", "Tomato", "Turquoise", &
                        "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen" }
                        
Long     il_Colors[] = { RGB( 240, 248, 255 ), RGB( 250, 235, 215 ), RGB( 0, 255, 255 ), RGB( 127, 255, 212 ), &
                         RGB( 240, 255, 255 ), RGB( 245, 245, 220 ), RGB( 255, 228, 196 ), RGB( 0, 0, 0 ), &
                         RGB( 255, 235, 205 ), RGB( 0, 0, 255 ), RGB( 138, 43, 226 ), RGB( 165, 42, 42 ), &
                         RGB( 222, 184, 135 ), RGB( 95, 158, 160 ), RGB( 127, 255, 0 ), RGB( 210, 105, 30 ), &
                         RGB( 255, 127, 80 ), RGB( 100, 149, 237 ), RGB( 255, 248, 220 ), RGB( 220, 20, 60 ), &
                         RGB( 0, 255, 255 ), RGB( 0, 0, 139 ), RGB( 0, 139, 139 ), RGB( 184, 134, 11 ), RGB( 169, 169, 169 ), &
                         RGB( 0, 100, 0 ), RGB( 189, 183, 107 ), RGB( 139, 0, 139 ), RGB( 85, 107, 47 ), &
                         RGB( 255, 140, 0 ), RGB( 153, 50, 204 ), RGB( 139, 0, 0 ), RGB( 233, 150, 122 ), &
                         RGB( 143, 188, 143 ), RGB( 72, 61, 139 ), RGB( 47, 79, 79 ), RGB( 0, 206, 209 ), &
                         RGB( 148, 0, 211 ), RGB( 255, 20, 147 ), RGB( 0, 191, 255 ), RGB( 105, 105, 105 ), &
                         RGB( 30, 144, 255 ), RGB( 178, 34, 34 ), RGB( 255, 250, 240 ), RGB( 34, 139, 34 ), &
                         RGB( 255, 0, 255 ), RGB( 220, 220, 220 ), RGB( 248, 248, 255 ), RGB( 255, 215, 0 ), &
                         RGB( 218, 165, 32 ), RGB( 128, 128, 128 ), RGB( 0, 128, 0 ), RGB( 173, 255, 47 ), &
                         RGB( 240, 255, 240 ), RGB( 255, 105, 180 ), RGB( 205, 92, 92 ), RGB( 75, 0, 130 ), &
                         RGB( 255, 255, 240 ), RGB( 240, 230, 140 ), RGB( 230, 230, 250 ), RGB( 255, 240, 245 ), &
                         RGB( 124, 252, 0 ), RGB( 255, 250, 205 ), RGB( 173, 216, 230 ), RGB( 240, 128, 128 ), &
                         RGB( 224, 255, 255 ), RGB( 250, 250, 210 ), RGB( 144, 238, 144 ), RGB( 211, 211, 211 ), &
                         RGB( 255, 182, 193 ), RGB( 255, 160, 122 ), RGB( 32, 178, 170 ), RGB( 135, 206, 250 ), &
                         RGB( 119, 136, 153 ), RGB( 176, 196, 222 ), RGB( 255, 255, 224 ), RGB( 0, 255, 0 ), &
                         RGB( 50, 205, 50 ), RGB( 250, 240, 230 ), RGB( 255, 0, 255 ), RGB( 128, 0, 0 ), &
                         RGB( 102, 205, 170 ), RGB( 0, 0, 205 ), RGB( 186, 85, 211 ), RGB( 147, 112, 219 ), &
                         RGB( 60, 179, 113 ), RGB( 123, 104, 238 ), RGB( 0, 250, 154 ), RGB( 72, 209, 204 ), &
                         RGB( 199, 21, 133 ), RGB( 25, 25, 112 ), RGB( 245, 255, 250 ), RGB( 255, 228, 225 ), &
                         RGB( 255, 228, 181 ), RGB( 255, 222, 173 ), RGB( 0, 0, 128 ), RGB( 253, 245, 230 ), &
                         RGB( 128, 128, 0 ), RGB( 107, 142, 35 ), RGB( 255, 165, 0 ), RGB( 255, 69, 0 ), &
                         RGB( 218, 112, 214 ), RGB( 238, 232, 170 ), RGB( 152, 251, 152 ), RGB( 175, 238, 238 ), &
                         RGB( 219, 112, 147 ), RGB( 255, 239, 213 ), RGB( 255, 218, 185 ), RGB( 205, 133, 63 ), &
                         RGB( 255, 192, 203 ), RGB( 221, 160, 221 ), RGB( 176, 224, 230 ), RGB( 128, 0, 128 ), &
                         RGB( 255, 0, 0 ), RGB( 188, 143, 143 ), RGB( 65, 105, 225 ), RGB( 139, 69, 19 ), &
                         RGB( 250, 128, 114 ), RGB( 244, 164, 96 ), RGB( 46, 139, 87 ), RGB( 255, 245, 238 ), &
                         RGB( 160, 82, 45 ), RGB( 192, 192, 192 ), RGB( 135, 206, 235 ), RGB( 106, 90, 205 ), &
                         RGB( 112, 128, 144 ), RGB( 255, 250, 250 ), RGB( 0, 255, 127 ), RGB( 70, 130, 180 ), &
                         RGB( 210, 180, 140 ), RGB( 0, 128, 128 ), RGB( 216, 191, 216 ), RGB( 255, 99, 71 ), &
                         RGB( 64, 224, 208 ), RGB( 238, 130, 238 ), RGB( 245, 222, 179 ), RGB( 255, 255, 255 ), &
                         RGB( 245, 245, 245 ), RGB( 255, 255, 0 ), RGB( 154, 205, 50 ) }
end variables

forward prototypes
public subroutine of_torgb (long al_color, ref integer ai_red, ref integer ai_green, ref integer ai_blue)
public function long of_lightencolor (readonly double ad_factor, readonly long al_color)
public function long of_getmidcolor (ref n_svc_mgr anv_svc, readonly long al_color1, readonly long al_color2)
public function long of_darkencolor (ref n_svc_mgr anv_svc, readonly long al_scale, readonly long al_color)
public function long of_lightencolor (ref n_svc_mgr anv_svc, readonly long al_scale, readonly long al_color)
public function long of_getcolorfromstring (readonly string as_colorname)
public subroutine of_getwebcolors (ref string as_colornames[], ref long al_colorvalues[])
public subroutine of_setvertex (ref trivertex astr_vertex, readonly integer ai_x, readonly integer ai_y, readonly integer ai_red, readonly integer ai_green, readonly integer ai_blue)
public subroutine of_drawgradient (readonly unsignedlong aul_dc, readonly rect ar_rect, readonly long al_colorstart, readonly long al_colorend, readonly boolean ab_vertical)
public function long of_getsyscolor (ref n_svc_mgr anv_svc, readonly integer ai_syscolor)
public function long of_colorfrompbcolor (ref n_svc_mgr anv_svc, readonly long al_pbcolor)
end prototypes

public subroutine of_torgb (long al_color, ref integer ai_red, ref integer ai_green, ref integer ai_blue);ai_red = Mod( al_color, 256 )
al_color /= 256
ai_green = Mod( al_color, 256 )
ai_blue = al_color / 256
end subroutine

public function long of_lightencolor (readonly double ad_factor, readonly long al_color);Integer   li_Red, li_Green, li_Blue, li_RedNew, li_GreenNew, li_BlueNew

li_Blue = al_Color / 65536
li_Green = ( al_Color - li_Blue * 65536 ) / 256
li_Red = al_Color - ( li_Green * 256 ) - ( li_Blue * 65536 )

li_RedNew = (( ad_factor * ( 255 - li_Red ) ) + li_Red )
li_GreenNew = (( ad_factor * ( 255 - li_Green ) ) + li_Green )
li_BlueNew = (( ad_factor * ( 255 - li_Blue ) ) + li_Blue )

Return Rgb( li_RedNew, li_GreenNew, li_BlueNew )
end function

public function long of_getmidcolor (ref n_svc_mgr anv_svc, readonly long al_color1, readonly long al_color2);Integer   li_Red1, li_Green1, li_Blue1, li_Red2, li_Green2, li_Blue2, li_RedNew, li_GreenNew, li_BlueNew
n_svc_win32 lnv_win32

li_Blue1 = al_Color1 / 65536
li_Green1 = ( al_Color1 - li_Blue1 * 65536 ) / 256
li_Red1 = al_Color1 - ( li_Green1 * 256 ) - ( li_Blue1 * 65536 )

li_Blue2 = al_Color2 / 65536
li_Green2 = ( al_Color2 - li_Blue2 * 65536 ) / 256
li_Red2 = al_Color2 - ( li_Green2 * 256 ) - ( li_Blue2 * 65536 )

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

li_RedNew = lnv_win32.MulDiv( 7, li_Red1, 10 ) + lnv_win32.MulDiv( 3, li_Red2, 10 )
li_GreenNew = lnv_win32.MulDiv( 7, li_Green1, 10 ) + lnv_win32.MulDiv( 3, li_Green2, 10 )
li_BlueNew = lnv_win32.MulDiv( 7, li_Blue1, 10 ) + lnv_win32.MulDiv( 3, li_Blue2, 10 )

Return Rgb( li_RedNew, li_GreenNew, li_BlueNew )
end function

public function long of_darkencolor (ref n_svc_mgr anv_svc, readonly long al_scale, readonly long al_color);Integer  li_Red, li_Green, li_Blue, li_RedNew, li_GreenNew, li_BlueNew
n_svc_win32 lnv_win32

li_Blue = al_Color / 65536
li_Green = ( al_Color - li_Blue * 65536 ) / 256
li_Red = al_Color - ( li_Green * 256 ) - ( li_Blue * 65536 )

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

li_RedNew = lnv_win32.MulDiv( li_Red, 255 - al_Scale, 255 )
li_GreenNew = lnv_win32.MulDiv( li_Green, 255 - al_Scale, 255 )
li_BlueNew = lnv_win32.MulDiv( li_Blue, 255 - al_Scale, 255 )

Return Rgb( li_RedNew, li_GreenNew, li_BlueNew )
end function

public function long of_lightencolor (ref n_svc_mgr anv_svc, readonly long al_scale, readonly long al_color);Integer li_Red, li_Green, li_Blue, li_RedNew, li_GreenNew, li_BlueNew
n_svc_win32 lnv_win32

li_Blue = al_Color / 65536
li_Green = ( al_Color - li_Blue * 65536 ) / 256
li_Red = al_Color - ( li_Green * 256 ) - ( li_Blue * 65536 )

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

li_RedNew = lnv_win32.MulDiv( 255 - li_Red, al_Scale, 255 ) + li_Red
li_GreenNew = lnv_win32.MulDiv( 255 - li_Green, al_Scale, 255 ) + li_Green
li_BlueNew = lnv_win32.MulDiv( 255 - li_Blue, al_Scale, 255 ) + li_Blue

Return Rgb( li_RedNew, li_GreenNew, li_BlueNew )
end function

public function long of_getcolorfromstring (readonly string as_colorname);long ll_count, n

ll_count = UPPERBOUND(is_colornames)

FOR n = 1 to ll_count
   IF LOWER(is_colornames[n]) = as_colorname THEN
      RETURN il_colors[n]
   END IF
NEXT

RETURN CRet.FAILURE
end function

public subroutine of_getwebcolors (ref string as_colornames[], ref long al_colorvalues[]);as_colornames = is_colornames
al_colorvalues = il_colors
end subroutine

public subroutine of_setvertex (ref trivertex astr_vertex, readonly integer ai_x, readonly integer ai_y, readonly integer ai_red, readonly integer ai_green, readonly integer ai_blue);astr_vertex.X = ai_x
astr_vertex.Y = ai_y
astr_vertex.Red = (ai_red / 255) * 65535
astr_vertex.Green = (ai_green / 255) * 65535
astr_vertex.Blue = (ai_blue / 255) * 65535
astr_vertex.Alpha = 0
end subroutine

public subroutine of_drawgradient (readonly unsignedlong aul_dc, readonly rect ar_rect, readonly long al_colorstart, readonly long al_colorend, readonly boolean ab_vertical);trivertex lstr_vert[2]
gradient_rect lgr[1]
integer li_red, li_green, li_blue
ulong lul_style

of_ToRGB(al_colorstart, li_red, li_green, li_blue)
of_SetVertex(lstr_vert[1], ar_rect.Left, ar_rect.Top, li_red, li_green, li_blue)
of_ToRGB(al_colorend, li_red, li_green, li_blue)
of_SetVertex(lstr_vert[2], ar_rect.Right, ar_rect.Bottom, li_red, li_green, li_blue)

lgr[1].UpperLeft = 0
lgr[1].LowerRight = 1

IF ab_vertical THEN
   lul_style = GRADIENT_FILL_RECT_V
ELSE
   lul_style = GRADIENT_FILL_RECT_H
END IF

GradientRect(aul_dc, lstr_vert, 2, lgr, 1, lul_style)
end subroutine

public function long of_getsyscolor (ref n_svc_mgr anv_svc, readonly integer ai_syscolor);n_svc_win32 lnv_win32

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

RETURN lnv_win32.GetSysColor(ai_syscolor)
end function

public function long of_colorfrompbcolor (ref n_svc_mgr anv_svc, readonly long al_pbcolor);long ll_ret

CHOOSE CASE al_pbcolor
   CASE CColor.ACTIVE_BORDER
      ll_ret = of_GetSysColor(anv_svc, ACTIVEBORDER)
   CASE CColor.ACTIVE_TITLE_BAR
      ll_ret = of_GetSysColor(anv_svc, ACTIVECAPTION)
   CASE CColor.ACTIVE_TITLE_BAR_TEXT
   CASE CColor.APPLICATION_WORKSPACE
   CASE CColor.BUTTON_DARK_SHADOW
   CASE CColor.BUTTON_FACE
      ll_ret = of_GetSysColor(anv_svc, BTNFACE)
   CASE CColor.BUTTON_HIGHLIGHT
   CASE CColor.BUTTON_LIGHT_SHADOW
   CASE CColor.BUTTON_SHADOW
   CASE CColor.BUTTON_TEXT
   CASE CColor.DESKTOP
      ll_ret = of_GetSysColor(anv_svc, DESKTOP)
   CASE CColor.DISABLED_TEXT
   CASE CColor.HIGHLIGHT
   CASE CColor.HIGHLIGHT_TEXT
   CASE CColor.INACTIVE_BORDER
   CASE CColor.INACTIVE_TITLE_BAR
   CASE CColor.INACTIVE_TITLE_BAR_TEXT
   CASE CColor.LINK
   CASE CColor.LINK_HOVER
   CASE CColor.LINK_ACTIVE
   CASE CColor.LINK_VISITED
   CASE CColor.MENU_BAR
   CASE CColor.MENU_TEXT
   CASE CColor.SCROLLBAR
   CASE CColor.SCROLL_BAR
   CASE CColor.TRANSPARENT
   CASE CColor.TOOLTIP
   CASE CColor.TOOLTIP_TEXT
   CASE CColor.WINDOW_BACKGROUND
   CASE CColor.WINDOW_FRAME
   CASE CColor.WINDOW_TEXT
   CASE ELSE
      ll_ret = al_pbcolor
END CHOOSE

RETURN ll_ret
end function

on n_svc_color.create
call super::create
end on

on n_svc_color.destroy
call super::destroy
end on