Hi
I'm having a problem with TGUI not adjusting mouse coordinates (responding to button events) when the view is set to any size other than the window size.
I'm trying to display a 1280x1024 picture with a button on the screen using different View sizes. Using sf::setView I can get the picture to scale with the view provided I use gui->draw(false) (i.e., no resize), but mouse coords are not converted (i.e., pressing the button does not trigger any events, but when I move the mouse pointer to actual screen corrds corresponding to non-resized button coords, I can press the button).
Below is the minimum code. How do i tell tgui to use resized (View) coords? What am I doing wrong?
Note, I have tried setting SView2 when drawing and then SView1 for event handling but that did not work. I don't want to manually resize and reposition all the GUI objects to suit different window sizes.
I'm having a problem with TGUI not adjusting mouse coordinates (responding to button events) when the view is set to any size other than the window size.
I'm trying to display a 1280x1024 picture with a button on the screen using different View sizes. Using sf::setView I can get the picture to scale with the view provided I use gui->draw(false) (i.e., no resize), but mouse coords are not converted (i.e., pressing the button does not trigger any events, but when I move the mouse pointer to actual screen corrds corresponding to non-resized button coords, I can press the button).
Below is the minimum code. How do i tell tgui to use resized (View) coords? What am I doing wrong?
Note, I have tried setting SView2 when drawing and then SView1 for event handling but that did not work. I don't want to manually resize and reposition all the GUI objects to suit different window sizes.
Code Select
#include <SFML/Graphics.hpp>
#include <TGUI/TGUI.hpp>
#include <windows.h>
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
{
// Initialise SFML Render Window
// Create Render Window
sf::RenderWindow window(sf::VideoMode(1280,1024), "Test", sf::Style::Fullscreen);
sf::View SView1;
sf::View SView2;
// Set view
SView1.reset(sf::FloatRect(0, 0, 1280, 1024));
SView2.reset(sf::FloatRect(0, 0, 2000, 2000));
window.setView(SView1); // SView1 works fine
// window.setView(SView2); // SView2 resizes okay, but gui button doesn't work
// Create GUI
tgui::Gui gui(window);
if (gui.setGlobalFont("../../Fonts/DejaVuSans.ttf") == false)
return(false);
// Load a 1280x1024 size form with a button
if (!gui.loadWidgetsFromFile("form.txt"))
return(false);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
else if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
case sf::Keyboard::Escape:
window.close();
break;
}
}
gui.handleEvent(event);
}
tgui::Callback callback;
while (gui.pollCallback(callback))
{
// Do event handler for gui here
}
window.clear();
gui.draw(false);
window.display();
}
return(0);
}