NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / win / win32 / mhsplash.c
blob38adbac3465c56eed04dd9fb13cb2748fe5f43e6
1 /* aNetHack 0.0.1 mhsplash.c $ANH-Date: 1449751714 2015/12/10 12:48:34 $ $ANH-Branch: aNetHack-3.6.0 $:$ANH-Revision: 1.27 $ */
2 /* Copyright (C) 2001 by Alex Kompel */
3 /* aNetHack may be freely redistributed. See license for details. */
5 #include "winMS.h"
6 #include "resource.h"
7 #include "mhsplash.h"
8 #include "mhmsg.h"
9 #include "mhfont.h"
10 #include "date.h"
11 #include "patchlevel.h"
12 #include "dlb.h"
14 #define LLEN 128
16 PNHWinApp GetNHApp(void);
18 INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
20 #define SPLASH_WIDTH 440
21 #define SPLASH_HEIGHT 322
22 #define SPLASH_VERSION_X 290
23 #define SPLASH_VERSION_Y 10
24 #define SPLASH_OFFSET_X 10
25 #define SPLASH_OFFSET_Y 10
27 extern HFONT version_splash_font;
29 void
30 mswin_display_splash_window(BOOL show_ver)
32 MSG msg;
33 int left, top;
34 RECT splashrt;
35 RECT clientrt;
36 RECT controlrt;
37 HWND hWnd;
38 int buttop;
39 int strsize = 0;
40 int bufsize = BUFSZ;
41 char *buf = malloc(bufsize);
43 if (buf == NULL)
44 panic("out of memory");
45 buf[0] = '\0';
47 hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
48 GetNHApp()->hMainWnd, NHSplashWndProc);
49 if (!hWnd)
50 panic("Cannot create Splash window");
51 mswin_init_splashfonts(hWnd);
52 GetNHApp()->hPopupWnd = hWnd;
53 /* Get control size */
54 GetWindowRect(GetDlgItem(hWnd, IDOK), &controlrt);
55 controlrt.right -= controlrt.left;
56 controlrt.bottom -= controlrt.top;
57 /* Get current client area */
58 GetClientRect(hWnd, &clientrt);
59 /* Get window size */
60 GetWindowRect(hWnd, &splashrt);
61 splashrt.right -= splashrt.left;
62 splashrt.bottom -= splashrt.top;
63 /* Get difference between requested client area and current value */
64 splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right;
65 splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3
66 - clientrt.bottom;
67 /* Place the window centered */
68 /* On the screen, not on the parent window */
69 left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2;
70 top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2;
71 MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
72 /* Place the OK control */
73 GetClientRect(hWnd, &clientrt);
74 MoveWindow(GetDlgItem(hWnd, IDOK),
75 (clientrt.right - clientrt.left - controlrt.right) / 2,
76 clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y,
77 controlrt.right, controlrt.bottom, TRUE);
78 buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y;
79 /* Place the text control */
80 GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
81 controlrt.right -= controlrt.left;
82 controlrt.bottom -= controlrt.top;
83 GetClientRect(hWnd, &clientrt);
84 MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO),
85 clientrt.left + SPLASH_OFFSET_X,
86 buttop - controlrt.bottom - SPLASH_OFFSET_Y,
87 clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
89 /* Fill the text control */
90 Sprintf(buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A,
91 COPYRIGHT_BANNER_B, COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D);
92 strsize = strlen(buf);
94 if (show_ver) {
95 /* Show complete version information */
96 dlb *f;
97 char verbuf[BUFSZ];
98 int verstrsize = 0;
100 getversionstring(verbuf);
101 verstrsize = strlen(verbuf);
102 if (verstrsize + strlen("\r\n\r\n") + 1 < BUFSZ - 1)
103 strcat(verbuf, "\r\n\r\n");
104 verstrsize = strlen(verbuf);
106 if (strsize + verstrsize + 1 > bufsize) {
107 bufsize += BUFSZ;
108 buf = realloc(buf, bufsize);
109 if (buf == NULL)
110 panic("out of memory");
112 strcat(buf, verbuf);
113 strsize = strlen(buf);
115 /* Add compile options */
116 f = dlb_fopen(OPTIONS_USED, RDTMODE);
117 if (f) {
118 char line[LLEN + 1];
120 while (dlb_fgets(line, LLEN, f)) {
121 size_t len;
122 len = strlen(line);
123 if (len > 0 && line[len - 1] == '\n') {
124 line[len - 1] = '\r';
125 line[len] = '\n';
126 line[len + 1] = '\0';
127 len++;
129 if (strsize + (int) len + 1 > bufsize) {
130 bufsize += BUFSZ;
131 buf = realloc(buf, bufsize);
132 if (buf == NULL)
133 panic("out of memory");
135 strcat(buf, line);
136 strsize += len;
138 (void) dlb_fclose(f);
140 } else {
141 /* Show news, if any */
142 if (iflags.news) {
143 FILE *nf;
145 iflags.news = 0; /* prevent newgame() from re-displaying news */
146 nf = fopen(NEWS, "r");
147 if (nf != NULL) {
148 char line[LLEN + 1];
150 while (fgets(line, LLEN, nf)) {
151 size_t len;
152 len = strlen(line);
153 if (len > 0 && line[len - 1] == '\n') {
154 line[len - 1] = '\r';
155 line[len] = '\n';
156 line[len + 1] = '\0';
157 len++;
159 if (strsize + (int) len + 1 > bufsize) {
160 bufsize += BUFSZ;
161 buf = realloc(buf, bufsize);
162 if (buf == NULL)
163 panic("out of memory");
165 strcat(buf, line);
166 strsize += len;
168 (void) fclose(nf);
169 } else {
170 strcat(buf, "No news.");
174 SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf);
175 free(buf);
176 ShowWindow(hWnd, SW_SHOW);
178 while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
179 if (!IsDialogMessage(hWnd, &msg)) {
180 TranslateMessage(&msg);
181 DispatchMessage(&msg);
185 GetNHApp()->hPopupWnd = NULL;
186 mswin_destroy_splashfonts();
189 INT_PTR CALLBACK
190 NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
192 HDC hdc;
194 UNREFERENCED_PARAMETER(lParam);
196 switch (message) {
197 case WM_INITDIALOG:
198 /* set text control font */
199 hdc = GetDC(hWnd);
200 SendMessage(hWnd, WM_SETFONT,
201 (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
203 ReleaseDC(hWnd, hdc);
205 SetFocus(GetDlgItem(hWnd, IDOK));
206 return FALSE;
208 case WM_PAINT: {
209 char VersionString[BUFSZ];
210 RECT rt;
211 HDC hdcBitmap;
212 HANDLE OldBitmap;
213 HANDLE OldFont;
214 PAINTSTRUCT ps;
216 hdc = BeginPaint(hWnd, &ps);
217 /* Show splash graphic */
219 hdcBitmap = CreateCompatibleDC(hdc);
220 SetBkMode(hdc, OPAQUE);
221 OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
222 (*GetNHApp()->lpfnTransparentBlt)(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
223 SPLASH_WIDTH, SPLASH_HEIGHT, hdcBitmap, 0,
224 0, SPLASH_WIDTH, SPLASH_HEIGHT,
225 TILE_BK_COLOR);
227 SelectObject(hdcBitmap, OldBitmap);
228 DeleteDC(hdcBitmap);
230 SetBkMode(hdc, TRANSPARENT);
231 /* Print version number */
233 SetTextColor(hdc, RGB(0, 0, 0));
234 rt.right = rt.left = SPLASH_VERSION_X;
235 rt.bottom = rt.top = SPLASH_VERSION_Y;
236 Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
237 PATCHLEVEL);
238 OldFont = SelectObject(hdc, version_splash_font);
239 DrawText(hdc, VersionString, strlen(VersionString), &rt,
240 DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
241 DrawText(hdc, VersionString, strlen(VersionString), &rt,
242 DT_LEFT | DT_NOPREFIX);
243 EndPaint(hWnd, &ps);
244 } break;
246 case WM_COMMAND:
247 switch (LOWORD(wParam)) {
248 case IDOK:
249 mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
250 if (GetNHApp()->hMainWnd == hWnd)
251 GetNHApp()->hMainWnd = NULL;
252 DestroyWindow(hWnd);
253 SetFocus(GetNHApp()->hMainWnd);
254 return TRUE;
256 break;
258 return FALSE;