Main Menu
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 - wmbuRn

#1
Folowing code works great:

#include <TGUI/TGUI.hpp>

void loadWidgets( tgui::Gui& gui )
{

    tgui::ChildWindow::Ptr child(gui, "childWindow");
  //  child->load("../../widgets/Black.conf");
  //  child->setIcon("../icon.jpg");
    child->load("Black.conf");
    child->setSize(400, 400);
    child->setBackgroundColor(sf::Color(80, 80, 80));
    child->setPosition(200, 100);
    child->setTitle("Child window");
    child->hide();
    child->bindCallback(tgui::ChildWindow::Closed);
    child->setCallbackId(2);



    tgui::Button::Ptr showChildWindow(gui);
    showChildWindow->load("Black.conf");
    showChildWindow->setSize(120, 40);
    showChildWindow->setPosition(100, 100);
    showChildWindow->setText("Show child window");
    showChildWindow->bindCallback(tgui::Button::LeftMouseClicked);
    showChildWindow->setCallbackId(1);


}

int main()
{
    // Create the main window
    sf::RenderWindow app(sf::VideoMode(800, 600), "Child window test");
    tgui::Gui gui(app);

   // gui.setGlobalFont("../../fonts/DejaVuSans.ttf");
     gui.setGlobalFont("DejaVuSans.ttf");


    loadWidgets(gui);

// Start the game loop
    while (app.isOpen())
    {
        // Process events
        sf::Event event;
        while (app.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                app.close();

            // Pass the event to all the widgets
            gui.handleEvent(event);
        }

            tgui::Callback callback;
            while (gui.pollCallback(callback))
            {

                if (callback.id == 1)
                {
                    tgui::ChildWindow::Ptr Child = gui.get("childWindow");
                    Child->show();

                }

                if ( callback.id == 2 )
                {
                tgui::ChildWindow::Ptr Child = gui.get("childWindow");
                Child->hide();
                }

            }



        // Clear screen
        app.clear();

        // Draw the sprite
        gui.draw();

        // Update the window
        app.display();
    }


    return EXIT_SUCCESS;
}


Just added

child->bindCallback(tgui::ChildWindow::Closed);
child->setCallbackId(2);

To child window

And

if ( callback.id == 2 )
{
        tgui::ChildWindow::Ptr Child = gui.get("childWindow");
        Child->hide();
}

Inside  while (gui.pollCallback(callback)) where all callbacks are checked.

I posted this "solution" in case somebody gets same problems as i did. If not nedded, feel free to delete entire topic (:
#2
No delete button on topic. Forget this topic, i didnt see

enum tgui::ChildWindow::ChildWindowCallbacks

Defines specific triggers to ChildWindow.
Enumerator
LeftMousePressed    

The left mouse button was pressed (child window was thus brough to front)
Closed    

Child window was closed.
Moved    

Child window was moved.
AllChildWindowCallbacks    

All triggers defined in ChildWindow and its base classes.

in documentation. Sorry
#3
Here is simple code


#include <TGUI/TGUI.hpp>

void loadWidgets( tgui::Gui& gui )
{

    tgui::ChildWindow::Ptr child(gui, "childWindow");
  //  child->load("../../widgets/Black.conf");
  //  child->setIcon("../icon.jpg");
    child->load("Black.conf");
    child->setSize(400, 400);
    child->setBackgroundColor(sf::Color(80, 80, 80));
    child->setPosition(200, 100);
    child->setTitle("Child window");
    child->hide();

    tgui::Button::Ptr showChildWindow(gui);
   // showChildWindow->load("../../widgets/Black.conf");
    showChildWindow->load("Black.conf");
    showChildWindow->setSize(120, 40);
    showChildWindow->setPosition(100, 100);
    showChildWindow->setText("Show child window");
    showChildWindow->bindCallback(tgui::Button::LeftMouseClicked);
    showChildWindow->setCallbackId(1);

}

int main()
{

    sf::RenderWindow app(sf::VideoMode(800, 600), "Child window test");
    tgui::Gui gui(app);

     // gui.setGlobalFont("../../fonts/DejaVuSans.ttf");
      gui.setGlobalFont("DejaVuSans.ttf");

    loadWidgets(gui);

    while (app.isOpen())
    {
        // Process events
        sf::Event event;
        while (app.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                app.close();

            // Pass the event to all the widgets
            gui.handleEvent(event);
        }

            tgui::Callback callback;
            while (gui.pollCallback(callback))
            {

                if (callback.id == 1)
                {
                    tgui::ChildWindow::Ptr Child = gui.get("childWindow");
                    Child->show();
                }

            }

        // Clear screen
        app.clear();

        // Draw the sprite
        gui.draw();

        // Update the window
        app.display();
    }


    return EXIT_SUCCESS;
}


What it does: Displays child window od given location. Problem is when clicking on  [X] on childwindow, it does close child window. But it doesnt hide it or anything, so i guess child window gets destroyed automaticly. After closing the child window, and clicking on same button to show child window i get core dumped. Which i guess its becouse child gets destroyed.

1. How to implement when clicking [X] button on child window, makes child window hide(), and not destroy()

2. I know i can add buttons to child window, and bindCallback to one button to serves as hide() for childwindow, but there still will be [X] displayed in child window titlebar when displaying child window, which i cant remove, and it is dangerous if somebody click on it.

#4
Help requests / Re: String/letters label
17 March 2014, 19:01:31
Downloading guthub version, will report back after i install and test. thank you

EDIT: It works perfectly with current github version of SFML. Thank you
#5
Help requests / Re: String/letters label
17 March 2014, 18:40:13
we are working on same project, labels are cut on my linux. Here is code for labels:


    tgui::Label::Ptr labelPlayerSettings(*settingsScreen);
    labelPlayerSettings->setText("Music Player:");
    labelPlayerSettings->setTextColor(sf::Color::White);
    labelPlayerSettings->setPosition(430, 20);
    labelPlayerSettings->setTextSize(20);

    tgui::Label::Ptr labelRandomSongs(*settingsScreen);
    labelRandomSongs->setText("Play random songs");
    labelRandomSongs->setTextColor(sf::Color::White);
    labelRandomSongs->setPosition(460, 60);
    labelRandomSongs->setTextSize(10);


And other code from picture below. Labels are cut on bottom.
using Linux: Elementary OS Luna.
TGUI: 0.6.2 just downloaded tham and installed
SFML: 2.1

picture: https://s18.postimg.org/8jts76j4p/cut_Label.png

EIDT: If needed i can make new project with just labels
#6
It works. I will check the docs. Thank you very much
#7
getValue() returns current value when program loads. When i move the thumb of the slider i dont get new values. I will code only for slider in 1-2 mins

Here is minimal code:

#include <TGUI/TGUI.hpp>

int main()
{
    // Create the main window
    sf::RenderWindow app(sf::VideoMode(400, 400), "slider test");
    tgui::Gui gui(app);

    tgui::Slider::Ptr slider(gui);
    slider->load("Black.conf");
    slider->setVerticalScroll(false);
    slider->setPosition(10, 10);
    slider->setSize(300, 25);
    slider->setMinimum(0);
    slider->setMaximum(100);

    std::cout << "Value is: " << slider->getValue() << std::endl;



// Start the game loop
    while (app.isOpen())
    {
        // Process events
        sf::Event event;
        while (app.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                app.close();

            gui.handleEvent(event);
        }

        tgui::Callback callback;
        while (gui.pollCallback(callback))
        {
        }

        // Clear screen
        app.clear();

        // Draw the sprite
        gui.draw();

        // Update the window
        app.display();
    }

    return EXIT_SUCCESS;
}
#8
I can always get slider value by using code
slider->getValue()

But i dont get new values when i move slider left or right. How to constantly get new values when i move slider left or right ?

side question: which one should i use as slider for music volume? slider2d or slider?

Thanks in advance
#9
It wasnt my pc, i was connected [teamviewer] to my gf computer trying to solve why things wont cmake on her pc. First she installen mingw in "C:/Program Files/Code Blocks/Mingw" while mingws site said to use path without spaces so ideal path will be "C:/mingw" . Didnt solved it yet, no internet in entire town where i live. Am online throught PC and tethering from my android phone :) will report back when internet comes back :)
#10
Let me check env paths again and will report back :)
#11
where is the source: C:/tgui-master/

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/TGUI-master/build/CMakeFiles/2.8.11.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/TGUI-master/build/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cmake
Configuring incomplete, errors occurred!




where is the source: when i set from C:/tgui-master/ to : C:/TGUI-master/cmake/Modules

CMake Error: The source directory "C:/TGUI-master/cmake/Modules" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.


Is it my mistake of somebody elses? :)
#12
I couldnt find diference between sfml 2.0 and 2.1. So i didnt know is sfml 2.1 is a bugfix release or api was changed. Yup since there is no sfml 2.1 on launchpad [yet?] i will have to build sfml and tgui from source. Am waiting for github to start working again to get tgui-0.6.

Thank you for your answer
wmbuRn
#13
General Discussion / tgui 0.6 and sfml 2.1
28 July 2013, 16:42:57
Sfml 2.1 is released this morning, and i am wondering is it safe to use tgui 0.6 with sfml 2.1?

Thank you :)
#14
Yeah i know i can change value like that, but i have about 3.300 checkboxes :) Anyway thanks for help. :)
#15
Help requests / checkbox and load from files
27 July 2013, 03:16:49
This is how i save isChecked()

bool saveUcenik1Trening(int Text)
{
std::ofstream saveFile;
saveFile.open("checkboxUcenik1.txt", std::ios::app);
    saveFile << Text;
    saveFile << " ";
saveFile.close();

return 0;
}


And it does save to file. This is how i load from "checkboxUcenik1.txt" file

std::ifstream loadFileUcenik1Trening("checkboxUcenik1.txt");
    int valueUcenik1[12];
    tgui::Checkbox::Ptr CheckBoxUcenik1[12];
if (loadFileUcenik1Trening.is_open())
{
    for (unsigned int i = 0; i < 12; ++i)
    {
     CheckBoxUcenik1[i] = Group1->get("Ucenik1Trening" + tgui::to_string(i));
     loadFileUcenik1Trening >> valueUcenik1[i];    // valueUcenik[i] 1 and 0 from file
     std::cout << valueUcenik1[i] << std::endl;  // terminal show valueUcenik have 1 and 0 loaded
     CheckBoxUcenik1[i]->check(valueUcenik1[i]);  // error here
     }
}
loadFileUcenik1Trening.close();
}
[/close]

error: no matching function for call to 'tgui::Checkbox::check(int&)' . Any idea how to fix this ?

Thank you in advance
wmbuRn
#16
Quotesf::String::toAnsiString() will return an std::string from the sf::String.

Dont know what to do with it :) Nevermind, will get back to reading documentation and will (hopefully) get it to work. Thanks for your help :)


EDIT: Solved it. Thank you
took me 12hrs to solve this, and it was simple noobish mistake. LOL.
#17
lol :) nice one.
Anyway vectors are pain in the ... After reading all of the documents there is for vectors my head is going to explode but vectorName.clear() and vectorName.resize() nor vectorName.erase(begin, end) vectorName.swap() does not do the job i want. [dont mind the name vectorName its just for argument, and all the calls have their respective values]

So i am in a little confusion. I took values from groups with this code:

for (unsigned i = 0; i < 30; ++i)
    {
    tgui::EditBox::Ptr Ime = Group1->get("Ime" + tgui::to_string(i));
    sf::String ValueIme = Ime->getText();

    tgui::EditBox::Ptr Ime1napomene = Group1Napomene->get("Ime" + tgui::to_string(i));
    Ime1napomene->setText(ValueIme);



// Code down is irrelevant lets focus on code above.

    // Uzmi Prezime iz Group1
    tgui::EditBox::Ptr Prezime = Group1->get("Prezime" + tgui::to_string(i));
    sf::String ValuePrezime = Prezime->getText();
    // Prebaci prezime iz Group1 u Group1Napomene
    tgui::EditBox::Ptr Prezime1napomene = Group1Napomene->get("Prezime" + tgui::to_string(i));
    Prezime1napomene->setText(ValuePrezime);


    // Uzmi BrojTelefona iz Group1
    tgui::EditBox::Ptr BrojTelefona = Group1->get("BrojTelefona" + tgui::to_string(i));
    sf::String ValueBrojTelefona = BrojTelefona->getText();
    // Prebaci BrojTelefona iz Group1 u Group1Napomene
    tgui::EditBox::Ptr BrojTelefona1napomene = Group1Napomene->get("BrojTelefona" + tgui::to_string(i));
    BrojTelefona1napomene->setText(ValueBrojTelefona);

    // Uzmi DatumRodjenja iz Group1
    tgui::EditBox::Ptr DatumRodjenja = Group1->get("DatumRodjenja" + tgui::to_string(i));
    sf::String ValueDatumRodjenja = DatumRodjenja->getText();
    // Prebaci DatumRodjenja iz Group1 u Group1Napomene
    tgui::EditBox::Ptr DatumRodjenja1napomene = Group1Napomene->get("DatumRodjenja" + tgui::to_string(i));
    DatumRodjenja1napomene->setText(ValueDatumRodjenja);

    }

Lets examine it.
tgui::EditBox::Ptr Ime = Group1->get("Ime" + tgui::to_string(i));  << Ime get EditBox named Ime + i
sf::String ValueIme = Ime->getText();   << sf::String get a value.

That code was for transfering from Group1 to Group2. Can i use that sf::String Ime to write it to .txt file? And since its for loop sf::String ime will get diferent values, and each values will be stored in .txt [with std::ios::app ] Which is better solution than this:

EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i)); // EditBoxNames is vector<tgui::EditBox.....>
GroupNames.push_back(EditBoxNames[i]->getText());       // GroupNames is vector<sf::String>....
saveGroup1Names(GroupNames);                                    // function with iterations to save to file


The only problem is: How to save to file when inputed string is sf::String instead of std::string.
Here is my function to save to .txt when is std::string

void saveIt(sf::String Text)
{
std::ofstream snimi;
snimi.open("Imena.txt", std::ios::app);
for (unsigned int i = 0; i < 30; ++i)
{
snimi << "Name" + tgui::to_string(i+1) + ": ";
snimi << Text;
snimi << "\n";
}
snimi.close();
}
And i get error in line " snimi << Text; " Gcc complain that it cant do anything with Text. error: no match for 'operator<<' in 'snimi << Text'
Any solution to this? Since i cant bust my head again with vectors.
#18
Ok. Thank you. Never done any GUI od 2d/3d programing so i never used vectors nor iterators :) so i didnt know are they part of tgui or standard c++.  its new to me :)


Texus you should use : https://lmgtfy.com/?q=vector%3A%3Apush_back lol :)

Thank you
#19
Searched entire Class reference and i couldnt find anything about push.back. And i used it in my code [Thanks to Texus] and i want to read more about it. Since TextBox doesnt have push.back i need to find another way to take typed text from Text box so i can store it into .txt. This is how i done for Editboxes:


EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i));
Group1Names.push_back(EditBoxNames[i]->getText());
saveGroup1(Group1Names);  // function to save vector into .txt


saveGroup1(Group1Names) function:

void saveGroup1(std::vector<sf::String> strings)
{
std::ofstream snimiGrupu1;
int i = 0;
snimiGrupu1.open ("Group1.txt", std::ios::trunc);
        if (snimiGrupu1.is_open())
        {
            for (std::vector<sf::String>::iterator itr = strings.begin(); itr != strings.end(); ++itr)
            {
            snimiGrupu1 << "Name" + tgui::to_string(i+1) + ": ";
            snimiGrupu1 << itr->toAnsiString();
            snimiGrupu1 << "\n";
            i = i + 1;
            }
        }

        else
        {
        snimiGrupu1.close();
        }
snimiGrupu1.close();
}


But i cant use push.back on TextBox so i need article [wont torture anyone to writte me code] to read to find another solution. :)

with respect
wmbuRn
#20

sf::Event event;
        while (screen.pollEvent(event))
        {

            if (event.type == sf::Event::Closed)
            {
                screen.close();
            }
                sf::sleep(sf::milliseconds(10));
                gui.handleEvent(event); // pass event to all widgets

        }  // end of (screen.pollEvent(event))


It randomly goes from 20%-34%-44%. I also have

sf::RenderWindow screen(sf::VideoMode(800, 600), "Titleeee");
    screen.setFramerateLimit(30);


Nevermind i will find it and will solve it. :)

And for the code i ment as a joke, i dont want somebody to do coding for me. Its not somebody job to do that for me. Anyway Thank you for your time and help :)

EDIT:
Just noticed it that  sf::sleep(sf::milliseconds(10)); was in my screen.pollEvent(). I moved it to while screen.isOpen(). Now program tooks 30% CPU nad wont rise nor fall. Which is good. Will try to reduce that. :)
#21
Yup, i was uploading code to pastebin and i noticed that mistake. Thank you for your help. I can upload entire project if you want to laught at my code :)
#22
Remember when you told me "Not to use for (unsigned i =1; i <= 30; ++i) ?
Well thats the problem. My Group1 EditBox Ime is (unsigned i =0; i < 30; ++i)
and Group1Napomene EditBox Ime is (unsigned i =1; i <= 30; ++i). That causes the problem. I just fixed it. Your code is working. Thank you.

Now i have to deal with "Why program takes 34-40% CPU when i click to open Group1, and it was using 4% when on main screen and loginScreen.
#23
Error: /usr/local/include/TGUI/SharedWidgetPtr.hpp:271: T* tgui::SharedWidgetPtr<T>::operator->() const [with T = tgui::EditBox]: Assertion `m_WidgetPtr != __null' failed.


DBG shows line: Ime1napomene->setText(text);


Code in that EDIT is working.But it is for only 1 Editbox. I need to transfer values from 30 editboxes [with vectors] to 30 diferent EditBoxes

psuedo code:
Group1.EditBox-Ime[0] send value to > Group1Napomene.EditBox-Ime[0]
Group1.EditBox-Ime[1] send value to > Group1Napomene.EditBox-Ime[1]
...
Group1.EditBox-Ime[30] send value to > Group1Napomene.EditBox-Ime[30]
/pseudo code

This is how i took values from Group1:

for (unsigned int i = 0; i < 30; ++i)
            {
tgui::Panel::Ptr Group1 = gui.get("Group1");
EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i));
Group1Names.push_back(EditBoxNames[i]->getText());
           }

And i am missing part of how to use Ime1napomene.setText(Group1Names).
#24
I did nothing with Ime1napomene. Its fresh variable for purpose of using it for transfering values betwean EditBoxes. Didnt use push.back() function. And even with that function i still get same core dumped.

In Ime1napomene should be EditBoxes named "Ime" + tgui::to_string(i)
So i can use
Ime1napomene.setText();

But obviusly i am failing at making it to work :)
#25
It compiles but i get Core dumped.

DBG said this line is error: Ime1napomene[i]->setText(Group1Names[i]);

for (unsigned i = 0; i < 30; ++i)
    {
    tgui::Panel::Ptr Group1 = gui.get("Group1");
    EditBoxNames[i] = Group1->get("Ime" + tgui::to_string(i));
    Group1Names.push_back(EditBoxNames[i]->getText());

    tgui::Panel::Ptr Group1Napomene = gui.get("Group1Napomene");
    Ime1napomene[i]->setText(Group1Names[i]);
    }


EDIT:
This is how i take values from 1 editBox and transfer that values to another EditBox:

tgui::Panel::Ptr Group1 = gui.get("Group1"); // open Group1
    tgui::EditBox::Ptr Ime1 = Group1->get("Ime1");   // open EditBox named Ime
    sf::String Ime = Ime1->getText();    // getText from editBox named Ime

    tgui::Panel::Ptr Group1Napomene = gui.get("Group1Napomene");    // open Group1Napomene
    tgui::EditBox::Ptr Ime1napomene = Group1Napomene->get("Ime1"); // Get EditBox Ime
    Ime1napomene->setText(Ime);    // Save value from EdidBox Ime from Group1 into
           // EditBox named Ime from Group1Napomene

I want to do that with vectors becouse i have a lot of EditBoxes[/code]