From daee11da8ab7a18b8e3af6aa99814d452b2c4350 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 4 Jan 2015 19:16:21 -0500 Subject: [PATCH] Fix graphics being squished slightly due to the Windows menubar being attached to the window --- src/boe.graphics.cpp | 12 +++++++----- src/boe.menus.win.cpp | 11 +++++++++++ src/classes/location.cpp | 8 +------- src/pcedit/pc.main.cpp | 3 ++- src/pcedit/pc.menus.win.cpp | 7 +++++++ src/scenedit/scen.graphics.cpp | 3 --- src/scenedit/scen.main.cpp | 3 ++- src/scenedit/scen.menus.win.cpp | 7 +++++++ 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/boe.graphics.cpp b/src/boe.graphics.cpp index 69584272..a9d3a1e3 100644 --- a/src/boe.graphics.cpp +++ b/src/boe.graphics.cpp @@ -27,6 +27,7 @@ #include "restypes.hpp" #include "boe.menus.h" +#include "winutil.h" extern sf::RenderWindow mainPtr; extern short stat_window; @@ -64,7 +65,6 @@ extern bool show_startup_splash; //*********************** rectangle menuBarRect; -short menuBarHeight; Region originalGrayRgn, newGrayRgn, underBarRgn; short terrain_there[9][9]; // this is an optimization variabel. Keeps track of what terrain @@ -164,17 +164,19 @@ location ok_space[4] = {loc(),loc(),loc(),loc()}; sf::Image hold_pict; void adjust_window_mode() { - rectangle r; + sf::FloatRect r; sf::ContextSettings winSettings; winSettings.stencilBits = 1; sf::VideoMode desktop = sf::VideoMode::getDesktopMode(); hideMenuBar(); + int menubarHeight = getMenubarHeight(); // TODO: Make display_mode an enum if(display_mode == 5) { ul.x = 14; ul.y = 2; - mainPtr.create(sf::VideoMode(605,430,32), "Blades of Exile", sf::Style::Titlebar | sf::Style::Close, winSettings); - mainPtr.setPosition({static_cast((desktop.width - 605) / 2), static_cast((desktop.height - 430) / 2)}); + int height = 430 + menubarHeight; + mainPtr.create(sf::VideoMode(605, height, 32), "Blades of Exile", sf::Style::Titlebar | sf::Style::Close, winSettings); + mainPtr.setPosition({static_cast((desktop.width - 605) / 2), static_cast((desktop.height - height) / 2)}); r = rectangle(mainPtr); } else { @@ -188,7 +190,7 @@ void adjust_window_mode() { case 3: ul.x = 10; ul.y = windRect.bottom - 422 - 6; break; case 4: ul.x = windRect.right - 570 - 6; ul.y = windRect.bottom - 422 - 6; break; } - + r = windRect; } redraw_screen(REFRESH_NONE); if(text_sbar != NULL) { diff --git a/src/boe.menus.win.cpp b/src/boe.menus.win.cpp index 7c6b9a40..390c4c32 100644 --- a/src/boe.menus.win.cpp +++ b/src/boe.menus.win.cpp @@ -7,10 +7,12 @@ #include "boe.infodlg.h" #include "boe.consts.h" #include "spell.hpp" +#include "winutil.h" // Include this last because some #defines in the Windows headers cause compile errors in my headers. // Fortunately they're on symbols not used in this file, so this should work. #include +#include // This is the index of each menu on the menubar enum { @@ -45,6 +47,13 @@ void init_menubar() { // Now we have to do a little hack to handle menu messages. // We replace SFML's window procedure with our own, which checks for menu events and then forwards to SFML's procedure. mainProc = SetWindowLongPtr(winHandle, GWLP_WNDPROC, reinterpret_cast(&menuProc)); + mainPtr.setActive(); + // Fix the window's viewport so that everything is drawn correctly + sf::Vector2u sz = mainPtr.getSize(); + double menubarHeight = getMenubarHeight(); + double usableHeight = sz.y - menubarHeight; + sf::View view(sf::FloatRect(0, 0, sz.x, usableHeight)); + mainPtr.setView(view); } void adjust_monst_menu() { @@ -192,11 +201,13 @@ void menu_activate() { } void hideMenuBar() { + if(menuHandle == NULL) return; SetMenu(mainPtr.getSystemHandle(), NULL); DrawMenuBar(mainPtr.getSystemHandle()); } void showMenuBar() { + if(menuHandle == NULL) return; SetMenu(mainPtr.getSystemHandle(), menuHandle); DrawMenuBar(mainPtr.getSystemHandle()); } diff --git a/src/classes/location.cpp b/src/classes/location.cpp index 179984c6..52878f76 100644 --- a/src/classes/location.cpp +++ b/src/classes/location.cpp @@ -73,13 +73,7 @@ rectangle::rectangle() : top(0), left(0), right(0), bottom(0) {} rectangle::rectangle(location tl, location br) : top(tl.y), left(tl.x), right(br.x), bottom(br.y) {} rectangle::rectangle(int t, int l, int b, int r) : top(t), left(l), right(r), bottom(b) {} rectangle::rectangle(sf::Texture& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {} -rectangle::rectangle(sf::RenderTarget& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) { - // This is a hack to work around the menubar in Windows affecting the rect returned by getSize(), despite the available area being unchanged. - extern sf::RenderWindow mainPtr; - extern int getMenubarHeight(); - if(&texture == &mainPtr) - bottom += getMenubarHeight(); -} +rectangle::rectangle(sf::RenderTarget& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {} bool rectangle::contains(location p){ if(p.y >= top && p.y <= bottom && p.x >= left && p.x <= right) diff --git a/src/pcedit/pc.main.cpp b/src/pcedit/pc.main.cpp index a8186b42..7fdfb862 100644 --- a/src/pcedit/pc.main.cpp +++ b/src/pcedit/pc.main.cpp @@ -152,7 +152,8 @@ void Initialize(void) { // The window is full screen size, made smaller to make it more visible. // // Size and style obtained from WIND resource #128 - mainPtr.create(sf::VideoMode(590, 440), "Blades of Exile Character Editor", sf::Style::Titlebar | sf::Style::Close); + int height = 440 + getMenubarHeight(); + mainPtr.create(sf::VideoMode(590, height), "Blades of Exile Character Editor", sf::Style::Titlebar | sf::Style::Close); init_menubar(); } diff --git a/src/pcedit/pc.menus.win.cpp b/src/pcedit/pc.menus.win.cpp index b8e88438..13cef85e 100644 --- a/src/pcedit/pc.menus.win.cpp +++ b/src/pcedit/pc.menus.win.cpp @@ -3,6 +3,7 @@ #include #include "Resource.h" #include "universe.h" +#include "winutil.h" // Include this last because some #defines in the Windows headers cause compile errors in my headers. // Fortunately they're on symbols not used in this file, so this should work. @@ -35,6 +36,12 @@ void init_menubar() { // Now we have to do a little hack to handle menu messages. // We replace SFML's window procedure with our own, which checks for menu events and then forwards to SFML's procedure. mainProc = SetWindowLongPtr(winHandle, GWLP_WNDPROC, reinterpret_cast(&menuProc)); + // Fix the window's viewport so that everything is drawn correctly + sf::Vector2u sz = mainPtr.getSize(); + double menubarHeight = getMenubarHeight(); + double usableHeight = sz.y - menubarHeight; + sf::View view(sf::FloatRect(0, 0, sz.x, usableHeight)); + mainPtr.setView(view); } void update_item_menu() { diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index 078fa655..1b41d0c4 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -432,11 +432,8 @@ void draw_main_screen() { } void draw_lb() { - rectangle temp_rect(mainPtr); short i; - temp_rect.right = RIGHT_AREA_UL_X - 2; - tileImage(mainPtr,temp_rect,bg[20]); for(i = 0; i < NLS; i++) draw_lb_slot(i,0); } diff --git a/src/scenedit/scen.main.cpp b/src/scenedit/scen.main.cpp index 2335cc32..4c0a1ea6 100644 --- a/src/scenedit/scen.main.cpp +++ b/src/scenedit/scen.main.cpp @@ -165,8 +165,9 @@ void Initialize(void) { rectangle windRect; windRect.width() = mode.width; windRect.height() = mode.height; + int height = 420 + getMenubarHeight(); - windRect.inset((windRect.right - 584) / 2,(windRect.bottom - 420) / 2); + windRect.inset((windRect.right - 584) / 2,(windRect.bottom - height) / 2); windRect.offset(0,18); // TODO: I think it should have a close button as well mainPtr.create(sf::VideoMode(windRect.width(), windRect.height()), "Blades of Exile Scenario Editor", sf::Style::Titlebar); diff --git a/src/scenedit/scen.menus.win.cpp b/src/scenedit/scen.menus.win.cpp index 2e7a378c..39d7dfb0 100644 --- a/src/scenedit/scen.menus.win.cpp +++ b/src/scenedit/scen.menus.win.cpp @@ -3,6 +3,7 @@ #include #include "Resource.h" #include "scenario.h" +#include "winutil.h" // Include this last because some #defines in the Windows headers cause compile errors in my headers. // Fortunately they're on symbols not used in this file, so this should work. @@ -36,6 +37,12 @@ void init_menubar() { // Now we have to do a little hack to handle menu messages. // We replace SFML's window procedure with our own, which checks for menu events and then forwards to SFML's procedure. mainProc = SetWindowLongPtr(winHandle, GWLP_WNDPROC, reinterpret_cast(&menuProc)); + // Fix the window's viewport so that everything is drawn correctly + sf::Vector2u sz = mainPtr.getSize(); + double menubarHeight = getMenubarHeight(); + double usableHeight = sz.y - menubarHeight; + sf::View view(sf::FloatRect(0, 0, sz.x, usableHeight)); + mainPtr.setView(view); } void update_item_menu() {