Fix graphics flickering/stretching on Windows (#367)
* DRY, standardized window top offset * handle_splash_events() handle multiple events per frame * accurate windows menubar height for multiple rows * Windows filter a resize event triggered by the menubar * windows expand small window to fit menubar * splash screens draw in view rect, not window rect
This commit is contained in:
@@ -142,16 +142,9 @@ int main(int argc, char* argv[]) {
|
||||
sf::FloatRect compute_viewport(const sf::RenderWindow& mainPtr, float ui_scale) {
|
||||
|
||||
// See compute_viewport() in boe.graphics.cpp
|
||||
int const os_specific_y_offset =
|
||||
#if defined(SFML_SYSTEM_WINDOWS) || defined(SFML_SYSTEM_MAC)
|
||||
0;
|
||||
#else
|
||||
getMenubarHeight();
|
||||
#endif
|
||||
|
||||
sf::FloatRect viewport;
|
||||
|
||||
viewport.top = float(os_specific_y_offset) / mainPtr.getSize().y;
|
||||
viewport.top = float(os_specific_y_offset()) / mainPtr.getSize().y;
|
||||
viewport.left = 0;
|
||||
viewport.width = ui_scale;
|
||||
viewport.height = ui_scale;
|
||||
@@ -164,11 +157,7 @@ void adjust_window (sf::RenderWindow& mainPtr, sf::View& mainView) {
|
||||
double ui_scale = get_float_pref("UIScale", 1.0);
|
||||
|
||||
int const width = ui_scale * 590;
|
||||
int const height = ui_scale * 440
|
||||
#ifndef SFML_SYSTEM_WINDOWS
|
||||
+ getMenubarHeight()
|
||||
#endif
|
||||
;
|
||||
int const height = ui_scale * 440 + os_specific_y_offset();
|
||||
|
||||
mainPtr.create(sf::VideoMode(width, height), "Blades of Exile Character Editor", sf::Style::Titlebar | sf::Style::Close);
|
||||
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
|
||||
@@ -191,6 +180,7 @@ void adjust_window (sf::RenderWindow& mainPtr, sf::View& mainView) {
|
||||
#endif
|
||||
|
||||
init_menubar();
|
||||
adjust_window_for_menubar(5, width, height);
|
||||
}
|
||||
|
||||
void handle_events() {
|
||||
|
@@ -55,16 +55,10 @@ void init_menubar() {
|
||||
if(winHandle == NULL) return;
|
||||
if(menuHandle == NULL)
|
||||
menuHandle = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU1));
|
||||
SetMenu(winHandle, menuHandle);
|
||||
// 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<LONG_PTR>(&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);
|
||||
SetMenu(winHandle, menuHandle);
|
||||
|
||||
// And now initialize the mapping from Windows menu commands to eMenu constants
|
||||
static bool inited = false;
|
||||
@@ -130,6 +124,16 @@ void menu_activate() {
|
||||
|
||||
LRESULT CALLBACK menuProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
MSG msg = {handle, message, wParam, lParam};
|
||||
|
||||
// Adding the menubar to the window for the first time triggers an unwanted
|
||||
// resizing of the window, which we skip processing because it skews our
|
||||
// viewport:
|
||||
static bool menubarTriggeredResize = false;
|
||||
if(message == WM_SIZE && !menubarTriggeredResize) {
|
||||
menubarTriggeredResize = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(HIWORD(wParam) != 1 || message != WM_COMMAND) {
|
||||
if(TranslateAccelerator(handle, accel.handle, &msg))
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user