I will not win a nobel price with this one ...
I hope it can be useful for someone
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Color Preview Gadget
; File Version : 1.0.0
; Programmation : OK
; Programmed by : Guimauve
; Date : 26-03-2006
; Last Update : 26-03-2006
; Coded for PureBasic V4.00
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure ColorPreviewGadget(GadgetID, x, y, Width, Height, Color)
CreateImage(GadgetID, Width, Height)
If StartDrawing(ImageOutput(GadgetID))
Box(0, 0, Width, Height, Color)
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, Width, Height, 0)
StopDrawing()
EndIf
ImageGadget(GadgetID, x, y, Width, Height, ImageID(GadgetID))
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure SetCurrentColorPreviewGadget(GadgetID, Color)
CreateImage(GadgetID, GadgetWidth(GadgetID), GadgetHeight(GadgetID))
If StartDrawing(ImageOutput(GadgetID))
Box(0, 0, GadgetWidth(GadgetID), GadgetHeight(GadgetID), Color)
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, GadgetWidth(GadgetID), GadgetHeight(GadgetID), 0)
StopDrawing()
EndIf
SetGadgetState(GadgetID, ImageID(GadgetID))
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure GetCurrentColorPreviewGadget(GadgetID)
If StartDrawing(ImageOutput(GadgetID))
CurrentColor.l = Point(GadgetWidth(GadgetID) >> 1, GadgetHeight(GadgetID) >> 1)
StopDrawing()
EndIf
ProcedureReturn CurrentColor
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure AskUserForNewColor(GadgetID)
Color.l = ColorRequester()
If Color > -1
SetCurrentColorPreviewGadget(GadgetID, Color)
EndIf
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Enumeration
#Main_Win
#ColorPreview_One
#ColorPreview_Two
#ColorPreview_Three
#ColorPreview_Four
#Btn_ColorPreview_One
#Btn_ColorPreview_Two
#Btn_ColorPreview_Three
#Btn_ColorPreview_Four
#Btn_MSGREQUESTER
EndEnumeration
Procedure MainWindow()
If OpenWindow(#Main_Win, 75,75, 300, 150,"Demo ColorPreviewGadget") <> 0
ColorPreviewGadget(#ColorPreview_One,5,5,60,20,RGB(000,000,255))
ColorPreviewGadget(#ColorPreview_Two,5,30,60,20,RGB(255,000,000))
ColorPreviewGadget(#ColorPreview_Three,5,55,60,20, RGB(255,255,000))
ColorPreviewGadget(#ColorPreview_Four,5,85,60,20,RGB(128,000,255))
ButtonGadget(#Btn_ColorPreview_One,75,5,60,20,"...")
ButtonGadget(#Btn_ColorPreview_Two,75,30,60,20, "...")
ButtonGadget(#Btn_ColorPreview_Three,75,55,60,20, "...")
ButtonGadget(#Btn_ColorPreview_Four,75,85,60,20,"...")
ButtonGadget(#Btn_MSGREQUESTER,5,110,100,25,"GetColor")
EndIf
EndProcedure
Procedure EventManager()
MainWindow()
Repeat
EventID = WindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case #Btn_ColorPreview_One
AskUserForNewColor(#ColorPreview_One)
Case #Btn_ColorPreview_Two
AskUserForNewColor(#ColorPreview_Two)
Case #Btn_ColorPreview_Three
AskUserForNewColor(#ColorPreview_Three)
Case #Btn_ColorPreview_Four
AskUserForNewColor(#ColorPreview_Four)
Case #Btn_MSGREQUESTER
For Index = #ColorPreview_One To #ColorPreview_Four
MessageRequester("Test", "The color number for the " + Str(Index)+ " ColorPreviewGadget is : " + Str(GetCurrentColorPreviewGadget(Index)))
Next
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
EventManager()
Guimauve