Selected toolbar buttons [MaxGUI]

BlitzMax Forums/BlitzMax Beginners Area/Selected toolbar buttons [MaxGUI]

po(Posted 2006) [#1]
Is there a way to make a toolbar(from pixmap) that has buttons you can 'select'? I can create a normal toolbar no problem, but what I need is to be able to click one of the buttons and they will stay held down or selected. It's kind of hard to explain, but it's popular in a lot of apps. It's like the radio buttons of toolbars...


Brucey(Posted 2006) [#2]
when you create the toolbar button using AddGadgetItem, for the flag parameter set it with GADGETITEM_TOGGLE.
When you click on that item, it should then stay selected.

:-)


po(Posted 2006) [#3]
Ah, it's so simple! Thanks.
I didn't see that in the docs :/


po(Posted 2006) [#4]
UGHHHHH.
This is so frustrating. When you create a toolbar it automatically puts the pixmap icons there and so the only way to make all the buttons toggle is if you delete all of them then use AddGadgetItem??
Local toolbar:TGadget=CreateToolBar(image.png",0,0,640,32,window)
	
	For Local n:Int=1 To 10
		RemoveGadgetItem(toolbar,n)		
	Next	
	For Local n:Int=1 To 10
		AddGadgetItem(toolbar,Null,2,n,"blah")
	Next


This doesn't even work becuase it keeps giving me and error 'index out of range'

Surely there is a better way?


po(Posted 2006) [#5]
PLEEeeeessseeee tell me if there is a better way somebody....


impixi(Posted 2006) [#6]

SuperStrict

Local window:TGadget=CreateWindow("My Window",40,40,320,240)

'Load your icon images from a file 
'Each icon should have two visual states: off and on, beside each other
Local icons:TIconStrip=LoadIconStrip("icons.png")

'Create an 'empty' toolbar
Local toolbar:TGadget=CreateToolBar("",0,0,640,32,window)

'Associate your icons with your toolbar
SetGadgetIconStrip(toolbar, icons)

'Attach each individual icon, set it as a toggle
'Remember, every second visual icon represent the 'on' state
For Local n:Int=0 To icons.count - 1 Step 2
  AddGadgetItem toolbar, String(n), GADGETITEM_TOGGLE,n
Next


While True
	WaitEvent 
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend
	
End




po(Posted 2006) [#7]
icons.count gave me an error, so I changed it to 19 (the number of frames-1).
Still doesn't work though, you can see that there is an empty toolbar there. I don't believe you can use SetGadgetIconStrip with toolbars.


assari(Posted 2006) [#8]
Working code example
SuperStrict 
            
Local Window:TGadget= CreateWindow ("My Window",50,50,800,600)
Local Panel:TGadget = CreatePanel (50,50,367,42,Window)
Local Toolbar:TGadget= CreateToolBar("",0,0,0,0,Panel)


Local url:String="D:\My Documents on E\_20060101\" '<---Change this location
Local icons:TIconStrip=LoadIconStrip(url+"icons.png")
SetGadgetIconStrip(toolbar, icons)

AddGadgetItem Toolbar,"",GADGETITEM_NORMAL,1,"New Map"
AddGadgetItem Toolbar,"",GADGETITEM_NORMAL,2,"Load Map"
AddGadgetItem Toolbar,"",GADGETITEM_NORMAL,3,"Save Map"
AddGadgetItem toolbar,"",0,0
AddGadgetItem Toolbar,"",GADGETITEM_TOGGLE | GADGETITEM_DEFAULT,4,"Pointer Tool"
AddGadgetItem Toolbar,"",GADGETITEM_TOGGLE,6,"Select Tool"
AddGadgetItem Toolbar,"",GADGETITEM_TOGGLE,8,"Tile Tool"
AddGadgetItem Toolbar,"",GADGETITEM_TOGGLE,10,"Fill Tool"
AddGadgetItem toolbar,"",0,0
AddGadgetItem Toolbar,"",GADGETITEM_NORMAL,12,"Zoom In"
AddGadgetItem Toolbar,"",GADGETITEM_NORMAL,13,"Zoom Out"

While WaitEvent()
	Select EventID()
		Case EVENT_GADGETACTION
			If EventSource()=toolbar 
				Print "ToolBar GadgetAction~nEventData()="+EventData()
			EndIf
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend

saveas this image
Image and code adapted from this thread http://www.blitzmax.com/Community/posts.php?topic=57815 and impixi's code above


impixi(Posted 2006) [#9]
@Po:

Interesting. It works flawlessly for me. I'll do some further testing.

It is possible I'm using an 'unsupported' feature.

What version of BlitzMax are you using and on what platform? Have you 'synchronized modules' recently?

EDIT
Thanks assari. Your code is more practical...


po(Posted 2006) [#10]
EDIT: Yey after syncmods, it works! thanks.