Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - starkhorn

#26
Help requests / V0.7 alphav0.2 listbox signals
15 October 2015, 22:24:55
Hey,

I'm trying to use the listbox signals but everytime I try to connect a signal to the listbox instance, I get an "Unhandled exception at 0x011611FA in BLAH.exe: 0xC0000005: Access violation reading location 0x000000A4."

When I break, it seems to be stopped in the signalbasewidget.hpp file at the below location

Code (cpp) Select

        template <typename Func, typename... Args>
        unsigned int connect(const std::string& signalNames, Func func, Args... args)
        {
            for (auto& signalName : extractSignalNames(signalNames))
            {
                if (m_signals.find(toLower(signalName)) != m_signals.end())     //<----------STOPS HERE STOPS HERE STOPS HERE
                {
                    try {
                        m_signals[toLower(signalName)]->connect(m_lastId, func, args...);
                        m_lastId++;
                    }
                    catch (const Exception& e) {
                        throw Exception{e.what() + (" The parameters are not valid for the '" + signalName + "' signal.")};
                    }
                }


I've tried ItemSelected, MouseEntered, MousePressed and all the same result. See below a full working exampe of what I am trying to do. Any ideas on what I am doing wrong here?

Code (cpp) Select

#include <TGUI/TGUI.hpp>
#include <string>
#include <math.h>
#define THEME_CONFIG_FILE "E:\\programming\\projects\\rome_vs2013\\rome_vs2013\\Debug\\\\widgets\\rome.txt"
#include "nation.h"

using namespace std;

class Test
{
public:

Test();

sf::RenderWindow gameWindow;
sf::VideoMode desktop;
sf::Event event;
tgui::Callback callback;
tgui::Gui gui;
sf::Texture mainMenuBackGround;
sf::Font font;

tgui::Theme::Ptr theme;

void initFont();
void setThemeConfigFile(string passed_filename);
void setupChildWindow(sf::Vector2i pos, sf::Vector2i size, string title_text, sf::Color titleText_Color, string passed_childName);
void setupCanvas(sf::Vector2i pos, sf::Vector2i size, string passed_canvasName, tgui::Container::Ptr container = NULL);
void initSubMenuCanvas(tgui::Container::Ptr container);
void setupListBox(sf::Vector2i pos, sf::Vector2i size, int passed_TextSize, sf::Color passed_colour, string listBoxID, string passed_themeSection, tgui::Container::Ptr container = NULL);
void addStringItemToListBox(string listBoxID, vector<string> passed_stringItemsToAdd);
void drawCitySubMenu(Nation *passed_Nation, tgui::Canvas::Ptr canvas);

};

Test::Test()
{
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.setFont("E:\\programming\\projects\\rome_vs2013\\rome_vs2013\\Debug\\\\inputfiles\\fonts\\DejaVuSans.ttf");
setThemeConfigFile(THEME_CONFIG_FILE);

}

void Test::initFont()
{
font.loadFromFile("E:\\programming\\projects\\rome_vs2013\\rome_vs2013\\Debug\\inputfiles\\fonts\\DejaVuSans.ttf");
}

void Test::setThemeConfigFile(string passed_filename)
{
// Load the black theme
theme = std::make_shared<tgui::Theme>(passed_filename);
}

void Test::setupChildWindow(sf::Vector2i pos, sf::Vector2i size, string title_text, sf::Color titleText_Color, string passed_childName)
{
if (gui.get(passed_childName) == NULL)
{
tgui::ChildWindow::Ptr childWin = theme->load("ChildWindow");
childWin->setPosition(pos.x, pos.y);
childWin->setSize(size.x, size.y);
childWin->getRenderer()->setTitleColor(titleText_Color);
childWin->setTitle(title_text);
gui.add(childWin, passed_childName);
}
}

void Test::setupCanvas(sf::Vector2i pos, sf::Vector2i size, string passed_canvasName, tgui::Container::Ptr container)
{
if ((container != NULL && container->get(passed_canvasName) == NULL) || (container == NULL && gui.get(passed_canvasName) == NULL))
{
auto canvas = std::make_shared<tgui::Canvas>();
canvas->setPosition(pos.x, pos.y);
canvas->setSize(size.x, size.y);

if (container == NULL)
{
gui.add(canvas, passed_canvasName);
}
else
{
container->add(canvas, passed_canvasName);
}
}
}

void Test::initSubMenuCanvas(tgui::Container::Ptr container)
{
float childSizeX = container->getSize().x;
float childSizeY = container->getSize().y;
sf::Vector2f scaledValues;

sf::Vector2i pos;
sf::Vector2i size(childSizeX, childSizeY);;

setupCanvas(pos, size, "subMenuCanvas", container);

tgui::Canvas::Ptr canvas = container->get<tgui::Canvas>("subMenuCanvas");
canvas->clear();
}

void Test::setupListBox(sf::Vector2i pos, sf::Vector2i size, int passed_TextSize, sf::Color passed_colour, string listBoxID, string passed_themeSection, tgui::Container::Ptr container)
{
if ((container != NULL && container->get(listBoxID) == NULL) || (container == NULL && gui.get(listBoxID) == NULL))
{
tgui::ListBox::Ptr listbox = theme->load(passed_themeSection);
listbox->setPosition(pos.x, pos.y);
listbox->setSize(size.x, size.y);
listbox->getRenderer()->setTextColor(passed_colour);
listbox->setItemHeight(passed_TextSize);

if (container == NULL)
{
gui.add(listbox, listBoxID);
}
else
{
container->add(listbox, listBoxID);
}
}
}

void Test::addStringItemToListBox(string listBoxID, vector<string> passed_stringItemsToAdd)
{
tgui::ListBox::Ptr listbox = gui.get<tgui::ListBox>(listBoxID, true);

if (listbox != NULL)
{
bool isLineAlreadyAdded = false;
vector<sf::String> itemsList;

for (int i = 0; i < passed_stringItemsToAdd.size(); i++)
{
itemsList = listbox->getItems();
isLineAlreadyAdded = false;
for (int j = 0; j < itemsList.size(); j++)
{
if (itemsList.at(j) == passed_stringItemsToAdd[i])
{
isLineAlreadyAdded = true;
}
}

if (!isLineAlreadyAdded)
{
listbox->addItem(passed_stringItemsToAdd[i]);
}
}

}
}

void Test::drawCitySubMenu(Nation *passed_Nation, tgui::Canvas::Ptr canvas)
{
sf::Text msg("", font);


msg.setCharacterSize(15);
msg.setColor(sf::Color::White);
msg.setPosition(10, 25);
msg.setString("This is draw city sub menu");
canvas->draw(msg);
}


int main()
{
Test testClass;
string themeSection;
string childWinName = "testChild";
string listboxID = "listbox";
Nation passed_Nation;

sf::Vector2i pos(testClass.gameWindow.getSize().x * 0.1, testClass.gameWindow.getSize().y * 0);
sf::Vector2i size((testClass.gameWindow.getSize().x - (testClass.gameWindow.getSize().x * 0.25)), 400);

testClass.setupChildWindow(pos, size, "Start Turn Summary", sf::Color::Red, childWinName);

tgui::Container::Ptr container = testClass.gui.get<tgui::Container>(childWinName);
testClass.initSubMenuCanvas(container);
tgui::Canvas::Ptr canvas = container->get<tgui::Canvas>("subMenuCanvas");
sf::Vector2f childSize(container->getSize());

pos.x = 0;
pos.y = 10;

testClass.setupListBox(pos, size, 15, sf::Color::Green, listboxID, "Listbox", container);
tgui::ListBox::Ptr regionListBox = testClass.gui.get<tgui::ListBox>(listboxID);
regionListBox->connect("ItemSelected", &Test::drawCitySubMenu, &testClass, &passed_Nation, canvas);
testClass.addStringItemToListBox(listboxID, passed_Nation.getNationListOfRegionsMenuData());

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


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

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

return 0;
}

#27
awesome - works a treat. Thank you.
#28
Is it possible to set the position of the text on a button? I have the text size small and I wanted it to be in the top left corner of the button.
#29
Help requests / Re: v0.7 add horizontal ListBox
28 September 2015, 21:12:01
Ok no problem. So to clarify I was going to suggest two new features.

1:- The horizontal scroll-bar on a listbox if the item is longer than the width of the listbox.
2:- Field formatting of items (in my case string items) on a per line basis.

i.e. I want to displaying something like below. So there is a delimiter that can seperate the items into fields/columns and the field/columns width or position can be defined. I know this is probably alot of work but I just thought to suggest it.

Code (cpp) Select


ListBoxCol1Row1 ListBoxCol2Row1 ListBoxCol3Row1
ListBoxCol1Row2 ListBoxCol2Row2 ListBoxCol3Row2

#30
Help requests / Re: v0.7 add horizontal ListBox
23 September 2015, 23:44:58
No worries mate - thanks for checking. Good luck with uni.

Should i post this new feature request somewhere so you can keep track of it when you next look at doing a new version?
#31
Help requests / v0.7 add horizontal ListBox
21 September 2015, 03:24:48
Hi Texus,

Is it possible to add a horizontal scrollbar to a listbox? I have some string items that are too long to display on a single line and I would like users to be able to scroll horizontally so they are see the end of each line.

Or is there a way to display a single item over multiple lines?

#32
Help requests / Re: v0.7 listbox auto scrolling
17 September 2015, 00:03:05
No worries at all and thanks for the help once again.

Quote from: texus on 16 September 2015, 14:08:30
But I'll add a setAutoScroll function in v0.7-alpha2, I'll probably even make it scroll by default so that you don't even have to call anything.

Yeah this would be a great idea - perhaps with a method to disable auto-scrolling as well?
#33
Help requests / Re: v0.7 listbox auto scrolling
14 September 2015, 01:17:11
Hey Texus,

Just wondering if you had a chance to look at this question ? I know you are busy so no worries if you need more time etc.
#34
Help requests / v0.7 listbox auto scrolling
12 September 2015, 04:00:03
Hi Texus,

In a chatbox, when I add a new line, if it is larger than the size of the chatbox, it automatically scrolls down.
However in a listbox, I do not get the same behaviour when I add a new item. I get the scrollbar fine and I can manually scroll up and down which is great.
Basically I want to use the listbox functionality of being able to select each line and call functions when a particular line is clicked. However I also want the chatbox functionality of autoscrolling when a new item is added.

Is there any flag on a listbox to enable this same behaviour?
#35
Help requests / v0.7 listbox textsize
12 September 2015, 03:06:38
Hi Texus,

I cannot seem to locate a setTextSize method for a listbox - (i.e. chatbox has such a method so I was looking for something similiar).

I see there is a setItemHeight method but in the documents is says "This size is always a little big greater than the text size."

So is this what actually determines the text size in a listbox?
#36
Help requests / Re: v0.7 widget.conf syntax
08 September 2015, 01:17:52
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! :)
#37
Help requests / Re: v0.7 widget.conf syntax
08 September 2015, 00:48:01
Thanks. I downloaded the pre-compiled file TGUI-0.7-alpha1 Visual C++12 (2013) - 32bit.zip
#38
Help requests / Re: v0.7 widget.conf syntax
08 September 2015, 00:41:26
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.
#39
Help requests / Re: v0.7 widget.conf syntax
08 September 2015, 00:20:47
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);
}
#40
Help requests / Re: v0.7 widget.conf syntax
08 September 2015, 00:17:18
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;
}

#41
Help requests / Re: v0.7 widget.conf syntax
07 September 2015, 22:17:48
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);
}

#42
Help requests / v0.7 widget.conf syntax
07 September 2015, 09:28:46
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;
        }


#43
sorry - yeah I was using the Visual C++ 11 (2012) - 32-bit sfml 2.3.1 dll files and not the Visual C++ 12 (2013) - 32-bit files.

Thanks again.
#44
So I am trying to add radio buttons using the black.txt file.
I've setup the theme as per the themes tutorial. (https://tgui.eu/tutorials/v0.7/using-themes/)

I have been able to create panels and labels without issue, but the radiobutton throws an error. I am using visual studio 2013 and I don't have a tgui.pdb so when it fails, I don't see the exact source line it fails. I get a Expression: pFirstBlock ==pHead error in the dbgheap.c.

My function is below and it fails at the "tgui::RadioButton::Ptr radioButton = theme->load("RadioButton");" line.

Code (cpp) Select

void Test::setupRadioButton(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_colour, vector<string> stringList, tgui::Container::Ptr container)
{
int yposIncrementer = 0;

for (int i = 0; i < stringList.size(); i++)
{
if (container != NULL && container->get(stringList[i]) == NULL)
{
tgui::RadioButton::Ptr radioButton = theme->load("RadioButton");
radioButton->setPosition(pos.x, pos.y + yposIncrementer);
radioButton->setSize(size.x, size.y);
radioButton->getRenderer()->setTextColor(passed_colour);
if (stringList.size() > 0)
{
radioButton->setText(stringList[i]);
}
container->add(radioButton, stringList[i]);
yposIncrementer += size.y;
}
}
}


Here is a full working example. The drawLoadingScreen method which uses a panel with labels works fine. However the drawMainMenu fails when I try to add a radiobutton. Am I doing something wrong here?

Code (cpp) Select

#include <TGUI/TGUI.hpp>
#include <string>
#include <math.h>
#define THEME_CONFIG_FILE "C:\\Programming\\Debug\\widgets\\Black.txt"

using namespace std;

class Test
{
public:

Test();

sf::RenderWindow gameWindow;
sf::VideoMode desktop;
sf::Event event;
tgui::Callback callback;
tgui::Gui gui;
sf::Texture mainMenuBackGround;

tgui::Theme::Ptr theme;
tgui::Layout windowWidth;
tgui::Layout windowHeight;
string mainPanelName;

void setThemeConfigFile(string passed_filename);
void initBackGroundTextures();
void initMainMenuPanel(sf::Vector2i pos, sf::Vector2i size);
void setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture = NULL);
void setupLabel(sf::Vector2i pos, int passed_TextSize, sf::Color passed_colour, string labelText, tgui::Container::Ptr container = NULL);
void setupRadioButton(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_colour, vector<string> stringList, tgui::Container::Ptr container = NULL);
bool drawLoadingScreenGUI();
bool drawMainMenuGUI(bool mainMenu); //main menu
};

Test::Test()
{
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");
initBackGroundTextures();
setThemeConfigFile(THEME_CONFIG_FILE);
mainPanelName = "mainPanel";
}

void Test::setThemeConfigFile(string passed_filename)
{
// Load the black theme
theme = std::make_shared<tgui::Theme>(passed_filename);

// Get a bound version of the window size
// Passing this to setPosition or setSize will make the widget automatically update when the view of the gui changes
windowWidth = tgui::bindWidth(gui);
windowHeight = tgui::bindHeight(gui);
}

void Test::initBackGroundTextures()
{
if (!mainMenuBackGround.loadFromFile("C:\\Users\\mcgoldrickb\\Documents\\Visual Studio 2013\\Projects\\rome_vs2013\\Debug\\images\\loading_screen.png"))
{
std::cout << "Failed to load mainMenuBackGround image!" << std::endl;
}
}

void Test::initMainMenuPanel(sf::Vector2i pos, sf::Vector2i size)
{
setupPanel(pos, size, sf::Color::Black, mainPanelName, &mainMenuBackGround);
}

void Test::setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture)
{

if (gui.get(passed_panelName) == NULL)
{
auto mainMenuPanel = std::make_shared<tgui::Panel>();
mainMenuPanel->setPosition(pos.x, pos.y);
mainMenuPanel->setSize(size.x, size.y);
mainMenuPanel->setBackgroundColor(passed_backGroundColour);
if (passed_texture != NULL)
{
mainMenuPanel->add(std::make_shared<tgui::Picture>(*passed_texture));
//mainMenuPanel->getRenderer()->setBackgroundTexture(passed_texture);
}
gui.add(mainMenuPanel, passed_panelName);
}
}

void Test::setupLabel(sf::Vector2i pos, int passed_TextSize, sf::Color passed_colour, string labelText, tgui::Container::Ptr container)
{
if (container->get(labelText) == NULL)
{
tgui::Label::Ptr label = theme->load("Label");
container->add(label, labelText);
label->setPosition(pos.x, pos.y);
label->setTextSize(passed_TextSize);
label->setTextColor(passed_colour);
label->setText(labelText);
}
}

void Test::setupRadioButton(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_colour, vector<string> stringList, tgui::Container::Ptr container)
{
int yposIncrementer = 0;

for (int i = 0; i < stringList.size(); i++)
{
if (container != NULL && container->get(stringList[i]) == NULL)
{
tgui::RadioButton::Ptr radioButton = theme->load("RadioButton");
radioButton->setPosition(pos.x, pos.y + yposIncrementer);
radioButton->setSize(size.x, size.y);
radioButton->getRenderer()->setTextColor(passed_colour);
if (stringList.size() > 0)
{
radioButton->setText(stringList[i]);
}
container->add(radioButton, stringList[i]);
yposIncrementer += size.y;
}
}
}

bool Test::drawLoadingScreenGUI()
{
sf::Vector2i pos, size((gameWindow.getSize().x), (gameWindow.getSize().y));
initMainMenuPanel(pos, size);

//Setup LoadingScreen Label
setupLabel(pos, 100, sf::Color::Red, "Roman Empire", gui.get<tgui::Container>(mainPanelName));


//This is the main menu instructions Label
pos.x = 25;
pos.y = gui.get(mainPanelName)->getSize().y - 100;
setupLabel(pos, 50, sf::Color::Red, "Loading game...", gui.get<tgui::Container>(mainPanelName));


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

return true;
}

bool Test::drawMainMenuGUI(bool mainMenu)
{
vector<string> widgetStrList;

//Initialize the main menu panel
sf::Vector2i pos, size((gameWindow.getSize().x), (gameWindow.getSize().y));
setupPanel(pos, size, sf::Color::Black, mainPanelName, &mainMenuBackGround);
sf::Vector2i panelSize(gui.get(mainPanelName)->getSize().x, gui.get(mainPanelName)->getSize().y);


//This is the main menu Title
pos.x = 25;
pos.y = 50;
setupLabel(pos, 100, sf::Color::Red, "Roman Empire - Main Menu", gui.get<tgui::Container>(mainPanelName));



//Setup Main Menu Radio Buttons
pos.y = 50 + 70;
size.x = 35;
size.y = 35;

widgetStrList.push_back("\tQuit Game");
widgetStrList.push_back("\tStart New Game");
widgetStrList.push_back("\tLoad Old Game");

if (mainMenu == true)
{
setupRadioButton(pos, size, sf::Color::Red, widgetStrList, gui.get<tgui::Container>(mainPanelName));
}
else if (mainMenu == false)
{
widgetStrList.push_back("\tSave Current Game");
widgetStrList.push_back("\tExit Main Menu");
setupRadioButton(pos, size, sf::Color::Red, widgetStrList, gui.get<tgui::Container>(mainPanelName));
}

widgetStrList.clear();

gameWindow.clear();

gui.draw();
gameWindow.display();
return true;
}

#45
awesome - thank you. Worked a treat.
#46
So what I am trying to do here is first setup a main menu panel where I had a background. I then want to put various widgets into the panel such as labels, radio buttons etc.

So I can create the panel without any issues.
Then the draw menu screen, I have a setupLabel function where one of the parameters to pass in is the tgui::Container::Ptr.
Now I use the gui.get to retrieve the panel but this returns type widget::ptr and so i get a compile error. I tried calling getparent but obviously this just returns gui.

Is there any to search the gui for the widget name and get the container back? Note right now it is a panel, but I also want to use setupLabel for say child windows or other container types.

Here is a full working example of what I'm trying to do.

See the drawLoadingScreenGUI() method.
It calls initMainMenuPanel() which adds a panel to gui. I now want to call setupLabel and pass in a ptr to the panel.
As you can see I'm calling gui.get("mainPanel") which does return the widget::ptr but I cannot add a label to a widget, I assume I need a container type?

Code (cpp) Select


#include <TGUI/TGUI.hpp>
#include <string>
#include <math.h>
#define THEME_CONFIG_FILE "C:\\programming\\rome_vs2013\\Debug\\widgets\\Black.txt"

using namespace std;

class Test
{
public:

Test();

sf::RenderWindow gameWindow;
sf::VideoMode desktop;
sf::Event event;
tgui::Callback callback;
tgui::Gui gui;
sf::Texture mainMenuBackGround;

tgui::Theme::Ptr theme;
tgui::Layout windowWidth;
tgui::Layout windowHeight;

void setThemeConfigFile(string passed_filename);
void initBackGroundTextures();
void initMainMenuPanel(sf::Vector2i pos, sf::Vector2i size);
void setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture = NULL);
void setupLabel(sf::Vector2i pos, int passed_TextSize, sf::Color passed_colour, string labelText, tgui::Container::Ptr container = NULL);
bool drawLoadingScreenGUI();
};

Test::Test()
{
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\\rome_vs2013\\Debug\\inputfiles\\fonts\\DejaVuSans.ttf");
initBackGroundTextures();
setThemeConfigFile(THEME_CONFIG_FILE);
}

void Test::setThemeConfigFile(string passed_filename)
{
// Load the black theme
theme = std::make_shared<tgui::Theme>(passed_filename);

// Get a bound version of the window size
// Passing this to setPosition or setSize will make the widget automatically update when the view of the gui changes
windowWidth = tgui::bindWidth(gui);
windowHeight = tgui::bindHeight(gui);
}

void Test::initBackGroundTextures()
{
if (!mainMenuBackGround.loadFromFile("C:\\progamming\\rome_vs2013\\Debug\\images\\loading_screen.png"))
{
std::cout << "Failed to load mainMenuBackGround image!" << std::endl;
}
}

void Test::initMainMenuPanel(sf::Vector2i pos, sf::Vector2i size)
{
setupPanel(pos, size, sf::Color::Black, "mainPanel", &mainMenuBackGround);
}

void Test::setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture)
{

if (gui.get(passed_panelName) == NULL)
{
auto mainMenuPanel = std::make_shared<tgui::Panel>();
mainMenuPanel->setPosition(pos.x, pos.y);
mainMenuPanel->setSize(size.x, size.y);
mainMenuPanel->setBackgroundColor(passed_backGroundColour);
if (passed_texture != NULL)
{
mainMenuPanel->add(std::make_shared<tgui::Picture>(*passed_texture));
}
gui.add(mainMenuPanel, passed_panelName);
}
}

void Test::setupLabel(sf::Vector2i pos, int passed_TextSize, sf::Color passed_colour, string labelText, tgui::Container::Ptr container)
{
if (container->get(labelText) == NULL)
{
tgui::Label::Ptr label = theme->load("Label");
container->add(label, labelText);
label->setPosition(pos.x, pos.y);
label->setTextSize(passed_TextSize);
label->setTextColor(passed_colour);
label->setText(labelText);
}
}

bool Test::drawLoadingScreenGUI()
{
sf::Vector2i pos, size((gameWindow.getSize().x), (gameWindow.getSize().y));
initMainMenuPanel(pos, size);

//Setup LoadingScreen Label
setupLabel(pos, 100, sf::Color::Red, "Roman Empire", gui.get("mainPanel"));



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

return true;
}


int main()
{
Test testClass;

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


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

testClass.drawLoadingScreenGUI();

}

return 0;
}

#47
Help requests / Re: v0.7 panel background textures
05 September 2015, 01:20:29
Ah ok cool. I'll let you know how that goes.

BTW, I really really like the new way of adding widgets to the gui or a container. Also I find the new get method to be able to retrieve the widget pointer really, really useful.

EDIT:- both of the recommendations above worked a treat.
#48
Help requests / v0.7 panel background textures
05 September 2015, 00:40:36
Hey,

I was trying to set the background texture for a panel.

I tried the line below, but there doesn't appear to be a setbackgroundtexture method. I don't see any panel renderer class? Is this coming in a later version? Any recommendations to get around this currently?

Code (cpp) Select

void drawEngine::setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture)
{

if (gui.get(passed_panelName) == NULL)
{
tgui::Panel::Ptr mainMenuPanel = theme->load(themeConfFile);
mainMenuPanel->setPosition(pos.x, pos.y);
mainMenuPanel->setSize(size.x, size.y);
mainMenuPanel->setBackgroundColor(passed_backGroundColour);
if (passed_texture != NULL)
{
mainMenuPanel->getRenderer()->setBackgroundTexture(passed_texture);
}
}
}
#49
Help requests / Re: v0.7 signals
04 September 2015, 22:59:18
Ok, so in the connect function, the signal "pressed" is actually not a user-definable signal. It is a signal that is part of the widget constructor,

i.e. in button.cpp I see the line below in the button constructor.

Code (cpp) Select


addSignal<sf::String>("Pressed");


For some reason I thought the first parameter of the connect function could be whatever we wanted, i.e. like the setCallbackId method.

Re-reading the class documentation of v0.7, I now see the signal section, so ok this makes more sense now.

https://tgui.eu/documentation/v0.7/classtgui_1_1Button.html

"Detailed Description

Button widget.

Signals:

    Pressed (the button was pressed)
        Optional parameter sf::String: Caption of the button
        Uses Callback member 'text'
    Inherited signals from ClickableWidget"

One question, what is difference between the button pressed and the clickableWidget clicked signal?
#50
Help requests / v0.7 signals
04 September 2015, 22:28:37
Hi,

Ok so I tried v0.7 for the first time today. I put in my v0.69 code and had zillions of compile errors as alot has changed. :)

Most are pretty easy to understand/modify, i.e. there is the renderer class and also there is no load method but we need to use the theme->load etc

However one thing that I am confused about is the change to signals.

In v0.69 there was the below in order to know when a button had been pressed with the left mouse button.

Code (cpp) Select

    button->bindCallback(tgui::Button::LeftMouseClicked);
    button->setCallbackId(1);


Now in v0.70, I get a compile error that tgui::Button::LeftMouseClicked does not exist.

I see in the v0.7 example code that it uses the connect method.

Code (cpp) Select

    // Call the login function when the button is pressed
    button->connect("pressed", login, editBoxUsername, editBoxPassword);


Ok seems simple enough but what I do not get there is how does the button widget know that this function gets triggered when the left mouse button is clicked. what if I wanted to do something if the right mouse button is clicked or if the middle button etc ?

I am sure I am missing something obvious here but I just don't quite get it. :)