Remember window positions as preferences
This commit is contained in:
@@ -742,13 +742,9 @@ void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter&
|
|||||||
case sf::Event::GainedFocus:
|
case sf::Event::GainedFocus:
|
||||||
case sf::Event::MouseMoved:
|
case sf::Event::MouseMoved:
|
||||||
// Did the window move, potentially dirtying the canvas below it?
|
// Did the window move, potentially dirtying the canvas below it?
|
||||||
auto winPosition = win.getPosition();
|
if(check_window_moved(win, winLastX, winLastY))
|
||||||
if (winLastX != winPosition.x || winLastY != winPosition.y) {
|
|
||||||
if (redraw_everything != NULL)
|
if (redraw_everything != NULL)
|
||||||
redraw_everything();
|
redraw_everything();
|
||||||
}
|
|
||||||
winLastX = winPosition.x;
|
|
||||||
winLastY = winPosition.y;
|
|
||||||
|
|
||||||
bool inField = false;
|
bool inField = false;
|
||||||
for(auto& ctrl : controls) {
|
for(auto& ctrl : controls) {
|
||||||
|
@@ -184,7 +184,9 @@ void adjust_window_mode() {
|
|||||||
mainPtr().create(sf::VideoMode(width, winHeight, 32), "Blades of Exile", sf::Style::Titlebar | sf::Style::Close, winSettings);
|
mainPtr().create(sf::VideoMode(width, winHeight, 32), "Blades of Exile", sf::Style::Titlebar | sf::Style::Close, winSettings);
|
||||||
|
|
||||||
// Center the small window on the desktop
|
// Center the small window on the desktop
|
||||||
mainPtr().setPosition({static_cast<int>((desktop.width - width) / 2), static_cast<int>((desktop.height - height) / 2)});
|
int win_x = get_int_pref("MainWindowX", static_cast<int>((desktop.width - width) / 2));
|
||||||
|
int win_y = get_int_pref("MainWindowY", static_cast<int>((desktop.height - height) / 2));
|
||||||
|
mainPtr().setPosition({win_x, win_y});
|
||||||
} else {
|
} else {
|
||||||
mainPtr().create(desktop, "Blades of Exile", sf::Style::None, winSettings);
|
mainPtr().create(desktop, "Blades of Exile", sf::Style::None, winSettings);
|
||||||
mainPtr().setPosition({0,0});
|
mainPtr().setPosition({0,0});
|
||||||
|
@@ -681,7 +681,10 @@ void init_mini_map() {
|
|||||||
if (map_scale < 0.1) map_scale = 1.0;
|
if (map_scale < 0.1) map_scale = 1.0;
|
||||||
if (mini_map().isOpen()) mini_map().close();
|
if (mini_map().isOpen()) mini_map().close();
|
||||||
mini_map().create(sf::VideoMode(map_scale*296,map_scale*277), "Map", sf::Style::Titlebar | sf::Style::Close);
|
mini_map().create(sf::VideoMode(map_scale*296,map_scale*277), "Map", sf::Style::Titlebar | sf::Style::Close);
|
||||||
mini_map().setPosition(sf::Vector2i(52,62));
|
// TODO why is 52,62 the default position, anyway?
|
||||||
|
int map_x = get_int_pref("MapWindowX", 52);
|
||||||
|
int map_y = get_int_pref("MapWindowY", 62);
|
||||||
|
mini_map().setPosition(sf::Vector2i(map_x,map_y));
|
||||||
sf::View view;
|
sf::View view;
|
||||||
view.reset(sf::FloatRect(0, 0, map_scale*296,map_scale*277));
|
view.reset(sf::FloatRect(0, 0, map_scale*296,map_scale*277));
|
||||||
view.setViewport(sf::FloatRect(0, 0, map_scale, map_scale));
|
view.setViewport(sf::FloatRect(0, 0, map_scale, map_scale));
|
||||||
|
@@ -1299,6 +1299,9 @@ void handle_quit_event() {
|
|||||||
All_Done = true;
|
All_Done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int last_window_x = 0;
|
||||||
|
int last_window_y = 0;
|
||||||
|
|
||||||
void handle_one_event(const sf::Event& event, cFramerateLimiter& fps_limiter) {
|
void handle_one_event(const sf::Event& event, cFramerateLimiter& fps_limiter) {
|
||||||
|
|
||||||
// What does this do and should it be here?
|
// What does this do and should it be here?
|
||||||
@@ -1334,11 +1337,13 @@ void handle_one_event(const sf::Event& event, cFramerateLimiter& fps_limiter) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case sf::Event::GainedFocus:
|
case sf::Event::GainedFocus:
|
||||||
|
check_window_moved(mainPtr(), last_window_x, last_window_y, "MainWindow");
|
||||||
makeFrontWindow(mainPtr());
|
makeFrontWindow(mainPtr());
|
||||||
change_cursor({event.mouseMove.x, event.mouseMove.y});
|
change_cursor({event.mouseMove.x, event.mouseMove.y});
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case sf::Event::MouseMoved:
|
case sf::Event::MouseMoved:
|
||||||
|
check_window_moved(mainPtr(), last_window_x, last_window_y, "MainWindow");
|
||||||
change_cursor({event.mouseMove.x, event.mouseMove.y});
|
change_cursor({event.mouseMove.x, event.mouseMove.y});
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1360,11 +1365,17 @@ void queue_fake_event(const sf::Event& event) {
|
|||||||
fake_event_queue.push_back(event);
|
fake_event_queue.push_back(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int last_map_x = 0;
|
||||||
|
int last_map_y = 0;
|
||||||
|
|
||||||
void handle_one_minimap_event(const sf::Event& event) {
|
void handle_one_minimap_event(const sf::Event& event) {
|
||||||
if(event.type == sf::Event::Closed) {
|
if(event.type == sf::Event::Closed) {
|
||||||
close_map(true);
|
close_map(true);
|
||||||
} else if(event.type == sf::Event::GainedFocus) {
|
} else if(event.type == sf::Event::GainedFocus) {
|
||||||
|
check_window_moved(mini_map(), last_map_x, last_map_y, "MapWindow");
|
||||||
makeFrontWindow(mainPtr());
|
makeFrontWindow(mainPtr());
|
||||||
|
}else if(event.type == sf::Event::MouseMoved){
|
||||||
|
check_window_moved(mini_map(), last_map_x, last_map_y, "MapWindow");
|
||||||
}else if(event.type == sf::Event::KeyPressed) {
|
}else if(event.type == sf::Event::KeyPressed) {
|
||||||
switch(event.key.code){
|
switch(event.key.code){
|
||||||
case sf::Keyboard::Escape:
|
case sf::Keyboard::Escape:
|
||||||
|
@@ -69,3 +69,24 @@ void launchDocs(std::string relative_url) {
|
|||||||
launchURL("http://openboe.com/docs/" + relative_url);
|
launchURL("http://openboe.com/docs/" + relative_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_window_moved(sf::RenderWindow& win, int& winLastX, int& winLastY, std::string position_pref) {
|
||||||
|
auto winPosition = win.getPosition();
|
||||||
|
bool moved = false;
|
||||||
|
if(winLastX != winPosition.x || winLastY != winPosition.y){
|
||||||
|
// Save the positions of main window and map window as hidden preferences
|
||||||
|
// (clamped to keep them fully on-screen when they appear the first time)
|
||||||
|
if(!position_pref.empty()){
|
||||||
|
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
|
||||||
|
|
||||||
|
int pref_x = minmax(0, desktop.width - win.getSize().x, winPosition.x);
|
||||||
|
int pref_y = minmax(0, desktop.height - win.getSize().y, winPosition.y);
|
||||||
|
set_pref(position_pref + "X", pref_x);
|
||||||
|
set_pref(position_pref + "Y", pref_y);
|
||||||
|
}
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
|
winLastX = winPosition.x;
|
||||||
|
winLastY = winPosition.y;
|
||||||
|
return moved;
|
||||||
|
}
|
@@ -88,6 +88,8 @@ inline double get_ui_scale_map() {
|
|||||||
|
|
||||||
void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height);
|
void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height);
|
||||||
|
|
||||||
|
bool check_window_moved(sf::RenderWindow& win, int& winLastX, int& winLastY, std::string position_pref = "");
|
||||||
|
|
||||||
class ModalSession {
|
class ModalSession {
|
||||||
void* session;
|
void* session;
|
||||||
sf::Window* parent;
|
sf::Window* parent;
|
||||||
|
Reference in New Issue
Block a user