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

#51
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.

#52
Looks awesome mate. I must get around to using the v0.7 more.....
#53
Help requests / The new renderer classes in v0.7
27 August 2015, 01:19:09
Hi Texus,

So I'm using v0.6.9 and I was looking to change the background image of a chatbox. I realized that there was no method for that but I spotted in the v0.7 docs that there is something called a chatbox renderer with such a method.

Now I am curious that is something new/different between v0.6.9 and v0.7 and I can see that lots of other widgets have such a class as well. So I was wondering how the renderer class would work/differ in v0.7?

I saw the below example code where we have to call the getRenderer() method. So just to confirm my understanding that from v0.7 onwards, all widget display methods need to go through the getRenderer() method first?

https://tgui.eu/example-code/v07/simple-console/
#54
Help requests / Accessing textures
04 July 2015, 04:45:21
In the theme conf file for child window, there is the setting for title bar where you specify the titlebar image file. I'm assuming tgui loads that in and stores it as a texture?

Now say I wanted to access that same texture again. For example say I want to sub divide the child window so I want to draw that titlebar again. Is there a way I can access that texture so I can assign it to a sf::sprite? Note I list childwindow as an example. I'd also be interested on how to access say the button png texture or radio button etc.

#55
Help requests / Re: m_callback size
01 July 2015, 01:46:46
Hi Texus,

Ok thanks again for your help and sorry it took me a while to figure this out....I'm trying to learn c++, sfml and tgui as I go. :) I really do appreciate you continued assistance and patience with my constant questions.
#56
Help requests / Re: m_callback size
30 June 2015, 05:35:22
Ok so I changed my initcallback function to below.....and had it run in the while gamewindow is open loop.  Now the m_callback size is zero whenever I click on a radiobutton.

So yeah clearly I should unbind first before rebind callbacks within the game loop. Right?

Code (cpp) Select


void Test::initRadioButtonCallbacks()
{
for (int i = 0; i < RadioButtonList.size(); i++)
{
RadioButtonList[i]->unbindAllCallback();
RadioButtonList[i]->setCallbackId(i);
RadioButtonList[i]->bindCallback(tgui::Button::LeftMouseClicked);
}
}

#57
Help requests / Re: m_callback size
30 June 2015, 03:40:14
No problem at all about being harsh and point taken that there isn't a valid use-case for it. I guess I was doing a hack for something else that I was doing incorrect.

I think you might have hit the nail on the head when you said

Code (cpp) Select

Are you sure you didn't accidentally give the other radio buttons the same id? Are you binding multiple triggers on the radio button?


I'm definitely not giving the other radio buttons the same id. I'm binding as below so you see each radio button within the radiobuttonlist vector is getting bound to the counter from the for loop.

Code (cpp) Select


void Test::initRadioButtonCallbacks()
{
for (int i = 0; i < RadioButtonList.size(); i++)
{
RadioButtonList[i]->setCallbackId(i);
RadioButtonList[i]->bindCallback(tgui::Button::LeftMouseClicked);
}
}



However, I'm calling the initRadioButtonCallbacks function each time I draw the menu, so I'm wondering if the multiple callback is what I am doing incorrectly. I did a few tests with some simple code - (see below if you wanted to copy/paste a full simple example).

When I have the initRadioButtonCallbacks outside the while gamewindow isOpen loop, then m_callback size is always zero when I press on a radiobutton. However say I put this with the while window isOpen loop (to simulate me calling it each time I draw a submenu), then the m_callback is very large.

So my question I guess becomes, does the bindCallback not overwrite the previous callbackID?

Code (cpp) Select


#include <TGUI/TGUI.hpp>
#include <string>
#define THEME_CONFIG_FILE "E:/programming/TGUI-0.6/widgets/Black.conf"

using namespace std;

class Test
{
public:

Test();

sf::RenderWindow gameWindow;
sf::VideoMode desktop;
sf::Event event;
tgui::Callback callback;
tgui::Gui gui;
vector<tgui::RadioButton::Ptr> RadioButtonList;

void initRadioButtonCallbacks();
void setupRadioButton(int passed_numWidgets, int maxNumWidgets,  sf::Color passed_colour, vector<string> stringList);
};

Test::Test()
{
desktop = sf::VideoMode::getDesktopMode();
gameWindow.create(sf::VideoMode(desktop.width * 0.5, desktop.height * 0.50, desktop.bitsPerPixel), "Test");
gameWindow.setPosition(sf::Vector2i(0, 0));
gui.setWindow(gameWindow);
}

void Test::setupRadioButton(int passed_numWidgets, int maxNumWidgets, sf::Color passed_colour, vector<string> stringList)
{
int listPreSize = RadioButtonList.size();
int listNewSize = passed_numWidgets + RadioButtonList.size();
int strListIndex = 0;
sf::Vector2i initPos(50,0);
sf::Vector2i initSize(25,25);

while (RadioButtonList.size() < listNewSize && RadioButtonList.size() < maxNumWidgets)
{
RadioButtonList.push_back(tgui::RadioButton::Ptr(gui));
}

int yposIncrementer = 0;

for (int i = listPreSize; i < RadioButtonList.size(); i++)
{
RadioButtonList[i]->load(THEME_CONFIG_FILE);
RadioButtonList[i]->setPosition(initPos.x, (initPos.y + yposIncrementer));
RadioButtonList[i]->setSize(initSize.x, initSize.y);
RadioButtonList[i]->setTextColor(passed_colour);
if (stringList.size() > 0)
{
RadioButtonList[i]->setText(stringList[strListIndex]);
}
yposIncrementer += initSize.y;
strListIndex++;
}
}

void Test::initRadioButtonCallbacks()
{
for (int i = 0; i < RadioButtonList.size(); i++)
{
RadioButtonList[i]->setCallbackId(i);
RadioButtonList[i]->bindCallback(tgui::Button::LeftMouseClicked);
}
}

int main()
{
Test testClass;
vector<string> widgetStrList;

//Do the radio buttons
widgetStrList.push_back("\tLow");
widgetStrList.push_back("\tNormal");
widgetStrList.push_back("\tHigh");

testClass.setupRadioButton(3, 3, sf::Color::Red, widgetStrList);
testClass.initRadioButtonCallbacks();

while (testClass.gameWindow.isOpen())
{

while (testClass.gameWindow.pollEvent(testClass.event))
        {
if (testClass.event.type == sf::Event::Closed)
{
testClass.gameWindow.close();
}

testClass.gui.handleEvent(testClass.event);
}



        while (testClass.gui.pollCallback(testClass.callback))
        {
if (testClass.callback.id == 0)
            {
int test = 0;
}
else if (testClass.callback.id == 1)
{
int test = 1;
}
else if (testClass.callback.id == 2)
{
int test = 2;
}
        }

testClass.gameWindow.clear(sf::Color::White);
        testClass.gui.draw();
        testClass.gameWindow.display();
}

return 0;
}







#58
Help requests / m_callback size
30 June 2015, 02:11:12
Hi Texus,

Sorry for another question......I have a few radio buttons and each radio button has it's own callback ID. Within my gui.pollCallback(callback) function, I check if the radio callback id is the one. Then I return true from the function...so basically I'm jumping out of the gui.pollCallback loop early here.

However I've realized that when i next call that pollCallback function, the radio button callback ID is still triggered. EVentually I realized that the gui.m_callback size is usually has 3-400 callback IDs...all of them the ID of the radio button. I'm not sure how/why this is the case?

Anyway, I wrote the below to clear out the m_callback queue when I no longer want to check for new events.

Code (cpp) Select

void drawEngine::clearCallBackQueue()
{
while (gui.pollCallback(callback))
{

}
}


I was wondering if there was any way to add a gui.m_callback.clear() instead as it would be a little faster? I cannot do that as m_callback is a private parameter.
#59
Help requests / Re: Different buttons
25 June 2015, 03:14:04
great thanks.
#60
ahhh - ok I see. Thank you yet again.
#61
Hi Texus,

I'm really confused on this one. So I set the callback as above ,i.e.

Code (cpp) Select

childWindow->bindCallback(tgui::ChildWindow::Closed);


Then in the gui.pollCallback loop, I'm checking if this callback id is hit, i.e.

Code (cpp) Select

if (callback.id == tgui::ChildWindow::Closed)
{
int test = 0;
}


However this doesn't get triggered - so I'm a bit confused here as to why I'm unable to detect when the closed child window is pressed.
#62
Help requests / Different buttons
22 June 2015, 10:29:01
Hey,

I've started playing with the config files to develop my own theme. One of the things that I'm wondering is that I want lots of different images for my buttons. For example, I have a button that is for finance so I want the image to be a png that has coins. Then say I've another button for armies so I want the image to an army png etc etc.

So I can see quite easily how to change the image in the config files, but what if I wanted several different types of buttons? i.e. as above. the functionality is the same, i.e. you click on them and bind callbacks to them etc. I just want a different image.

Is there a way to do this easily via the theme config file?
#63
Oh and thank you yet again. :)
#64
arrggghhhhhh...... ok thanks. Obvious when you point it out. :)
#65
So I create a child window with a background image. I then want to display an image on the child window which can divide up the child window in different sections. Then exact position will change depending on the data - so I decided to use a canvas.

First I create the child window with these 2 functions. initPos and initSize are just structs that have x and y values. There is a childwindow vector of all childwindows within the class.

Code (cpp) Select

void drawEngine::initSubMenuChildWin()
{
initPos.setPos(gameWindow.getSize().x * 0.5, gameWindow.getSize().y * 0);
initSize.setPos((gameWindow.getSize().x - (gameWindow.getSize().x * 0.5)), getLowerScreenPos().getPosY());
setupChildWindow("Finance Menu", sf::Color::Red, financeChildWin, &subMenuBackGround);
}

void drawEngine::setupChildWindow(string title_text, sf::Color titleText_Color, string passed_childName, sf::Texture *passed_texture)
{
int listPreSize = childWindowList.size();

if (!IsChildWinAlreadyInChildList(passed_childName))
{
childWindowList.push_back(tgui::ChildWindow::Ptr(gui, passed_childName));
}

for (int i = listPreSize; i < childWindowList.size(); i++)
{
childWindowList[i]->load(themeConfFile);
childWindowList[i]->setPosition(initPos.getPosX(), initPos.getPosY());
childWindowList[i]->setSize((initSize.getPosX()), (initSize.getPosY()));
childWindowList[i]->setTitleColor(titleText_Color);
childWindowList[i]->setTitle(title_text);
if (passed_texture != NULL)
{
childWindowList[i]->setBackgroundTexture(passed_texture);
}
}
}

tgui::ChildWindow::Ptr drawEngine::getChildWindow(string passed_widgetName)
{
string retrievedWidgetName;

for (int i = 0; i < childWindowList.size(); i++)
    {
if (gui.getWidgetName(childWindowList[i], retrievedWidgetName))
{
if (retrievedWidgetName == passed_widgetName)
{
return childWindowList[i];
}
}
    }
    return NULL;
}



Then in my code I use this to put the canvas in the childwindow and draw the sprite within the canvas.

Code (cpp) Select


initSubMenuChildWin();
float childSizeX = getChildWindow(financeChildWin)->getSize().x;
float childSizeY = getChildWindow(financeChildWin)->getSize().y;

sf::Sprite sprite(largeTitleBar);

tgui::Canvas::Ptr canvas(*getChildWindow(financeChildWin));
canvas->setSize(childSizeX, childSizeY);
canvas->clear();

sprite.setPosition(40, getChildWindow(financeChildWin)->getSize().y * 0.5);
canvas->draw(sprite);
canvas->display();



When I call this the largeTitleBar sprite displays fine, but the background image of the childwindow is gone - i.e. all black.
If I change the above so the canvas size and position are the same as the sprite, the largeTitleBar sprite does not get displayed and instead the black canvas gets displayed.

So I guess I'm struggling to understand how to use canvas properly. Any ideas/suggestions?
#66
I'm looking for a way to see if the close button in a child window title bar has been pressed. Is there a hard-coded callback ID for example? Basically as well as just closing the child window, I also want to trigger other events as well.
#67
Hi Texus,

Ok thanks for the response. I've not used template before so this looks like a good time to start... :)
#68
I should add, that if I remove the vector and try to pass in a single childwindow or panel into the function, as below there is no issue.

So I'm assuming that this is actually a std::vector issue?

Code (cpp) Select


bool drawEngine::IsPanelAlreadyInPanelList(string passed_widgetName)
{
bool returnVal = false;

    for (int i = 0; i < PanelList.size(); i++)
    {
returnVal = isWidgetPresentInContainer(passed_widgetName, PanelList[i]);
    }

return returnVal;
}

bool drawEngine::IsChildWinAlreadyInChildList(string passed_widgetName)
{
bool returnVal = false;

    for (int i = 0; i < childWindowList.size(); i++)
    {
returnVal = isWidgetPresentInContainer(passed_widgetName, childWindowList[i]);
    }

return returnVal;
}

bool drawEngine::isWidgetPresentInContainer(string passed_widgetName, tgui::Container::Ptr container)
{
string retrievedWidgetName;

if (gui.getWidgetName(container, retrievedWidgetName))
{
if (retrievedWidgetName == passed_widgetName)
{
return true;
}
}
return false;
}

#69
So I've a vector of panels and also a vector of childwindows

Code (cpp) Select

vector<tgui::Panel::Ptr> PanelList;
vector<tgui::ChildWindow::Ptr> childWindowList;


I have a function that wants to check if a panel or child window is already present in either vector. I use the get widgetname function.

Code (cpp) Select

bool drawEngine::isWidgetPresentInContainer(string passed_widgetName, vector<tgui::Container::Ptr> containerList)
{
string retrievedWidgetName;

for (int i=0; i < containerList.size(); i++)
{
if (gui.getWidgetName(containerList[i], retrievedWidgetName))
{
if (retrievedWidgetName == passed_widgetName)
{
return true;
}
}
}
return false;
}


Now as you can see I've defined the parameter in the function as  vector<tgui::Container::Ptr>.
As both panels and childwindows inherit from this class and the method of getWidgetName is within the container class then I kinda hoped that I could write one function regardless whether the vector is a panel or a child window.

However obviously when I call it I get

Code (cpp) Select

215 IntelliSense: no suitable user-defined conversion from "std::vector<tgui::ChildWindow::Ptr, std::allocator<tgui::ChildWindow::Ptr>>" to "tgui::Container::Ptr" exists


Is there any way to do this ?
#70
Help requests / Sliders
03 June 2015, 04:50:22
Hi,

I was playing with sliders and I'm trying to understand how they work. Now with scrollbar there is a method called setArrowScrollAmount which controls how big you can scroll up/down the scrollbar. I was looking for something similiar with the slider but there isn't any such method.

Basically what I am trying to achieve is to have a slider which only allows 4 or 5 positions. So you have the first position which is far left. Then if you try to move the slider button right, it will go to the next position which is say 50 pixels to the right etc. So it isn't a smooth movement, but a jump along the slider.

Unsure if this is feasible with a slider or if there is another widget that I should look into instead?
#71
Help requests / Re: Highlight background text
11 April 2015, 07:04:36
sorry, another related question.......

So I've tried the setbackground colour of the labels but it actually only highlights the text. I have a row of seperate labels all on the ypos. I want to highlight the entire ypos row...including the gaps in between each label.

These labels are in a panel. So instead I was trying to create a sf::RectangleShape set to the row y size. I have the below which creates the rectange to the size and position within the panel.

My question is how can I add this rectangle shape so that it is displayed within the panel. I need to draw the rectangle shape before the labels as well. The below setPositions are valid within the panel only.

Code (cpp) Select


for (int i = 0; i < LabelList.size(); i++)
{
if (LabelList[i]->getPosition().y  == passed_pos.getPosY() && LabelList[i]->getPosition().x < maxX)
{
                        sf::RectangleShape labelBackground;
labelBackground.setSize(sf::Vector2f(maxX, getDataRowSize()));
labelBackground.setPosition(LabelList[i]->getPosition().x, LabelList[i]->getPosition().y);
labelBackground.setFillColor(sf::Color::Red);
}
}

#72
Help requests / Re: Highlight background text
11 April 2015, 05:57:46
oh for labels, I just saw the background color method - I somehow missed seeing that one - sorry.

void tgui::Label::setBackgroundColor    (    const sf::Color &     backgroundColor   )

So my question then becomes, can i do something similiar for the radio and check button text?
#73
Help requests / Highlight background text
11 April 2015, 05:52:37
Is there a way for text that is set for radio or check buttons to be highlighted when the actual checkbox or radio button is selected?

Also, I have same question for labels as well. Basically I have a long list of checkbox but due to the fact I wanted to format the text in neat columns, I displayed them as labels.

I have had a look and I cannot seem to find any such method? Does one exist or are any in the works?
#74
Help requests / Re: scrollbar example code
10 April 2015, 03:50:25
Well when scrollRightPanelHorizontal gets called when I put the max amount to a value under low amount, it resets previousRightPanelScrollbarValueX to 0 as the callback.value is zero. So all of the widgets move back to the original position.

So the scenario I have is:-

1:- 1 large panel with a vertical scrollbar.
2:- There are 2 columns of labels within this single panel that I want to display. Each column can have different number of rows independently
3:- So column 1, has say 4 rows which is less than the low amount. I call the updateMaxAmount script which sets to that value and the scrollbar doesn't get displayed. Normal.
4:- Column 2, has 10 rows and this exceeds the low amount. So I call the updateMaxAmount script. Maxamount gets updates. Scrollbar displays - all perfect.
5:- I push the scrolldown button. It moves down. The labels in both columns moved down by the move amount - again exactly what I want.
6:- However during the next pass of the function, updateMaxAmount gets called for column 1 again which is less than lowermount and all of the widgets have their position reset back to zero.

I'm pretty sure my solution is not to update maxamount at step3 and only do so if the update amount if greater than current max amount.
#75
Help requests / Re: scrollbar example code
10 April 2015, 01:14:30
Ok so here is the code where i can see it happeneing.

Basically, what I figured out (after my post last night), is that during a function call I set the maximum so that the scrollbar appears. Then later the maximum amount gets updated where it is less than the low amount. At this point the callback function gets called which in turn updates the previousRightPanelScrollbarValueX value so all of the widgets got back to their original position.

Obviously I should likely ensure that I only update the maximum if it my update value is larger than the current maximum value. However I thought you just let you know how/where I see this behaviour. Unsure if this is what you'd expect?

Code (cpp) Select

#include <TGUI/TGUI.hpp>

class scrollTest
{
public:
scrollTest();

void scrollRightPanelHorizontal(tgui::Panel::Ptr panel, const tgui::Callback& callback);
void updateScrollBarMaxAmount(int passed_MaxAmount, tgui::Scrollbar::Ptr passed_scrollbar);
int previousRightPanelScrollbarValueX;

private:


};

scrollTest::scrollTest()
{
previousRightPanelScrollbarValueX = 0;
}

void scrollTest::scrollRightPanelHorizontal(tgui::Panel::Ptr panel, const tgui::Callback& callback)
{
    int distanceToMove = previousRightPanelScrollbarValueX - callback.value;

    // Move all widgets that are inside the panel
    for (auto& widget : panel->getWidgets())
{
        widget->setPosition(widget->getPosition().x + distanceToMove, widget->getPosition().y);
}

    previousRightPanelScrollbarValueX = callback.value;
}

void scrollTest::updateScrollBarMaxAmount(int passed_MaxAmount, tgui::Scrollbar::Ptr passed_scrollbar)
{
passed_scrollbar->setMaximum(passed_MaxAmount);
}




int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
    tgui::Gui gui(window);
scrollTest scrollClass;

    if (gui.setGlobalFont("E:/programming/TGUI-0.6/fonts/DejaVuSans.ttf") == false)
        return 1;

    // Create the panel
    tgui::Panel::Ptr panel(gui);
    panel->setPosition(50, 50);
    panel->setSize(240, 360);
    panel->setBackgroundColor(sf::Color(200, 200, 200));

    // Add some widgets to it (image1.png to image5.png)
    for (unsigned int i = 1; i <= 5; ++i)
    {
        tgui::Picture::Ptr pic(*panel);
        pic->load("E:/programming/projects/romeGameGUI_noViews/images/arrow_" + std::to_string(i) + ".png");
        pic->setSize(240, 180);
        pic->setPosition(0, (i-1) * 180);
    }

    // Add a scrollbar
    // Note that we add it to the gui and not to the panel.
    // Doing so allows us to easily move everything inside the panel when scrolling
    tgui::Scrollbar::Ptr scrollbar(gui);
    scrollbar->load("E:/programming/TGUI-0.6/widgets/Black.conf");
    scrollbar->setSize(20, 360);
    scrollbar->setPosition(panel->getPosition() + sf::Vector2f(panel->getSize().x, 0));
scrollbar->setVerticalScroll(false);
    scrollbar->setArrowScrollAmount(15);
    scrollbar->setLowValue(360); // Viewable area (height of the panel)
    scrollbar->setMaximum(360); // so scroll-bar should not go visible

    // Call the scrollPanel function that we defined above when scrolling
scrollbar->bindCallbackEx(std::bind(&scrollTest::scrollRightPanelHorizontal, &scrollClass, panel, std::placeholders::_1), tgui::Scrollbar::ValueChanged);
 

    // Mainloop
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            gui.handleEvent(event);
        }

scrollClass.updateScrollBarMaxAmount(580, scrollbar); //becomes visible

if (scrollClass.previousRightPanelScrollbarValueX > 30)
{
scrollClass.updateScrollBarMaxAmount(360, scrollbar); //here where the max amount goes down. when the set maximum is called it calls the bindCallbackEx function
}

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

    return 0;
}