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 - wizzard

#26
I think there should be a way to get lines in the ChatBox so I can implement my own copy and pasting functionality.
It would also be nice to have a callback for when a line is right-clicked.
#27
Hello,

I'm trying to get chat boxes to scroll with the mouse wheel.
Currently, the scroll bar thumb must be clicked and dragged to move the chat box contents.
I see there exists this function

    void tgui::ChatBox::mouseWheelMoved(int delta);

However, I do not know how to activate it properly.
I'm using the following code and playing around everywhere with the mouse wheel with no effect:
#include <TGUI/TGUI.hpp>

#define THEME_CONFIG_FILE "widgets/Black.conf"

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
    tgui::Gui gui(window);

    if (gui.setGlobalFont("fonts/DejaVuSans.ttf") == false)
        return 1;

    tgui::ChatBox::Ptr chatbox(gui);
    chatbox->load(THEME_CONFIG_FILE);
    chatbox->setSize(200, 100);
    chatbox->setTextSize(20);
    chatbox->setPosition(400, 25);
    chatbox->addLine("Line 1", sf::Color::Red);
    chatbox->addLine("Line 2", sf::Color::Blue);
    chatbox->addLine("Line 3", sf::Color::Green);
    chatbox->addLine("Line 4", sf::Color::Yellow);
    chatbox->addLine("Line 5", sf::Color::Cyan);
    chatbox->addLine("Line 6", sf::Color::Magenta);

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


I noticed that tgui::EventManager::handleEvent has the following code

        // Check for mouse wheel scrolling
        else if (event.type == sf::Event::MouseWheelMoved)
        {
            // Find the widget under the mouse
            Widget::Ptr widget = mouseOnWidget(static_cast<float>(event.mouseWheel.x), static_cast<float>(event.mouseWheel.y));
            if (widget != nullptr)
            {
                // Send the event to the widget
                widget->mouseWheelMoved(event.mouseWheel.delta, event.mouseWheel.x,  event.mouseWheel.y);
                return true;
            }

            return false;
        }


So, it seems like the feature is there already. I just don't know how to activate it.
Maybe the widget under the mouse is never set to a non-null value?
#28
Yay. It works. I didn't know such a limitation existed.
#29
It appears focused, but you cannot type into it unless you actually click on it.

At least, that is my problem.
#30
Ah, it looks like a bug because it works as expected when there is no ChildWindow involved. (using latest version)

#include <TGUI/TGUI.hpp>

#define THEME_CONFIG_FILE "widgets/Black.conf"

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
    window.setVerticalSyncEnabled(true);

    tgui::Gui gui(window);

    if (gui.setGlobalFont("fonts/DejaVuSans.ttf") == false)
        return 1;

    tgui::ChildWindow::Ptr childWindow(gui);
    childWindow->load(THEME_CONFIG_FILE);
    childWindow->setPosition(20, 20);
    childWindow->setSize(400, 300);

    tgui::EditBox::Ptr editBox(*childWindow);
    editBox->load(THEME_CONFIG_FILE);
    editBox->setPosition(40, 200);
    editBox->setSize(300, 30);

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::TextEntered && event.text.unicode == '`')
                editBox->focus(); // tilde key pressed

            gui.handleEvent(event);
        }

        window.clear();
        gui.draw();
        window.display();
    }

    return 0;
}
#31
I was using an EditBox in a ChildWindow today and I wanted to make it so that when the ChildWindow pops up, the EditBox would automatically get keyboard focus so that one does not have to explicitly click on the EditBox to start putting text into it.
I assumed that EditBox::Focus would do the job but it only gave the appearance that the EditBox was selected (its border gets darker when selected).
So, I also tried EditBox::enable and EditBox::show but neither of those worked too.
Its really inconvenient to the user to not have this as it is to be expected out of the type of dialog that I am giving.
I'm not sure if this is a bug or a new feature or if I missed how to do it.
#33
When using TGUI in a window and not full-screen, I think that child windows that are being dragged should stop being dragged when the mouse leaves the rendering region.
I can continually drag around a window if my left mouse button is not down if I just release my mouse outside of the window.

Edit: So, my fix would be just detecting MouseLeft events with the ChildWindow and then stop dragging when they are detected.
#34
I know libRocket does it the "backwards" way too. GWEN does it the "right" way.
Just a minor style choice, so it does not really matter
#35
Awesome stuff! Thanks!

Quote from: texus on 30 July 2013, 01:02:06
The function will now return true when the gui didn't handle the event and false when the event was consumed.
Doesn't the inverse make a bit more sense though? If the event was handled when calling handle event, handle event should return true. If the event was not handled when calling handle event, handle event should return false. It seems backwards to me because usually when a function fails it returns false.


if (!gui.handleEvent(event)) {
    // The GUI did not handle the event, and so we will
}
#36
I have used both GWEN and libRocket before trying this library and they both had bools returning when an event was "consumed" by the GUI.
Check out the prototypes for libRocket's input functions here.
Notice that ProcessKeyDown, ProcessKeyUp, ProcessTextInput, and ProcessMouseWheel return booleans.
For some reason ProcessMouseDown and ProcessMouseUp do not have this happening in libRocket.
GWEN definitely has functions for mouse button down and mouse button up events being ignored,
but it has no proper online documentation for me to link here to show you.

Anyways, I think it is currently possible in TGUI to ignore the events that the GUI "consumes".
It just takes a lot of extra code because it is not just the mouse events.
Note that I am unsure if mouse move events should be considered in events that are potentially ignored.
I actually recommend leaving mouse move events up to me whether they are ignored or not by forcing me to manually implement ignoring of them.

To sum up the events that are potentially consumed, they are:

  • TextEntered
  • KeyPressed
  • KeyReleased
  • MouseWheelMoved
  • MouseButtonPressed
  • MouseButtonReleased
  • MouseMoved (maybe)

Key and text events are only consumed if a widget has focus that takes text(?).
#37
Also, why not use a union here?

// Only one of these things can be filled at a given time
bool checked;
int value;
Vector2f value2d;
Vector2f position;
Vector2f size;
unsigned int index;
#38
In my game editor, I want events that the GUI uses to be ignored by the game editor. So, if there is a window there and you have the object placing tool in use, objects won't be placed behind the window when you are clicking on the window. I can do this currently but it requires doing a bunch of bounds checking and stuff outside of TGUI that TGUI already does internally. It'd be nice if a bool was returned that told me whether an event was a GUI-only event or not.