diff --git a/sc2/src/uqm/confirm.c b/sc2/src/uqm/confirm.c index 4820a2961..b6c30bf58 100644 --- a/sc2/src/uqm/confirm.c +++ b/sc2/src/uqm/confirm.c @@ -22,6 +22,7 @@ #include "setup.h" #include "sounds.h" #include "gamestr.h" +#include "util.h" #include "libs/graphics/widgets.h" #include "libs/sound/trackplayer.h" #include "libs/log.h" @@ -89,7 +90,7 @@ DoConfirmExit (void) { RECT r; STAMP s; - FRAME F; + RECT ctxRect; CONTEXT oldContext; RECT oldRect; BOOLEAN response = FALSE, done; @@ -98,13 +99,12 @@ DoConfirmExit (void) GetContextClipRect (&oldRect); SetContextClipRect (NULL); + GetContextClipRect (&ctxRect); r.extent.width = CONFIRM_WIN_WIDTH + 4; r.extent.height = CONFIRM_WIN_HEIGHT + 4; - r.corner.x = (SCREEN_WIDTH - r.extent.width) >> 1; - r.corner.y = (SCREEN_HEIGHT - r.extent.height) >> 1; - s.origin = r.corner; - F = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); - + r.corner.x = (ctxRect.extent.width - r.extent.width) >> 1; + r.corner.y = (ctxRect.extent.height - r.extent.height) >> 1; + s = SaveContextFrame (&r); SetSystemRect (&r); DrawConfirmationWindow (response); @@ -142,7 +142,7 @@ DoConfirmExit (void) SleepThread (ONE_SECOND / 30); } while (!done); - s.frame = F; + // Restore the screen under the confirmation window DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); ClearSystemRect (); @@ -192,9 +192,7 @@ DoPopupWindow (const char *msg) stringbank *bank = StringBank_Create (); const char *lines[30]; WIDGET_LABEL label; - RECT r; STAMP s; - FRAME F; CONTEXT oldContext; RECT oldRect; RECT windowRect; @@ -224,15 +222,9 @@ DoPopupWindow (const char *msg) GetContextClipRect (&oldRect); SetContextClipRect (NULL); - /* TODO: Better measure of dimensions than this */ - r.extent.width = SCREEN_WIDTH; - r.extent.height = SCREEN_HEIGHT; - r.corner.x = (SCREEN_WIDTH - r.extent.width) >> 1; - r.corner.y = (SCREEN_HEIGHT - r.extent.height) >> 1; - F = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); - - s.origin = r.corner; - s.frame = F; + // TODO: Maybe DrawLabelAsWindow() should return a saved STAMP? + // We do not know the dimensions here, and so save the whole context + s = SaveContextFrame (NULL); Widget_SetFont (StarConFont); Widget_SetWindowColors (SHADOWBOX_BACKGROUND_COLOR, SHADOWBOX_DARK_COLOR, diff --git a/sc2/src/uqm/gameopt.c b/sc2/src/uqm/gameopt.c index 266112084..3b4ff895b 100644 --- a/sc2/src/uqm/gameopt.c +++ b/sc2/src/uqm/gameopt.c @@ -78,12 +78,7 @@ ConfirmSaveLoad (STAMP *MsgStamp) r.extent.height += 8; if (MsgStamp) { - MsgStamp->origin = r.corner; - r.corner.x += clip_r.corner.x; - r.corner.y += clip_r.corner.y; - MsgStamp->frame = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); - r.corner.x -= clip_r.corner.x; - r.corner.y -= clip_r.corner.y; + *MsgStamp = SaveContextFrame (&r); } DrawStarConBox (&r, 2, BUILD_COLOR (MAKE_RGB15 (0x10, 0x10, 0x10), 0x19), diff --git a/sc2/src/uqm/save.c b/sc2/src/uqm/save.c index bd4faa5a8..7f2e0a2f2 100644 --- a/sc2/src/uqm/save.c +++ b/sc2/src/uqm/save.c @@ -536,6 +536,8 @@ SaveProblemMessage (STAMP *MsgStamp) TEXT t; UNICODE *ppStr[MAX_MSG_LINES]; + // TODO: This should probably just use DoPopupWindow() + ppStr[0] = GAME_STRING (SAVEGAME_STRING_BASE + 2); SetContextFont (StarConFont); @@ -566,17 +568,7 @@ SaveProblemMessage (STAMP *MsgStamp) r.extent.width += 8; r.extent.height += 8; - { - RECT clip_r; - - GetContextClipRect (&clip_r); - MsgStamp->origin = r.corner; - r.corner.x += clip_r.corner.x; - r.corner.y += clip_r.corner.y; - MsgStamp->frame = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); - r.corner.x -= clip_r.corner.x; - r.corner.y -= clip_r.corner.y; - } + *MsgStamp = SaveContextFrame (&r); BatchGraphics (); DrawStarConBox (&r, 2, @@ -613,9 +605,8 @@ SaveProblem (void) WaitForAnyButton (TRUE, WAIT_INFINITE, FALSE); LockMutex (GraphicsLock); - BatchGraphics (); + // Restore the screen under the message DrawStamp (&s); - UnbatchGraphics (); SetContext (OldContext); DestroyDrawable (ReleaseDrawable (s.frame)); UnlockMutex (GraphicsLock); diff --git a/sc2/src/uqm/util.c b/sc2/src/uqm/util.c index 0bbc87e67..b6d74d4e9 100644 --- a/sc2/src/uqm/util.c +++ b/sc2/src/uqm/util.c @@ -143,7 +143,8 @@ PauseGame (void) RECT r; STAMP s; CONTEXT OldContext; - FRAME F; + STAMP saveStamp; + RECT ctxRect; POINT oldOrigin; RECT OldRect; @@ -163,12 +164,15 @@ PauseGame (void) GetContextClipRect (&OldRect); SetContextClipRect (NULL); + GetContextClipRect (&ctxRect); GetFrameRect (ActivityFrame, &r); - r.corner.x = (SCREEN_WIDTH - r.extent.width) >> 1; - r.corner.y = (SCREEN_HEIGHT - r.extent.height) >> 1; + r.corner.x = (ctxRect.extent.width - r.extent.width) >> 1; + r.corner.y = (ctxRect.extent.height - r.extent.height) >> 1; + saveStamp = SaveContextFrame (&r); + + // TODO: This should draw a localizable text message instead s.origin = r.corner; s.frame = ActivityFrame; - F = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); SetSystemRect (&r); DrawStamp (&s); @@ -198,9 +202,8 @@ PauseGame (void) GamePaused = FALSE; - s.frame = F; - DrawStamp (&s); - DestroyDrawable (ReleaseDrawable (s.frame)); + DrawStamp (&saveStamp); + DestroyDrawable (ReleaseDrawable (saveStamp.frame)); ClearSystemRect (); SetContextClipRect (&OldRect);