Skip to content

Commit

Permalink
Move window fix into a function. Fix #59
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Jun 24, 2024
1 parent 603970e commit efed1f6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
16 changes: 1 addition & 15 deletions src/game/boe.graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,7 @@ void adjust_window_mode() {
#endif

init_menubar();
#ifdef SFML_SYSTEM_WINDOWS
if (mode == 5) {
// On Windows, the menubar DOES take up space in the window,
// but this is not handled with os_specific_y_offset() because
// y = 0 still refers to the bottom of the menubar on Windows.

// getMenuBarHeight() has to be called AFTER init_menubar() for this,
// because different combinations of OS and BOE scaling options can
// result in a menubar with more than one row, which can only be measured
// after it is placed in the window
int winHeight = height;
winHeight += getMenubarHeight();
mainPtr.setSize({ (unsigned int)width, (unsigned int)winHeight });
}
#endif
adjust_window_for_menubar(mode, width, height);
showMenuBar();
}

Expand Down
7 changes: 1 addition & 6 deletions src/pcedit/pc.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,7 @@ void adjust_window (sf::RenderWindow& mainPtr, sf::View& mainView) {
#endif

init_menubar();
#ifdef SFML_SYSTEM_WINDOWS
// see adjust_window_mode() in boe.graphics.cpp for an explanation of this:
int winHeight = height;
winHeight += getMenubarHeight();
mainPtr.setSize({ (unsigned int)width, (unsigned int)winHeight });
#endif
adjust_window_for_menubar();
}

void handle_events() {
Expand Down
8 changes: 1 addition & 7 deletions src/scenedit/scen.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,7 @@ void adjust_windows (sf::RenderWindow & mainPtr, sf::View & mainView) {
mainPtr.setIcon(icon->getSize().x, icon->getSize().y, icon->copyToImage().getPixelsPtr());
#endif
init_menubar();

#ifdef SFML_SYSTEM_WINDOWS
// see adjust_window_mode() in boe.graphics.cpp for an explanation of this:
int winHeight = height;
winHeight += getMenubarHeight();
mainPtr.setSize({ (unsigned int)width, (unsigned int)winHeight });
#endif
adjust_window_for_menubar();
}

void process_args(int argc, char* argv[]) {
Expand Down
2 changes: 2 additions & 0 deletions src/tools/winutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ inline int os_specific_y_offset() {
#endif
}

void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height);

class ModalSession {
void* session;
sf::Window* parent;
Expand Down
3 changes: 3 additions & 0 deletions src/tools/winutil.linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,6 @@ int getMenubarHeight() {
// return MENUBAR_HEIGHT;
return 20;
}

void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height) {
}
3 changes: 3 additions & 0 deletions src/tools/winutil.mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ int getMenubarHeight() {
return 0;
}

void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height) {
}

NSOpenPanel* dlg_get_scen;
NSOpenPanel* dlg_get_game;
NSOpenPanel* dlg_get_rsrc;
Expand Down
19 changes: 19 additions & 0 deletions src/tools/winutil.win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,22 @@ int getMenubarHeight() {
return GetSystemMetrics(SM_CYMENU);
}
}

void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height) {
// On Windows, the menubar DOES take up space in the window,
// but this is not handled with os_specific_y_offset() because
// y = 0 still refers to the bottom of the menubar on Windows.

// getMenuBarHeight() has to be called again AFTER init_menubar() for this,
// because different combinations of OS and BOE scaling options can
// result in a menubar with more than one row, which can only be measured
// after it is placed in the window
if (mode != 5) {
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
width = desktop.width;
height = desktop.height;
}

height += getMenubarHeight();
mainPtr.setSize({ width, height });
}

0 comments on commit efed1f6

Please sign in to comment.