From a77c75a0971e35bd109b66c87e4d9e54e6be8a11 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 21 Mar 2019 10:04:58 +0100 Subject: [PATCH] Make graphics modes configurable (#44) * Make graphics modes configurable [devilutionx] scale quality=2 fullscreen=1 grab input=1 * Update dx.cpp --- SourceX/DiabloUI/diabloui.cpp | 20 ++++++++++++++++++++ SourceX/DiabloUI/diabloui.h | 3 +++ SourceX/dx.cpp | 5 ++++- SourceX/miniwin/misc.cpp | 11 ++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/SourceX/DiabloUI/diabloui.cpp b/SourceX/DiabloUI/diabloui.cpp index e54ee524e..66ec17bba 100644 --- a/SourceX/DiabloUI/diabloui.cpp +++ b/SourceX/DiabloUI/diabloui.cpp @@ -819,4 +819,24 @@ void DrawMouse() DrawArt(MouseX, MouseY, &ArtCursor); } +/** + * @brief Get int from ini, if not found the provided value will be added to the ini instead + */ +void DvlIntSetting(const char *valuename, int *value) +{ + if (!SRegLoadValue("devilutionx", valuename, 0, value)) { + SRegSaveValue("devilutionx", valuename, 0, *value); + } +} + +/** + * @brief Get string from ini, if not found the provided value will be added to the ini instead + */ +void DvlStringSetting(const char *valuename, char *string, int len) +{ + if (!SRegLoadString("devilutionx", valuename, 0, string, len)) { + SRegSaveString("devilutionx", valuename, 0, string); + } +} + } diff --git a/SourceX/DiabloUI/diabloui.h b/SourceX/DiabloUI/diabloui.h index 91451f2a3..70a37eb7b 100644 --- a/SourceX/DiabloUI/diabloui.h +++ b/SourceX/DiabloUI/diabloui.h @@ -118,4 +118,7 @@ void UiRender(); void UiRenderItems(UI_Item *items, int size); void WordWrap(UI_Item *item); +void DvlIntSetting(const char *valuename, int *value); +void DvlStringSetting(const char *valuename, char *string, int len); + } diff --git a/SourceX/dx.cpp b/SourceX/dx.cpp index 0b93c0617..926d2b017 100644 --- a/SourceX/dx.cpp +++ b/SourceX/dx.cpp @@ -358,7 +358,10 @@ void dx_init(HWND hWnd) return; } - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); + char scaleQuality[2] = "2"; + DvlStringSetting("scaling quality", scaleQuality, 2); + + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaleQuality); if (SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT) != 0) { SDL_Log("SDL_RenderSetLogicalSize: %s\n", SDL_GetError()); return; diff --git a/SourceX/miniwin/misc.cpp b/SourceX/miniwin/misc.cpp index af091179f..925388cc2 100644 --- a/SourceX/miniwin/misc.cpp +++ b/SourceX/miniwin/misc.cpp @@ -282,10 +282,15 @@ HWND CreateWindowExA( } atexit(SDL_Quit); - int flags = SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_INPUT_GRABBED; - if (!fullscreen) { - flags = SDL_WINDOW_RESIZABLE; + DvlIntSetting("fullscreen", &fullscreen); + int flags = fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; + + int grabInput = 1; + DvlIntSetting("grab input", &grabInput); + if (grabInput) { + flags |= SDL_WINDOW_INPUT_GRABBED; } + window = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, nWidth, nHeight, flags); atexit(FakeWMDestroy);