; English forum: http://www.purebasic.fr/english/viewtopic.php?t=26742 ; Author: walker ; Date: 22. April 2007 ; OS: Windows, Linux ; Demo: Yes ; --------------------------------------------------------------------- ; Generated by Glade2PB V0.6.2 © 2006 walker ; Glade2PB converts Glade C-outputfile to PB-Code ; --------------------------------------------------------------------- ; Color-Picker Gadget ; 2007 walker ; 2 possible modes; 1 = as a popup at any position you want ; 2 = as a toolbarbutton with dropdown; will be implemented in ToolBar Pro.... ; --------------------------------------------------------------------------- DeclareCDLL on_close_clicked (Window, Event, Gadget, Type) DeclareCDLL on_color_clicked (Window, Event, Gadget, Type) DeclareCDLL on_f_color_clicked (Window, Event, Gadget, Type) DeclareCDLL on_remove_clicked (Window, Event, Gadget, Type) Global *col_picker Global *button3 Global *button4 ; --------------------------------------------------------------------- ; Global Dim b_utton(36) Global Dim c_olors(37) Global Dim c_mcol(37) Global actual_color.l = 0; a color from 1 to 36 stored in c_mcol() Global button_size.l =20 ; size of the 36 color buttons - a size between 20 and 30 is ok but can be greater... Global quit=0 Structure AsyncGadgets Gadget.l EventFunction.l EndStructure ; Global NewList EventProcedures.AsyncGadgets() ; Procedure RegisterGadgetEvent(Gadget, *Function) If IsGadget(Gadget) AddElement(EventProcedures()) EventProcedures()\Gadget = Gadget EventProcedures()\EventFunction = *Function EndIf EndProcedure ; Procedure CallEventFunction(Window, Event, Gadget, Type) ForEach EventProcedures() If EventProcedures()\Gadget = Gadget CallCFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type) LastElement(EventProcedures()) EndIf Next EndProcedure ; ProcedureCDLL col_picker (b_size,back_color) ; b_size = size of the colorbuttons ; back_color = background color of the window gap=5 ; gap = space between the buttons and the bordersize b_heigth=28 ;heigth of the two buttons close and custom b_width = 60 ;width of the 2 buttons If b_size<20 b_size=20 EndIf winw=(6*b_size)+(7*gap) winh = (6*b_size)+(9*gap)+(b_heigth*2) *col_picker=OpenWindow(#PB_Any,DesktopMouseX(),DesktopMouseY(),winw,winh,"Select Color",#PB_Window_BorderLess|#PB_Window_Invisible) CreateGadgetList(WindowID(*col_picker)) *button1=ButtonGadget(#PB_Any,0+gap,0+gap,winw-(2*gap),b_heigth,"remove color") x=0 y=0 x+gap y+gap+b_heigth+gap bpr=1 Restore colors For n=1 To 36 ;creating the 36 predifined color images id=CreateImage(#PB_Any,b_size,b_size) StartDrawing(ImageOutput(id)) Read mycolor FillArea(0,0,-1,mycolor) StopDrawing() c_olors(n)=ImageID(id) c_mcol(n)=mycolor Next For n = 1 To 6 ;creating the buttons... 6 rows and 6 each row For m= 1 To 6 b_utton(bpr) = ButtonImageGadget(#PB_Any,x,y,b_size,b_size,c_olors(bpr)) x+b_size+gap bpr+1 Next y+b_size+gap x=gap Next *button3=ButtonGadget(#PB_Any,0+gap, winh-b_heigth-gap,b_width,b_heigth,"close") *button4=ButtonGadget(#PB_Any,winw-gap-b_width, winh-b_heigth-gap,b_width,b_heigth,"custom") RegisterGadgetEvent(*button1,@on_remove_clicked()) RegisterGadgetEvent(*button3,@on_close_clicked()) RegisterGadgetEvent(*button4,@on_color_clicked()) For m= 0 To bpr-1 RegisterGadgetEvent(b_utton(m),@on_f_color_clicked()) Next HideWindow(*col_picker,#False) StickyWindow(*col_picker,#True) If back_color>-1 SetWindowColor(*col_picker,back_color) EndIf Repeat c_event=WaitWindowEvent(1) c_Gadget = EventGadget() c_Type = EventType() c_Window = EventWindow() If c_event=#PB_Event_Gadget CallEventFunction(c_Window, c_Event, c_Gadget, c_Type) EndIf If IsWindow(*col_picker) = 0 quit=1 EndIf Until quit=1 quit=0 If actual_color=-2 ProcedureReturn -2 ;if no color is choosen ElseIf actual_color = -1 ProcedureReturn -1 ;remove color Else ProcedureReturn c_mcol(actual_color) ;actual color EndIf EndProcedure ProcedureCDLL on_remove_clicked (Window, Event, Gadget, Type) actual_color=-1 CloseWindow(window) ProcedureReturn -1 EndProcedure ProcedureCDLL on_close_clicked (Window, Event, Gadget, Type) ;Your code here If IsWindow(*col_picker):CloseWindow(*col_picker):EndIf actual_color=-2 ProcedureReturn -2 EndProcedure ProcedureCDLL on_color_clicked (Window, Event, Gadget, Type) ;Your code here StickyWindow(*col_picker,#False) If actual_color >-1 mcolor= ColorRequester(c_mcol(actual_color)) Else mcolor= ColorRequester() EndIf If mcolor <>-1 c_mcol(37)=mcolor actual_color=37 CloseWindow(window) quit=1 EndIf ProcedureReturn c_mcol(actual_color) EndProcedure ProcedureCDLL on_f_color_clicked (Window, Event, Gadget, Type) ;Your code here For n=0 To 36 If gadget = b_utton(n) actual_color=n quit=1 ; SetWindowColor(0,c_mcol(actual_color)) CloseWindow(window) ProcedureReturn c_mcol(actual_color) EndIf Next EndProcedure DataSection colors: Data.l $0000FF Data.l $00FF00 Data.l $FF0000 Data.l $00FFFF Data.l $FFFF00 Data.l $FF00FF Data.l $FFFFFF Data.l $000000 Data.l $44BABB Data.l $63A29C Data.l $4171BE Data.l $C397CA Data.l $833F7C ;greys Data.l $0C0C0C Data.l $191919 Data.l $262626 Data.l $333333 Data.l $3F3F3F Data.l $4C4C4C Data.l $595959 Data.l $666666 Data.l $727272 Data.l $7F7F7F Data.l $8C8C8C Data.l $999999 Data.l $A5A5A5 Data.l $B2B2B2 Data.l $BFBFBF Data.l $CCCCCC Data.l $D8D8D8 Data.l $E5E5E5 Data.l $F2F2F2 Data.l $545454 Data.l $BFBFBF Data.l $A8A8A8 Data.l $CCCCCC EndDataSection ; IDE Options = PureBasic v4.02 (Windows - x86) ; Folding = s- ; Executable = col_picker