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

#76
Help requests / Re: scrollbar example code
09 April 2015, 13:04:56
Hi Texus,

Sorry to ask another question. I'm having a situation with the scroll-bars, where I only want the scrollbar to appear when the content expands to a size that is outside of the panel. So this means, I'm updating the maximum as the content grows. However if I then call the setMaximum, the callback function gets called as I assume the trigger of tgui::ScrollBar::ValueChanged gets hit when I update the maximum.

so one idea I had was prior to changing the maximum, was to unbind the function callback, change the maximum and then rebind it again. Question is how do I get the callback function details? i.e. as per the below pseudo code. I temporarily stored the original scrollbar prior to changes. I unbind and change the maximum. How can I get the the bind function from the original scrollbar so that I can re-set it? (BTW getScrollbar just retrieves the scrollbar ptr from a std::vector based on widget name.

Code (cpp) Select


if (IsScollBarAlreadyInList(scrollbarName))
{
tgui::Scrollbar origScrollbar = *getScrollbar(scrollbarName);

getScrollbar(scrollbarName)->unbindAllCallback();
getScrollbar(scrollbarName)->setMaximum(passed_MaxAmount);
}

#77
Help requests / Re: WidgetTypes
05 April 2015, 07:47:15
Thanks Texus - I didn't think to look in globals.cpp......I hate using windows as I don't have grep. I should probably install cygwin. :)
#78
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.
#79
Awesome - thank you so much. Obvious now that I see it.  :-[
#80
Help requests / Re: scrollbar example code
30 March 2015, 19:20:04
many thanks again Texus - worked a treat. Thanks for explaining why as well.
#81
just wondering if anyone has any ideas on this one?
#82
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);
#83
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;
}

#84
Help requests / Re: Grid and sf::Text
13 February 2015, 19:31:57
Ok sorry, let me clarify in more detail.

I init a vector string (strVector) with the data that i want to display. Each entry is a row, for example as below (with title) entry within this vector is below.

"Name,Age,Skl,Lyl,Rank"
"Cmdr Name, 24, 5, 5, Governor"

In parallel, I define a vector<int> which has the column width for each column. Example as below. So 160 is the width for the Name, etc.
160, 40, 40, 40, 160

I wrote a function to create a vector<sf::Text> using this vector<string> and vector<int>. I basically splits up each csv delimited row into individual strings. Then using the column width vector<int>, it assigns the x and y pos for each sf::Text. It then returns a vector of sf::Text where the position of each Text is defined so that it's position is a nice column/row output. This is what I had before deciding to add tgui/buttons etc.

Code (cpp) Select

vector<sf::Text> drawEngine::setupColsOfText(vector<string> strVector, vector<int> columnWidthSizes, position passed_pos, bool underline)
{
vector<sf::Text> tmpColsOfText;
vector<string> splitRow;
displayDataRow rowData;
position pos = passed_pos;
float newRowStartXPos;

for (int i = 0; i < strVector.size(); i++)
{
splitRow = rowData.splitCsvStr(strVector[i]);
newRowStartXPos = pos.getPosX();
for (int j = 0; j < splitRow.size(); j++)
{
tmpColsOfText.push_back(setText(splitRow[j], pos.getPosX(), pos.getPosY(), underline));
pos.setPosX(pos.getPosX() + columnWidthSizes[j]);

}

if (pos.getPosY() < getMaxCurrentViewYPos())
{
pos.setPosX(newRowStartXPos);
pos.setPosY(pos.getPosY() + getDataRowSize());
}
else
{
pos.setPosX((newRowStartXPos + getColumnWidthTotal(columnWidthSizes) + 20));
pos.setPosY(passed_pos.getPosY());
}

splitRow.clear();
}

return tmpColsOfText;
}


Now I want the user to be able to tick a checkbox for each row. So I create a vector of checkbox's. I add a new checkbox for each row of data from the strVector. Note I do not set the text field of each checkbox. The reason is that I want to align each of my columns neatly and the name of each character varies in length. If there is some way to do that though - please let me know. :)

See below an example of the code. Note I've not shown how I init the strVector nor the columnwidth int vector but that is a series of simply push_back.

Code (cpp) Select

position dataPos;
dataPos.setPos(50, 20);

vector<sf::Text> colsOfText = setupColsOfText(StrVector, columnWidthSizes, dataPos, true);

vector<tgui::Checkbox::Ptr> CheckboxList;
CheckboxList.push_back(tgui::Checkbox::Ptr(gui));
position initPos, initSize;

int yposIncrementer = 0;

initPos.setPos(colsOfText[0].getPosition().x, colsOfText[0].getPosition().y);
initSize.setPos(20,20);

for (int i = 0; i < CheckboxList.size(); i++)
{
CheckboxList[i]->load(themeConfFile);
CheckboxList[i]->setPosition(initPos.getPosX() - 50, (initPos.getPosY() + yposIncrementer));
CheckboxList[i]->setSize(initSize.getPosX(), initSize.getPosY());
yposIncrementer += initSize.getPosY();
}


When I do it this way, though - sometimes the checkbox doesn't quite line up on the y position, i.e. sometimes it is a little below the vector of sf::text or higher...depending on the menu. See below. Is there an easier way to do all of this?

#85
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?
#86
Help requests / Re: Adding scollbar to a panel?
11 February 2015, 23:10:11
Awesome - thank you so much yet again Texus.
#87
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.
#88
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.
#89
no worries at all mate and many thanks for looking at this so quickly.
I'm definitely using sfml2.2, so I'll grab the updated v0.7 and see if it makes a difference. however concentrate on your exams first....this can wait. :)
#90
Hi Texus,

Many thanks and yes I'm sorry that the information that I've provided has been less than helpful. I've put in the .pdb file and now I can see more info in the stack trace etc. It actually refers to the Textbox.cpp now.



Now I've gone through each stack trace file and copy/pasted a snippet from each file. Look for the //stopped here message. I started at begining of the trace and worked upwards.

dbgheap.c
Code (cpp) Select

        /* optionally reclaim memory */
        if (!(_crtDbgFlag & _CRTDBG_DELAY_FREE_MEM_DF))
        {
            /* remove from the linked list */
            if (pHead->pBlockHeaderNext)
            {
                pHead->pBlockHeaderNext->pBlockHeaderPrev = pHead->pBlockHeaderPrev;
            }
            else
            {
                _ASSERTE(_pLastBlock == pHead);
                _pLastBlock = pHead->pBlockHeaderPrev;
            }

            if (pHead->pBlockHeaderPrev)
            {
                pHead->pBlockHeaderPrev->pBlockHeaderNext = pHead->pBlockHeaderNext;
            }
            else
            {
                _ASSERTE(_pFirstBlock == pHead); //<---------Stopped here
                _pFirstBlock = pHead->pBlockHeaderNext;
            }

            /* fill the entire block including header with dead-land-fill */
            memset(pHead, _bDeadLandFill,
                sizeof(_CrtMemBlockHeader) + pHead->nDataSize + nNoMansLandSize);
            _free_base(pHead);
        }


xmemory0   
Code (cpp) Select

void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
::operator delete(_Ptr); //<-----stopped here line 586
}


xstring
Code (cpp) Select

void _Free_proxy()
{ // destroy proxy
typename _Alloc::template rebind<_Container_proxy>::other
_Alproxy;
this->_Orphan_all();
_Alproxy.destroy(this->_Myproxy);
_Alproxy.deallocate(this->_Myproxy, 1);
this->_Myproxy = 0; //<---------- stopped here line 683
}


xstring (again)

Code (cpp) Select

#else /* _ITERATOR_DEBUG_LEVEL == 0 */
_String_alloc(const _Alloc& = _Alloc())
{ // construct allocator from _Al
_Alloc_proxy();
}

~_String_alloc() _NOEXCEPT
{ // destroy the object
_Free_proxy();
} //<----------stopped here line 656


xstring

Code (cpp) Select

~basic_string() _NOEXCEPT
{ // destroy the string
_Tidy(true);
} //<-----stopped here line 965


TextBox.cpp (tgui::TextBox::updateDisplayedText)

Code (cpp) Select

        // Loop through every character
        for (unsigned i=1; i < m_Text.getSize() + 1; ++i)
        {
            // Make sure the character is not a newline
            if (m_Text[i-1] != '\n')
            {
                // Add the next character to the text widget
                tempText.setString(m_Text.toWideString().substr(beginChar, i - beginChar));

                // Check if the string still fits on the line
                if (tempText.findCharacterPos(i).x > maxLineWidth) //<-------stopped here line 2114
                {
                    // Insert the newline character
                    m_DisplayedText.insert(i + newlinesAdded - 1, '\n');

                    // Prepare to find the next line end
                    beginChar = i - 1;
                    ++newlinesAdded;
                    ++m_Lines;
                }
            }


TextBox.cpp (tgui::TextBox::setSelectionPointPosition)

Code (cpp) Select

        // Check if there is a scrollbar
        if (m_Scroll != nullptr) //<------ stopped here line 650
        {
            unsigned int newlines = 0;
            unsigned int newlinesAdded = 0;
            unsigned int totalLines = 0;


TextBox.cpp (tgui::TextBox::addText)
Code (cpp) Select

    void TextBox::addText(const sf::String& text)
    {
        // Don't do anything when the text box wasn't loaded correctly
        if (m_Loaded == false)
            return;

        // Add the text
        m_Text += text;

        // Set the selection point behind the last character
        setSelectionPointPosition(m_Text.getSize());
    } // <------stopped here line 405