How do you make an image transparent on a button?
Posted: Thu Jan 15, 2009 8:18 pm
I want to use images for buttons but I want them to appear to be translucent. The issue is that when I use _gui->getSkin()->setColor(...) it does nothing to the images. It makes text and sliders and buttons translucent but the image remains the same. Any help would be awesome.
I then go through all of the items in the gui and set the alpha value to 150 so they appear translucent:
I could just do a _gui->addimage(...) and set the translucentness of the image but it would be nicer to use the already written button functionality so I don't have to rewrite what has already been done.
Screenshot:
Left is a button with an image on it and right is a plain button. Both have the _gui->getSkin()->setColor(...) applied to them with a 100 alpha. The left has no change and the right is see through.
Code: Select all
// create a button
gui::IGUIButton *b1 = _gui->addButton(core::rect<s32>(0,0,128,128));
//remove the border of the button.
b1->setDrawBorder(false);
// set the image
b1->setImage(device->getVideoDriver()->getTexture("../../media/button1.png"));
// use the alpha channel so we get no background
b1->setUseAlphaChannel(true);
Code: Select all
// loop through all items and set alpha to 150
for (s32 i=0; i<gui::EGDC_COUNT ; ++i)
{
video::SColor col = _gui->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);
col.setAlpha(150);
_gui->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)i, col);
}
Screenshot:
Left is a button with an image on it and right is a plain button. Both have the _gui->getSkin()->setColor(...) applied to them with a 100 alpha. The left has no change and the right is see through.