I'm experiencing a problem with window mouse coords when resizing the window. Everything works fine until the window is re-sized, at which point the coords being generated appear to be based on the original window size, not the new one*. I do not change the standard view when resizing, I just update everything accordingly, including the UI elements within the window.
*Actually what really seems to be happening is that the new window size coords are converted back to the view from the old window size, such that when the Mousemoved event is passed into my UI elements, they get a messed up coord.
I hope I'm explaining this problem well.
Please help. Thanks.
#include <sstream>
#include <TGUI/TGUI.hpp>
#include "../rgm_system/system.h"
#include "../rgm_ui/ui.h"
#include "../rgm_ui/ui_window.h"
void menuDisplaySettingsResetElements(int y, int x, Sys::System& rS)
{
tgui::Window& window = *rS.win;
tgui::Label* label1 = window.addLabel();
label1->setText("Fullscreen Enabled");
label1->setTextSize(18);
label1->setTextColor(sf::Color::Black);
label1->setPosition(x, y+24*1);
tgui::Checkbox* checkbox1 = window.addCheckbox("display_settings_fullscreen_mode");
checkbox1->load("TGUI/objects/Checkbox/Black");
checkbox1->setText("");
checkbox1->setPosition(x+250-36, y+24*1);
checkbox1->setSize(24.0, 24.0);
tgui::Label* label2 = window.addLabel();
label2->setText("Scale to Fit");
label2->setTextSize(18);
label2->setTextColor(sf::Color::Black);
label2->setPosition(x, y+24*3);
tgui::Checkbox* checkbox2 = window.addCheckbox("display_settings_scale_to_fit");
checkbox2->load("TGUI/objects/Checkbox/Black");
checkbox2->setText("");
checkbox2->setPosition(x+250-36, y+24*3);
checkbox2->setSize(24.0, 24.0);
tgui::Label* label3 = window.addLabel();
label3->setText("Tile Smoothing");
label3->setTextSize(18);
label3->setTextColor(sf::Color::Black);
label3->setPosition(x, y+24*5);
tgui::Checkbox* checkbox3 = window.addCheckbox("display_settings_tile_smoothing");
checkbox3->load("TGUI/objects/Checkbox/Black");
checkbox3->setText("");
checkbox3->setPosition(x+250-36, y+24*5);
checkbox3->setSize(24.0, 24.0);
tgui::Label* label4 = window.addLabel();
label4->setText("Framerate Limit");
label4->setTextSize(18);
label4->setTextColor(sf::Color::Black);
label4->setPosition(x, y+24*7);
tgui::EditBox* editBox1 = window.addEditBox();
editBox1->load("TGUI/objects/EditBox/Black");
editBox1->setTextSize(18);
editBox1->setBorders(6, 4, 6, 4);
editBox1->setPosition(x+250-112, y+24*7);
editBox1->setText("60");
editBox1->setSize(100, 24);
tgui::Label* label5 = window.addLabel();
label5->setText("Fullscreen Mode");
label5->setTextSize(18);
label5->setTextColor(sf::Color::Black);
label5->setPosition(x+250, y+24*1);
tgui::Label* label6 = window.addLabel();
label6->setText("Window Height");
label6->setTextSize(18);
label6->setTextColor(sf::Color::Black);
label6->setPosition(x, y+24*9);
tgui::EditBox* editBox2 = window.addEditBox();
editBox2->load("TGUI/objects/EditBox/Black");
editBox2->setTextSize(18);
editBox2->setBorders(6, 4, 6, 4);
editBox2->setPosition(x+250-12-100, y+24*9);
editBox2->setText("600");
editBox2->setSize(100, 24);
tgui::Label* label7 = window.addLabel();
label7->setText("Window Width");
label7->setTextSize(18);
label7->setTextColor(sf::Color::Black);
label7->setPosition(x+250, y+24*9);
tgui::EditBox* editBox3 = window.addEditBox();
editBox3->load("TGUI/objects/EditBox/Black");
editBox3->setTextSize(18);
editBox3->setBorders(6, 4, 6, 4);
editBox3->setPosition(x+500-12-100, y+24*9);
editBox3->setText("1024");
editBox3->setSize(100, 24);
tgui::Listbox* listbox = window.addListbox();
listbox->load(125, 144, "TGUI/objects/Scrollbar/Black", 20);
listbox->setBorders(2, 2, 2, 2);
listbox->setPosition(x+500-12-125, y+24*1);
std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
for (auto it : modes)
{
if (it.bitsPerPixel == 32 && it.width >= 854 && it.height >= 480)
{
std::stringstream ss;
ss << it.width << " x " << it.height;
listbox->addItem(ss.str());
}
}
listbox->changeColors(rS.guiInst.barDDdivideColour,
sf::Color::White,
rS.guiInst.barHighlightColour,
sf::Color::White);
tgui::Button* button1 = window.addButton();
button1->load("TGUI/objects/Button/Black");
button1->setTextSize(18);
button1->setText("OK");
button1->setSize(100.0, 24.0);
button1->setPosition(x, y+24*12);
tgui::Button* button2 = window.addButton();
button2->load("TGUI/objects/Button/Black");
button2->setTextSize(18);
button2->setText("Cancel");
button2->setSize(100.0, 24.0);
button2->setPosition(x+106, y+24*12);
}
void Sys::menuDisplaySettings(System& rS)
{
sf::Event event;
Sys::SubWindow w(350, 500, rS);
w.setPositionAuto();
w.setTitle("Display Settings");
w.enableVertDiv();
menuDisplaySettingsResetElements(w.yBegin+30, w.xBegin+6, rS);
int windowHeight = 600;
int windowWidth = 1024;
int fsHeight = 600;
int fsWidth = 1024;
int fullscreen = 0;
int scaleToFit = 0;
int smoothTiles = 0;
int frameRateLimit = 60;
for ( ; ; )
{
int resize = 0;
int width = 0;
int height = 0;
while (rS.win->pollEvent(event))
{
rS.win->handleEvent(event);
if (event.type == sf::Event::Closed) return;
if (event.type == sf::Event::Resized)
{
resize = 1;
width = event.size.width;
height = event.size.height;
}
}
if (resize)
{
rS.win->removeAllObjects();
rS.win->create(sf::VideoMode(width, height, 32), "SFML Window");
rS.winPixelWidth = width;
rS.winPixelHeight = height;
w.setPositionAuto();
menuDisplaySettingsResetElements(w.yBegin+30, w.xBegin+6, rS);
}
rS.win->clear();
rS.displayTiles();
rS.displayUI();
w.displayWindow();
rS.win->drawGUI();
rS.win->display();
}
}