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

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