1 /* aNetHack 0.0.1 mhrip.c $ANH-Date: 1432512812 2015/05/25 00:13:32 $ $ANH-Branch: master $:$ANH-Revision: 1.19 $ */
2 /* Copyright (C) 2001 by Alex Kompel */
3 /* aNetHack may be freely redistributed. See license for details. */
12 #define RIP_HEIGHT 200
14 #define RIP_GRAVE_HEIGHT 120
15 #define RIP_GRAVE_WIDTH 115
16 #define RIP_GRAVE_X 90
17 #define RIP_GRAVE_Y 60
19 #define RIP_OFFSET_X 10
20 #define RIP_OFFSET_Y 10
22 PNHWinApp
GetNHApp(void);
24 typedef struct mswin_anethack_text_window
{
28 } NHRIPWindow
, *PNHRIPWindow
;
30 INT_PTR CALLBACK
NHRIPWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
31 static void onMSNHCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
34 mswin_init_RIP_window()
39 ret
= CreateDialog(GetNHApp()->hApp
, MAKEINTRESOURCE(IDD_NHRIP
),
40 GetNHApp()->hMainWnd
, NHRIPWndProc
);
42 panic("Cannot create rip window");
44 data
= (PNHRIPWindow
) malloc(sizeof(NHRIPWindow
));
46 panic("out of memory");
48 ZeroMemory(data
, sizeof(NHRIPWindow
));
49 SetWindowLongPtr(ret
, GWLP_USERDATA
, (LONG_PTR
) data
);
54 mswin_display_RIP_window(HWND hWnd
)
66 data
= (PNHRIPWindow
) GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
68 GetNHApp()->hPopupWnd
= hWnd
;
69 mapWnd
= mswin_hwnd_from_winid(WIN_MAP
);
70 if (!IsWindow(mapWnd
))
71 mapWnd
= GetNHApp()->hMainWnd
;
72 GetWindowRect(mapWnd
, &rt
);
73 GetWindowRect(hWnd
, &riprt
);
74 GetClientRect(hWnd
, &clientrect
);
75 textrect
= clientrect
;
76 textrect
.top
+= RIP_OFFSET_Y
;
77 textrect
.left
+= RIP_OFFSET_X
;
78 textrect
.right
-= RIP_OFFSET_X
;
79 if (data
->window_text
) {
81 OldFont
= SelectObject(hdc
, mswin_get_font(NHW_TEXT
, 0, hdc
, FALSE
));
82 DrawText(hdc
, data
->window_text
, strlen(data
->window_text
), &textrect
,
83 DT_LEFT
| DT_NOPREFIX
| DT_CALCRECT
);
84 SelectObject(hdc
, OldFont
);
87 if (textrect
.right
- textrect
.left
> RIP_WIDTH
)
88 clientrect
.right
= textrect
.right
+ RIP_OFFSET_X
- clientrect
.right
;
91 textrect
.left
+ 2 * RIP_OFFSET_X
+ RIP_WIDTH
- clientrect
.right
;
93 textrect
.bottom
+ RIP_HEIGHT
+ RIP_OFFSET_Y
- clientrect
.bottom
;
94 GetWindowRect(GetDlgItem(hWnd
, IDOK
), &textrect
);
95 textrect
.right
-= textrect
.left
;
96 textrect
.bottom
-= textrect
.top
;
97 clientrect
.bottom
+= textrect
.bottom
+ RIP_OFFSET_Y
;
98 riprt
.right
-= riprt
.left
;
99 riprt
.bottom
-= riprt
.top
;
100 riprt
.right
+= clientrect
.right
;
101 riprt
.bottom
+= clientrect
.bottom
;
102 rt
.left
+= (rt
.right
- rt
.left
- riprt
.right
) / 2;
103 rt
.top
+= (rt
.bottom
- rt
.top
- riprt
.bottom
) / 2;
105 MoveWindow(hWnd
, rt
.left
, rt
.top
, riprt
.right
, riprt
.bottom
, TRUE
);
106 GetClientRect(hWnd
, &clientrect
);
107 MoveWindow(GetDlgItem(hWnd
, IDOK
),
108 (clientrect
.right
- clientrect
.left
- textrect
.right
) / 2,
109 clientrect
.bottom
- textrect
.bottom
- RIP_OFFSET_Y
,
110 textrect
.right
, textrect
.bottom
, TRUE
);
111 ShowWindow(hWnd
, SW_SHOW
);
113 while (IsWindow(hWnd
) && GetMessage(&msg
, NULL
, 0, 0) != 0) {
114 if (!IsDialogMessage(hWnd
, &msg
)) {
115 TranslateMessage(&msg
);
116 DispatchMessage(&msg
);
120 GetNHApp()->hPopupWnd
= NULL
;
124 NHRIPWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
129 data
= (PNHRIPWindow
) GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
132 /* set text control font */
134 SendMessage(hWnd
, WM_SETFONT
,
135 (WPARAM
) mswin_get_font(NHW_TEXT
, ATR_NONE
, hdc
, FALSE
),
137 ReleaseDC(hWnd
, hdc
);
139 SetFocus(GetDlgItem(hWnd
, IDOK
));
142 case WM_MSNH_COMMAND
:
143 onMSNHCommand(hWnd
, wParam
, lParam
);
155 hdc
= BeginPaint(hWnd
, &ps
);
156 OldFont
= SelectObject(hdc
, mswin_get_font(NHW_TEXT
, 0, hdc
, FALSE
));
157 hdcBitmap
= CreateCompatibleDC(hdc
);
158 SetBkMode(hdc
, TRANSPARENT
);
159 GetClientRect(hWnd
, &clientrect
);
160 textrect
= clientrect
;
161 textrect
.top
+= RIP_OFFSET_Y
;
162 textrect
.left
+= RIP_OFFSET_X
;
163 textrect
.right
-= RIP_OFFSET_X
;
164 if (data
->window_text
) {
165 DrawText(hdc
, data
->window_text
, strlen(data
->window_text
),
166 &textrect
, DT_LEFT
| DT_NOPREFIX
| DT_CALCRECT
);
167 DrawText(hdc
, data
->window_text
, strlen(data
->window_text
),
168 &textrect
, DT_LEFT
| DT_NOPREFIX
);
170 OldBitmap
= SelectObject(hdcBitmap
, GetNHApp()->bmpRip
);
171 SetBkMode(hdc
, OPAQUE
);
172 bitmap_offset
= (textrect
.right
- textrect
.left
- RIP_WIDTH
) / 2;
173 BitBlt(hdc
, textrect
.left
+ bitmap_offset
, textrect
.bottom
, RIP_WIDTH
,
174 RIP_HEIGHT
, hdcBitmap
, 0, 0, SRCCOPY
);
175 SetBkMode(hdc
, TRANSPARENT
);
176 if (data
->rip_text
) {
177 textrect
.left
+= RIP_GRAVE_X
+ bitmap_offset
;
178 textrect
.top
= textrect
.bottom
+ RIP_GRAVE_Y
;
179 textrect
.right
= textrect
.left
+ RIP_GRAVE_WIDTH
;
180 textrect
.bottom
= textrect
.top
+ RIP_GRAVE_HEIGHT
;
181 DrawText(hdc
, data
->rip_text
, strlen(data
->rip_text
), &textrect
,
182 DT_CENTER
| DT_VCENTER
| DT_NOPREFIX
| DT_WORDBREAK
);
184 SelectObject(hdcBitmap
, OldBitmap
);
185 SelectObject(hdc
, OldFont
);
191 switch (LOWORD(wParam
)) {
193 mswin_window_mark_dead(mswin_winid_from_handle(hWnd
));
194 if (GetNHApp()->hMainWnd
== hWnd
)
195 GetNHApp()->hMainWnd
= NULL
;
197 SetFocus(GetNHApp()->hMainWnd
);
203 /* if we get this here, we saved the bones so we can just force a quit
206 mswin_window_mark_dead(mswin_winid_from_handle(hWnd
));
207 if (GetNHApp()->hMainWnd
== hWnd
)
208 GetNHApp()->hMainWnd
= NULL
;
210 SetFocus(GetNHApp()->hMainWnd
);
211 program_state
.stopprint
++;
216 if (data
->window_text
)
217 free(data
->window_text
);
219 free(data
->rip_text
);
220 if (data
->rip_bmp
!= NULL
)
221 DeleteObject(data
->rip_bmp
);
223 SetWindowLongPtr(hWnd
, GWLP_USERDATA
, (LONG_PTR
) 0);
231 onMSNHCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
234 static int InRipText
= 1;
235 data
= (PNHRIPWindow
) GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
237 case MSNH_MSG_PUTSTR
: {
238 PMSNHMsgPutstr msg_data
= (PMSNHMsgPutstr
) lParam
;
242 if (!data
->window_text
) {
243 text_size
= strlen(msg_data
->text
) + 4;
245 (TCHAR
*) malloc(text_size
* sizeof(data
->window_text
[0]));
246 ZeroMemory(data
->window_text
,
247 text_size
* sizeof(data
->window_text
[0]));
250 _tcslen(data
->window_text
) + strlen(msg_data
->text
) + 4;
251 data
->window_text
= (TCHAR
*) realloc(
252 data
->window_text
, text_size
* sizeof(data
->window_text
[0]));
254 if (!data
->window_text
)
257 _tcscat(data
->window_text
, NH_A2W(msg_data
->text
, wbuf
, BUFSZ
));
258 _tcscat(data
->window_text
, TEXT("\r\n"));
261 case MSNH_MSG_DIED
: {
262 data
->rip_text
= data
->window_text
;
263 data
->window_text
= NULL
;
270 mswin_finish_rip_text(winid wid
)
272 SendMessage(mswin_hwnd_from_winid(wid
), WM_MSNH_COMMAND
, MSNH_MSG_DIED
,