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

#21
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/
#22
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.

#23
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.
#24
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?
#25
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?
#26
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.
#27
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 ?
#28
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?
#29
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?
#30
Help requests / WidgetTypes
02 April 2015, 22:14:19
Hi Texus,

I have a panel that has labels and the gui that have labels. Depending on what the user clicks, the content of the labels may change. Now rather than try to figure out what label changes and update the text, I've decided at the beginning of each menu call, to remove all label type widgets from the gui and any panels within the gui. Then re-add them with potentially new text.

So essentially it is pretty simple

- if widget type = label then remove widget
- else if widget type = panel then
       - get all widgets assigned to the panel
       - if any panel widgets are label then remove them from the panel


I've written the below which I think will do it? LabelList is a vector of labels that I use to set the position, text etc of the label. I tried just clearing this vector but the gui and panels always seem to retain the widgets. Unsure if there is an easier way to do this?

Code (cpp) Select

void guiEngine::clearLabelWidgets()
{
LabelList.clear();

vector<Widget::Ptr> widgetList = gui.getWidgets();

for (int i = 0; i < widgetList.size(); i++)
{
if (widgetList[i]->getWidgetType() == "Label")
{
gui.remove(widgetList[i]);
}
else if (widgetList[i]->getWidgetType() == "Panel")
{
vector<Widget::Ptr> panelWidgetList = widgetList[i]->getWidgets();

for (int j = 0; j < panelWidgetList.size(); j++)
{
if (widgetList[i]->getWidgetType() == "Label")
{
widgetList[i]->remove(panelWidgetList[j]);
}
}
}
}
}


Anyway, the above doesn't compile as "Label" isn't a valid WidgetType. I've looked at the documentation but it doesn't give a list of each valid i.e.

https://tgui.eu/documentation/v0.6/namespacetgui.html#a6f721be5dfcacf4e5b73b8d3aef75b14

I looked in the source files of widget.cpp but I couldn't see them in there either.
#31
Hi Folks,

So I have a vector of panels as below.

Code (cpp) Select

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


So depending on whatever menu or phase needs to be displayed, then panels are added and removed from this PanelList.
Now I need a way to be able to identify each panel, ideally with a string but not fussed. I tried adding widget name but when I call the getWidgetName, it always seem to return blank.

As below, I push_back a new panel to gui and also construct it with a passed in string for the widgetname.
I then tried to get the widget name but I always get blank. I've tried getWidgetName and Names. Obviously I think I'm not using them correctly. Any ideas what I'm doing wrong?

Code (cpp) Select

PanelList.push_back(tgui::Panel::Ptr(gui, passed_panelName));
string test;
PanelList.back()->getWidgetName(PanelList.back(), test);
#32
Help requests / scrollbar example code
28 March 2015, 03:11:25
Hey,

I've followed the scroll bar example code (really awesome example btw).
https://tgui.eu/example-code/v06/scrollable-panel/

I got it working as it was exactly defined, but when I tried to put the scrollPanel function in a class, I get hundreds of errors. I'm using v0.6, sfml2.2 and visual studio express 2012 on windows.

I get this error:-

Code (cpp) Select

Error 2 error C3867: 'scrollTest::scrollPanel': function call missing argument list; use '&scrollTest::scrollPanel' to create a pointer to member


Then the bind throw lots of errors like below. Any ideas?

Code (cpp) Select

Error 3 error C2780: 'enable_if<!std::is_same<_Ty1,_Ty2>::value,std::_Bind<true,_Ret,std::_Pmf_wrap<_Rx(__thiscall _Farg0::* )(_V0_t,_V1_t,_V2_t,_V3_t,_V4_t) volatile const,_Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t>,_Vx0_t,_Vx1_t,_Vx2_t,_Vx3_t,_Vx4_t>>::type std::bind(_Rx (__thiscall _Farg0::* const )(_V0_t,_V1_t,_V2_t,_V3_t,_V4_t) volatile const,_Vx0_t &&,_Vx1_t &&,_Vx2_t &&,_Vx3_t &&,_Vx4_t &&)' : expects 6 arguments - 3 provided



Here is the modified code, basically, I put the function into a class.

Code (cpp) Select


#include <TGUI/TGUI.hpp>

class scrollTest
{
public:
scrollTest();
void scrollPanel(tgui::Panel::Ptr panel, const tgui::Callback& callback);

private:
int previousScrolbarValue;
};

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


// Function that will be called when scrolling
void scrollTest::scrollPanel(tgui::Panel::Ptr panel, const tgui::Callback& callback)
{
    int distanceToMove = previousScrolbarValue - callback.value;

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

    previousScrolbarValue = callback.value;
}

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

    if (gui.setGlobalFont("C:/Users/mcgoldrickb/Documents/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("C:/Users/mcgoldrickb/Documents/Visual Studio 2012/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("C:/Users/mcgoldrickb/Documents/TGUI-0.6/widgets/Black.conf");
    scrollbar->setSize(20, 360);
    scrollbar->setPosition(panel->getPosition() + sf::Vector2f(panel->getSize().x, 0));
    scrollbar->setArrowScrollAmount(30);
    scrollbar->setLowValue(360); // Viewable area (height of the panel)
    scrollbar->setMaximum(5 * 180); // Total area (height of the 5 images)

    // Call the scrollPanel function that we defined above when scrolling
    scrollbar->bindCallbackEx(std::bind(scrollClass.scrollPanel, 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);
        }

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

    return 0;
}

#33
Help requests / Grid and sf::Text
13 February 2015, 17:38:22
Hi,

Sorry another question as I struggle to learn sfml and tgui :)

I have a vector of  sf::Text that I want to output, I've got the positions defined for each sf::Text element so that they all align up nicely in 4-5 columns and a series of rows, i.e. as below.

      <col1>   <col2>   <col3>   <col4>
<row1>
<row2>
etc

I want to add a list of radioButtons (or in other menus a list of checkboxs) that line up with each row. I define the xpos, ypos of each widget using the positions defined within the <vector> of the sf::text....however they always seem a little out of alignment.

I wanted to try to use a grid so that all would align up nicely. However from the grid tutorial it said "Grid allows you to automatically position your widgets."

So is there a way for me to insert sf::Text as well as widget elements into a grid?
#34
Help requests / Adding scollbar to a panel?
11 February 2015, 00:33:06
Is is possible to add a vertical and horizontal scrollbar to a panel? I don't want to use a child window as I don't want the user to move the panel.
If so, is there any example code that shows how to do this?

Many thanks in advance.
#35
I've set the text to a label, but I'd like to say add an underline or make it bold, i.e. the stuff can be set with sf::Text test.setStyle();
I've tried the below but obviously it says that m_text isn't accessible.

Code (cpp) Select

LabelList->m_Text.setStyle(sf::Text::Underlined);


So I tried the below, where i define the sf::Text string and style. However I get a cannot convert parameter error.

Code (cpp) Select

tgui::Label::Ptr LabelList;
sf::Text str;

str.setString("Global Nation Treasury");
str.setStyle(sf::Text::Underlined);
LabelList->setText(str);

Error 17 error C2664: 'tgui::Label::setText' : cannot convert parameter 1 from 'sf::Text' to 'const sf::String &'


PS. Sorry for all of the posts recently - I really hope that I'm not asking obvious things here. I did try to search the forums beforehand.
#36
Help requests / Error when adding text to textBox
22 January 2015, 09:27:00
Hey Folks,

So I'm trying to use textBox where I display some game data in an efficient way with scoll-bars. However I get an error when using the setText or addText methods. (using v0.6 btw)

Code (cpp) Select


tgui::TextBox::Ptr textBoxList;

textBoxList->load(themeConfFile);
textBoxList->setPosition(20, 20);
textBoxList->setSize(600, 300);
textBoxList->setBackgroundColor(sf::Color::White);
textBoxList->setSize(600, 300);
textBoxList->setText("Nation\t");



I get an run error with visual studio.



When I press retry, it breakpoints into dbgheap.c at line 1424.

Also I had another question about textbox and chatbox. Is there a way to automatically scroll down the textbox, i.e. if the amount of text exceeds the ysize, then can I move the scroll automatically so the last entry is the one that stays in focus within the textbox?
#37
Help requests / Menu hot-keys
18 January 2015, 04:05:36
So is there a way to have multiple call-backs be defined to the same call-backID?

i.e. so I define an ENUM like below for each call-back event

Code (cpp) Select


enum GUICallBackID {
QUIT_GAME,
NEW_GAME,
LOAD_GAME,
SAVE_GAME,
EXIT_GAME,
NEXT,
};



Now I define radio buttons for each of these menu options, with the mouse clicked event bound to each id. for example, this is the quit menu callback ID.
(RadioButtonList is vector containing each radio button.)

Code (cpp) Select

RadioButtonList[i]->setCallbackId(QUIT_GAME);
RadioButtonList[i]->bindCallback(tgui::Button::LeftMouseClicked);


However what I also want to do is for the QUIT_GAME callbackID to be trigger if the user presses a hot-key, like say Q or 0 for menu option 0. Is there a way to do this? I tried adding a second bindCallback function but that obviously simply overwrote the left mouse clicked event.

Many thanks in advance.
#38
Help requests / views in TGUI
17 January 2015, 07:36:48
Hey Folks,

I'm still new to programming in general and new to SFML. I've just installed TGUI and I'm trying to provide user input with a more professional feel than what I've been previous doing.

With SFML, I setup 3 views.
1 mainView where the game action happens.
1 lowerView which updates with stats info as the game progress
1 rightView which has some static data.

What I'd like to do with TGUI is to have 3 seperate views like above. I want to be able to display all of my game images in the mainView. however I want the option to have a menu bar within this mainview.

From what I see the tgui::Gui gui; doesn't have any views. So is there a way to create 3 seperate windows? With the main window I want to draw images that only appear within this window, i.e. if the image overlaps the mainview size, then it should not appear in right or lower views.

I see there is a child window but I don't want the user to be able to close any of those child windows - is there a way to remove close X button in a child window? Do child window's fufill the same function in tgui as view did in SFML? i.e. the ability to split up the window into multiple screens.