Custom GUI Element

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Custom GUI Element

Post by Arclamp »

So, beginning to explore further, without recompiling base library.



I have basically copied and renamed ICGUIButton.
I've incorporated a pointer to the device and swapped out getTime().

Then I create the a new instance of the element and set the device.
In the render loop I call draw() and it gets drawn, excellent!

Next I passed a pointer of the element to the event receiver, and in OnEvent() I pass on the call to the instance, but nothing happens when the button is pressed.


What needs to be added to get this fully working, and if possible, actually registered so not have to call draw() and OnEvent() manually?

Cheers
Last edited by Arclamp on Sun Jul 30, 2017 10:30 am, edited 2 times in total.
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Custom GUI Element

Post by Arclamp »

:D

So, I needed to add a parent instead of using 0!
Then remove my own call to OnEvent().
Also removed own call to draw().

Works brilliant!
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom GUI Element

Post by CuteAlien »

Guess you found out yourself while I was still typing the answer. I'll have to type faster :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: [SOLVED] Custom GUI Element

Post by Arclamp »

Thanks, you'll probably know this one though...

The only change I was playing with was to colourise a custom image, e.g.

Code: Select all

 
driver->draw2DImage(Image,
                    ScaleImage? AbsoluteRect :
                        core::recti(pos, ImageRect.getSize()),
                    ImageRect, &AbsoluteClippingRect,
                    [b]img_color[/b], UseAlphaChannel);
 
which works fine, but how do I get rid of the button fade / gradient overlay please?
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Custom GUI Element

Post by CuteAlien »

@ Arclamp: Hm, maybe give me a screenshot so I know what you mean to clarify (you can put it on a service like imgur and link to it here). Do you mean maybe you draw that draw2DImage over the same position where you have a button and the image has alpha - so the button shows behind it? You can change skin-colors for gui with IGUISkin->setColor, you have to experiment a little which one affects buttons. Button has functions to use images directly by the way (even got more features if you use Irrlicht svn trunk version). What's missing is disabling skin-drawing completely if no image is set (I guess you could set an invisible image).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: [SOLVED] Custom GUI Element

Post by Arclamp »

I will later...

So, if I use setTexture() on a standard button, its that texture as is, nice and clear.

Now I've ripped it out (and use new instead of create...()), the button gets another skin (yes, like window bg) layer once I add the texture. Seems odd, tried commenting out loads, but always comes???

I'll post image later, cheers
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Custom GUI Element

Post by CuteAlien »

Arclamp wrote:So, if I use setTexture() on a standard button, its that texture as is, nice and clear.
Should be possible, I think...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: [SOLVED] Custom GUI Element

Post by Arclamp »

Image

The full red is a tinted IGUIImage, original is a standard IGUIButton, and custom is basically a standard button but with only the following change:

Code: Select all

 
void TestButton::draw()
{
            ...
            
            driver->draw2DImage(Image,
                    ScaleImage? AbsoluteRect :
                        core::recti(pos, ImageRect.getSize()),
                    ImageRect, &AbsoluteClippingRect,
                    img_color, UseAlphaChannel);
                    //0, UseAlphaChannel);
 
Oh, I also set image to scaled so can see easier...
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Custom GUI Element

Post by CuteAlien »

"Custom" looks strange. My guess would be that texture has that kind of alpha? Maybe compare how it looks when you disable alpha on drawing? Because that kind of gray doesn't look like the gray you would get for buttons (that one is uniform usually I think - unless you have a custom skin as well).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: [SOLVED] Custom GUI Element

Post by Arclamp »

Its baffling, defies logic!

No custom skin, its basically just the GUI Demo.
Virtually the same with alpha, drawborder, etc...

I'll try again from scratch later n see if I did something I don't remember (was a late night off the cuff thing).

Oh, the texture is just "media/stones.jpg" and I not set any colorkey...
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Custom GUI Element

Post by CuteAlien »

Sorry, don't know how alpha's look in that texture (alpha is hard to see in most tools...). And texture can have alpha without colorkey (in case someone put some alpha in there in the paint program).

So... try another texture.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: [SOLVED] Custom GUI Element

Post by Arclamp »

As far I'm aware without checking is that it doesn't have any alpha, also it works on the others using exactly the same loaded texture.

Code: Select all

 
void TestButton::draw()
{
            ...
            driver->draw2DImage(Image,
                    ScaleImage? AbsoluteRect :
                        core::recti(pos, ImageRect.getSize()),
                    ImageRect, &AbsoluteClippingRect,
                    img_color, UseAlphaChannel);
                    //0, UseAlphaChannel);
 
when I changed back to this (earlier), then it works as expected... (but without extra new colour)

Code: Select all

 
void TestButton::draw()
{
            ...
            driver->draw2DImage(Image,
                    ScaleImage? AbsoluteRect :
                        core::recti(pos, ImageRect.getSize()),
                    ImageRect, &AbsoluteClippingRect,
                    //img_color, UseAlphaChannel);
                    0, UseAlphaChannel);
 
I couldn't see anything else that I'd changed in the button code.
I checked addButton() in env...cpp and saw nothing I wasn't doing...

also I tried swapping the lower draw method of:

Code: Select all

 
//skin->draw3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect);
skin->draw2DRectangle()...
 

Good news, overriding font colour works fine... :D
Post Reply