Best way to extend GUI elements to add features

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
rubenwardy
Posts: 91
Joined: Mon Mar 05, 2012 4:51 pm
Location: Bristol, UK
Contact:

Best way to extend GUI elements to add features

Post by rubenwardy »

Hi!

Unfortunately, I project I'm working with is stuck with Irrlicht's built-in GUIs until we get around to making a replacement. I'd like to add the ability to dynamically style elements.
Working picture showing you what I mean:

Image

I've copied CGUIButton and CGUISKin to my project.
I had to do the former because you don't allow subclassing due to the inaccessible headers for CGUIButton, which is incredibly annoying.
I had to do the latter to implement a drawColored3DButtonStandard and drawColored3DButtonPressed, but I may try moving these functions into CGUIButton itself to reduce the risk of breakages.

Is there a better way of doing this?

I've effectively backported a few of the button improvements including override colors, which means that I have to have ugly code like this:

Code: Select all

 
#if (IRRLICHT_VERSION_MAJOR > 1 || IRRLICHT_VERSION_MINOR != 8 || IRRLICHT_VERSION_REVISION < 5)
    namespace irr { namespace gui {
 
        //! State of buttons used for drawing texture images.
        //! Note that only a single state is active at a time
        //! Also when no image is defined for a state it will use images from another state
        //! and if that state is not set from the replacement for that,etc.
        //! So in many cases setting EGBIS_IMAGE_UP and EGBIS_IMAGE_DOWN is sufficient.
        enum EGUI_BUTTON_IMAGE_STATE {
            //! When no other states have images they will all use this one.
                    EGBIS_IMAGE_UP,
            //! When not set EGBIS_IMAGE_UP is used.
                    EGBIS_IMAGE_UP_MOUSEOVER,
            //! When not set EGBIS_IMAGE_UP_MOUSEOVER is used.
                    EGBIS_IMAGE_UP_FOCUSED,
            //! When not set EGBIS_IMAGE_UP_FOCUSED is used.
                    EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER,
            //! When not set EGBIS_IMAGE_UP is used.
                    EGBIS_IMAGE_DOWN,
            //! When not set EGBIS_IMAGE_DOWN is used.
                    EGBIS_IMAGE_DOWN_MOUSEOVER,
            //! When not set EGBIS_IMAGE_DOWN_MOUSEOVER is used.
                    EGBIS_IMAGE_DOWN_FOCUSED,
            //! When not set EGBIS_IMAGE_DOWN_FOCUSED is used.
                    EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER,
            //! When not set EGBIS_IMAGE_UP or EGBIS_IMAGE_DOWN are used (depending on button state).
                    EGBIS_IMAGE_DISABLED,
            //! not used, counts the number of enumerated items
                    EGBIS_COUNT
        };
 
        //! Names for gui button image states
        const c8 *const GUIButtonImageStateNames[EGBIS_COUNT + 1] =
                {
                        "Image",    // not "ImageUp" as it otherwise breaks serialization of old files
                        "ImageUpOver",
                        "ImageUpFocused",
                        "ImageUpFocusedOver",
                        "PressedImage",    // not "ImageDown" as it otherwise breaks serialization of old files
                        "ImageDownOver",
                        "ImageDownFocused",
                        "ImageDownFocusedOver",
                        "ImageDisabled",
                        0    // count
                };
 
    }}
 
#endif
 
It would be great if you could release more regularly, releases don't need to be big.

Here's the link to the code: https://github.com/minetest/minetest/pull/8383

TL;DR: how would you recommend extending GUI elements to support more draw features?
Last edited by rubenwardy on Sat Mar 16, 2019 12:29 am, edited 1 time in total.
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: Best way to extend GUI elements to add features

Post by chronologicaldot »

Unfortunately, Irrlicht was written with a primitive view of the needs of a GUI, so I've had to resort to copying things as you have. Sorry, no workarounds. One alternative I've found is simply creating a wrapper GUI element and just passing info along to the private element. Essentially, you're using the GUI element as a storage class, and it's still inconvenient depending on what you need it for.

If you only need to change the GUI button color, then you could just use a custom skin. The IGUISkin interface receives a pointer to the GUI element, and you can use that pointer to compare with a list (inside the skin class) of known buttons that have their colors changed. It's slow (if the list gets big) but probably not as messy as what you're doing.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Best way to extend GUI elements to add features

Post by CuteAlien »

Yeah, copying code and modifying stuff yourself is the easiest way.

Another way is to use Irrlicht trunk and post patches for the stuff you need. At least some of them will find their way in the engine and improve life for everyone.

And yes, more releases would have been great. But unfortunately around half a decade ago we opened up too many construction sides all over the engine and then also some people familar with those construction sides left. Which added a few nice features back then, but unfortunately also ended up with lots of stuff being unfinished/broken until today, so we still can't release 1.9. I still work on Irrlicht, so hopefully one day there will be another release. Everyone can help by reporting bugs and writing patches (and writing tests for their patches).
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
rubenwardy
Posts: 91
Joined: Mon Mar 05, 2012 4:51 pm
Location: Bristol, UK
Contact:

Re: Best way to extend GUI elements to add features

Post by rubenwardy »

I really don't want to touch SVN or Source Forge: both suck so bad
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: Best way to extend GUI elements to add features

Post by chronologicaldot »

Meh. You get used to it. Every repo type has its advantages and disadvantages. Don't be afraid of the console/terminal.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Best way to extend GUI elements to add features

Post by CuteAlien »

Yeah, absolutely. I use git at work, hg at most of my home projects and svn for Irrlicht. And really every one has advantages/disadvantages depending on the situation. svn seriously lacks features (especially local branching), but also nearly never causes troubles. git has great features, but still raises my wtf count after using it for years. hg is certainly perfect (just joking, I use for way smaller projects than the other 2 systems, so I simply don't run into much troubles with it).

Anway - you can check-out Irrlicht with svn and put it into your local git (or hg) repository. You have no write access for svn anyway. Make sure to ignore all .svn folders in your .gitignore and from there on you are fine with occasional svn updates followed by git-commits.
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
rubenwardy
Posts: 91
Joined: Mon Mar 05, 2012 4:51 pm
Location: Bristol, UK
Contact:

Re: Best way to extend GUI elements to add features

Post by rubenwardy »

I'm not afraid of the terminal, I use it for git and compiling all the time. I just don't want to use malware infected sites like sourceforge or slow tools like svn

But I can just send patches anyway
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Best way to extend GUI elements to add features

Post by CuteAlien »

Note that the malware stuff was done by old Sourceforge owners. They got sold shortly after that and one of the first things the new owners did was to remove all that crap from installers again. Not that Irrlicht was ever affected as we just distributed our own .zip file. And svn downloads never were affected for anyone.

github became owned by Microsoft in the meantime (they probably will do a good job 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
Post Reply