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.


Topics - starkhorn

Pages: 1 2 [3]
31
Help requests / Assign unique identier to a vector of Panels
« on: 28 March 2015, 05:49:58 »
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
« on: 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
« on: 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?
« on: 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
Help requests / Is is possible to set the text style in a Label ?
« on: 25 January 2015, 01:02:52 »
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
« on: 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
« on: 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
« on: 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.

Pages: 1 2 [3]