Toolbar icons

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
nkwinder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Sun Nov 23, 2008 2:32 pm

Toolbar icons

Post by nkwinder »

i know this subject has been discussed over and over again, with many related threads but i still can't find a suitable workflow with good results.

My wish is (you guessed it) png embedded.

I tried wxInclude, but i had error messages popping up at startup saying image can't be added to image list (or sth like that).

I then tried a function i found in this forum, which loads png from resource file. This worked partially. I couldn't use these images for the disabled state of a toolbar button.

Then i left the idea of png, and tried xpm. First bad thing is that it supports only 1 bit alpha. Anyway, at least i see the images in both enabled and disabled states.

But i still have problems. See this image for an example. Outside the box boundaries, image should be transparent. This is true, if the button is unpressed, but when it is pressed transparency is gone! It seems like windows trying to fake transparency, by applying the background color...?

Image

Code: Select all

/* XPM */
static char * select_xpm[] = {
"25 25 3 1",
" 	c None",
".	c #45464E",
"+	c #BFBDBC",
"                         ",
"                         ",
"                         ",
"   ....   .....   ....   ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"    +++++++++++++++++    ",
"    +++++++++++++++++    ",
"    +++++++++++++++++    ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"    +++++++++++++++++    ",
"    +++++++++++++++++    ",
"    +++++++++++++++++    ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"   .+++++++++++++++++.   ",
"   ....   .....   ....   ",
"                         ",
"                         ",
"                         "};

Another problem now... If a check tool button is unpressed and gets disabled, then the assigned disabled state image is shown. But if the button is pressed, and then gets disabled the active image is shown (although the button is indeed disabled).

I would be really thankful if someone told me a nice way of dealing with all these issues, once and forever. It's really disappointing in 2009 to fight for some decent transparency :lol:.


p.s i use vista
Last edited by nkwinder on Sat Feb 07, 2009 1:42 pm, edited 1 time in total.
nkwinder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Sun Nov 23, 2008 2:32 pm

Post by nkwinder »

so no one has anything to say about this subject? I guess then none of you use images in your application huh?
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch »

To embed images (like a png), I've made a quick and sloppy utility in the past which just converts the .png file into a .h file with a big static const array. Kind of like how xpm is the image as a big string -- except the .png will be much smaller (usually -- for very small images it might not be). I never heard of/tried wxInclude -- I might have to look at it.

From there I just #include the header and load the wxImage via a wxMemoryInputStream. After converting to wxBitmap, I can then add it to my toolbar without problems. This has worked with both pngs with an alpha channel as well as ones with just a tRNS tag.

I have never experienced your weird problem with the colors screwing up so I don't know what could be happening. However I did notice this blurb in the wxToolBar documentation:
wxToolBar95: Note that this toolbar paints tools to reflect system-wide colours. If you use more than 16 colours in your tool bitmaps, you may wish to suppress this behaviour, otherwise system colours in your bitmaps will inadvertently be mapped to system colours. To do this, set the msw.remap system option before creating the toolbar:

wxSystemOptions::SetOption(wxT("msw.remap"), 0);

If you wish to use 32-bit images (which include an alpha channel for transparency) use:

wxSystemOptions::SetOption(wxT("msw.remap"), 2);
Maybe try slipping that call into your init code to see if it helps.
nkwinder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Sun Nov 23, 2008 2:32 pm

Post by nkwinder »

let's focus in these two things:

1. If a check tool button is unpressed and gets disabled, then the assigned disabled state image is shown. But if the button is pressed, and then gets disabled the active image is shown (although the button is indeed disabled).

2. Has anyone tried the SetToolDisabledBitmap() with an embeded png?
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch »

1. I just confirmed this happens on my machine running Win2K as well. I wonder if this is a bug in wx? Strangely, if you don't specify a disabled bitmap, then the disabled version of the normal bitmap shows fine when the checkbox is disabled -- but not if you do specify a disable bitmap.

Very strange. Though SetToolDisableBitmap does have the following blurb about it:
wxToolBar page wrote: NOTE: The native toolbar classes on the main platforms all synthesize the disabled bitmap from the normal bitmap, so this function will have no effect on those platforms.
It would be nice to know which platforms it's specifically talking about.

But yeah, anyway I don't know what the problem is here. This is definately weird. I guess the best advice I'd have is to not use the disabled bitmap for checkboxes orradio buttons and let the synthesised version be used instead -- but I've found this looks horrible for images which make heavy use of alpha blending.



2. Yes. Aside from the above anomoly it works fine. Whether or not the image is embedded can't make any difference as long as it's loaded properly.
Post Reply