New new GUI Skin

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

New new GUI Skin

Post by Halan »

Hey guys,

it doesn't seem as if anyone would care but i tried improving Klaskers ImageGUI in the last days.

I now reads from zip file holding a xml and all the textures. Also it is easier to inegrate as you now only need that one Class not others to load the config.
The skin-file can also load fonts and smiliar.

I would like this to get as Irrlicht-friendly as possible and see it in vanillla irrlicht, but I don't know what bitplane thinks about such a ImageGUI.

This is how creating the skin looks like

Code: Select all

  skin = new irr::gui::CImageGUISkin(irrGui , "default.skin");
    irrGui->setSkin(skin);
Loading is handled like that

Code: Select all

CImageGUISkin::CImageGUISkin( IGUIEnvironment* guiEnv, core::stringc filePath)
{
    VideoDriver = guiEnv->getVideoDriver();
    FallbackSkin = guiEnv->getSkin();
    FallbackSkin->grab();

    //! Load the config
    guiEnv->getFileSystem()->addZipFileArchive(filePath.c_str());
    io::IXMLReader* xml = guiEnv->getFileSystem()->createXMLReader("guiskin.xml");

    //! Pointer to the current style
    SImageGUIElementStyle* currentElement = 0;

    while(xml && xml->read())
    {
        switch(xml->getNodeType())
        {
            case io::EXN_ELEMENT:
            {
                //! New Element to read
                if(core::stringw("element") == xml->getNodeName())
                {
                    core::stringw name = xml->getAttributeValue(L"name");

                    if(name == core::stringw("SunkenPane"))
                        currentElement = &Config.SunkenPane;
                    else if(name == core::stringw("Window"))
                        currentElement = &Config.Window;
                    else if(name == core::stringw("Button"))
                        currentElement = &Config.Button;
                    else if(name == core::stringw("ButtonPressed"))
                        currentElement = &Config.ButtonPressed;
                    else if(name == core::stringw("ProgressBar"))
                        currentElement = &Config.ProgressBar;
                    else if(name == core::stringw("ProgressBarFilled"))
                        currentElement = &Config.ProgressBarFilled;
                }
                else if(core::stringw("dstBorder") == xml->getNodeName())
                {
                    if(currentElement)
                    {
                        currentElement->DstBorder.Top = xml->getAttributeValueAsInt(L"top");
                        currentElement->DstBorder.Left = xml->getAttributeValueAsInt(L"left");
                        currentElement->DstBorder.Bottom = xml->getAttributeValueAsInt(L"bottom");
                        currentElement->DstBorder.Right = xml->getAttributeValueAsInt(L"right");
                    }
                }
                else if(core::stringw("srcBorder") == xml->getNodeName())
                {
                    if(currentElement)
                    {
                        currentElement->SrcBorder.Top = xml->getAttributeValueAsInt(L"top");
                        currentElement->SrcBorder.Left = xml->getAttributeValueAsInt(L"left");
                        currentElement->SrcBorder.Bottom = xml->getAttributeValueAsInt(L"bottom");
                        currentElement->SrcBorder.Right = xml->getAttributeValueAsInt(L"right");
                    }
                }
                else if(core::stringw("srcBorder") == xml->getNodeName())
                {
                    if(currentElement)
                    {
                        currentElement->SrcBorder.Top = xml->getAttributeValueAsInt(L"top");
                        currentElement->SrcBorder.Left = xml->getAttributeValueAsInt(L"left");
                        currentElement->SrcBorder.Bottom = xml->getAttributeValueAsInt(L"bottom");
                        currentElement->SrcBorder.Right = xml->getAttributeValueAsInt(L"right");
                    }
                }
                else if(core::stringw("color") == xml->getNodeName())
                {
                    if(currentElement)
                    {
                        currentElement->Color = video::SColor(
                        xml->getAttributeValueAsInt(L"alpha"),
                        xml->getAttributeValueAsInt(L"red"),
                        xml->getAttributeValueAsInt(L"green"),
                        xml->getAttributeValueAsInt(L"blue"));
                    }
                }
                else if(core::stringw("texture") == xml->getNodeName())
                {
                    if(currentElement)
                    {
                        currentElement->Texture = VideoDriver->getTexture( core::stringc( xml->getAttributeValue(L"file") ).c_str() );
                    }
                }
                else if(core::stringw("font") == xml->getNodeName())
                {
                    irr::gui::IGUIFont* font = guiEnv->getFont( core::stringc( xml->getAttributeValue(L"file") ).c_str() );

                    if(font)
                    {
                        if(core::stringw("default") == xml->getAttributeValue(L"type"))
                            this->setFont(font, EGDF_DEFAULT);
                        else if(core::stringw("button") == xml->getAttributeValue(L"type"))
                            this->setFont(font, EGDF_BUTTON);
                        else if(core::stringw("window") == xml->getAttributeValue(L"type"))
                            this->setFont(font, EGDF_WINDOW);
                        else if(core::stringw("menu") == xml->getAttributeValue(L"type"))
                            this->setFont(font, EGDF_MENU);
                        else if(core::stringw("tooltip") == xml->getAttributeValue(L"type"))
                            this->setFont(font, EGDF_TOOLTIP);
                    }
                }
                break;

            }
            case io::EXN_ELEMENT_END:
            {
                //! Finished reading one elemnt
                if(core::stringw("element") == xml->getNodeName())
                    currentElement = 0;

                break;
            }

            case io::EXN_TEXT:
            case io::EXN_NONE:
            case io::EXN_COMMENT:
            case io::EXN_CDATA:
            case io::EXN_UNKNOWN:
            break;
        }
    }

    if(xml)
        xml->drop();
}
Here are the files. I hope Klasker is okay with the changes :)
http://uploaded.to/?id=7phyd7

Greets,
Halan

Ps: As i mentioned in the other threads. I would like to have sperate methods to draw CheckBoxes and LoadingBars. Also im wondering if clipRects.h is still needed as Klaskers calls it a bug-fix.

EDIT: i just saw that theres still a defenition of loadConfig in the header. You can remove that as it isn't needed anymore.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Klasker's GUI has already been added to irrExt. This is the place where further development from our side will happen.
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post by Halan »

hybrid wrote:Klasker's GUI has already been added to irrExt. This is the place where further development from our side will happen.
oh okay. I replied in the original thread but nobody answered so i thought it wasn't that popular.

Tthat means i wasted some hours of work. But maybe you will find my changes helpful somehow so i can feel like having spend my time useful :P

thanks for replying,
Halan
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

lets asume i'm changing the gui in midgame.

which file will be loaded when i call the following?

Code: Select all

guiEnv->getFileSystem()->addZipFileArchive(filePath.c_str());
    io::IXMLReader* xml = guiEnv->getFileSystem()->createXMLReader("guiskin.xml");
The new guiskin.xml? or the one already in memory? i would say the one in memory. Your idea is nice but i guess it won't work.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply