January 16, 2018, 09:39:50 PM

Author Topic: ModifyGadgetItem  (Read 223 times)

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
ModifyGadgetItem
« on: November 27, 2017, 03:02:03 PM »
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

Offline Henri

  • Jr. Member
  • **
  • Posts: 58
Re: ModifyGadgetItem
« Reply #1 on: November 27, 2017, 06:07:07 PM »
Hi,

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

Example:

Code: BlitzMax
  1. AddGadgetItem( Toolbar, "", GADGETITEM_TOGGLE, 3,"My tool")

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

-Henri

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
Re: ModifyGadgetItem
« Reply #2 on: November 27, 2017, 06:15:54 PM »
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.

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
Re: ModifyGadgetItem
« Reply #3 on: November 27, 2017, 06:24:40 PM »
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!

Offline Henri

  • Jr. Member
  • **
  • Posts: 58
Re: ModifyGadgetItem
« Reply #4 on: November 27, 2017, 06:35:58 PM »
Can you show how you create your toolbar ?

-Henri

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
Re: ModifyGadgetItem
« Reply #5 on: November 28, 2017, 01:33:53 AM »
dup

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
Re: ModifyGadgetItem
« Reply #6 on: November 28, 2017, 01:38:28 AM »
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).

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
Re: ModifyGadgetItem
« Reply #7 on: November 28, 2017, 01:41:16 AM »
' 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.

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
Re: ModifyGadgetItem
« Reply #8 on: November 28, 2017, 11:25:17 AM »
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.

Offline Henri

  • Jr. Member
  • **
  • Posts: 58
Re: ModifyGadgetItem
« Reply #9 on: November 28, 2017, 01:37:21 PM »
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
  1. Strict
  2.  
  3. Import maxgui.drivers
  4.  
  5. Global toolbar_pix:TPixmap = LoadPixmap("toolbar.png")
  6. Global icon_strip:TIconStrip = LoadIconStrip( toolbar_pix )
  7.  
  8. Local window:TGadget    = CreateWindow("MyWindow",0 , 0, 600, 400)
  9. Local toolbar:TGadget   = CreateToolbar( "", 0, 0, 0, 0, window )
  10.  
  11. SetGadgetIconStrip( toolbar , icon_strip )
  12.  
  13. 'Lets assume iconstrip has 10 icons, but we use only first five for this toolbar
  14. AddGadgetItem( toolbar , "" , GADGETITEM_NORMAL , 0 , "New" , Null )
  15. AddGadgetItem( toolbar , "" , GADGETITEM_NORMAL , 1 , "Open" , Null )
  16. AddGadgetItem( toolbar , "" , GADGETITEM_NORMAL , 2 , "Save" , Null )
  17. AddGadgetItem( toolbar , "" , GADGETITEM_TOGGLE , 3 , "Toggle" , Null )
  18.  
  19. While WaitEvent()
  20.         Print CurrentEvent.ToString()
  21.         Select EventID()
  22.                 Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE;End
  23.                 'ToolBar Event(s)
  24.                 'EventData() holds the index of the toolbar item clicked.
  25.                 Case EVENT_GADGETACTION
  26.                         Select EventSource()
  27.                                 Case toolbar
  28.                                         SetStatusText window, "Toolbar Item Clicked: " + EventData()
  29.                         EndSelect
  30.         End Select
  31. WenD
  32.  

-Henri

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 13
Re: ModifyGadgetItem
« Reply #10 on: January 12, 2018, 01:26:15 AM »
Thanks H. Sorry, I've been away for a month!