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. */
4
5 #include "win10.h"
6 #include "winMS.h"
7 #include "resource.h"
8 #include "mhsplash.h"
9 #include "mhmsg.h"
10 #include "mhfont.h"
11 #include "date.h"
12 #include "patchlevel.h"
13 #include "dlb.h"
14
15 #define LLEN 128
16
17 PNHWinApp GetNHApp(void);
18
19 INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
20
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
27
28 typedef struct {
29 int boarder_width;
30 int boarder_height;
31 int client_width;
32 int client_height;
33 int ok_control_width;
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;
41 int window_width;
42 int window_height;
43 int width;
44 int height;
45 int offset_x;
46 int offset_y;
47 int version_x;
48 int version_y;
49 HFONT hFont;
50 } SplashData;
51
52 static void
mswin_set_splash_data(HWND hWnd,SplashData * sd,double scale)53 mswin_set_splash_data(HWND hWnd, SplashData * sd, double scale)
54 {
55 RECT client_rect;
56 RECT window_rect;
57 RECT ok_control_rect;
58 RECT text_control_rect;
59
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);
64
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);
69
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;
72
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);
79
80 sd->client_width = sd->width + sd->offset_x * 2;
81 sd->client_height = sd->height + sd->ok_control_height +
82 sd->offset_y * 3;
83
84 sd->window_width = sd->client_width + sd->boarder_width;
85 sd->window_height = sd->client_height + sd->boarder_height;
86
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;
89
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;
92
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;
96
97 if (sd->hFont != NULL)
98 DeleteObject(sd->hFont);
99
100 sd->hFont = mswin_create_splashfont(hWnd);
101
102 MoveWindow(hWnd, window_rect.left, window_rect.top,
103 sd->window_width, sd->window_height, TRUE);
104
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);
108
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);
112
113 }
114
115 void
mswin_display_splash_window(BOOL show_ver)116 mswin_display_splash_window(BOOL show_ver)
117 {
118 MSG msg;
119 strbuf_t strbuf;
120
121 strbuf_init(&strbuf);
122
123 HWND hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
124 GetNHApp()->hMainWnd, NHSplashWndProc);
125 if (!hWnd)
126 panic("Cannot create Splash window");
127
128 MonitorInfo monitorInfo;
129 win10_monitor_info(hWnd, &monitorInfo);
130
131 SplashData splashData;
132 memset(&splashData, 0, sizeof(splashData));
133 mswin_set_splash_data(hWnd, &splashData, monitorInfo.scale);
134
135 SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) &splashData);
136
137 GetNHApp()->hPopupWnd = hWnd;
138
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);
142
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);
147
148 if (show_ver) {
149 /* Show complete version information */
150 dlb *f;
151 char verbuf[BUFSZ];
152 int verstrsize = 0;
153
154 getversionstring(verbuf);
155 strbuf_append(&strbuf, verbuf);
156 strbuf_append(&strbuf, "\n\n");
157
158 /* Add compile options */
159 f = dlb_fopen(OPTIONS_USED, RDTMODE);
160 if (f) {
161 char line[LLEN + 1];
162
163 while (dlb_fgets(line, LLEN, f))
164 strbuf_append(&strbuf, line);
165 (void) dlb_fclose(f);
166 }
167 } else {
168 /* Show news, if any */
169 if (iflags.news) {
170 FILE *nf;
171
172 iflags.news = 0; /* prevent newgame() from re-displaying news */
173 /* BUG: this relies on current working directory */
174 nf = fopen(NEWS, "r");
175 if (nf != NULL) {
176 char line[LLEN + 1];
177
178 while (fgets(line, LLEN, nf))
179 strbuf_append(&strbuf, line);
180 (void) fclose(nf);
181 } else {
182 strbuf_append(&strbuf, "No news.");
183 }
184 }
185 }
186
187 strbuf_nl_to_crlf(&strbuf);
188 SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), strbuf.str);
189 strbuf_empty(&strbuf);
190 ShowWindow(hWnd, SW_SHOW);
191
192 while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
193 if (!IsDialogMessage(hWnd, &msg)) {
194 TranslateMessage(&msg);
195 DispatchMessage(&msg);
196 }
197 }
198
199 GetNHApp()->hPopupWnd = NULL;
200 DeleteObject(splashData.hFont);
201 }
202
203 INT_PTR CALLBACK
NHSplashWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)204 NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
205 {
206 UNREFERENCED_PARAMETER(lParam);
207
208 switch (message) {
209 case WM_INITDIALOG: {
210 HDC hdc = GetDC(hWnd);
211 cached_font * font = mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE);
212 /* set text control font */
213 SendMessage(hWnd, WM_SETFONT, (WPARAM)font->hFont, 0);
214 ReleaseDC(hWnd, hdc);
215
216 SetFocus(GetDlgItem(hWnd, IDOK));
217 } break;
218
219 case WM_PAINT: {
220 char VersionString[BUFSZ];
221 RECT rt;
222 HDC hdcBitmap;
223 HANDLE OldBitmap;
224 HANDLE OldFont;
225 PAINTSTRUCT ps;
226
227 SplashData *splashData = (SplashData *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
228
229 HDC hdc = BeginPaint(hWnd, &ps);
230 /* Show splash graphic */
231
232 hdcBitmap = CreateCompatibleDC(hdc);
233 SetBkMode(hdc, OPAQUE);
234 OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
235 (*GetNHApp()->lpfnTransparentBlt)(hdc,
236 splashData->offset_x, splashData->offset_y,
237 splashData->width, splashData->height, hdcBitmap,
238 0, 0, SPLASH_WIDTH_96DPI, SPLASH_HEIGHT_96DPI,
239 TILE_BK_COLOR);
240
241 SelectObject(hdcBitmap, OldBitmap);
242 DeleteDC(hdcBitmap);
243
244 SetBkMode(hdc, TRANSPARENT);
245 /* Print version number */
246
247 SetTextColor(hdc, RGB(0, 0, 0));
248 rt.right = rt.left = splashData->offset_x + splashData->version_x;
249 rt.bottom = rt.top = splashData->offset_y + splashData->version_y;
250 Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
251 PATCHLEVEL);
252 OldFont = SelectObject(hdc, splashData->hFont);
253 DrawText(hdc, VersionString, strlen(VersionString), &rt,
254 DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
255 DrawText(hdc, VersionString, strlen(VersionString), &rt,
256 DT_LEFT | DT_NOPREFIX);
257 EndPaint(hWnd, &ps);
258 } break;
259
260 case WM_COMMAND:
261 switch (LOWORD(wParam)) {
262 case IDCANCEL:
263 case IDOK:
264 mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
265 if (GetNHApp()->hMainWnd == hWnd)
266 GetNHApp()->hMainWnd = NULL;
267 DestroyWindow(hWnd);
268 SetFocus(GetNHApp()->hMainWnd);
269 return TRUE;
270 }
271 break;
272
273 case WM_DPICHANGED: {
274 SplashData *splashData = (SplashData *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
275
276 MonitorInfo monitorInfo;
277 win10_monitor_info(hWnd, &monitorInfo);
278
279 mswin_set_splash_data(hWnd, splashData, monitorInfo.scale);
280
281 InvalidateRect(hWnd, NULL, TRUE);
282 } break;
283
284 }
285 return FALSE;
286 }
287