v0.7 widget.conf syntax

Started by starkhorn, 07 September 2015, 09:28:46

starkhorn

Sorry for all of the v0.7 questions lately - I really do appreciate your help.

In v0.69 I had a button conf like below

Code (cpp) Select


Button:
    NormalImage  = "../../images/icons/romeNationIcon_v2.png" (  56,  0,  48, 64)
    HoverImage   = "../../images/icons/romeNationIcon_v2.png" (  56,  65,  48, 64)
    DownImage    = "../../images/icons/romeNationIcon_v2.png" (  56,  129,  48, 64)
   
    TextColor          = (200, 200, 200)
    SeparateHoverImage = true


So in v0.7, I created a new section as below

Code (cpp) Select


CustomButtonRomeAR {
    NormalImage  : "../../images/icons/romeNationIcon_v2.png" (  248,  0,  48, 64);
    HoverImage   : "../../images/icons/romeNationIcon_v2.png" (  248,  65,  48, 64);
    DownImage    : "../../images/icons/romeNationIcon_v2.png" (  248,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}


however whenever I try to create a button with this section, it throws an error

Code (cpp) Select

tgui::Button::Ptr button = theme->load(passed_themeSection);


where passed_themeSection = "CustomButtonRomeHI"

I am assuming I've gotten the syntax incorrect here?

Sorry error is:

"tgui::Exception at memory location 0x0014CF08."

It breaks into WidgetConverter.hpp at line 65

Code (cpp) Select


      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// @brief Cast the widget to the required type
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        template <class T>
        operator std::shared_ptr<T>()
        {
            std::shared_ptr<T> result = std::dynamic_pointer_cast<T>(m_widget);

            if (result == nullptr)
                throw Exception{"Value returned by Theme::load must match type of variable!"};

            return result;
        }



texus

#1
This reminds me that I still have to write a tutorial on the new theme files :)

The new syntax is:
Button.CustomButtonRomeAR { ... }

This is done so that the theme knows what type of widget it should create.

If you just write "Button" it is actually the same as writing "Button.Button".

I'm going to take a closer look at that exception though, because the code was supposed to detect this earlier and throw before the WidgetConverter is even created.

starkhorn

Ok I changed my section to Button.CustomButtonRomeHI in the text file. I then ensure that passed_themeSection is as below.

Code (cpp) Select

passed_themeSection "Button.CustomButtonRomeHI"


however I still get same error. I notice the Button section has a Part and Middle, whereas I did not have that. So I also tried the below but same result

Code (cpp) Select

Button.CustomButtonRomeHI {
    NormalImage  : "../../images/icons/romeNationIcon_v2.png" Part(  56,  0,  48, 64);
    HoverImage   : "../../images/icons/romeNationIcon_v2.png" Part(  56,  65,  48, 64);
    DownImage    : "../../images/icons/romeNationIcon_v2.png" Part(  56,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}


texus

Something is clearly wrong but I don't know what it could be. If I have a section called CustomButtonRomeAR then I get the exception "Failed to load widget of type 'custombuttonromear'. No constructor function was set for that type." which is the error that you were supposed to have to begin with.

When I rename the section to "Button.CustomButtonRomeAR" as it is supposed to be and I put the contents from the button in Black.conf there (because it otherwise fails to load your images which I don't have) then it works fine.

The only way to get the exception from WidgetConverter is when you have something like "tgui::EditBox::Ptr editBox = theme->load("ButtonSection")" but the code in WidgetConverter can only be executed after it has loaded it, so it can't happen when the section isn't found.

Perhaps you can narrow it down a little more? (e.g. check if it also occurs when you just have a main function with just creating a button with that that section)

starkhorn

Hi Texus,

Ok I tried the below which is pretty much as per one of tutorials and example codes.

Here is my new widget config file - rest of the txt file is unchanged and i did not change the Button section at all. I thought maybe it couldn't find the png as it was in a different folder, so I copied it into the same folder as the rome.txt file and removed the ..\..\ lines but same thing.

Note when I change to just below then it works fine

Code (cpp) Select

tgui::Button::Ptr button = theme->load("Button");



Code (cpp) Select

Button {
    NormalImage     : "Black.png" Part( 0, 64, 45, 50) Middle(10, 0, 25, 50);
    HoverImage      : "Black.png" Part(45, 64, 45, 50) Middle(10, 0, 25, 50);
    DownImage       : "Black.png" Part(90, 64, 45, 50) Middle(10, 0, 25, 50);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

Button.CustomButtonRomeAR {
    NormalImage  : "romeNationIcon_v2.png" Part(  248,  0,  48, 64);
    HoverImage   : "romeNationIcon_v2.png" Part(  248,  65,  48, 64);
    DownImage    : "romeNationIcon_v2.png" Part(  248,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

Button.CustomButtonRomeCMD {
    NormalImage  : "romeNationIcon_v2.png" Part(  296,  0,  48, 64);
    HoverImage   : "romeNationIcon_v2.png" Part(  296,  65,  48, 64);
    DownImage    : "romeNationIcon_v2.png" Part(  296,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

Button.CustomButtonRomeHC {
    NormalImage  : "romeNationIcon_v2.png" Part(  152,  0,  48, 64);
    HoverImage   : "romeNationIcon_v2.png" Part(  152,  65,  48, 64);
    DownImage    : "romeNationIcon_v2.png" Part(  152,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

Button.CustomButtonRomeHI {
    NormalImage  : "romeNationIcon_v2.png" Part(  56,  0,  48, 64);
    HoverImage   : "romeNationIcon_v2.png" Part(  56,  65,  48, 64);
    DownImage    : "romeNationIcon_v2.png" Part(  56,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

Button.CustomButtonRomeLC {
    NormalImage  : "romeNationIcon_v2.png" Part(  200,  0,  48, 64);
    HoverImage   : "romeNationIcon_v2.png" Part(  200,  65,  48, 64);
    DownImage    : "romeNationIcon_v2.png" Part(  200,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

Button.CustomButtonRomeLI {
    NormalImage  : "romeNationIcon_v2.png" Part(  104,  0,  48, 64);
    HoverImage   : "romeNationIcon_v2.png" Part(  104,  65,  48, 64);
    DownImage    : "romeNationIcon_v2.png" Part(  104,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}




Code (cpp) Select


#include <TGUI/TGUI.hpp>
#include <string>
#include <math.h>
#define THEME_CONFIG_FILE "C:\\programming\\Debug\\widgets\\rome.txt"
using namespace std;

void buttonFunction()
{
std::cout << "Button pressed" << std::endl;
}


void loadWidgets(tgui::Gui& gui)
{
// Load the black theme
tgui::Theme::Ptr theme = std::make_shared<tgui::Theme>(THEME_CONFIG_FILE);


// Create the login button
tgui::Button::Ptr button = theme->load("Button.CustomButtonRomeHI");
button->setSize(100, 40);
button->setPosition(50, 50);
button->setText("Test");
button->connect("pressed", buttonFunction);
gui.add(button);

// Call the login function when the button is pressed

}

int main()
{
sf::RenderWindow gameWindow;
sf::VideoMode desktop;
sf::Event event;
tgui::Gui gui;

desktop = sf::VideoMode::getDesktopMode();
gameWindow.create(sf::VideoMode(desktop.width, desktop.height, desktop.bitsPerPixel), "Test");
gameWindow.setPosition(sf::Vector2i(0, 0));
gui.setWindow(gameWindow);
gui.setGlobalFont("C:\\programming\\Debug\\inputfiles\\fonts\\DejaVuSans.ttf");

loadWidgets(gui);


// Main loop
while (gameWindow.isOpen())
{

while (gameWindow.pollEvent(event))
{
// When the window is closed, the application ends
if (event.type == sf::Event::Closed)
gameWindow.close();


// Pass the event to all the widgets
gui.handleEvent(event);
}

gameWindow.clear();
gui.draw();
gameWindow.display();
}

return 0;
}


starkhorn

#5
Also I tried using the Black.png as well but no joy

i.e.

Code (cpp) Select

Button.CustomButtonRomeHI {
    NormalImage  : "Black.png" Part(  56,  0,  48, 64);
    HoverImage   : "Black.png" Part(  56,  65,  48, 64);
    DownImage    : "Black.png" Part(  56,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}



I also tried coping the entire Button section into the new section as well but same thing.

i.e. this is the exact same as the Button section which works.

Code (cpp) Select

Button.CustomButtonRomeHI {
    NormalImage     : "Black.png" Part( 0, 64, 45, 50) Middle(10, 0, 25, 50);
    HoverImage      : "Black.png" Part(45, 64, 45, 50) Middle(10, 0, 25, 50);
    DownImage       : "Black.png" Part(90, 64, 45, 50) Middle(10, 0, 25, 50);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

texus

I is supposed to be:
Code (cpp) Select
tgui::Button::Ptr button = theme->load("CustomButtonRomeHI");

without the "Button." in front of it. But I still don't get how you could get an exception WidgetConverer. That object is only created once the button was fully loaded.

starkhorn

Do you know how/where I can get a tgui-d.pdb? I can try to debug further but now I keep getting tgui-d.pdb not loaded.....unsure how it was working earlier.

texus

#8
The pdb files are created when you compile tgui yourself. If you downloaded the precompiled libraries from my site then you should tell me which one and I'll upload the pdb files that were created on my pc. (you probably already told me which version you have but I can't remember who is using what)

Edit: btw, what happens if you put the stuff from "Button.CustomButtonRomeHI" into the normal "Button" section and load that one?

starkhorn

Thanks. I downloaded the pre-compiled file TGUI-0.7-alpha1 Visual C++12 (2013) - 32bit.zip

texus

I no longer have the pdb files from the alpha build unfortunately, they get erased every time I build a new version and they got overwritten while testing a new build script.

So you would have to replace your tgui libraries (and to be sure the header files too) with the one included in the zip file to use the included pdb file.

https://www.dropbox.com/s/mkfie2n21mbdtak/TGUI-122-ffe014140c5623e46b5eb4d20ced2f57f5f24dd6.zip?dl=1

starkhorn

Ok thanks. I'm at work now (based in New Zealand) so I'll try that when I get home.

To confirm the below

Quote from: texus on 08 September 2015, 00:21:58
I is supposed to be:
Code (cpp) Select
tgui::Button::Ptr button = theme->load("CustomButtonRomeHI");

without the "Button." in front of it. But I still don't get how you could get an exception WidgetConverer. That object is only created once the button was fully loaded.

Ok so in the main example, indeed it worked when I dropped the preceding "Button.".
Then I went back to my class but still got same error.
After a bit more tinkering, I realized that I had only updated the Button.CustomButtonRomeHI section with the Part(56,  0,  48, 64);

All of the others were as below. So the CustomButtonRomeHI got created fine, but none of the others. Obviously Part is mandatory now then. :)

Code (cpp) Select

Button.CustomButtonRomeLI {
    NormalImage  : "..\images\icons\romeNationIcon_v3.png" (  104,  0,  48, 64);
    HoverImage   : "..\images\icons\romeNationIcon_v3.png" (  104,  65,  48, 64);
    DownImage    : "..\images\icons\romeNationIcon_v3.png" (  104,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}


For how I got an exception in WidgetConverer then I'm not sure. I will put back my original file and re-test when I get the pdb file. Likely tonight (your tomorrow) though.

Thanks for all of your help and sorry for all of the questions with v0.7! :)

texus

QuoteObviously Part is mandatory now then.
Yep. The new themes files were not meant to be compatible with the previous ones, I never even thought about just using a Part-rect when there is no "Middle" or "Part" in front of it to make porting v0.6 files to v0.7 easier.

Quotesorry for all of the questions
I don't mind. If I get questions it means that people are using tgui which makes me happy.