#include "fivewin.ch"
#include "constant.ch"
STATIC c_path
FUNCTION MAIN()
Local oDlg, oBtn1, oBtn2, oBtn3, oBtnFont, oBmp1, oBmp2
Local oGet1, oGet2, nColorPos := 1, nRed, nGreen, nBlue, nCOLORVAL := 8355839
Local cRGB := "nRGB( 255, 127, 127 )"
Local aColors := ;
{ rgb( 255, 127, 127), rgb( 255, 255, 127), rgb( 127, 255, 127),;
rgb( 0, 255, 127), rgb( 127, 255, 255), rgb( 0, 127, 255),;
rgb( 255, 127, 191), rgb( 255, 127, 255), rgb( 255, 0, 0),;
rgb( 255, 255, 0), rgb( 127, 255, 0), rgb( 0, 255, 63),;
rgb( 0, 255, 255), rgb( 0, 127, 191), rgb( 127, 127, 191),;
rgb( 255, 0, 255), rgb( 127, 63, 63), rgb( 255, 127, 63),;
rgb( 0, 255, 0), rgb( 0, 127, 127), rgb( 0, 63, 127),;
rgb( 127, 127, 255), rgb( 127, 0, 63), rgb( 255, 0, 127),;
rgb( 127, 0, 0), rgb( 255, 127, 0), rgb( 0, 127, 0),;
rgb( 0, 127, 63), rgb( 0, 0, 255), rgb( 0, 0, 159),;
rgb( 127, 0, 127), rgb( 127, 0, 255), rgb( 63, 0, 0),;
rgb( 127, 63, 0), rgb( 0, 63, 0), rgb( 0, 63, 63),;
rgb( 0, 0, 127), rgb( 0, 0, 63), rgb( 63, 0, 63),;
rgb( 63, 0, 127), rgb( 0, 0, 0), rgb( 127, 127, 0),;
rgb( 127, 127, 63), rgb( 127, 127, 127), rgb( 63, 127, 127),;
rgb( 191, 191, 191), rgb( 63, 0, 63), rgb( 255, 255, 255) }
c_path := cFilePath(GetModuleFileName( GetInstance() ) )
DEFINE FONT oBtnFont NAME "Arial" SIZE 0, -16 BOLD
nColorPos := GET_INI()
DEFINE DIALOG oDlg ;
TITLE "Change color" ;
SIZE 500, 400 TRANSPARENT PIXEL
@ 150, 10 GET oGet1 VAR nCOLORVAL SIZE 85, 12 FONT oBtnFont PIXEL CENTERED
@ 170, 10 BUTTON oBtn1 PROMPT "&Numeric" SIZE 85, 18 FONT oBtnFont PIXEL OF oDlg ;
ACTION ( nColorPos := PICK_COLOR(aColors, nColorPos), ;
SAVE_INI(nColorPos), ;
nCOLORVAL := aColors[nColorPos], ;
oGet1:Refresh(), ;
nRed := nRGBRed( aColors[nColorPos] ), ;
nGreen := nRGBGreen( aColors[nColorPos] ), ;
nBlue := nRGBBlue( aColors[nColorPos] ), ;
cRGB := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ALLTRIM(STR(nGreen)) + ", " + ;
ALLTRIM(STR(nBlue)) + " )", oGet2:Refresh(), ;
D_BACKGRD( oDlg, aColors[nColorPos] ) )
@ 150, 100 GET oGet2 VAR cRGB SIZE 90, 12 FONT oBtnFont PIXEL CENTERED
@ 170, 100 BUTTON oBtn2 PROMPT "&RGB-string" SIZE 90, 18 FONT oBtnFont PIXEL OF oDlg ;
ACTION ( nColorPos := PICK_COLOR(aColors, nColorPos), ;
SAVE_INI(nColorPos), ;
nRed := nRGBRed( aColors[nColorPos] ), ;
nGreen := nRGBGreen( aColors[nColorPos] ), ;
nBlue := nRGBBlue( aColors[nColorPos] ), ;
cRGB := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ALLTRIM(STR(nGreen)) + ", " + ;
ALLTRIM(STR(nBlue)) + " )", oGet2:Refresh(), ;
nCOLORVAL := aColors[nColorPos], ;
oGet1:Refresh(), ;
D_BACKGRD( oDlg, aColors[nColorPos] ) )
@ 170, 200 BUTTON oBtn3 PROMPT "&Exit" SIZE 40, 18 FONT oBtnFont PIXEL OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT D_BACKGRD( oDlg, aColors[nColorPos] )
oBtnFont:End()
RETURN NIL
// -------- DIALOG - Background ---------------
FUNCTION D_BACKGRD( oDlg, nDColor )
Local oBrush
DEFINE BRUSH oBrush COLOR nDColor
oDlg:SetBrush( oBrush )
RELEASE BRUSH oBrush
RETURN( NIL )
// ------------------
FUNCTION PICK_COLOR(aColors, nColorPos)
Local oDlg1, oBtn, oCrsSelect
Local nSeleccion := nColorPos, n := 0, lExit :=.F.
Local nTop := 1
Local nCol := 1
Local nBottom := 10
Local nRight := 12
Local aButtons :={}, nColor
Local nWidth := Max( nRight * DLG_CHARPIX_W, 195 )
Local nHeight := nBottom * DLG_CHARPIX_H
Local aGetcolor[48]
DEFINE FONT oBtnFont NAME "Arial" SIZE 0, -16 BOLD
DEFINE CURSOR oCrsSelect DRAG
DEFINE DIALOG oDlg1 ;
TITLE "Color Pick" ;
SIZE nWidth, nHeight TRANSPARENT PIXEL
k := 0
FOR n := 1 to 48
@ ntop,ncol FLATBTN oBtn PROMPT "x" OF oDlg1 SIZE 12, 12 COLOR aColors[n],aColors[n] FONT oBtnFont
oBtn:oCursor := oCrsSelect
AADD(aButtons, oBtn)
aButtons[n]:Cargo := n
aButtons[n]:bAction := {|self| nSeleccion:= ::cargo, ;
lExit := .T., oDlg1:end() }
k+=1
nCol+= 12
If k = 8
nCol := 1
k :=0
nTop := nTop+12
Endif
NEXT n
ACTIVATE DIALOG oDlg1 CENTERED VALID lExit
RETURN nSeleccion
// --------- INI Write------------------------
FUNCTION SAVE_INI(nColorPos)
LOCAL cIniFile := c_path + "\COLOR.INI"
WritePProString( "Dialog", "Color-Pos", ALLTRIM(STR(nColorPos)), cIniFile )
RETURN( NIL )
// --------- INI Read ------------------------
FUNCTION GET_INI(nColorPos)
LOCAL oIni, cIniFile := c_path + "COLOR.INI"
IF !FILE ( c_path + "COLOR.ini" )
SAVE_INI(nColorPos)
ELSE
INI oIni FILE c_path + "COLOR.INI"
nColorPos := Val(GetPvProfString( "Dialog","Color-Pos", "1" , cIniFile ) )
ENDINI
ENDIF
RETURN( nColorPos )