1 /* NetHack 3.6 mhsplash.c $NHDT-Date: 1449751714 2015/12/10 12:48:34 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.27 $ */
2 /* Copyright (C) 2001 by Alex Kompel */
3 /* NetHack may be freely redistributed. See license for details. */
12 #include "patchlevel.h"
17 PNHWinApp GetNHApp(void);
19 INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
21 #define SPLASH_WIDTH_96DPI 440
22 #define SPLASH_HEIGHT_96DPI 322
23 #define SPLASH_OFFSET_X_96DPI 10
24 #define SPLASH_OFFSET_Y_96DPI 10
25 #define SPLASH_VERSION_X_96DPI 280
26 #define SPLASH_VERSION_Y_96DPI 0
34 int ok_control_height;
35 int ok_control_offset_x;
36 int ok_control_offset_y;
37 int text_control_width;
38 int text_control_height;
39 int text_control_offset_x;
40 int text_control_offset_y;
53 mswin_set_splash_data(HWND hWnd, SplashData * sd, double scale)
58 RECT text_control_rect;
60 GetClientRect(hWnd, &client_rect);
61 GetWindowRect(hWnd, &window_rect);
62 GetWindowRect(GetDlgItem(hWnd, IDOK), &ok_control_rect);
63 GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &text_control_rect);
65 sd->boarder_width = (window_rect.right - window_rect.left) -
66 (client_rect.right - client_rect.left);
67 sd->boarder_height = (window_rect.bottom - window_rect.top) -
68 (client_rect.bottom - client_rect.top);
70 sd->ok_control_width = ok_control_rect.right - ok_control_rect.left;
71 sd->ok_control_height = ok_control_rect.bottom - ok_control_rect.top;
73 sd->width = (int)(scale * SPLASH_WIDTH_96DPI);
74 sd->height = (int)(scale * SPLASH_HEIGHT_96DPI);
75 sd->offset_x = (int)(scale * SPLASH_OFFSET_X_96DPI);
76 sd->offset_y = (int)(scale * SPLASH_OFFSET_Y_96DPI);
77 sd->version_x = (int)(scale * SPLASH_VERSION_X_96DPI);
78 sd->version_y = (int)(scale * SPLASH_VERSION_Y_96DPI);
80 sd->client_width = sd->width + sd->offset_x * 2;
81 sd->client_height = sd->height + sd->ok_control_height +
84 sd->window_width = sd->client_width + sd->boarder_width;
85 sd->window_height = sd->client_height + sd->boarder_height;
87 sd->ok_control_offset_x = (sd->client_width - sd->ok_control_width) / 2;
88 sd->ok_control_offset_y = sd->client_height - sd->ok_control_height - sd->offset_y;
90 sd->text_control_width = sd->client_width - sd->offset_x * 2;
91 sd->text_control_height = text_control_rect.bottom - text_control_rect.top;
93 sd->text_control_offset_x = sd->offset_x;
94 sd->text_control_offset_y = sd->ok_control_offset_y - sd->offset_y -
95 sd->text_control_height;
97 if (sd->hFont != NULL)
98 DeleteObject(sd->hFont);
100 sd->hFont = mswin_create_splashfont(hWnd);
102 MoveWindow(hWnd, window_rect.left, window_rect.top,
103 sd->window_width, sd->window_height, TRUE);
105 MoveWindow(GetDlgItem(hWnd, IDOK),
106 sd->ok_control_offset_x, sd->ok_control_offset_y,
107 sd->ok_control_width, sd->ok_control_height, TRUE);
109 MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO),
110 sd->text_control_offset_x, sd->text_control_offset_y,
111 sd->text_control_width, sd->text_control_height, TRUE);
116 mswin_display_splash_window(BOOL show_ver)
121 strbuf_init(&strbuf);
123 HWND hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
124 GetNHApp()->hMainWnd, NHSplashWndProc);
126 panic("Cannot create Splash window");
128 MonitorInfo monitorInfo;
129 win10_monitor_info(hWnd, &monitorInfo);
131 SplashData splashData;
132 memset(&splashData, 0, sizeof(splashData));
133 mswin_set_splash_data(hWnd, &splashData, monitorInfo.scale);
135 SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) &splashData);
137 GetNHApp()->hPopupWnd = hWnd;
139 int left = monitorInfo.left + (monitorInfo.width - splashData.window_width) / 2;
140 int top = monitorInfo.top + (monitorInfo.height - splashData.window_height) / 2;
141 MoveWindow(hWnd, left, top, splashData.window_width, splashData.window_height, TRUE);
143 /* Fill the text control */
144 strbuf_reserve(&strbuf, BUFSIZ);
145 Sprintf(strbuf.str, "%s\n%s\n%s\n%s\n\n", COPYRIGHT_BANNER_A,
146 COPYRIGHT_BANNER_B, COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D);
149 /* Show complete version information */
154 getversionstring(verbuf);
155 strbuf_append(&strbuf, verbuf);
156 strbuf_append(&strbuf, "\n\n");
158 /* Add compile options */
159 f = dlb_fopen(OPTIONS_USED, RDTMODE);
163 while (dlb_fgets(line, LLEN, f))
164 strbuf_append(&strbuf, line);
165 (void) dlb_fclose(f);
168 /* Show news, if any */
172 iflags.news = 0; /* prevent newgame() from re-displaying news */
173 nf = fopen(NEWS, "r");
177 while (fgets(line, LLEN, nf))
178 strbuf_append(&strbuf, line);
181 strbuf_append(&strbuf, "No news.");
186 strbuf_nl_to_crlf(&strbuf);
187 SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), strbuf.str);
188 strbuf_empty(&strbuf);
189 ShowWindow(hWnd, SW_SHOW);
191 while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
192 if (!IsDialogMessage(hWnd, &msg)) {
193 TranslateMessage(&msg);
194 DispatchMessage(&msg);
198 GetNHApp()->hPopupWnd = NULL;
199 DeleteObject(splashData.hFont);
203 NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
205 UNREFERENCED_PARAMETER(lParam);
208 case WM_INITDIALOG: {
209 HDC hdc = GetDC(hWnd);
210 cached_font * font = mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE);
211 /* set text control font */
212 SendMessage(hWnd, WM_SETFONT, (WPARAM)font->hFont, 0);
213 ReleaseDC(hWnd, hdc);
215 SetFocus(GetDlgItem(hWnd, IDOK));
219 char VersionString[BUFSZ];
226 SplashData *splashData = (SplashData *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
228 HDC hdc = BeginPaint(hWnd, &ps);
229 /* Show splash graphic */
231 hdcBitmap = CreateCompatibleDC(hdc);
232 SetBkMode(hdc, OPAQUE);
233 OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
234 (*GetNHApp()->lpfnTransparentBlt)(hdc,
235 splashData->offset_x, splashData->offset_y,
236 splashData->width, splashData->height, hdcBitmap,
237 0, 0, SPLASH_WIDTH_96DPI, SPLASH_HEIGHT_96DPI,
240 SelectObject(hdcBitmap, OldBitmap);
243 SetBkMode(hdc, TRANSPARENT);
244 /* Print version number */
246 SetTextColor(hdc, RGB(0, 0, 0));
247 rt.right = rt.left = splashData->offset_x + splashData->version_x;
248 rt.bottom = rt.top = splashData->offset_y + splashData->version_y;
249 Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
251 OldFont = SelectObject(hdc, splashData->hFont);
252 DrawText(hdc, VersionString, strlen(VersionString), &rt,
253 DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
254 DrawText(hdc, VersionString, strlen(VersionString), &rt,
255 DT_LEFT | DT_NOPREFIX);
260 switch (LOWORD(wParam)) {
262 mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
263 if (GetNHApp()->hMainWnd == hWnd)
264 GetNHApp()->hMainWnd = NULL;
266 SetFocus(GetNHApp()->hMainWnd);
271 case WM_DPICHANGED: {
272 SplashData *splashData = (SplashData *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
274 MonitorInfo monitorInfo;
275 win10_monitor_info(hWnd, &monitorInfo);
277 mswin_set_splash_data(hWnd, splashData, monitorInfo.scale);
279 InvalidateRect(hWnd, NULL, TRUE);