Adding images to combobox items

BlitzMax Forums/BlitzMax Beginners Area/Adding images to combobox items

Marco A G Pinto(Posted 2013) [#1]
Hello!

I was trying to add images to comboboxes but the help talks about a strip command or something like that which I haven't been able to understand.

	CreateLabel("Automata:",5,10,120,16+1,panel_main)
	Global combo_automata=CreateComboBox:TGadget(5+5,10+16+3,100+30,16+1-2,panel_main,0)
	AddGadgetItem combo_automata,"Custom"
	AddGadgetItem combo_automata,"Wolfram, p. 24", True


I wanted to replace the text with an image for each item.

How can I do it?

Thanks!

Kind regards,
>Marco A.G.Pinto
--------------------


jsp(Posted 2013) [#2]
Here is an example. You need to refer to your own icons of course...




Marco A G Pinto(Posted 2013) [#3]
jsp: Thank you for your help.

I can't understand the code though :(

Could you give an example with one more icon, because the example you gave only shows the first item of the combobox with the image?

Thanks!

Kind regards,
>Marco A.G.Pinto
--------------------


Brucey(Posted 2013) [#4]
An iconstrip image is a long, single image made up of a horizontal row of individual icons of a specific size. The width of the iconstrip is usually a multiple of the height, and indicates how many icons are in the file.

Have a look at the toolbar.png image in the maxgui.mod/doc folder, as an example.


Marco A G Pinto(Posted 2013) [#5]
Thanks, my dear ones!

I finally understood it!

Kind regards,
>Marco A.G.Pinto
--------------------


Derron(Posted 2013) [#6]
Hmm on linux I got no icons shown in the dropdown (just created a pixmap live without success, nor when using a predefined png).

@Marco:
Check whether your Image is:
width: iconsCount*Height
height: iconsHeight you define for yourself.
so for 8 different icons at 16x16 you need a horizontal aligned icon strip of 128x16.

bye
Ron


jsp(Posted 2013) [#7]
The example should show 5 items in the combobox, all with an icon in front.

I suspect your iconstrip is may not in the right shape.
I used for the example a strip 120pixel (width) x 24pixel (height)

Some explanations:

Creating a window nothing special...
Local Window1:TGadget = CreateWindow("Window1",342,190,196,87,Null,WINDOW_TITLEBAR|WINDOW_RESIZABLE |WINDOW_STATUS |WINDOW_CLIENTCOORDS )

Creating the combobox, the window is the parent.
Local Combo1:TGadget = CreateComboBox(28,24,135,39,Window1,Null)

Loading the iconstrip as "pixmap" into Combo1_Icons:TPixmap , (was 120x24 saved as png)
This is done to be as flexible as possible.
Local Combo1_Icons:TPixmap = LoadPixmap( "IconStrip.png" )

Load the pixmap into the IconStrip format Combo1_Strip:TIconStrip.
The TIconStrip is the format which ca be attached to listbased gadget.
Local Combo1_Strip:TIconStrip = LoadIconStrip( Combo1_Icons )

Attach the strip the combobox
That means the combobox can use when you refer to it during adding new items
SetGadgetIconStrip( Combo1 , Combo1_Strip )

Add a new item (text could be empty) and attach icon number 0 (here the last parameter)
AddGadgetItem( Combo1,"Item1",GADGETITEM_NORMAL,0 )

All following items just use the next icon in the strip.
0 to 4 (5 icons 24x24= 120x24)
The last parameter in the AddGadgetItem refers to to icon position inside the strip
The position you point to don't need to be the next but can be any, or even several times the same


Marco A G Pinto(Posted 2013) [#8]
Thanks for all your help, I was able to add icons to my combobox :)


Derron(Posted 2013) [#9]
like said... no luck with linux and fltk.

bye
Ron


Brucey(Posted 2013) [#10]
... and fltk

*cough*


GaryV(Posted 2013) [#11]
Derron: Welcome to MaxGUI on Linux.


Derron(Posted 2013) [#12]
@Gary: ... I got welcomed to linux and blitz/Max/Gui ages ago :D.

Just wanted to rant against the current linux-maxgui/blitzmax-support.
Aehh I mean I just wanted to mention that the solution above is not cross platform.


@Brucey: do not cough! safe your breath and continue doing magic... or write something to your blogs... last update: Wednesday, 16 January 2013... *cough* :-).


bye
Ron


Henri(Posted 2013) [#13]
Perhaps Brucey was trying to hint that there is a alternative to MaxGUI default Linux/fltk implementation ?

-Henri


GaryV(Posted 2013) [#14]
Just wanted to rant against the current linux-maxgui/blitzmax-support.



If one didn't know better one would think the owner abandoned ship and started a whole new product and site...