Select colors with / for ButtonImageGadget
Posted: Wed Oct 16, 2002 2:55 pm
Code updated for 5.20+
Restored from previous forum. Originally posted by fweil.
Hello,
As an example of use of colors and buttons, I post a cut of an application program I have (first purpose is to build dynamic popup menus in JS, this part being a color selector). Click one of the buttons to change its color.
I find this code nice to show ...
Francois Weil
14, rue Douer
F64100 Bayonne
Restored from previous forum. Originally posted by fweil.
Hello,
As an example of use of colors and buttons, I post a cut of an application program I have (first purpose is to build dynamic popup menus in JS, this part being a color selector). Click one of the buttons to change its color.
I find this code nice to show ...
Code: Select all
Procedure.l MyImage(ImageNumber.l, Width.l, Height.l, Color.l)
ImageID.l = CreateImage(ImageNumber, Width, Height)
StartDrawing(ImageOutput(ImageNumber))
Box(0, 0, Width, Height, Color)
StopDrawing()
ProcedureReturn ImageID
EndProcedure
;
; Main starts here
;
Quit.l = #False
If OpenWindow(0, 200, 200, 320, 200, "F.Weil - Colored buttons", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)
FrameGadget(205, 100, 80, 80, 60, "Color1", 0)
ButtonImageGadget(105, 120, 100, 40, 20, MyImage(1, 40, 20, $996600))
FrameGadget(206, 180, 80, 80, 60, "Color2", 0)
ButtonImageGadget(106, 200, 100, 40, 20, MyImage(2, 40, 20, $999933))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = #True
Case #PB_Event_Menu
Select EventMenu()
Case 99
Quit = #True
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 105 ; Select first color
FreeGadget(105)
ButtonImageGadget(105, 120, 100, 40, 20, MyImage(1, 40, 20, ColorRequester()))
Case 106 ; Select second color
FreeGadget(106)
ButtonImageGadget(106, 200, 100, 40, 20, MyImage(2, 40, 20, ColorRequester()))
EndSelect
EndSelect
Until Quit
EndIf
End
14, rue Douer
F64100 Bayonne