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.


Messages - Maksat

Pages: [1] 2
1
Wow! I don’t have to implement it myself. I just can use tgui::Texture and tgui::Sprite! Thank you very much for your library! It is very useful to me. I am very grateful to you.

2
Hi Texus! Could you tell me how you implemented the "Middle" parameter on themes syntax? How do you scale given rect of texture and remain unchanged other parts?

3
Help requests / Re: Adding signals to derived widgets
« on: 28 December 2019, 15:37:14 »
It worked! Thanks!

4
Help requests / Adding signals to derived widgets
« on: 28 December 2019, 13:08:52 »
Hello! I made class inherited from tgui::Group, which contains some other widgets. Is it possible to add new signal like "GropWidgetPressed" so I could use it like this:
myGroupWidget.connect("GropWidgetPressed", [](){});
 

5
Help requests / Re: Increasing scroll sensitivity
« on: 15 June 2019, 13:37:32 »
Thanks!

6
Help requests / Increasing scroll sensitivity
« on: 14 June 2019, 06:25:21 »
Hi! I could not find any way to increase scroll sensitivity of ScrollablePanel. It's very inconvenient to scroll to the end of the content of ScrollablePanel with low contentOffset, when it has wide content height

7
Help requests / Re: unfocusing widgets
« on: 24 May 2019, 15:10:07 »
Ok, thank you!

8
Help requests / Re: unfocusing widgets
« on: 24 May 2019, 14:11:02 »
So basically call gui.handleEvent for every event except for the space key press event.
how can I do that?
if(event.type == Event::KeyPressed && event.key.code == Keyboard::Space)
{
    handleSpaceKeyEvent();
    return;
}
gui.handleEvent();
/* handle other events */
 

like this?

9
Help requests / unfocusing widgets
« on: 24 May 2019, 11:26:24 »
Hi!
auto button = tgui::Button::create();
button->setRenderer(theme.getRenderer("Button"));
button->connect("pressed", [](){std::cout<<"button pressed" << endl;});
gui->add(button);

/* --- */

sf::Event event;
while (window->isOpen())
{
        while (window->pollEvent(event))
        {
                /* --- */
                gui.handleEvent(event);
               
                if (event->type == Event::KeyPressed)
                        switch (event->key.code)
                        {
                        case Keyboard::Space:
                                cout<< "space key pressed"<<endl;
                                break;
                                /* --- */
                        }

                        /* --- */
        }
}
 

if you press the button and then the space key, you will see:
button pressed
button pressed
space key pressed

I use many buttons and i have another function bind to the space key. I have to unfocus widget every time i pressed it. Is there any option to disable auto focusing last pressed widget?

10
Help requests / Re: ComboBox and State pattern
« on: 14 March 2019, 09:44:02 »
Thank you!

11
Help requests / Re: ComboBox and State pattern
« on: 13 March 2019, 06:09:51 »
Why not make an item selection and call a binded function after releasing the mouse button? For example, if you hold down the mouse button on the list of items and move the mouse over them, the items will be selected immediately after the mouse overlaps the element. This may not be convenient if it is binded to a heavy function, and you did not plan to select this element. Selecting an item after releasing the mouse button would solve this problem. And mine, by the way, too =)

here is example code
int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
        window.setFramerateLimit(60);

        tgui::Gui gui(window);

        try
        {
                tgui::Theme theme{ "../themes/Black.txt" };

                gui.add(tgui::Picture::create("../RedBackground.jpg"));

                auto label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText("Hold down the mouse button on list box and move the mouse over items");
                label->setPosition(70, 30);
                label->setTextSize(18);
                gui.add(label);

                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText("ComboBox");
                label->setPosition(150, 80);
                label->setTextSize(18);
                gui.add(label);
                       
                auto comboBox = tgui::ComboBox::create();
                comboBox->setRenderer(theme.getRenderer("ComboBox"));
                comboBox->setSize(200, 21);
                comboBox->setPosition(150, 100);
                comboBox->connect("ItemSelected", []() { cout << "Item selected" << endl; });
                comboBox->addItem("Item 1");
                comboBox->addItem("Item 2");
                comboBox->addItem("Item 3");
                comboBox->addItem("Item 4");
                comboBox->addItem("Item 5");
                comboBox->addItem("Item 6");
                comboBox->setSelectedItem("Item 2");
                gui.add(comboBox);


                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText("ComboBox with heavy functions");
                label->setPosition(450, 80);
                label->setTextSize(18);
                gui.add(label);

                comboBox = tgui::ComboBox::create();
                comboBox->setRenderer(theme.getRenderer("ComboBox"));
                comboBox->setSize(200, 21);
                comboBox->setPosition(450, 100);
                comboBox->connect("ItemSelected", []() {this_thread::sleep_for(500ms); cout << "hard work done" << endl; });
                comboBox->addItem("Item 1");
                comboBox->addItem("Item 2");
                comboBox->addItem("Item 3");
                comboBox->addItem("Item 4");
                comboBox->addItem("Item 5");
                comboBox->addItem("Item 6");
                comboBox->setSelectedItem("Item 2");
                gui.add(comboBox);

       
                auto button = tgui::Button::create();
                button->setRenderer(theme.getRenderer("Button"));
                button->setPosition(window.getSize().x - 115.f, window.getSize().y - 50.f);
                button->setText("Exit");
                button->setSize(100, 40);
                button->connect("pressed", [&]() { window.close(); });
                gui.add(button);
        }
        catch (const tgui::Exception& e)
        {
                std::cerr << "TGUI Exception: " << e.what() << std::endl;
                return EXIT_FAILURE;
        }

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

12
Help requests / Re: ComboBox and State pattern
« on: 13 March 2019, 04:48:08 »
I don't use gui in B state. How can I use same gui for both states? Static gui object in BaseWindow? Is it ok to create static gui objects? As I know, nothing good wil come if you create static SFML objects.

13
Help requests / ComboBox and State pattern
« on: 12 March 2019, 15:10:31 »
Hi! Here is a little example of how I implement State pattern in my program to manage windows. When I click ComboBox item, contex changes its state from Awindow to Bwindow, which will draw loading animationw while loading some resources and return back to A state. The problem is that when I press mouse button, contex changes it's state to B immediadetly and A state does not have time to accept the mouseButtonReleased event. So when contex returned back to the state A, the ComboBox will think that I'm still holding mouse button. How can I solve this problem?
 class BaseWindow;
class myRWindow : public sf::RenderWindow
{
        BaseWindow * state;
public:
        void changeState(BaseWindow *st) { state = st; }
        void handleEvent(Event *event) { state->handleEvent(event); }
        void drawCurrentState() { state->draw(); };
};

class BaseWindow
{
public:
        virtual void draw() = 0;
        virtual void handleEvent(sf::Event *) = 0;
protected:
        myRWindow *contex;
};

class WindowStateA : public BaseWindow
{
private:
        tgui::Gui gui;

        void onComboBoxItemSelected(tgui::Widget::Ptr, const sf::String&)
        {
                /* --- */
                WindowStateB *windB = WindowStateB::getInstance();
                contex->changeState(windB);
                windB->doSomethingAndReturn(this);
        };
public:
        virtual void draw();
        virtual void handleEvent(sf::Event & ev) { gui.handleEvent(ev); };

};

class WindowStateB : public BaseWindow
{
public:
        void doSomethingAndReturn(BaseWindow * wst) // and return to window
        {
                auto contWind = contex;
                auto changeState = [contWind, wst]() {contWind->changeState(wst); };
                /* --- */
                // working in another thread while showong animation. After finishing work  changeState will be called
                /* --- */
        }

        virtual void draw();
        virtual void handleEvent(sf::Event & ev);

};

14
Thank you very much!

15
What should the function do exactly? Place some text in the ComboBox when none of its items are selected yet?
Yes

Pages: [1] 2