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

Topics - starkhorn

#1
Help requests / ListBox sounds
10 June 2016, 06:21:13
Hi Texus,

So I have a listbox setup fine but I wanted to play a sound when my mouse hovered over an item and also when an item was selected.
Now I think I can trap the item selected easily enough using the ItemSelected signal but what signal can be used when hovering over an item in a listbox? Is it the widgets MouseEntered ? Does that get triggered each time the mouse enters an item?

#2
Hi Texus,

I was using Textboxes but I found I could not alter the colour of specific lines of a text and I could not put them into columns. So instead I have created a panel and adding Labels to the panel.

However one thing that I was missing is that the textbox had a nice border around it's panel. Is there an easy way to add this to a panel?
#3
I'm having trouble getting a scrollbar to appear when adding it to a child window container.
In drawStartTurnSummarySubMenu, I create the child window with the setupChildWindow method.
I then try to add a scrollbar to the child window using setupScrollBarHorz and passing the child window as a container.
I can see that the number of widgets in the child window increases when I add the scrollbar but it never appears. (Note I put autohide to false).
However if I change the line in setupScrollBarHorz

Code (cpp) Select

container->add(scrollbar, scrollBarName);


To the below, the scollbar appears.
Code (cpp) Select

//gui.add(scrollbar, scrollBarName);


However if I move the childwindow the position of the scrollbar doesn't move. Basically I want the scrollbar to control widgets inside a panel which inside a child window. Here are the methods in question.

Code (cpp) Select


void Test::drawStartTurnSummarySubMenu()
{
sf::Vector2i pos(gameWindow.getSize().x * 0.1, gameWindow.getSize().y * 0);
sf::Vector2i size((gameWindow.getSize().x - (gameWindow.getSize().x * 0.25)), gameWindow.getSize().y * 0.750);

setupChildWindow(pos, size, "Start Turn Summary", sf::Color::Red, "startTurn");
tgui::Container::Ptr container = gui.get<tgui::Container>("startTurn");

pos = sf::Vector2i(0, 0);
void (Test::*ptrToMember)(const tgui::Callback&) = NULL; // creating function ptr
ptrToMember = &Test::scrollBarHorzSignalFunction; // assigning function ptr to appropraite function

setupScrollBarHorz("regionPanelScrollHorz", ptrToMember, container);

//clear game window
gameWindow.clear();

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

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);
}
}

bool Test::setupScrollBarHorz(string scrollBarName, void (Test::*ptrToMember)(const tgui::Callback&),tgui::Container::Ptr container)
{
if ((container != NULL && container->get(scrollBarName) == NULL) || (container == NULL && gui.get(scrollBarName) == NULL))
{
tgui::Scrollbar::Ptr scrollbar = theme->load("Scrollbar");
scrollbar->setPosition(container->getPosition() + sf::Vector2f(container->getSize().x, 0));
scrollbar->setSize(20, container->getSize().y);
scrollbar->connectEx("ValueChanged", ptrToMember, this);
scrollbar->setAutoHide(false);
container->add(scrollbar, scrollBarName);
//gui.add(scrollbar, scrollBarName);
return true;
}
else
{
return false;
}
}

void Test::scrollBarHorzSignalFunction(const tgui::Callback& callback)
{
int scrollbarMove = callback.value;
}
#4
Help requests / table widget
22 April 2016, 01:04:24
Hi Texus,

I was looking at the table.cpp for the new table widget. It looks awesome.

I want to put it into a child window which I can do easily enough but I was wondering if there is a way to get a scroll bar both vertical and horizontal on that?
#5
Help requests / Optional custom widget config
06 April 2016, 00:58:49
Hi Texus,

I was wondering if you could advise if any of the below config is optional? As you can see I basically want the RGB and image to be the same for normal, hover and down events. I have alot of these widgets to create in the conf file so I was wondering if there was a way to remove optional parameters? i.e. if HoverImage isn't present will it use the normalImage by default etc?

Code (cpp) Select

Button.CustomButtonNonClickRomeHI {
    NormalImage  : "..\images\icons\romeNationIcon_v3.png" Part(  56,  0,  48, 64);
    HoverImage   : "..\images\icons\romeNationIcon_v3.png" Part(  56,  0,  48, 64);
    DownImage    : "..\images\icons\romeNationIcon_v3.png" Part(  56,  0,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(190, 190, 190);
    TextColorDown   : rgb(190, 190, 190);
}
#6
Help requests / v0.7 using the tgui::picture
05 April 2016, 08:46:32
Hey Texus,

So I want to setup a picture using a texture. However I only want to set the picture to have the picture defined in a sf::IntRect.
Basically I have a sprite that has it's setTextureRect to a subset of a larger texture, and I want the tgui::picture to only display this subset/IntRect.

I don't see a setTextureRect method in tgui::picture so I was wondering if there was a way to do it? Again this is me trying to get around using canvas due to the blinking issue with my graphics card. So instead of sprites, I am trying to use tgui::pictures.
#7
So I have a strange issue and I am not even sure how to explain it properly. :)

I have code that creates a childwindow. I then want a canvas on the childwindow so I can draw lots of sprite, SFtexts etc.
Now when I reach part of the code that has a childwindow with a canvas (which is virtually all my childwindows), the screen blinks for a split second. It is hard to describe but it looks like the gamewindow is cleared or refreshed or that I quickly pressed alt-tab really quickly (which I did not). As my game relies on lots of childwindows opening and closing frequently then this makes the game all but unplayable.
Note it only seems to happen when in fullscreen mode.

Now when I comment out the line that creates a canvas, the blinking/refreshing does not happen.

First see the code where I call the childwindow and canvas in one of my menu methods. If I comment out the //initSubMenuCanvas method in this function then the blinking does not happen. (obviously I have to comment out all of the lines that are drawing to that canvas as well).

Code (cpp) Select

void drawEngine::drawStartTurnSummarySubMenu(Nation *passed_Nation)
{
sf::Vector2i pos(gameWindow.getSize().x * 0.1, gameWindow.getSize().y * 0);
sf::Vector2i size((gameWindow.getSize().x - (gameWindow.getSize().x * 0.25)), getLowerScreenPos().y);

setupChildWindow(pos, size, "Start Turn Summary", sf::Color::Red, battleChildWin);

tgui::Container::Ptr container = gui.get<tgui::Container>(battleChildWin);
        initSubMenuCanvas(container);
.....
.....
//lots of draw sprites or sf texts onto the canvas throughout the rest of this method.




So you can see below the functions where I actually create the childwindow and canvas. In the initSubMenuCanvas I have tried removing everything except the setupCanvas call but it makes not difference. I had wanted to provide a full working example but the code is quite long and complex now.

Code (cpp) Select


bool drawEngine::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);
cout << "creating win " << passed_childName << "\n";
return true;
}

return false;
}

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

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

if (setupCanvas(pos, size, "subMenuCanvas", container))
{
scaledValues = calcScale(childSizeX, childSizeY, subMenuBackGround.getSize());
subMenuBackGroundSprite.setScale(scaledValues.x, scaledValues.y);

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

bool drawEngine::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);
}

return true;
}

return false;
}

#8
Help requests / listbox text color
20 October 2015, 02:41:19
Is there a way to have different text color for different items in he same listbox?

I've various strings and I want to color code them differently depending on certain criteria. Now I can get see in the listbox renderer a text color method but it seems to be for all text and not specific to a certain item. Is there a way to do that?
#9
So I have visual studio 2013 express so according to the signal tutorial, I need to use the connectEX method.

So when an item is selected in a listbox, is there a way to get the itemID in the callback? I have the below simple signal function but the itemID is always empty.

Code (cpp) Select


void drawEngine::armyUnitListBoxSignalFunction(const tgui::Callback& callback)
{
string item = callback.text;
string itemID = callback.itemId;
}



it is called using the below call

Code (cpp) Select

        tgui::ListBox::Ptr armyUnitListBox = gui.get<tgui::ListBox>(ListBoxID, true);
armyUnitListBox->connectEx("ItemSelected", &drawEngine::armyUnitListBoxSignalFunction, this);
#10
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;
}

#11
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.
#12
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?

#13
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?
#14
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?
#15
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;
        }


#16
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;
}

#17
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;
}

#18
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);
}
}
}
#19
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. :)
#20
Help requests / Defining chatbox via a class
01 September 2015, 01:06:35
Ok, I feel a bit silly here but I'm confused and I'm looking for a bit of help.

So I have a class where one of the data items is a chatbox



class Test
{
public:
Test();

sf::RenderWindow gameWindow;
tgui::Gui gui;
tgui::ChatBox::Ptr chatbox;
};




Now in the class constructor, I want to set the chatbox container so that it is in the gui, i.e. like below.



tgui::ChatBox::Ptr chatbox(gui);


Now obviously if I do this in the class definition, it does not compile. So I'm assuming there is a method that I call call in the Test class constructor but I cannot for the life figure out which method to call.