ModifyGadgetItem

Started by Juiceter, November 27, 2017, 15:02:03

Previous topic - Next topic

Juiceter

Hey all,

I'm having a bit of trouble with gadgetstrips.

I want to click an icon and have its graphic change to another icon.

The problem comes with ModifyGadgetItem(), in that it only seems to allow you to change one icon to another in the strip. This is fine, but only if you extend the strip out of the view area, and change a visible icon to one that is out of view, but this means you have to extend the strip off the screen, which is messy (especially if you have only a few icons in the strip).

Is there any other way to do this (i.e. load in an alternate icon pixmap and toggle between that instead)? Any pointers?

Thanks in advance

Henri

#1
Hi,

you could use AddGadgetItem with GADGETITEM_TOGGLE flag to create alternating image.

Example:

Code (blitzmax) Select

AddGadgetItem( Toolbar, "", GADGETITEM_TOGGLE, 3,"My tool")


This would create an alternating icon between icons 3 & 4 from your iconstrip.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Juiceter

#2
Thanks H, I'll have a look and see if that works for me.

Edit: well it presents the same problem does it not? I don't want to select any other visible icon to replace an icon (say if I have a green square as an icon, i want to replace it with a blue square, and back to a green square again if it's clicked on again).

I'm looking at removing then adding at the minute, but its a bit of a roundabout way of doing things. I was hoping you could load an icon and simply replace the clicked icon with that and toggle between the two.

Juiceter

Quote from: Juiceter on November 27, 2017, 18:15:54
Thanks H, I'll have a look and see if that works for me.

Edit: well it presents the same problem does it not? I don't want to select any other visible icon to replace an icon (say if I have a green square as an icon, i want to replace it with a blue square, and back to a green square again if it's clicked on again).

I'm looking at removing then adding at the minute, but its a bit of a roundabout way of doing things. I was hoping you could load an icon and simply replace the clicked icon with that and toggle between the two.

Maybe I'm just looking at this wrong and the answer will come with a little tinkering!

Henri

Can you show how you create your toolbar ?

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Juiceter

#5
dup

Juiceter

#6
Basically when I click the blue icon, i want to swap it for an unshown green icon rather than the first one in the list (in the code below).

Juiceter

Quote from: Juiceter on November 28, 2017, 01:38:28
Quote from: Juiceter on November 28, 2017, 01:33:53
' 1. load the strip in
Incbin "Icon Strip.png"             ; Global icons=LoadPixmap:TPixmap("Icon Strip.png")


' 2. needs to be global (parms dont matter)
Global toolbar:TGadget=CreateToolbar(icons,0,0,24*16,24,window) ; HideGadget toolbar
Global bgndadd=0 ' Background addition type (default Sea). Variable for the Icon toggle.



' 3. problem area (within case statement)

                  Case 6 ' Background addition.
                     If(bgndadd=0)
                        bgndadd=bgnd
                        ModifyGadgetItem(toolbar,6,"",,0,"Background Addition: Land",Null)   
                     Else
                        bgndadd=0
                        ModifyGadgetItem(toolbar,6,"",,6,"Background Addition: Sea",Null)   
                     EndIf


end of code


This swaps icon 6 (the Sea tile icon) for icon 0 (actually the icon to change the direction of the cursor) and back again (works but not what I want).
Instead of icon 0 i want an icon in the strip that hasn't already been displayed (the land icon). The problem is it will only work with an icon currently in the strip. If I could get it to toggle between an external icon rather than the one at index 0 and back to 6 again then i'd be in business!

Of course, if you could hide individual icons in the toolbar then it wouldn't be a problem (maybe you can?). The only way I can get it to work is if I extend the toolbar off the screen and pick an icon that isnt in view.

Hope this helps. I'm fairly new to maxGUI and don't know all the intricacies of it yet.

Juiceter

#8
Ok - i think ive got it.

add the extra icon (green) and then remove it before you start...

RemoveGadgetItem(toolbar,16)

this makes it invisible on the toolbar, but it can still be accessed.

So then all you need to do is

ModifyGadgetItem(toolbar,6,"",,16,"Background Addition: Land",Null).


This works, but the toolbar does flicker as it does so, which is unfortunate. Not sure if theres a way to get rid of the flicker in windowed mode.

Henri

You can create iconstrip seperately and attach it to toolbar afterwards. Then you can add toolbar items one by one with AddGadgetItem. This way your iconstrip can be as large as you like and have more control which icons are shown.


Example:

Code (blitzmax) Select

Strict

Import maxgui.drivers

Global toolbar_pix:TPixmap = LoadPixmap("toolbar.png")
Global icon_strip:TIconStrip = LoadIconStrip( toolbar_pix )

Local window:TGadget = CreateWindow("MyWindow",0 , 0, 600, 400)
Local toolbar:TGadget = CreateToolbar( "", 0, 0, 0, 0, window )

SetGadgetIconStrip( toolbar , icon_strip )

'Lets assume iconstrip has 10 icons, but we use only first five for this toolbar
AddGadgetItem( toolbar , "" , GADGETITEM_NORMAL , 0 , "New" , Null )
AddGadgetItem( toolbar , "" , GADGETITEM_NORMAL , 1 , "Open" , Null )
AddGadgetItem( toolbar , "" , GADGETITEM_NORMAL , 2 , "Save" , Null )
AddGadgetItem( toolbar , "" , GADGETITEM_TOGGLE , 3 , "Toggle" , Null )

While WaitEvent()
Print CurrentEvent.ToString()
Select EventID()
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE;End
'ToolBar Event(s)
'EventData() holds the index of the toolbar item clicked.
Case EVENT_GADGETACTION
Select EventSource()
Case toolbar
SetStatusText window, "Toolbar Item Clicked: " + EventData()
EndSelect
End Select
WenD


-Henri
- Got 01100011 problems, but the bit ain't 00000001

Juiceter

Thanks H. Sorry, I've been away for a month!