toolbar+gadgetitem_toggle
BlitzMax Forums/MaxGUI Module/toolbar+gadgetitem_toggle
| ||
Strict Import maxgui.drivers Local window:TGadget=CreateWindow("My Window",50,50,480,240) Local toolbar:TGadget=CreateToolBar("icons.PNG",0,0,0,0,window) ModifyGadgetItem toolbar,0,"FIRST",GADGETITEM_TOGGLE,0,"First...." 'please note INDEX=0, ICON=0 ---> it should be the same or Not? While WaitEvent() Select EventID() Case EVENT_GADGETACTION If EventSource()=toolbar Print "ToolBar GadgetAction~nEventData()="+EventData() EndIf Case EVENT_WINDOWCLOSE End End Select Wend With MODIFYGADGETITEM I set the FIRST icon to be 'switchable': when the user press the icon this one should change its own aspect in another one (the parameter ICON I suppose...). Well, someone can explain me why I click on the first icon this one changes in the SECOND icon-pixmap? How it works exactly? Thanks |
| ||
I don't quite understand what you would like to do. :( If you want to change the icon displayed for a certain toolbar icon via clicking, you can use "ModifyGadgetItem" for this. In this case you have to create an iconstrip with all icons in one file and simply set the according "ModifyGadgetItem" icon flag. |
| ||
With MODIFYGADGETITEM I set the FIRST icon to be 'switchable': when the user press the icon this one should change its own aspect in another one (the parameter ICON I suppose...). Don't know what you mean by 'parameter' ICON Well, someone can explain me why I click on the first icon this one changes in the SECOND icon-pixmap? That is how it works. Every gadgetitem defined as GADGETITEM_TOGGLE will use the next icon in sequence of the iconstrip. If you want the icon in question just looking selected like an on/off switch you need to put the same icon twice in the strip. |
| ||
In addition: The iconindex inside the strip starts with 0...endofstrip-1! |
| ||
I don't quite understand what you would like to do. :( Ok, my bad...sorry! Every gadgetitem defined as GADGETITEM_TOGGLE will use the next icon in sequence of the iconstrip. If you want the icon in question just looking selected like an on/off switch you need to put the same icon twice in the strip. Thanks for the clarification Don't know what you mean by 'parameter' ICON I was reffering to this ModifyGadgetItem( gadget:TGadget,index,text$,flags=0,icon=-1,tip$="",extra:Object=Null ) Thank you very much for your explanations. Now it seems all more clear... At last I managed to obtain my result Here the small source code Strict Import maxgui.drivers Local window:TGadget=CreateWindow("My Window",50,50,480,240) Local toolbar:TGadget=CreateToolBar("icons2.PNG",0,0,0,0,window) SetToolBarTips toolbar,["New","Open","Close","Save","","Cut","Copy","Paste","Find","","Build","Build","Build And Run","Run","Step","Step In","Step Out","Stop","","Home","Back","Forward"] RemoveGadgetItem toolbar,12 ModifyGadgetItem toolbar,11,"Debug Mode",GADGETITEM_TOGGLE,11,"Debug mode" While WaitEvent() Select EventID() Case EVENT_GADGETACTION If EventSource()=toolbar Print "ToolBar GadgetAction~nEventData()="+EventData() EndIf Case EVENT_WINDOWCLOSE End End Select Wend To be honest, make everything 'double' (icons and tooltips) and removing an item is quite 'strange', but it works... Question: Is there a way to build 'manually' a toolbar (I mean: add every single item (icon+tooltip)...) from start without using CreateToolBar? CreateToolBar requires a pixmap: loading a dummy pixmap to remove it after, is not very intelligent...I know that the way CreateToolBar is implemented is because it's the common way to use a toolbar - nothing to say about this - and it's logic and useful. |
| ||
Question: Is there a way to build 'manually' a toolbar (I mean: add every single item (icon+tooltip)...) from start without using CreateToolBar? See below how I do it in Logic Gui. I do it more or less all in single steps, thus I have a better control over it. The user is able to click it's own iconstrip together in the gui and the sequence is not that important any more. Nevertheless one need to keep in mind that a toggle icon requires the next icon in order, this is something we can't control from outside. Local Window1:TGadget = CreateWindow:TGadget("Window1",433,72,217,161,Logic_Gui:TGadget,WINDOW_TITLEBAR|WINDOW_RESIZABLE |WINDOW_STATUS |WINDOW_CLIENTCOORDS ) Local Window1_Icons:TPixmap = LoadPixmap:TPixmap( "Window.png" ) Local Window1_Strip:TIconStrip = LoadIconStrip:TIconStrip( Window1_Icons:TPixmap ) Local Window1_Toolbar:TGadget = CreateToolBar( "",0,0,0,0, Window1:TGadget ) SetGadgetIconStrip( Window1_Toolbar:TGadget , Window1_Strip:TIconStrip ) AddGadgetItem( Window1_Toolbar:TGadget , "" , GADGETITEM_NORMAL , 8 , "First" , Null ) AddGadgetItem( Window1_Toolbar:TGadget , "" , GADGETITEM_NORMAL , 6 , "Second" , Null ) AddGadgetItem( Window1_Toolbar:TGadget , "" , GADGETITEM_NORMAL , 1 , "Third" , Null ) AddGadgetItem( Window1_Toolbar:TGadget , "" , GADGETITEM_NORMAL , 0 , "Fourth" , Null ) AddGadgetItem( Window1_Toolbar:TGadget , "" , GADGETITEM_NORMAL , 12 , "Last" , Null ) |
| ||
ok, thanks. I'm quite dumb today...I didn't realize I can pass a null URL parameter for the pixmap and assign after with loadpixmap/SetGadgetIconStrip... Thank you again |
| ||
No problem, it's everything else than obvious. |
| ||
After some tests under Linux I've found a bug with RemoveGadgetItem: this force me to create a toolbar 'icon by icon', so I managed these 2 functions, maybe someone can found them usefulImport MaxGui.Drivers Strict Global window:TGadget=CreateWindow("My Window",50,50,480,240,,WINDOW_TITLEBAR|WINDOW_cENTER) Global toolbar:tgadget=MakeToolBar(window,"icons_test.png") 'there are only 4 icon displayed in the toolbar, while the iconstrip have 6 items!! Local tb1:Int[]=[0,1,2,4] Local tb2:String[]=["One","Two","Activate","Activate"] Local tb3:Int[]=[2,3]' these indeces refer to the tb1 index (item 2 and item 3) ToolbarItems(toolbar,tb1,tb2,tb3) While WaitEvent() Select EventID() Case EVENT_GADGETACTION If EventSource()=toolbar Print "ToolBar GadgetAction~nEventData()="+EventData() EndIf Case EVENT_WINDOWCLOSE End End Select Wend Rem bbdoc: This function returns a toolbar attached to the window @win using the image @url about: The funcion prepares an empty toolbar with a pixmap (@url) returns: a toolbar gadget End Rem Function MakeToolBar:tgadget(win:tgadget,url$="") If url="" Return Null Local Window1_Icons:TPixmap = LoadPixmap:TPixmap( url) Local Window1_Strip:TIconStrip = LoadIconStrip:TIconStrip( Window1_Icons:TPixmap ) If window1_strip=Null Return Null Local Window1_Toolbar:TGadget = CreateToolBar( "",0,0,0,0, win) SetGadgetIconStrip( Window1_Toolbar, Window1_Strip:TIconStrip ) Return window1_toolbar End Function Rem bbdoc: this function adds to a toolbar the icons, the tooptips and what icons are 'tooglable' or not about: @tb is the toolbar already created by the function MakeToolBar @index is an array (INT) of the pixmap indeces that will be used into the toolbar @test is an array of STRING for the icon tips @toggle is an array that contains what items are togglable ie: ToolbarItems(tb,[0,1,2,3],["New","Load","Save","Active"],[3]) End Rem Function ToolbarItems(tb:tgadget=Null,index:Int[],text$[],TOgGLE:Int[]=Null) If tb=Null Return If index=Null Return If text=Null Return Local cc:Int,GSTATE:Int=GADGETITEM_NORMAL If text.length<index.length text=text[..index.length] For cc=0 Until index.length If toggle For Local c1:Int=0 Until toggle.length If toggle[c1]=cc GSTATE=GADGETITEM_TOGGLE toggle[c1]=-1 Exit Else GSTATE=GADGETITEM_NORMAL End If Next End If AddGadgetItem tb,"",GSTATE,index[cc],text[cc] Next End Function |