1 /* Copyright (C) 2001 by Alex Kompel <shurikk@pacbell.net> */
2 /* NetHack may be freely redistributed. See license for details. */
9 #include "patchlevel.h"
14 PNHWinApp GetNHApp(void);
16 BOOL CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
18 #define SPLASH_WIDTH 440
19 #define SPLASH_HEIGHT 322
20 #define SPLASH_VERSION_X 290
21 #define SPLASH_VERSION_Y 10
22 #define SPLASH_OFFSET_X 10
23 #define SPLASH_OFFSET_Y 10
25 extern HFONT version_splash_font;
27 void mswin_display_splash_window (BOOL show_ver)
40 char *buf = malloc(bufsize);
42 panic("out of memory");
45 hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
46 GetNHApp()->hMainWnd, NHSplashWndProc);
47 if( !hWnd ) panic("Cannot create Splash window");
48 mswin_init_splashfonts(hWnd);
49 GetNHApp()->hPopupWnd = hWnd;
50 mapWnd = mswin_hwnd_from_winid(WIN_MAP);
51 if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd;
52 /* Get control size */
53 GetWindowRect (GetDlgItem(hWnd, IDOK), &controlrt);
54 controlrt.right -= controlrt.left;
55 controlrt.bottom -= controlrt.top;
56 /* Get current client area */
57 GetClientRect (hWnd, &clientrt);
59 GetWindowRect(hWnd, &splashrt);
60 splashrt.right -= splashrt.left;
61 splashrt.bottom -= splashrt.top;
62 /* Get difference between requested client area and current value */
63 splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right;
64 splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3 - clientrt.bottom;
65 /* Place the window centered */
66 /* On the screen, not on the parent window */
67 left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2;
68 top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2;
69 MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
70 /* Place the OK control */
71 GetClientRect (hWnd, &clientrt);
72 MoveWindow (GetDlgItem(hWnd, IDOK),
73 (clientrt.right - clientrt.left - controlrt.right) / 2,
74 clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y,
75 controlrt.right, controlrt.bottom, TRUE);
76 buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y;
77 /* Place the text control */
78 GetWindowRect (GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
79 controlrt.right -= controlrt.left;
80 controlrt.bottom -= controlrt.top;
81 GetClientRect (hWnd, &clientrt);
82 MoveWindow (GetDlgItem(hWnd, IDC_EXTRAINFO),
83 clientrt.left + SPLASH_OFFSET_X,
84 buttop - controlrt.bottom - SPLASH_OFFSET_Y,
85 clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
86 /* Fill the text control */
87 Sprintf(buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A, COPYRIGHT_BANNER_B,
88 COPYRIGHT_BANNER_B2, COPYRIGHT_BANNER_C);
89 strsize = strlen(buf);
92 /* Show complete version information */
95 getversionstring(buf + strsize);
96 strcat(buf, "\r\n\r\n");
97 strsize = strlen(buf);
99 /* Add compile options */
100 f = dlb_fopen(OPTIONS_USED, RDTMODE);
104 while (dlb_fgets(line, LLEN, f)) {
107 if (len > 0 && line[len - 1] == '\n') {
108 line[len - 1] = '\r';
110 line[len + 1] = '\0';
113 if (strsize + (int)len + 1 > bufsize)
116 buf = realloc(buf, bufsize);
118 panic("out of memory");
123 (void) dlb_fclose(f);
126 /* Show news, if any */
130 iflags.news = 0; /* prevent newgame() from re-displaying news */
131 nf = fopen(NEWS, "r");
135 while (fgets(line, LLEN, nf)) {
138 if (len > 0 && line[len - 1] == '\n') {
139 line[len - 1] = '\r';
141 line[len + 1] = '\0';
144 if (strsize + (int)len + 1 > bufsize)
147 buf = realloc(buf, bufsize);
149 panic("out of memory");
158 strcat(buf, "No news.");
162 SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf);
164 ShowWindow(hWnd, SW_SHOW);
166 while( IsWindow(hWnd) &&
167 GetMessage(&msg, NULL, 0, 0)!=0 ) {
168 if( !IsDialogMessage(hWnd, &msg) ) {
169 TranslateMessage(&msg);
170 DispatchMessage(&msg);
174 GetNHApp()->hPopupWnd = NULL;
175 mswin_destroy_splashfonts();
178 BOOL CALLBACK NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
184 /* set text control font */
186 SendMessage(hWnd, WM_SETFONT,
187 (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
188 ReleaseDC(hWnd, hdc);
190 SetFocus(GetDlgItem(hWnd, IDOK));
195 char VersionString[BUFSZ];
202 hdc = BeginPaint (hWnd, &ps);
203 /* Show splash graphic */
205 hdcBitmap = CreateCompatibleDC(hdc);
206 SetBkMode (hdc, OPAQUE);
207 OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
208 nhapply_image_transparent(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
209 SPLASH_WIDTH, SPLASH_HEIGHT,
210 hdcBitmap, 0, 0, SPLASH_WIDTH, SPLASH_HEIGHT,
213 SelectObject (hdcBitmap, OldBitmap);
214 DeleteDC (hdcBitmap);
216 SetBkMode (hdc, TRANSPARENT);
217 /* Print version number */
219 SetTextColor (hdc, RGB(0, 0, 0));
220 rt.right = rt.left = SPLASH_VERSION_X;
221 rt.bottom = rt.top = SPLASH_VERSION_Y;
222 Sprintf (VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
224 OldFont = SelectObject(hdc, version_splash_font);
225 DrawText (hdc, VersionString, strlen(VersionString), &rt,
226 DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
227 DrawText (hdc, VersionString, strlen(VersionString), &rt,
228 DT_LEFT | DT_NOPREFIX);
230 EndPaint (hWnd, &ps);
235 switch (LOWORD(wParam))
238 mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
239 if( GetNHApp()->hMainWnd==hWnd )
240 GetNHApp()->hMainWnd=NULL;
242 SetFocus(GetNHApp()->hMainWnd);