From c53ca1a62a567fefa922d5729f14368f139f73a2 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 28 Sep 2020 02:53:02 +0200 Subject: [PATCH] Adjust resolution to monitor default on startup --- Source/control.cpp | 69 ++++++++------ Source/init.cpp | 2 +- Source/inv.cpp | 205 ++++++++++++++++++++++------------------ SourceS/ui_fwd.h | 7 +- SourceX/display.cpp | 136 +++++++++++++++++++++----- SourceX/display.h | 2 +- SourceX/storm/storm.cpp | 2 +- defs.h | 12 +-- 8 files changed, 275 insertions(+), 160 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 5dcfdd50d..64071a663 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -169,14 +169,14 @@ char SpellITbl[MAX_SPELLS] = { /** Maps from panel_button_id to the position and dimensions of a panel button. */ int PanBtnPos[8][5] = { // clang-format off - { PANEL_LEFT + 9, PANEL_TOP + 9, 71, 19, TRUE }, // char button - { PANEL_LEFT + 9, PANEL_TOP + 35, 71, 19, FALSE }, // quests button - { PANEL_LEFT + 9, PANEL_TOP + 75, 71, 19, TRUE }, // map button - { PANEL_LEFT + 9, PANEL_TOP + 101, 71, 19, FALSE }, // menu button - { PANEL_LEFT + 560, PANEL_TOP + 9, 71, 19, TRUE }, // inv button - { PANEL_LEFT + 560, PANEL_TOP + 35, 71, 19, FALSE }, // spells button - { PANEL_LEFT + 87, PANEL_TOP + 91, 33, 32, TRUE }, // chat button - { PANEL_LEFT + 527, PANEL_TOP + 91, 33, 32, TRUE }, // friendly fire button + { 9, 9, 71, 19, TRUE }, // char button + { 9, 35, 71, 19, FALSE }, // quests button + { 9, 75, 71, 19, TRUE }, // map button + { 9, 101, 71, 19, FALSE }, // menu button + { 560, 9, 71, 19, TRUE }, // inv button + { 560, 35, 71, 19, FALSE }, // spells button + { 87, 91, 33, 32, TRUE }, // chat button + { 527, 91, 33, 32, TRUE }, // friendly fire button // clang-format on }; /** Maps from panel_button_id to hotkey name. */ @@ -850,9 +850,9 @@ void DrawCtrlBtns() for (i = 0; i < 6; i++) { if (!panbtn[i]) - DrawPanelBox(PanBtnPos[i][0] - PANEL_LEFT, PanBtnPos[i][1] - (PANEL_TOP - 16), 71, 20, PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y); + DrawPanelBox(PanBtnPos[i][0], PanBtnPos[i][1] + 16, 71, 20, PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + PANEL_Y); else - CelDraw(PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y + 18, pPanelButtons, i + 1, 71); + CelDraw(PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + PANEL_Y + 18, pPanelButtons, i + 1, 71); } if (numpanbtns == 8) { CelDraw(87 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[6] + 1, 33); @@ -928,8 +928,8 @@ void DoPanBtn() int i; for (i = 0; i < numpanbtns; i++) { - if (MouseX >= PanBtnPos[i][0] && MouseX <= PanBtnPos[i][0] + PanBtnPos[i][2]) { - if (MouseY >= PanBtnPos[i][1] && MouseY <= PanBtnPos[i][1] + PanBtnPos[i][3]) { + if (MouseX >= PanBtnPos[i][0] + PANEL_LEFT && MouseX <= PanBtnPos[i][0] + PANEL_LEFT + PanBtnPos[i][2]) { + if (MouseY >= PanBtnPos[i][1] + PANEL_TOP && MouseY <= PanBtnPos[i][1] + PANEL_TOP + PanBtnPos[i][3]) { panbtn[i] = TRUE; drawbtnflag = TRUE; panbtndown = TRUE; @@ -951,16 +951,16 @@ void control_set_button_down(int btn_id) void control_check_btn_press() { - if (MouseX >= PanBtnPos[3][0] - && MouseX <= PanBtnPos[3][0] + PanBtnPos[3][2] - && MouseY >= PanBtnPos[3][1] - && MouseY <= PanBtnPos[3][1] + PanBtnPos[3][3]) { + if (MouseX >= PanBtnPos[3][0] + PANEL_LEFT + && MouseX <= PanBtnPos[3][0] + PANEL_LEFT + PanBtnPos[3][2] + && MouseY >= PanBtnPos[3][1] + PANEL_TOP + && MouseY <= PanBtnPos[3][1] + PANEL_TOP + PanBtnPos[3][3]) { control_set_button_down(3); } - if (MouseX >= PanBtnPos[6][0] - && MouseX <= PanBtnPos[6][0] + PanBtnPos[6][2] - && MouseY >= PanBtnPos[6][1] - && MouseY <= PanBtnPos[6][1] + PanBtnPos[6][3]) { + if (MouseX >= PanBtnPos[6][0] + PANEL_LEFT + && MouseX <= PanBtnPos[6][0] + PANEL_LEFT + PanBtnPos[6][2] + && MouseY >= PanBtnPos[6][1] + PANEL_TOP + && MouseY <= PanBtnPos[6][1] + PANEL_TOP + PanBtnPos[6][3]) { control_set_button_down(6); } } @@ -988,9 +988,9 @@ void CheckPanelInfo() panelflag = FALSE; ClearPanel(); for (i = 0; i < numpanbtns; i++) { - xend = PanBtnPos[i][0] + PanBtnPos[i][2]; - yend = PanBtnPos[i][1] + PanBtnPos[i][3]; - if (MouseX >= PanBtnPos[i][0] && MouseX <= xend && MouseY >= PanBtnPos[i][1] && MouseY <= yend) { + xend = PanBtnPos[i][0] + PANEL_LEFT + PanBtnPos[i][2]; + yend = PanBtnPos[i][1] + PANEL_TOP + PanBtnPos[i][3]; + if (MouseX >= PanBtnPos[i][0] + PANEL_LEFT && MouseX <= xend && MouseY >= PanBtnPos[i][1] + PANEL_TOP && MouseY <= yend) { if (i != 7) { strcpy(infostr, PanBtnStr[i]); } else { @@ -1094,10 +1094,10 @@ void CheckBtnUp() panbtn[i] = FALSE; - if (MouseX < PanBtnPos[i][0] - || MouseX > PanBtnPos[i][0] + PanBtnPos[i][2] - || MouseY < PanBtnPos[i][1] - || MouseY > PanBtnPos[i][1] + PanBtnPos[i][3]) { + if (MouseX < PanBtnPos[i][0] + PANEL_LEFT + || MouseX > PanBtnPos[i][0] + PANEL_LEFT + PanBtnPos[i][2] + || MouseY < PanBtnPos[i][1] + PANEL_TOP + || MouseY > PanBtnPos[i][1] + PANEL_TOP + PanBtnPos[i][3]) { continue; } @@ -1671,12 +1671,19 @@ void DrawDurIcon() PlayerStruct *p; int x; - if ((chrflag || questlog) && (invflag || sbookflag)) - return; + bool hasRoomBetweenPanels = SCREEN_WIDTH >= PANEL_WIDTH + 16 + (32 + 8 + 32 + 8 + 32 + 8 + 32) + 16; + bool hasRoomUnderPanels = SCREEN_HEIGHT >= SPANEL_HEIGHT + PANEL_HEIGHT + 16 + 32 + 16; + + if (!hasRoomBetweenPanels && !hasRoomUnderPanels) { + if ((chrflag || questlog) && (invflag || sbookflag)) + return; + } x = PANEL_X + PANEL_WIDTH - 32 - 16; - if (invflag || sbookflag) - x -= SPANEL_WIDTH; + if (!hasRoomUnderPanels) { + if (invflag || sbookflag) + x -= SPANEL_WIDTH - (SCREEN_WIDTH - PANEL_WIDTH) / 2; + } p = &plr[myplr]; x = DrawDurIcon4Item(&p->InvBody[INVLOC_HEAD], x, 4); diff --git a/Source/init.cpp b/Source/init.cpp index f84b00471..e9a488911 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -57,7 +57,7 @@ void init_cleanup() void init_create_window() { - if (!SpawnWindow(PROJECT_NAME, SCREEN_WIDTH, SCREEN_HEIGHT)) + if (!SpawnWindow(PROJECT_NAME)) app_fatal("Unable to create main window"); dx_init(NULL); was_window_init = true; diff --git a/Source/inv.cpp b/Source/inv.cpp index a2679dbea..3d51832d6 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -31,79 +31,79 @@ int sgdwLastTime; // check name const InvXY InvRect[] = { // clang-format off // X, Y - { RIGHT_PANEL + 132, 31 }, // helmet - { RIGHT_PANEL + 160, 31 }, // helmet - { RIGHT_PANEL + 132, 59 }, // helmet - { RIGHT_PANEL + 160, 59 }, // helmet - { RIGHT_PANEL + 45, 205 }, // left ring - { RIGHT_PANEL + 247, 205 }, // right ring - { RIGHT_PANEL + 204, 59 }, // amulet - { RIGHT_PANEL + 17, 104 }, // left hand - { RIGHT_PANEL + 46, 104 }, // left hand - { RIGHT_PANEL + 17, 132 }, // left hand - { RIGHT_PANEL + 46, 132 }, // left hand - { RIGHT_PANEL + 17, 160 }, // left hand - { RIGHT_PANEL + 46, 160 }, // left hand - { RIGHT_PANEL + 247, 104 }, // right hand - { RIGHT_PANEL + 276, 104 }, // right hand - { RIGHT_PANEL + 247, 132 }, // right hand - { RIGHT_PANEL + 276, 132 }, // right hand - { RIGHT_PANEL + 247, 160 }, // right hand - { RIGHT_PANEL + 276, 160 }, // right hand - { RIGHT_PANEL + 132, 104 }, // chest - { RIGHT_PANEL + 160, 104 }, // chest - { RIGHT_PANEL + 132, 132 }, // chest - { RIGHT_PANEL + 160, 132 }, // chest - { RIGHT_PANEL + 132, 160 }, // chest - { RIGHT_PANEL + 160, 160 }, // chest - { RIGHT_PANEL + 17, 250 }, // inv row 1 - { RIGHT_PANEL + 46, 250 }, // inv row 1 - { RIGHT_PANEL + 75, 250 }, // inv row 1 - { RIGHT_PANEL + 104, 250 }, // inv row 1 - { RIGHT_PANEL + 133, 250 }, // inv row 1 - { RIGHT_PANEL + 162, 250 }, // inv row 1 - { RIGHT_PANEL + 191, 250 }, // inv row 1 - { RIGHT_PANEL + 220, 250 }, // inv row 1 - { RIGHT_PANEL + 249, 250 }, // inv row 1 - { RIGHT_PANEL + 278, 250 }, // inv row 1 - { RIGHT_PANEL + 17, 279 }, // inv row 2 - { RIGHT_PANEL + 46, 279 }, // inv row 2 - { RIGHT_PANEL + 75, 279 }, // inv row 2 - { RIGHT_PANEL + 104, 279 }, // inv row 2 - { RIGHT_PANEL + 133, 279 }, // inv row 2 - { RIGHT_PANEL + 162, 279 }, // inv row 2 - { RIGHT_PANEL + 191, 279 }, // inv row 2 - { RIGHT_PANEL + 220, 279 }, // inv row 2 - { RIGHT_PANEL + 249, 279 }, // inv row 2 - { RIGHT_PANEL + 278, 279 }, // inv row 2 - { RIGHT_PANEL + 17, 308 }, // inv row 3 - { RIGHT_PANEL + 46, 308 }, // inv row 3 - { RIGHT_PANEL + 75, 308 }, // inv row 3 - { RIGHT_PANEL + 104, 308 }, // inv row 3 - { RIGHT_PANEL + 133, 308 }, // inv row 3 - { RIGHT_PANEL + 162, 308 }, // inv row 3 - { RIGHT_PANEL + 191, 308 }, // inv row 3 - { RIGHT_PANEL + 220, 308 }, // inv row 3 - { RIGHT_PANEL + 249, 308 }, // inv row 3 - { RIGHT_PANEL + 278, 308 }, // inv row 3 - { RIGHT_PANEL + 17, 337 }, // inv row 4 - { RIGHT_PANEL + 46, 337 }, // inv row 4 - { RIGHT_PANEL + 75, 337 }, // inv row 4 - { RIGHT_PANEL + 104, 337 }, // inv row 4 - { RIGHT_PANEL + 133, 337 }, // inv row 4 - { RIGHT_PANEL + 162, 337 }, // inv row 4 - { RIGHT_PANEL + 191, 337 }, // inv row 4 - { RIGHT_PANEL + 220, 337 }, // inv row 4 - { RIGHT_PANEL + 249, 337 }, // inv row 4 - { RIGHT_PANEL + 278, 337 }, // inv row 4 - { PANEL_LEFT + 205, PANEL_TOP + 33 }, // belt - { PANEL_LEFT + 234, PANEL_TOP + 33 }, // belt - { PANEL_LEFT + 263, PANEL_TOP + 33 }, // belt - { PANEL_LEFT + 292, PANEL_TOP + 33 }, // belt - { PANEL_LEFT + 321, PANEL_TOP + 33 }, // belt - { PANEL_LEFT + 350, PANEL_TOP + 33 }, // belt - { PANEL_LEFT + 379, PANEL_TOP + 33 }, // belt - { PANEL_LEFT + 408, PANEL_TOP + 33 } // belt + { 132, 31 }, // helmet + { 160, 31 }, // helmet + { 132, 59 }, // helmet + { 160, 59 }, // helmet + { 45, 205 }, // left ring + { 247, 205 }, // right ring + { 204, 59 }, // amulet + { 17, 104 }, // left hand + { 46, 104 }, // left hand + { 17, 132 }, // left hand + { 46, 132 }, // left hand + { 17, 160 }, // left hand + { 46, 160 }, // left hand + { 247, 104 }, // right hand + { 276, 104 }, // right hand + { 247, 132 }, // right hand + { 276, 132 }, // right hand + { 247, 160 }, // right hand + { 276, 160 }, // right hand + { 132, 104 }, // chest + { 160, 104 }, // chest + { 132, 132 }, // chest + { 160, 132 }, // chest + { 132, 160 }, // chest + { 160, 160 }, // chest + { 17, 250 }, // inv row 1 + { 46, 250 }, // inv row 1 + { 75, 250 }, // inv row 1 + { 104, 250 }, // inv row 1 + { 133, 250 }, // inv row 1 + { 162, 250 }, // inv row 1 + { 191, 250 }, // inv row 1 + { 220, 250 }, // inv row 1 + { 249, 250 }, // inv row 1 + { 278, 250 }, // inv row 1 + { 17, 279 }, // inv row 2 + { 46, 279 }, // inv row 2 + { 75, 279 }, // inv row 2 + { 104, 279 }, // inv row 2 + { 133, 279 }, // inv row 2 + { 162, 279 }, // inv row 2 + { 191, 279 }, // inv row 2 + { 220, 279 }, // inv row 2 + { 249, 279 }, // inv row 2 + { 278, 279 }, // inv row 2 + { 17, 308 }, // inv row 3 + { 46, 308 }, // inv row 3 + { 75, 308 }, // inv row 3 + { 104, 308 }, // inv row 3 + { 133, 308 }, // inv row 3 + { 162, 308 }, // inv row 3 + { 191, 308 }, // inv row 3 + { 220, 308 }, // inv row 3 + { 249, 308 }, // inv row 3 + { 278, 308 }, // inv row 3 + { 17, 337 }, // inv row 4 + { 46, 337 }, // inv row 4 + { 75, 337 }, // inv row 4 + { 104, 337 }, // inv row 4 + { 133, 337 }, // inv row 4 + { 162, 337 }, // inv row 4 + { 191, 337 }, // inv row 4 + { 220, 337 }, // inv row 4 + { 249, 337 }, // inv row 4 + { 278, 337 }, // inv row 4 + { 205, 33 }, // belt + { 234, 33 }, // belt + { 263, 33 }, // belt + { 292, 33 }, // belt + { 321, 33 }, // belt + { 350, 33 }, // belt + { 379, 33 }, // belt + { 408, 33 } // belt // clang-format on }; @@ -358,7 +358,7 @@ void DrawInv() invtest[i] = FALSE; if (plr[myplr].InvGrid[i] != 0) { InvDrawSlotBack( - InvRect[i + SLOTXY_INV_FIRST].X + SCREEN_X, + InvRect[i + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, InvRect[i + SLOTXY_INV_FIRST].Y + SCREEN_Y - 1, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); @@ -384,19 +384,19 @@ void DrawInv() } CelBlitOutline( color, - InvRect[j + SLOTXY_INV_FIRST].X + SCREEN_X, + InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, InvRect[j + SLOTXY_INV_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width); } if (plr[myplr].InvList[ii]._iStatFlag) { CelClippedDraw( - InvRect[j + SLOTXY_INV_FIRST].X + SCREEN_X, + InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, InvRect[j + SLOTXY_INV_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width); } else { CelDrawLightRed( - InvRect[j + SLOTXY_INV_FIRST].X + SCREEN_X, + InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, InvRect[j + SLOTXY_INV_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width, 1); } @@ -420,7 +420,7 @@ void DrawInvBelt() continue; } - InvDrawSlotBack(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, 28, 28); + InvDrawSlotBack(InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, 28, 28); frame = plr[myplr].SpdList[i]._iCurs + CURSOR_FIRSTITEM; frame_width = InvItemWidth[frame]; @@ -431,13 +431,13 @@ void DrawInvBelt() if (!plr[myplr].SpdList[i]._iStatFlag) color = ICOL_RED; if (!sgbControllerActive || invflag) - CelBlitOutline(color, InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width); + CelBlitOutline(color, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, pCursCels, frame, frame_width); } if (plr[myplr].SpdList[i]._iStatFlag) { - CelClippedDraw(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width); + CelClippedDraw(InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, pCursCels, frame, frame_width); } else { - CelDrawLightRed(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X, InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width, 1); + CelDrawLightRed(InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, pCursCels, frame, frame_width, 1); } if (AllItemsList[plr[myplr].SpdList[i].IDidx].iUsable @@ -445,7 +445,7 @@ void DrawInvBelt() && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) { fi = i + 49; ff = fontframe[gbFontTransTbl[fi]]; - PrintChar(InvRect[i + SLOTXY_BELT_FIRST].X + SCREEN_X + 28 - fontkern[ff], InvRect[i + SLOTXY_BELT_FIRST].Y + SCREEN_Y - 1, ff, 0); + PrintChar(InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X + 28 - fontkern[ff], InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, ff, 0); } } } @@ -689,8 +689,15 @@ void CheckInvPaste(int pnum, int mx, int my) sy = icursH28; done = FALSE; for (r = 0; (DWORD)r < NUM_XY_SLOTS && !done; r++) { - if (i >= InvRect[r].X && i < InvRect[r].X + INV_SLOT_SIZE_PX) { - if (j >= InvRect[r].Y - INV_SLOT_SIZE_PX - 1 && j < InvRect[r].Y) { + int xo = RIGHT_PANEL; + int yo = 0; + if (r >= SLOTXY_BELT_FIRST) { + xo = PANEL_LEFT; + yo = PANEL_TOP; + } + + if (i >= InvRect[r].X + xo && i < InvRect[r].X + xo + INV_SLOT_SIZE_PX) { + if (j >= InvRect[r].Y + yo - INV_SLOT_SIZE_PX - 1 && j < InvRect[r].Y + yo) { done = TRUE; r--; } @@ -1126,11 +1133,18 @@ void CheckInvCut(int pnum, int mx, int my) done = FALSE; for (r = 0; (DWORD)r < NUM_XY_SLOTS && !done; r++) { + int xo = RIGHT_PANEL; + int yo = 0; + if (r >= SLOTXY_BELT_FIRST) { + xo = PANEL_LEFT; + yo = PANEL_TOP; + } + // check which inventory rectangle the mouse is in, if any - if (mx >= InvRect[r].X - && mx < InvRect[r].X + (INV_SLOT_SIZE_PX + 1) - && my >= InvRect[r].Y - (INV_SLOT_SIZE_PX + 1) - && my < InvRect[r].Y) { + if (mx >= InvRect[r].X + xo + && mx < InvRect[r].X + xo + (INV_SLOT_SIZE_PX + 1) + && my >= InvRect[r].Y + yo - (INV_SLOT_SIZE_PX + 1) + && my < InvRect[r].Y + yo) { done = TRUE; r--; } @@ -1927,10 +1941,17 @@ char CheckInvHLight() char rv; for (r = 0; (DWORD)r < NUM_XY_SLOTS; r++) { - if (MouseX >= InvRect[r].X - && MouseX < InvRect[r].X + 29 - && MouseY >= InvRect[r].Y - 29 - && MouseY < InvRect[r].Y) { + int xo = RIGHT_PANEL; + int yo = 0; + if (r >= SLOTXY_BELT_FIRST) { + xo = PANEL_LEFT; + yo = PANEL_TOP; + } + + if (MouseX >= InvRect[r].X + xo + && MouseX < InvRect[r].X + xo + 29 + && MouseY >= InvRect[r].Y + yo - 29 + && MouseY < InvRect[r].Y + yo) { break; } } diff --git a/SourceS/ui_fwd.h b/SourceS/ui_fwd.h index 006d63c32..4bea142ed 100644 --- a/SourceS/ui_fwd.h +++ b/SourceS/ui_fwd.h @@ -2,7 +2,12 @@ namespace dvl { -bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight); +extern int screenWidth; +extern int screenHeight; +extern int viewportHeight; +extern int borderRight; + +bool SpawnWindow(const char *lpWindowName); void UiErrorOkDialog(const char *text, const char *caption, bool error = true); } // namespace dvl diff --git a/SourceX/display.cpp b/SourceX/display.cpp index 5083a3032..97cd29017 100644 --- a/SourceX/display.cpp +++ b/SourceX/display.cpp @@ -9,20 +9,30 @@ #ifndef SDL1_VIDEO_MODE_FLAGS #define SDL1_VIDEO_MODE_FLAGS SDL_SWSURFACE #endif -#ifndef SDL1_VIDEO_MODE_WIDTH -#define SDL1_VIDEO_MODE_WIDTH SCREEN_WIDTH +#ifdef SDL1_VIDEO_MODE_WIDTH +#define DEFAULT_WIDTH SDL1_VIDEO_MODE_WIDTH #endif -#ifndef SDL1_VIDEO_MODE_HEIGHT -#define SDL1_VIDEO_MODE_HEIGHT SCREEN_HEIGHT +#ifdef SDL1_VIDEO_MODE_HEIGHT +#define DEFAULT_HEIGHT SDL1_VIDEO_MODE_HEIGHT #endif #endif -namespace dvl { +#ifndef DEFAULT_WIDTH +#define DEFAULT_WIDTH 640 +#endif +#ifndef DEFAULT_HEIGHT +#define DEFAULT_HEIGHT 480 +#endif -extern BOOL was_window_init; /** defined in dx.cpp */ +namespace dvl { extern SDL_Surface *renderer_texture_surface; /** defined in dx.cpp */ +int screenWidth; +int screenHeight; +int viewportHeight; +int borderRight; + #ifdef USE_SDL1 void SetVideoMode(int width, int height, int bpp, uint32_t flags) { SDL_Log("Setting video mode %dx%d bpp=%u flags=0x%08X", width, height, bpp, flags); @@ -33,11 +43,11 @@ void SetVideoMode(int width, int height, int bpp, uint32_t flags) { ghMainWnd = SDL_GetVideoSurface(); } -void SetVideoModeToPrimary(bool fullscreen) { +void SetVideoModeToPrimary(bool fullscreen, int width, int height) { int flags = SDL1_VIDEO_MODE_FLAGS | SDL_HWPALETTE; if (fullscreen) flags |= SDL_FULLSCREEN; - SetVideoMode(SDL1_VIDEO_MODE_WIDTH, SDL1_VIDEO_MODE_HEIGHT, SDL1_VIDEO_MODE_BPP, flags); + SetVideoMode(width, height, SDL1_VIDEO_MODE_BPP, flags); if (OutputRequiresScaling()) SDL_Log("Using software scaling"); } @@ -47,7 +57,62 @@ bool IsFullScreen() { } #endif -bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight) +void AdjustToScreenGeometry(int width, int height) +{ + screenWidth = width; + screenHeight = height; + + borderRight = 64; + if (screenWidth % 4) { + // The buffer needs to be devisable by 4 for the engine to blit correctly + borderRight += 4 - screenWidth % 4; + } + + viewportHeight = screenHeight; + if (screenWidth <= PANEL_WIDTH) { + // Part of the screen is fully obscured by the UI + viewportHeight -= PANEL_HEIGHT; + } +} + +void CalculatePreferdWindowSize(int &width, int &height, bool useIntegerScaling) +{ +#ifdef USE_SDL1 + const SDL_VideoInfo &best = *SDL_GetVideoInfo(); + SDL_Log("Best video mode reported as: %dx%d bpp=%d hw_available=%u", + best.current_w, best.current_h, best.vfmt->BitsPerPixel, best.hw_available); +#else + SDL_DisplayMode mode; + if (SDL_GetDesktopDisplayMode(0, &mode) != 0) { + ErrSdl(); + } + + if (!useIntegerScaling) { + float wFactor = (float)mode.w / width; + float hFactor = (float)mode.h / height; + + if (wFactor > hFactor) { + width = mode.w * height / mode.h; + } else { + height = mode.h * width / mode.w; + } + return; + } + + int wFactor = mode.w / width; + int hFactor = mode.h / height; + + if (wFactor > hFactor) { + width = mode.w / hFactor; + height = mode.h / hFactor; + } else { + width = mode.w / wFactor; + height = mode.h / wFactor; + } +#endif +} + +bool SpawnWindow(const char *lpWindowName) { if (SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_HAPTIC) <= -1) { ErrSdl(); @@ -60,20 +125,36 @@ bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight) InitController(); #endif - int upscale = 1; - DvlIntSetting("upscale", &upscale); + int width = DEFAULT_WIDTH; + DvlIntSetting("width", &width); + int height = DEFAULT_HEIGHT; + DvlIntSetting("height", &height); + BOOL integerScalingEnabled = false; + DvlIntSetting("integer scaling", &integerScalingEnabled); + if (fullscreen) - DvlIntSetting("fullscreen", (int *)&fullscreen); + DvlIntSetting("fullscreen", &fullscreen); - int grabInput = 1; + int grabInput = 0; DvlIntSetting("grab input", &grabInput); + BOOL upscale = true; + DvlIntSetting("upscale", &upscale); + BOOL oar = false; + DvlIntSetting("original aspect ratio", &oar); + + if (upscale && !oar) { + CalculatePreferdWindowSize(width, height, integerScalingEnabled); + AdjustToScreenGeometry(width, height); + } + #ifdef USE_SDL1 + if (upscale) { + upscale = false; + SDL_Log("upscaling not supported with USE_SDL1"); + } SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME); - const SDL_VideoInfo &best = *SDL_GetVideoInfo(); - SDL_Log("Best video mode reported as: %dx%d bpp=%d hw_available=%u", - best.current_w, best.current_h, best.vfmt->BitsPerPixel, best.hw_available); - SetVideoModeToPrimary(fullscreen); + SetVideoModeToPrimary(fullscreen, width, height); if (grabInput) SDL_WM_GrabInput(SDL_GRAB_ON); atexit(SDL_VideoQuit); // Without this video mode is not restored after fullscreen. @@ -96,7 +177,7 @@ bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight) flags |= SDL_WINDOW_INPUT_GRABBED; } - ghMainWnd = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, nWidth, nHeight, flags); + ghMainWnd = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); #endif if (ghMainWnd == NULL) { ErrSdl(); @@ -113,9 +194,7 @@ bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight) refreshDelay = 1000000 / refreshRate; if (upscale) { -#ifdef USE_SDL1 - SDL_Log("upscaling not supported with USE_SDL1"); -#else +#ifndef USE_SDL1 Uint32 rendererFlags = SDL_RENDERER_ACCELERATED; vsyncEnabled = 1; @@ -129,21 +208,28 @@ bool SpawnWindow(const char *lpWindowName, int nWidth, int nHeight) ErrSdl(); } - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, nWidth, nHeight); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height); if (texture == NULL) { ErrSdl(); } - int integerScalingEnabled = 0; - DvlIntSetting("integer scaling", &integerScalingEnabled); if (integerScalingEnabled && SDL_RenderSetIntegerScale(renderer, SDL_TRUE) < 0) { ErrSdl(); } - if (SDL_RenderSetLogicalSize(renderer, nWidth, nHeight) <= -1) { + if (SDL_RenderSetLogicalSize(renderer, width, height) <= -1) { ErrSdl(); } #endif + } else { +#ifdef USE_SDL1 + const SDL_VideoInfo ¤t = *SDL_GetVideoInfo(); + width = current.current_w; + height = current.current_h; +#else + SDL_GetWindowSize(ghMainWnd, &width, &height); +#endif + AdjustToScreenGeometry(width, height); } return ghMainWnd != NULL; diff --git a/SourceX/display.h b/SourceX/display.h index b5ca3fa9f..345e8309f 100644 --- a/SourceX/display.h +++ b/SourceX/display.h @@ -21,7 +21,7 @@ extern unsigned int pal_surface_palette_version; #ifdef USE_SDL1 void SetVideoMode(int width, int height, int bpp, uint32_t flags); bool IsFullScreen(); -void SetVideoModeToPrimary(bool fullscreen = IsFullScreen()); +void SetVideoModeToPrimary(bool fullscreen, int width, int height); #endif // Returns: diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index c22cd9f10..50489b126 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -822,7 +822,7 @@ void SVidPlayEnd(HANDLE video) } } #else - if (IsSVidVideoMode) SetVideoModeToPrimary(); + if (IsSVidVideoMode) SetVideoModeToPrimary(IsFullScreen(), screenWidth, screenHeight); #endif } diff --git a/defs.h b/defs.h index b7de351ae..059de08e7 100644 --- a/defs.h +++ b/defs.h @@ -108,8 +108,8 @@ #define PAL16_RED 224 #define PAL16_GRAY 240 -#define SCREEN_WIDTH 640 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH dvl::screenWidth +#define SCREEN_HEIGHT dvl::screenHeight // If defined, use 32-bit colors instead of 8-bit [Default -> Undefined] //#define RGBMODE @@ -122,7 +122,7 @@ #define BORDER_LEFT 64 #define BORDER_TOP 160 -#define BORDER_RIGHT 64 +#define BORDER_RIGHT dvl::borderRight #define BORDER_BOTTOM 16 #define SCREEN_X BORDER_LEFT @@ -150,11 +150,7 @@ #define RIGHT_PANEL (SCREEN_WIDTH - SPANEL_WIDTH) #define RIGHT_PANEL_X (SCREEN_X + RIGHT_PANEL) -#if SCREEN_WIDTH <= PANEL_WIDTH -#define VIEWPORT_HEIGHT (SCREEN_HEIGHT - PANEL_HEIGHT) -#else -#define VIEWPORT_HEIGHT SCREEN_HEIGHT -#endif +#define VIEWPORT_HEIGHT dvl::viewportHeight #define DIALOG_TOP ((SCREEN_HEIGHT - PANEL_HEIGHT) / 2 - 18) #define DIALOG_Y (SCREEN_Y + DIALOG_TOP)