From 358053d189e3e16cd7e6ecb27cd91abdbd0db12c Mon Sep 17 00:00:00 2001 From: mcmartin Date: Thu, 30 Nov 2006 08:23:06 +0000 Subject: [PATCH] Generic DoPopupWindow() command git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2565 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/src/sc2code/confirm.c | 82 ++++++++++++++++++++++++++++++++++++++ sc2/src/sc2code/controls.h | 1 + 3 files changed, 84 insertions(+) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index c8a3b5abe..aa5716e74 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.6: +- Generic DoPopupWindow() command for status messages of all sorts - Update the 'current selection' icon after deleting or inserting ships in a fleet in SuperMelee - SvdB - Correct some background pixels in melebkgd.{25,26}.png - SvdB diff --git a/sc2/src/sc2code/confirm.c b/sc2/src/sc2code/confirm.c index 535d8042f..abdda7517 100644 --- a/sc2/src/sc2code/confirm.c +++ b/sc2/src/sc2code/confirm.c @@ -27,8 +27,11 @@ #include "libs/graphics/widgets.h" #include "libs/inplib.h" #include "libs/sound/trackplayer.h" +#include "libs/log.h" +#include "libs/resource/stringbank.h" #include +#include #define CONFIRM_WIN_WIDTH 80 @@ -188,4 +191,83 @@ DoConfirmExit (void) return (result); } +typedef struct popup_state +{ + // standard state required by DoInput + BOOLEAN (*InputFunc) (struct popup_state *self); + COUNT MenuRepeatDelay; +} POPUP_STATE; +static BOOLEAN +DoPopup (struct popup_state *self) +{ + (void)self; + SleepThread (ONE_SECOND / 20); + return !(PulsedInputState.menu[KEY_MENU_SELECT] || + PulsedInputState.menu[KEY_MENU_CANCEL]); +} + +void +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; + POPUP_STATE state; + MENU_SOUND_FLAGS s0, s1; + + + if (!bank) + { + log_add (log_Fatal, "FATAL: Memory exhaustion when preparing popup window"); + exit (EXIT_FAILURE); + } + + label.tag = WIDGET_TYPE_LABEL; + label.parent = NULL; + label.handleEvent = Widget_HandleEventIgnoreAll; + label.receiveFocus = Widget_ReceiveFocusRefuseFocus; + label.draw = Widget_DrawLabel; + label.height = Widget_HeightLabel; + label.width = Widget_WidthFullScreen; + label.line_count = SplitString (msg, '\n', 30, lines, bank); + label.lines = lines; + + LockMutex (GraphicsLock); + + oldContext = SetContext (ScreenContext); + GetContextClipRect (&oldRect); + SetContextClipRect (NULL_PTR); + + /* 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; + + DrawLabelAsWindow (&label); + + GetMenuSounds (&s0, &s1); + SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE); + + state.InputFunc = DoPopup; + DoInput (&state, TRUE); + + DrawStamp (&s); + DestroyDrawable (ReleaseDrawable (s.frame)); + FlushInput (); + SetContextClipRect (&oldRect); + SetContext (oldContext); + UnlockMutex (GraphicsLock); + SetMenuSounds (s0, s1); + StringBank_Free (bank); +} diff --git a/sc2/src/sc2code/controls.h b/sc2/src/sc2code/controls.h index b3aa05520..c0ec3807b 100644 --- a/sc2/src/sc2code/controls.h +++ b/sc2/src/sc2code/controls.h @@ -109,6 +109,7 @@ void TFB_Abort (void); BOOLEAN WaitAnyButtonOrQuit (BOOLEAN CheckSpecial); void WaitForNoInput (SIZE Duration); BOOLEAN ConfirmExit (void); +void DoPopupWindow(const char *msg); void DoInput (PVOID pInputState, BOOLEAN resetInput); BATTLE_INPUT_STATE p1_combat_summary (COUNT player, STARSHIPPTR StarShipPtr);