AmendHub

Download:

jcs

/

wikipedia

/

amendments

/

3

util: Sync with upstream


jcs made amendment 3 about 1 year ago
--- util.c Thu Aug 18 23:17:52 2022 +++ util.c Sun Aug 21 12:18:59 2022 @@ -419,23 +419,16 @@ void vwarn(short alert_func, const char *format, va_list ap) { Rect bounds; - short height, width, hit; + short hit; WindowPtr win, dialog; GetPort(&win); vsnprintf(err_str, ERROR_STRING_SIZE, format, ap); - width = 300; - height = 100; - bounds.left = (screenBits.bounds.right - width) / 2; - bounds.right = bounds.left + width; - bounds.top = GetMBarHeight() + - ((screenBits.bounds.bottom - height) / 2.5); - bounds.bottom = bounds.top + height; - ParamText(CtoPstr(err_str), "\p", "\p", "\p"); + center_in_screen(300, 100, false, &bounds); dialog = NewDialog(nil, &bounds, "\p", false, dBoxProc, (WindowPtr)-1L, false, 0, alert_ditl_h); @@ -538,7 +531,7 @@ short ask(const char *format, ...) { Rect bounds; - short height, width, hit; + short hit; WindowPtr win, dialog; va_list ap; @@ -548,14 +541,6 @@ ask(const char *format, ...) vsnprintf(err_str, ERROR_STRING_SIZE, format, ap); va_end(ap); - width = 300; - height = 100; - bounds.left = (screenBits.bounds.right - width) / 2; - bounds.right = bounds.left + width; - bounds.top = GetMBarHeight() + - ((screenBits.bounds.bottom - height) / 2.5); - bounds.bottom = bounds.top + height; - ParamText(CtoPstr(err_str), "\p", "\p", "\p"); ask_ditl_h = xNewHandle(sizeof(ask_ditl)); @@ -563,6 +548,7 @@ ask(const char *format, ...) memcpy(*ask_ditl_h, ask_ditl, sizeof(ask_ditl)); HUnlock(ask_ditl_h); + center_in_screen(300, 100, false, &bounds); dialog = NewDialog(nil, &bounds, "\p", false, dBoxProc, (WindowPtr)-1L, false, 0, ask_ditl_h); @@ -586,7 +572,7 @@ progress(char *format, ...) static Str255 progress_s; Handle thandle; va_list argptr; - Rect bounds = { 100, 90, 160, 420 }; /* tlbr */ + Rect bounds; Rect trect; short ttype; @@ -610,6 +596,7 @@ progress(char *format, ...) memcpy(*progress_ditl_h, progress_ditl, sizeof(progress_ditl)); HUnlock(progress_ditl_h); + center_in_screen(330, 60, false, &bounds); progress_dialog = NewDialog(nil, &bounds, "\p", false, dBoxProc, (WindowPtr)-1L, false, 0, progress_ditl_h); } @@ -629,6 +616,17 @@ window_rect(WindowPtr win, Rect *ret) ret->right -= 2; ret->top -= 1; ret->bottom -= 1; +} + +void +center_in_screen(short width, short height, bool titlebar, Rect *b) +{ + b->left = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - + (width / 2); + b->top = ((screenBits.bounds.bottom - screenBits.bounds.top) / 2) - + (height / 2) + (titlebar ? GetMBarHeight() : 0); + b->right = b->left + width; + b->bottom = b->top + height; } /* --- util.h Thu Aug 18 22:36:49 2022 +++ util.h Sun Aug 21 12:18:42 2022 @@ -119,6 +119,7 @@ short ask(const char *format, ...); #define ASK_NO 2 void progress(char *format, ...); void window_rect(WindowPtr win, Rect *ret); +void center_in_screen(short width, short height, bool titlebar, Rect *b); Handle xNewHandle(size_t size); Handle xGetResource(ResType type, short id);