Mouse wheel and the chat box not working

Started by wizzard, 27 August 2013, 11:27:26

wizzard

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?

texus

It's fixed now.
I once made a change to the function, but it seems like I didn't update all widgets.

The mistake becomes clearly visible if you put these lines below each other :)
Code (cpp) Select
void tgui::ChatBox::mouseWheelMoved(int delta);
widget->mouseWheelMoved(event.mouseWheel.delta, event.mouseWheel.x,  event.mouseWheel.y);

wizzard