added worldarea -> will be responsible for world map rendering
[dboe.git] / dlogtool.c
blob873e2c87fdcacce0fe80ef62425d4757fef07472
2 #include <windows.h>
4 #define ND 15
5 #define NI 500
6 #define NL 100
7 #define NUM_DLOG_B 53
9 #include "string.h"
11 #include "global.h"
12 #include "graphutl.h"
13 #include "stdio.h"
14 #include "exlsound.h"
15 #include "dlogtool.h"
16 #include "text.h"
17 #include "locutils.h"
19 extern Boolean play_sounds,cursor_shown,dialog_not_toast,block_erase;
20 extern HBITMAP mixed_gworld, pc_stats_gworld, item_stats_gworld, text_area_gworld;
21 extern HBITMAP storage_gworld,terrain_screen_gworld,text_bar_gworld,orig_text_bar_gworld,buttons_gworld;
22 extern HBITMAP party_template_gworld,items_gworld,tiny_obj_gworld,fields_gworld;
23 extern HBITMAP dlg_buttons_gworld,spec_scen_g;
24 extern HBITMAP pcs_gworld,dlogpics_gworld;
25 extern HFONT fantasy_font,font,italic_font,underline_font,bold_font,tiny_font,small_bold_font;
26 extern HWND mainPtr;
27 extern HPALETTE hpal;
28 extern HDC main_dc;
29 extern HANDLE store_hInstance;
30 long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG);
31 extern Boolean modeless_exists[18];
32 extern HWND modeless_dialogs[18];
33 extern HBRUSH bg[14];
35 // Necessary evil
36 extern HBITMAP anim_gworld,pcs_gworld;
37 extern HBITMAP map_gworld,mixed_gworld;
38 extern HBITMAP button_num_gworld;
39 extern HBITMAP terrain_screen_gworld, buttons_gworld, text_screen_gworld,text_bar_gworld,orig_text_bar_gworld;
40 extern HBITMAP pc_info_screen_gworld,orig_pc_info_screen_gworld,terrain_gworld, party_template_gworld;
41 extern HBITMAP monster_template_gworld;
42 extern HBITMAP startmsc_gworld;
43 extern short far terrain_pic[256];
46 extern HANDLE accel;
47 extern unsigned char m_pic_index_x[200];
48 extern unsigned char m_pic_index_y[200];
49 extern unsigned char m_pic_index[200];
51 short current_key = 0;
52 short far dlg_keys[ND];
53 short far dlg_types[ND];
54 HWND dlgs[ND];
55 HWND dlg_parent[ND];
56 short far dlg_highest_item[ND];
57 Boolean dlg_draw_ready[ND];
59 short far item_dlg[NI];
60 short far item_number[NI];
61 char far item_type[NI];
62 RECT far item_rect[NI];
63 short far item_flag[NI];
64 char far item_active[NI];
65 char far item_key[NI];
66 short far item_label[NI];
67 short far item_label_loc[NI];
69 char far text_long_str[10][256];
70 char far text_short_str[140][35];
71 char far labels[NL][25];
72 Boolean far label_taken[NL];
74 HWND edit_box = NULL;
75 HWND store_edit_parent; // kludgy
76 FARPROC edit_proc,old_edit_proc;
78 HDC dlg_force_dc = NULL; // save HDCs when dealing with dlogs
80 short store_free_slot,store_dlog_num;
81 HWND store_parent;
83 short available_dlog_buttons[NUM_DLOG_B] = {0,63,64,65,1,4,5,8,
84 128,
86 10, // 10
87 11,12,13,
88 14,15,16,17,29, 51,
89 60,61,62, // 20
90 66,69,70, 71,72,73,74,79,
91 80,83,86,87,88, 91,92,93,99,100,
92 101,102,104, 129,130,131,132,133,134,135,136,137};
93 short button_type[150] = {1,1,4,5,1,1,0,0,1,1,
94 1,1,1,1,1,1,1,1,8,8,
95 9,9,9,1,1,2,1,6,7,1,
96 1,12,1,1,2,0,0,0,0,0,
97 0,0,0,0,0,0,0,0,0,0,
98 0,1,1,1,2,1,1,1,2,2, // 50
99 1,1,1,1,1,1,2,3,1,1,
100 1,1,1,1,2,2,2,2,2,1,
101 1,1,1,1,2,2,1,1,1,2,
102 0,1,1,1,14,13,12,12,12,1,
103 1,1,1,2,1,2,2,2,2,1, // 100
104 2,2,2,2,2,2,2,2,2,2,
105 2,2,2,2,2,2,2,2,1,1,
106 1,1,1,1,1,1,1,1,0,0,
107 0,0,0,0,0,0,0,0,0,0};
108 char *button_strs[150] = {"Done ","Ask"," "," ","Keep", "Cancel","+","-","Buy","Leave",
109 "Get","1","2","3","4","5","6","Cast"," "," ",
110 " "," "," ","Buy","Sell","Other Spells","Buy x10"," "," ","Save",
111 "Race","Train","Items","Spells","Heal Party","1","2","3","4","5",
112 "6","7","8","9","10","11","12","13","14","15",
113 /*50*/ "16","Take","Create","Delete","Race/Special","Skill","Name","Graphic","Bash Door","Pick Lock",
114 "Leave","Steal","Attack","OK","Yes","No","Step In"," ","Record","Climb",
115 "Flee","Onward","Answer","Drink","Approach","Mage Spells","Priest Spells","Advantages","New Game","Land",
116 "Under","Restore","Restart","Quit","Save First","Just Quit","Rest","Read","Pull","Alchemy",
117 "17","Push","Pray","Wait","","","Delete","Graphic","Create","Give",
118 /*100*/ "Destroy","Pay","Free","Next Tip","Touch", "Select Icon","Create/Edit","Clear Special","Edit Abilities","Choose",
119 "Go Back","Create New","General","One Shots","Affect PCs","If-Thens","Town Specs","Out Specs","Advanced","Weapon Abil",
120 "General Abil.","NonSpell Use","Spell Usable","Reagents","Missiles","Abilities","Pick Picture","Animated","Enter","Burn",
121 "Insert","Remove","Accept","Refuse","Open","Close","Sit","Stand","","",
122 "18","19","20","Invisible!","","","","","",""};
124 short far button_left_adj[150] = {0,0,0,0,0, 0,0,0,0,0,
125 0,0,0,0,0, 0,0,0,0,0,
126 0,0,0,0,0, 0,0,0,0,0,
127 0,0,0,0,0, 0,0,0,0,0,
128 0,0,0,0,0, 0,0,0,0,0,
129 0,0,0,0,0, 0,0,0,0,0, // 50
130 0,0,0,0,0, 0,0,0,0,0,
131 0,0,0,0,0, 0,0,0,0,0,
132 0,0,0,0,0, 0,0,0,0,0,
133 0,0,0,0,0, 0,0,0,0,0,
134 0,0,0,0,0, 0,0,0,0,0,
135 0,0,0,0,0, 0,0,0,0,0,
136 0,0,0,0,0, 0,0,0,0,0,
137 0,0,0,0,0, 0,0,0,0,0,
138 0,0,0,0,0, 0,0,0,0,0};
139 char button_def_key[150] = {0,0,20,21,'k', 24,0,0,0,0,
140 'g','1','2','3','4', '5','6',0,0,0,
141 0,0,0,0,0,' ',0,22,23,0,
142 0,0,0,0,0,'1','2','3','4','5',
143 '6','7','8','9','a', 'b','c','d','e','f',
144 'g',0,0,0,0,0,0,0,0,0,
145 0,0,0,0,'y','n',0,'?','r',0,
146 0,0,0,0,0,0,0,0,0, 0,
147 0,0,0,0,0,0,0,0,0,0,
148 'g',0,0,0,0,0,0,0,0,0,
149 0,0,0,0,0,0,0,0,0,0,
150 0,0,0,0,0,0,0,0,0,0,
151 0,0,0,0,0,0,0,0,0,0,
152 0,0,0,0,0,0,0,0,0,0,
153 0,0,0,0,0,0,0,0,0,0
155 // specials ... 20 - <- 21 - -> 22 up 23 down 24 esc
156 // 25-30 ctrl 1-6 31 - return\
158 short button_ul_x[15] = {0,46,0,126,0, 0,126,126,126,138, 166,0,0,126,172};
159 short button_ul_y[15] = {0,0,132,23,46, 69,46,69,36,36, 36,23,92,92,0};
160 short button_width[15] = {23,63,102,16,63, 63,63,63,6,14, 14,63,63,63,30};
161 short button_height[15] = {23,23,23,13,23, 23,23,23,6,10,10,23,40,40,30};
163 BOOL FAR PASCAL _export dummy_dialog_proc
164 (HWND hDlg, UINT message, UINT wParam, LONG lParam);
165 long FAR PASCAL _export fresh_edit_proc(HWND hwnd, UINT message, UINT wParam, LONG lParam);
168 FARPROC d_proc;
170 extern char szAppName[];
171 extern char szWinName[];
173 void cd_init_dialogs()
175 short i;
177 for (i = 0; i < ND; i++) {
178 dlg_keys[i] = -1;
179 dlg_types[i] = 0;
180 dlgs[i] = NULL;
181 dlg_highest_item[i] = 0;
183 for (i = 0; i < NI; i++) {
184 item_dlg[i] = -1;
186 for (i = 0; i < NL; i++) {
187 label_taken[i] = FALSE;
189 d_proc = MakeProcInstance((FARPROC) dummy_dialog_proc,store_hInstance);
190 edit_proc = MakeProcInstance ((FARPROC) fresh_edit_proc,store_hInstance);
193 long FAR PASCAL _export fresh_edit_proc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
196 switch (message) {
197 case WM_KEYDOWN:
198 if (wParam == VK_RETURN)
199 SendMessage(store_edit_parent,WM_COMMAND,9,0);
200 if (wParam == VK_ESCAPE)
201 SendMessage(store_edit_parent,WM_COMMAND,8,0);
202 break;
204 return CallWindowProc(old_edit_proc,hwnd,message,wParam,lParam);
207 short cd_create_dialog_parent_num(short dlog_num,short parent)
209 short i;
211 if ((parent == 0) || (parent == 1))
212 return cd_create_dialog(dlog_num,mainPtr);
213 i = cd_get_dlg_index(parent);
214 if (i < 0)
215 return -1;
216 return cd_create_dialog(dlog_num,dlgs[i]);
220 short cd_create_custom_dialog(HWND parent,
221 char *str_block,short pic_num,short buttons[3])
224 short i,j,free_slot = -1,free_item = -1,str_width,cur_but_right = 0;
225 HWND dlg;
226 short total_len = 0;
228 char item_str[256];
229 short type,flag;
230 char strs[6][256];
232 short cur_item = 1,cur_bottom = 8;
233 short but_items[3] = {-1,-1,-1};
234 RECT measure_rect,pic_rect = {8,8,44,44},cur_text_rect = {50,2,0,0};
235 short win_width = 100, win_height = 100;
237 for (i = 0; i < 256; i++) {
238 strs[0][i] = str_block[i];
239 strs[1][i] = str_block[i + 256];
240 strs[2][i] = str_block[i + 512];
241 strs[3][i] = str_block[i + 768];
242 strs[4][i] = str_block[i + 1024];
243 strs[5][i] = str_block[i + 1280];
246 if (parent != NULL) {
247 if (IsWindowEnabled(parent) == 0)
248 return -1;
250 store_dlog_num = 900;
251 //store_parent = parent;
252 for (i = 0; i < ND; i++) {
253 if ((dlg_keys[i] >= 0) && (dlg_types[i] == 900))
254 return -1;
256 for (i = 0; i < ND; i++) {
257 if (dlg_keys[i] < 0) {
258 free_slot = i;
259 i = 500;
262 if (free_slot < 0)
263 return -2;
265 // quick check, to make sure there's at least 1 button
266 if ((buttons[0] < 0) && (buttons[1] < 0) && (buttons[2] < 0))
267 buttons[0] = 1;
268 current_key++;
269 dlg_keys[free_slot] = current_key;
270 dlg_types[free_slot] = 900;
271 dlg_highest_item[free_slot] = 1;
272 dlg_draw_ready[free_slot] = FALSE;
273 dlgs[free_slot] = NULL;
275 // first, create dummy dlog
276 store_free_slot = free_slot;
277 // dlg = GetNewDialog (900, NIL, IN_FRONT);
278 // dlgs[free_slot] = dlg;
279 // if (dlgs[free_slot] == NULL) {
280 // play_sound(3);
281 /// return -3;
282 // }
284 dlgs[free_slot] = CreateWindow (szWinName,
285 "Blades of Exile",
286 0,// was visible
289 100,
290 100,
291 NULL,
292 NULL,
293 store_hInstance,
294 NULL);
295 if (dlgs[free_slot] == NULL) {
296 play_sound(3);
297 return -3;
300 dlg_parent[free_slot] = parent;
302 //process_new_window (dlgs[free_slot]);
303 // instead of this, custom make items
304 free_item = -1;
306 // first, do 1-3 buttons
307 for (i = 0; i < 3; i++)
308 if (buttons[i] >= 0) {// buttons
309 for (j = 150; j < NI; j++)
310 if (item_dlg[j] < 0) {
311 free_item = j;
312 j = NI + 1;
314 item_dlg[free_item] = store_dlog_num;
315 item_type[free_item] = (i == 0) ? 1 : 0;
316 item_number[free_item] = cur_item;
317 //item_rect[free_item] = get_item_rect(hDlg,i + 1);
319 item_flag[free_item] = available_dlog_buttons[buttons[i]];
320 item_active[free_item] = 1;
321 item_label[free_item] = 0;
322 item_label_loc[free_item] = -1;
323 item_key[free_item] = button_def_key[available_dlog_buttons[buttons[i]]];
324 if (i == 0)
325 item_key[free_item] = 31;
326 but_items[i] = free_item; // remember this to set item rect later
327 cur_item++;
329 // next, the upper left picture (always there)
330 for (j = 150; j < NI; j++)
331 if (item_dlg[j] < 0) {
332 free_item = j;
333 j = NI + 1;
335 item_dlg[free_item] = store_dlog_num;
336 item_type[free_item] = 5;
337 item_number[free_item] = cur_item;
338 item_rect[free_item] = pic_rect;
340 if (pic_num < 0) {
341 item_flag[free_item] = pic_num * -1;
343 else //if (pic_num < 1000)
344 item_flag[free_item] = pic_num;
345 // else item_flag[free_item] = (pic_num % 1000) + 2400;
346 // if (pic_num >= 2000)
347 // item_flag[free_item] += 300;
348 item_active[free_item] = 1;
349 item_label[free_item] = 0;
350 item_label_loc[free_item] = -1;
351 item_key[free_item] = 0;
352 cur_item++;
354 // finally, 0-6 text, first do preprocessing to find out how much room we need
355 for (i = 0; i < 6; i++)
356 total_len += string_length((char *) strs[i],main_dc);
357 total_len = total_len * 12;
358 str_width = 100 + 20;
359 //print_nums(0,total_len,str_width);
360 if (str_width < 340)
361 str_width = 340;
362 cur_text_rect.right = cur_text_rect.left + str_width;
363 // finally, 0-6 text, then create the items
364 for (i = 0; i < 6; i++)
365 if (strlen((char *) strs[i]) > 0) {// text
366 for (j = 0; j < 10; j++)
367 if (item_dlg[j] < 0) {
368 free_item = j;
369 j = NI + 1;
371 item_dlg[free_item] = store_dlog_num;
372 item_type[free_item] = 9;
373 item_number[free_item] = cur_item;
374 item_rect[free_item] = cur_text_rect;
375 measure_rect.top = 0; measure_rect.bottom = 0;
376 measure_rect.left = 0; measure_rect.right = 340;
377 DrawText(main_dc, (char *) strs[i],strlen((char *) strs[i]),
378 &measure_rect,DT_CALCRECT | DT_WORDBREAK);
379 item_rect[free_item].bottom = item_rect[free_item].top +
380 (measure_rect.bottom - measure_rect.top) + 16;
381 //((string_length((char *) strs[i],main_dc) + 60) / str_width) * 12 + 16;
382 //item_rect[free_item].right += 20;
384 //print_nums(i,string_length((char *) strs[i]),str_width);
385 cur_text_rect.top = item_rect[free_item].bottom + 8;
386 item_flag[free_item] = 0;
387 item_active[free_item] = 1;
388 item_label[free_item] = 0;
389 item_label_loc[free_item] = -1;
390 item_key[free_item] = 0;
391 sprintf(text_long_str[free_item],"%s",
392 (char *) strs[i]);
393 cur_item++;
396 dlg_highest_item[free_slot] = cur_item - 1;
398 // finally, do button rects
399 cur_but_right = cur_text_rect.right + 30;
400 //cur_text_rect.top += 8;
401 for (i = 0; i < 3; i++)
402 if (buttons[i] >= 0) {
403 item_rect[but_items[i]].right = cur_but_right;
404 item_rect[but_items[i]].top = cur_text_rect.top;
405 item_rect[but_items[i]].bottom = item_rect[but_items[i]].top + 23;
406 if (button_type[available_dlog_buttons[buttons[i]]] == 1)
407 item_rect[but_items[i]].left = item_rect[but_items[i]].right - 63;
408 else item_rect[but_items[i]].left = item_rect[but_items[i]].right - 110;
409 cur_but_right = item_rect[but_items[i]].left - 4;
410 if (i == 0) {
411 win_width = item_rect[but_items[i]].right + 6;
412 win_height = item_rect[but_items[i]].bottom + 6;
416 //MoveWindow(dlgs[free_slot],(windRect.right - win_width) / 2,(windRect.bottom - win_width) / 2 + 20,FALSE);
417 //SizeWindow(dlgs[free_slot],win_width,win_height,FALSE);
418 win_height += 18;
420 MoveWindow(dlgs[free_slot],0,0,win_width,win_height,FALSE);
421 center_window(dlgs[free_slot]);
422 ShowWindow(dlgs[free_slot],SW_SHOW);
424 if (dlg_parent[free_slot] != NULL) {
425 EnableWindow(dlg_parent[free_slot],FALSE);
426 if (dlg_parent[free_slot] == mainPtr)
427 for (i = 0; i < 18; i++)
428 if (modeless_exists[i] == TRUE)
429 EnableWindow(modeless_dialogs[i],FALSE);
431 dialog_not_toast = TRUE;
432 return 0;
436 short cd_create_dialog(short dlog_num,HWND parent)
438 short i,j,free_slot = -1,free_item = -1;
439 HWND dlg;
441 char item_str[256];
442 short type,flag;
443 HDC win_dc;
445 if (parent != NULL) {
446 if (IsWindowEnabled(parent) == 0)
447 return -1;
450 store_dlog_num = dlog_num;
451 store_parent = parent;
453 for (i = 0; i < ND; i++) {
454 if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
455 return -1;
457 for (i = 0; i < ND; i++) {
458 if (dlg_keys[i] < 0) {
459 free_slot = i;
460 i = 500;
463 if (free_slot < 0)
464 return -2;
465 current_key++;
466 dlg_keys[free_slot] = current_key;
467 dlg_types[free_slot] = dlog_num;
468 dlg_highest_item[free_slot] = 1;
469 dlg_draw_ready[free_slot] = FALSE;
470 dlgs[free_slot] = NULL;
472 // first, create dummy dlog
473 store_free_slot = free_slot;
474 dlg = CreateDialog(store_hInstance,MAKEINTRESOURCE(dlog_num),0,d_proc);
476 if (dlgs[free_slot] == NULL) {
477 play_sound(3);
478 return -3;
480 center_window(dlgs[free_slot]);
484 dlg_parent[free_slot] = parent;
486 switch (dlog_num) {
487 case 958: SetWindowText(dlgs[free_slot],"Tip of the Day"); break;
488 case 959: SetWindowText(dlgs[free_slot],"Getting a Job"); break;
489 case 960: SetWindowText(dlgs[free_slot],"Talking Notes"); break;
490 case 961: SetWindowText(dlgs[free_slot],"Adventure Notes"); break;
491 case 962: SetWindowText(dlgs[free_slot],"Adventure Journal"); break;
492 case 970: case 971: case 972: case 973: SetWindowText(dlgs[free_slot],"Blades of Exile"); break;
493 case 987: SetWindowText(dlgs[free_slot],"Getting Items"); break;
494 case 988: SetWindowText(dlgs[free_slot],"Casting Simulacrum"); break;
495 case 989: SetWindowText(dlgs[free_slot],"Create a Party"); break;
496 case 991: SetWindowText(dlgs[free_slot],"Character Statistics"); break;
497 case 996: SetWindowText(dlgs[free_slot],"Known Alchemy"); break;
498 case 997: SetWindowText(dlgs[free_slot],"Getting Help"); break;
499 case 998: SetWindowText(dlgs[free_slot],"Item Information"); break;
500 case 999: SetWindowText(dlgs[free_slot],"Monster Stats"); break;
501 case 1012: SetWindowText(dlgs[free_slot],"How many?"); break;
502 case 1013: SetWindowText(dlgs[free_slot],"Race/Advantages/Disadvantages"); break;
504 case 1010: SetWindowText(dlgs[free_slot],"Training a PC"); break;
505 case 1014: SetWindowText(dlgs[free_slot],"Reading a Sign"); break;
506 case 1017: SetWindowText(dlgs[free_slot],"Blades of Exile"); break;
507 case 1018: SetWindowText(dlgs[free_slot],"Select a PC"); break;
508 case 1019: SetWindowText(dlgs[free_slot],"Character Statistics"); break;
509 case 1020: SetWindowText(dlgs[free_slot],"In a Shop"); break;
510 case 1021: SetWindowText(dlgs[free_slot],"Buying Food"); break;
511 case 1047: SetWindowText(dlgs[free_slot],"Select Alchemy"); break;
512 case 1048: SetWindowText(dlgs[free_slot],"Visiting the Healer"); break;
513 case 1050: SetWindowText(dlgs[free_slot],"Pick PC Graphic"); break;
514 case 1051: SetWindowText(dlgs[free_slot],"Pick PC Name"); break;
515 case 1073: SetWindowText(dlgs[free_slot],"How to Order"); break;
516 case 1075: SetWindowText(dlgs[free_slot],"Register Blades of Exile"); break;
517 case 1096: SetWindowText(dlgs[free_slot],"Spells Help"); break;
518 case 1097: SetWindowText(dlgs[free_slot],"Skills Help"); break;
519 case 1098: SetWindowText(dlgs[free_slot],"Cast a Spell"); break;
520 case 1099: SetWindowText(dlgs[free_slot],"Preferences"); break;
521 default: SetWindowText(dlgs[free_slot],"Blades of Exile"); break;
523 ShowWindow(dlgs[free_slot],SW_SHOW);
524 DestroyWindow(dlg); //Necesary? Dunno.
526 if (dlg_parent[free_slot] != NULL) {
527 EnableWindow(dlg_parent[free_slot],FALSE);
528 if (dlg_parent[free_slot] == mainPtr)
529 for (i = 0; i < 18; i++)
530 if (modeless_exists[i] == TRUE)
531 EnableWindow(modeless_dialogs[i],FALSE);
533 dialog_not_toast = TRUE;
534 return 0;
537 BOOL FAR PASCAL _export dummy_dialog_proc
538 (HWND hDlg, UINT message, UINT wParam, LONG lParam) {
539 short i,j,k,free_slot = -1,free_item = -1,type,flag;
540 char item_str[256];
541 Boolean str_stored = FALSE;
542 RECT dlg_rect;
543 short win_height = 0, win_width = 0;
544 short str_offset = 1;
546 free_slot = store_free_slot;
548 switch (message) {
549 case WM_INITDIALOG:
551 // now, make a window, matching dialog
552 GetWindowRect(hDlg,&dlg_rect);
553 dlgs[store_free_slot] = CreateWindow (szWinName,
554 "Blades of Exile Dialog",
555 0,// was visible
558 dlg_rect.right - dlg_rect.left,
559 dlg_rect.bottom - dlg_rect.top,
560 NULL,
561 NULL,
562 store_hInstance,
563 NULL);
564 // Now, give the window its items
565 for (i = 0; i < 200; i++)
566 if (GetDlgItem(hDlg,i) != NULL) {
567 GetDlgItemText(hDlg,i,item_str,256);
568 str_offset = 1;
569 dlg_highest_item[free_slot] = i;
570 str_stored = FALSE;
571 if (strlen((char *)item_str) == 0) {
572 sprintf((char *) item_str, "+");
573 type = 3;
574 flag = 0;
575 str_stored = TRUE;
577 else if (item_str[0] == '+') { // default is framed text
578 type = 3;
579 flag = 1;
580 str_stored = TRUE;
582 else if (item_str[0] == '*') {
583 type = 3;
584 flag = 0;
585 str_stored = TRUE;
587 else if (item_str[0] == '~') {
588 type = 7;
589 flag = 0;
590 str_stored = TRUE;
592 else if (item_str[0] == '!') {
593 type = 4;
594 flag = 0;
595 str_stored = TRUE;
597 else if (item_str[0] == '=') {
598 type = 9;
599 flag = 1;
600 str_stored = TRUE;
602 else if (((item_str[0] >= 65) && (item_str[0] <= 122)) || (item_str[0] == '"')) {
603 type = 9;
604 flag = 0;
605 str_offset = 0;
606 str_stored = TRUE;
608 else if ((item_str[0] == '^') || (item_str[0] == '&')) {
609 type = (item_str[0] == '^') ? 10 : 11;
610 flag = 1;
611 //if (string_length((char *) item_str) > 55)
612 // flag = 2;
613 str_stored = TRUE;
615 else sscanf(item_str,"%d_%d",&type,&flag);
617 free_item = -1;
618 // find free item
619 switch (type) {
620 case 0: case 1: case 2: case 5: case 6:
621 for (j = 150; j < NI; j++)
622 if (item_dlg[j] < 0) {
623 free_item = j;
624 j = NI + 1;
626 break;
627 default:
628 if ((type == 9) ||
629 ((str_stored == TRUE) && (strlen((char *) item_str) > 35))) {
630 for (j = 0; j < 10; j++)
631 if (item_dlg[j] < 0) {
632 free_item = j;
633 j = NI + 1;
636 else {
637 for (j = 10; j < 140; j++)
638 if (item_dlg[j] < 0) {
639 free_item = j;
640 j = NI + 1;
643 break;
646 if (free_item >= 0) {
647 item_dlg[free_item] = store_dlog_num;
648 item_type[free_item] = type;
649 item_number[free_item] = i;
651 item_rect[free_item] = get_item_rect(hDlg,i);
652 item_rect[free_item].top = item_rect[free_item].top / 2;
653 item_rect[free_item].left = item_rect[free_item].left / 2;
654 item_rect[free_item].bottom = item_rect[free_item].bottom / 2;
655 item_rect[free_item].right = item_rect[free_item].right / 2;
657 if ((type != 5) && ((store_dlog_num >= 2000) || (store_dlog_num == 986))) {
658 item_rect[free_item].top =
659 (item_rect[free_item].top * 11) / 10;
660 item_rect[free_item].bottom =
661 (item_rect[free_item].bottom * 11) / 10;
664 item_flag[free_item] = flag;
665 item_active[free_item] = 1;
666 item_label[free_item] = 0;
667 item_label_loc[free_item] = -1;
668 item_key[free_item] = 0;
670 switch (type) {
671 case 0: case 1:
672 if (item_flag[free_item] != 143) {
673 item_rect[free_item].right = item_rect[free_item].left + button_width[button_type[flag]];
674 item_rect[free_item].bottom = item_rect[free_item].top + button_height[button_type[flag]];
676 item_key[free_item] = button_def_key[flag];
677 if (type == 1)
678 item_key[free_item] = 31;
680 break;
681 case 2:
682 item_rect[free_item].right = item_rect[free_item].left + 14;
683 item_rect[free_item].bottom = item_rect[free_item].top + 10;
684 item_key[free_item] = 255;
685 break;
686 case 3: case 4: case 7: case 8: case 9: case 10: case 11:
687 sprintf(((free_item < 10) ? text_long_str[free_item] : text_short_str[free_item - 10]),"");
688 if (str_stored == TRUE) {
689 if (free_item < 10) {
690 sprintf(text_long_str[free_item],"%s",
691 (char *) (item_str + str_offset));
692 for (k = 0; k < 256; k++) {
693 if (text_long_str[free_item][k] == '|')
694 text_long_str[free_item][k] = 13;
695 if (text_long_str[free_item][k] == '_')
696 text_long_str[free_item][k] = '"';
698 // give text a little extra room
699 //if ((store_dlog_num >= 2000) || (store_dlog_num == 986))
700 // item_rect[free_item].right += 20;
702 else {
703 sprintf(text_short_str[free_item - 10],"%-34s",
704 (char *) (item_str + str_offset));
705 for (k = 0; k < 35; k++) {
706 if (text_short_str[free_item][k] == '|')
707 text_short_str[free_item][k] = 13;
708 if (text_short_str[free_item][k] == '_')
709 text_short_str[free_item][k] = '"';
713 item_key[free_item] = 255;
714 if (type >= 10) { // never got used
715 break;
716 //store_rect = dlg_buttons_gworld[1][0]->portRect;
717 //item_rect[free_item].right = item_rect[free_item].left + store_rect.right;
718 //item_rect[free_item].bottom = item_rect[free_item].top + store_rect.bottom;
719 //if (type == 11)
720 // item_key[free_item] = 31;
722 break;
723 case 6:
725 edit_box = CreateWindow("edit",NULL,WS_CHILD | WS_BORDER | WS_VISIBLE,
726 item_rect[free_item].left,item_rect[free_item].top,
727 item_rect[free_item].right - item_rect[free_item].left,
728 item_rect[free_item].bottom - item_rect[free_item].top,
729 dlgs[free_slot],150,store_hInstance,NULL);
730 store_edit_parent = dlgs[free_slot];
731 old_edit_proc = (FARPROC) GetWindowLong(edit_box,GWL_WNDPROC);
732 SetWindowLong(edit_box,GWL_WNDPROC,(LONG) edit_proc);
734 break;
736 win_height = max(win_height, item_rect[free_item].bottom + 28);
737 win_width = max(win_width, item_rect[free_item].right + 11);
742 MoveWindow(dlgs[free_slot],0,0,win_width,win_height,FALSE);
743 EndDialog(hDlg, 0);
744 return TRUE;
746 return TRUE;
749 void cd_set_edit_focus()
750 { if (edit_box != NULL)
751 SetFocus(edit_box);
754 short cd_kill_dialog(short dlog_num,short parent_message)
756 short i,which_dlg = -1;
758 for (i = 0; i < ND; i++)
759 if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
760 which_dlg = i;
761 if (which_dlg < 0)
762 return -1;
764 for (i = 0; i < NI; i++)
765 if (item_dlg[i] == dlog_num) {
766 if (item_type[i] == 6) {
767 DestroyWindow(edit_box);
768 edit_box = NULL;
770 if (item_label[i] > 0)
771 label_taken[item_label_loc[i]] = FALSE;
772 item_dlg[i] = -1;
775 if (dlg_parent[which_dlg] != NULL) {
776 EnableWindow(dlg_parent[which_dlg],TRUE);
777 if (dlg_parent[which_dlg] == mainPtr)
778 for (i = 0; i < 18; i++)
779 if (modeless_exists[i] == TRUE)
780 EnableWindow(modeless_dialogs[i],TRUE);
781 SetFocus(dlg_parent[which_dlg]);
782 SetWindowPos(dlg_parent[which_dlg],HWND_TOP,0,0,100,100,
783 SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW);
784 cd_set_edit_focus();
787 if (parent_message > 0)
788 SendMessage(dlg_parent[which_dlg],WM_COMMAND,parent_message,0);
790 DestroyWindow(dlgs[which_dlg]);
791 dlg_keys[which_dlg] = -1;
792 dialog_not_toast = TRUE;
793 block_erase = TRUE;
794 return 0;
797 short cd_process_click(HWND window,POINT the_point, UINT wparam, LONG lparam,short *item)
799 short i,which_dlg,dlg_num,item_id;
800 short dlog_key;
802 if ((which_dlg = cd_find_dlog(window,&dlg_num,&dlog_key)) < 0)
803 return -1;
806 for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
807 if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
808 if ((PtInRect(&item_rect[item_id],the_point)) && (item_active[item_id] > 0)
809 && ((item_type[item_id] < 3) || (item_type[item_id] == 8)
810 || (item_type[item_id] == 10)|| (item_type[item_id] == 11))) {
811 *item = i;
812 if (MK_CONTROL & wparam)
813 *item += 100;
814 if (item_type[item_id] != 8)
815 cd_press_button(dlg_num,i);
816 return dlg_num;
819 return -1;
822 short cd_process_syskeystroke(HWND window,UINT wparam, LONG lparam,short *item)
824 short i,which_dlg,dlg_num,dlg_key,item_id;
825 char char_hit;
828 if ((which_dlg = cd_find_dlog(window,&dlg_num,&dlg_key)) < 0)
829 return -1;
830 // specials ... 20 - <- 21 - -> 22 up 23 down 24 esc
831 // 25-30 ctrl 1-6
833 switch (wparam) {
834 case VK_ESCAPE:
835 char_hit = 24;
836 break;
837 //case VK_SPACE:
838 // char_hit = ' ';
839 // break;
840 case VK_LEFT:
841 char_hit = 20;
842 break;
843 case VK_UP:
844 char_hit = 22;
845 break;
846 case VK_RIGHT:
847 char_hit = 21;
848 break;
849 case VK_DOWN:
850 char_hit = 23;
851 break;
852 case VK_RETURN:
853 char_hit = 31;
854 break;
855 default:
856 return -1;
859 for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
860 if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
861 if ((item_key[item_id] == char_hit) && (item_active[item_id] > 0)
862 && ((item_type[item_id] < 3) || (item_type[item_id] == 8))) {
863 *item = i;
864 if (item_type[item_id] != 8)
865 cd_press_button(dlg_num,i);
866 return dlg_num;
869 // kludgy. If you get an escape and is isn't processed, make it an enter
870 if (wparam == VK_ESCAPE) {
871 char_hit = 31;
872 for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
873 if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
874 if ((item_key[item_id] == char_hit) && (item_active[item_id] > 0)
875 && ((item_type[item_id] < 3) || (item_type[item_id] == 8))) {
876 *item = i;
877 if (item_type[item_id] != 8)
878 cd_press_button(dlg_num,i);
879 return dlg_num;
884 return -1;
887 short cd_process_keystroke(HWND window,UINT wparam, LONG lparam,short *item)
889 short i,which_dlg,dlg_num,dlg_key,item_id;
890 char char_hit;
892 if ((which_dlg = cd_find_dlog(window,&dlg_num,&dlg_key)) < 0)
893 return -1;
894 // specials ... 20 - <- 21 - -> 22 up 23 down 24 esc
895 // 25-30 ctrl 1-6
897 char_hit = (char) wparam;
899 for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
900 if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
901 if ((item_key[item_id] == char_hit) && (item_active[item_id] > 0)
902 && ((item_type[item_id] < 3) || (item_type[item_id] == 8))) {
903 *item = i;
904 if (item_type[item_id] != 8)
905 cd_press_button(dlg_num,i);
906 return dlg_num;
909 return -1;
912 void cd_init_button(short dlog_num,short item_num, short button_num, short status)
914 short dlg_index,item_index;
916 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
917 return;
918 if (item_type[item_index] > 1) {
919 beep();
920 return;
922 item_flag[item_index] = button_num;
923 item_active[item_index] = status;
924 item_rect[item_index].right = item_rect[item_index].left + button_width[button_num];
925 item_rect[item_index].bottom = item_rect[item_index].top + button_width[button_num];
926 item_key[item_index] = button_def_key[button_num];
927 cd_draw_item(dlog_num,item_num);
930 void cd_attach_key(short dlog_num,short item_num,char key)
932 short dlg_index,item_index;
934 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
935 return;
937 if ((item_type[item_index] > 2) && (item_type[item_index] != 8)) {
938 beep();
939 return;
941 item_key[item_index] = key;
944 void cd_set_pict(short dlog_num, short item_num, short pict_num)
946 short dlg_index,item_index;
947 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
948 return;
949 if (item_type[item_index] != 5) {
950 beep();
951 return;
953 item_flag[item_index] = pict_num;
954 if (pict_num == -1)
955 cd_erase_item(dlog_num,item_num);
956 else cd_draw_item(dlog_num,item_num);
959 void cd_activate_item(short dlog_num, short item_num, short status)
961 short dlg_index,item_index;
962 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
963 return;
965 item_active[item_index] = status;
966 cd_draw_item(dlog_num,item_num);
969 short cd_get_active(short dlog_num, short item_num)
971 short dlg_index,item_index;
972 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
973 return -1;
975 return item_active[item_index];
979 void cd_get_item_text(short dlog_num, short item_num, char *str)
981 short dlg_index,item_index;
982 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
983 return ;
984 if (item_type[item_index] == 6) {
985 //print_nums(0,0,GetWindowText(edit_box,str,255));
986 if (edit_box != NULL)
987 GetWindowText(edit_box,str,255);
988 else sprintf(str,"");
989 //add_string_to_buf(str);
990 return;
992 if (item_index >= 150) {
993 beep();
994 return;
996 if (item_index < 10)
997 sprintf(str,"%s",text_long_str[item_index]);
998 else sprintf(str,"%s",text_short_str[item_index - 10]);
1001 void cd_get_text_edit_str(short dlog_num, char *str)
1003 if (edit_box != NULL)
1004 GetWindowText(edit_box,str,255);
1005 else str[0] = 0;
1007 // NOTE!!! Expects a c string
1008 void cd_set_text_edit_str(short dlog_num, char *str)
1010 if (edit_box != NULL)
1011 SetWindowText(edit_box,str);
1013 void cdsin(short dlog_num, short item_num, short num)
1015 cd_set_item_num( dlog_num, item_num, num);
1017 void csit(short dlog_num, short item_num, char *str)
1019 cd_set_item_text( dlog_num, item_num, str);
1021 void csp(short dlog_num, short item_num, short pict_num)
1023 cd_set_pict( dlog_num, item_num, pict_num);
1027 void cd_set_item_text(short dlog_num, short item_num, char *str)
1029 short k,dlg_index,item_index;
1030 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1031 return ;
1032 if (item_type[item_index] == 6) {
1033 if (edit_box != NULL)
1034 SetWindowText(edit_box,str);
1035 return;
1037 if (item_index >= 150) {
1038 beep();
1039 return;
1041 if (item_index < 10) {
1042 sprintf(text_long_str[item_index],"%s",str);
1043 for (k = 0; k < 256; k++) {
1044 if (text_long_str[item_index][k] == '|')
1045 text_long_str[item_index][k] = 13;
1046 if (text_long_str[item_index][k] == '_')
1047 text_long_str[item_index][k] = '"';
1051 else sprintf(text_short_str[item_index - 10],"%-34s",str);
1052 cd_draw_item( dlog_num,item_num);
1055 void cd_set_item_num(short dlog_num, short item_num, short num)
1057 short dlg_index,item_index;
1058 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1059 return ;
1060 if (item_index >= 150) {
1061 beep();
1062 return;
1064 if (item_index < 10)
1065 sprintf(text_long_str[item_index],"%d",num);
1066 else sprintf(text_short_str[item_index - 10],"%d",num);
1067 cd_draw_item( dlog_num,item_num);
1070 void cd_set_flag(short dlog_num,short item_num,short flag)
1072 short dlg_index,item_index;
1074 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1075 return;
1077 item_flag[item_index] = flag;
1078 cd_draw_item(dlog_num,item_num);
1081 void cd_set_led(short dlog_num,short item_num,short state)
1083 short dlg_index,item_index;
1085 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1086 return;
1088 if (item_type[item_index] != 2) {
1089 beep();
1090 return;
1092 item_flag[item_index] = state;
1093 cd_draw_item(dlog_num,item_num);
1096 short cd_get_led(short dlog_num,short item_num)
1098 short dlg_index,item_index;
1100 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1101 return 0;
1103 if (item_type[item_index] != 2) {
1104 beep();
1105 return 0;
1107 return item_flag[item_index];
1111 void cd_text_frame(short dlog_num,short item_num,short frame)
1113 short dlg_index,item_index;
1115 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1116 return;
1118 if (item_index >= 150) {
1119 beep();
1120 return;
1122 item_flag[item_index] = frame;
1123 cd_draw_item(dlog_num,item_num);
1126 void cd_add_label(short dlog_num, short item_num, char *label, short label_flag)
1128 short dlg_index,item_index,label_loc = -1;
1129 short i;
1131 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1132 return;
1134 if (item_label_loc[item_index] < 0) {
1135 item_label[item_index] = label_flag;
1136 for (i = 0; i < 100; i++)
1137 if (label_taken[i] == FALSE) {
1138 label_loc = i;
1139 label_taken[i] = TRUE;
1140 i = 100;
1142 if (label_loc < 0) {
1143 beep();
1144 return;
1146 item_label_loc[item_index] = label_loc;
1148 else cd_erase_item(dlog_num,item_num + 100);
1149 label_loc = item_label_loc[item_index];
1150 sprintf((char *) labels[label_loc],"%-24s",label);
1151 if (item_active[item_index] > 0)
1152 cd_draw_item(dlog_num,item_num);
1155 void cd_take_label(short dlog_num, short item_num)
1157 short dlg_index,item_index;
1159 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1160 return;
1161 item_label[item_index] = 0;
1162 label_taken[item_label_loc[item_index]] = FALSE;
1165 void cd_key_label(short dlog_num, short item_num,short loc)
1167 short dlg_index,item_index;
1168 char str[10];
1169 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1170 return;
1171 sprintf((char *) str," ");
1172 str[0] = item_key[item_index];
1173 cd_add_label(dlog_num,item_num, str, 7 + loc * 100);
1176 void cd_draw_item(short dlog_num,short item_num)
1178 short dlg_index,item_index,store_label;
1179 HDC win_dc;
1180 COLORREF colors[4] = {RGB(0,0,0),RGB(255,0,0),RGB(0,0,102),RGB(255,255,255)};
1181 UINT c[4];
1182 RECT from_rect,to_rect;
1183 HFONT old_font;
1185 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1186 return;
1187 if (dlg_draw_ready[dlg_index] == FALSE)
1188 return;
1190 c[0] = GetNearestPaletteIndex(hpal,colors[0]);
1191 c[1] = GetNearestPaletteIndex(hpal,colors[1]);
1192 c[2] = GetNearestPaletteIndex(hpal,colors[2]);
1193 c[3] = GetNearestPaletteIndex(hpal,colors[3]);
1194 win_dc = cd_get_dlog_dc(dlg_index);
1195 old_font = SelectObject(win_dc,small_bold_font);
1196 dlg_force_dc = win_dc;
1198 if (item_active[item_index] == 0) {
1199 cd_erase_item(dlog_num,item_num);
1200 cd_erase_item(dlog_num,item_num + 100);
1202 else {
1203 switch (item_type[item_index]) {
1204 case 0: case 1: case 10: case 11:
1205 if (item_flag[item_index] == 143)
1206 break;
1207 from_rect.top = button_ul_y[button_type[item_flag[item_index]]];
1208 from_rect.left = button_ul_x[button_type[item_flag[item_index]]];
1209 from_rect.bottom = from_rect.top + button_height[button_type[item_flag[item_index]]];
1210 from_rect.right = from_rect.left + button_width[button_type[item_flag[item_index]]];
1211 rect_draw_some_item(dlg_buttons_gworld,from_rect,win_dc,item_rect[item_index],0,2);
1213 SelectObject(win_dc,bold_font);
1214 SetTextColor(win_dc,PALETTEINDEX(c[2]));
1215 if (item_type[item_index] < 2)
1216 OffsetRect(&item_rect[item_index],-1 * button_left_adj[item_flag[item_index]],0);
1217 if (item_type[item_index] < 2) {
1218 char_win_draw_string(win_dc,item_rect[item_index],
1219 (char *) (button_strs[item_flag[item_index]]),1,8);
1221 else {
1222 char_win_draw_string(win_dc,item_rect[item_index],
1223 (char *) ((item_index < 10) ? text_long_str[item_index] :
1224 text_short_str[item_index - 10]),1,8);
1226 if (item_type[item_index] < 2)
1227 OffsetRect(&item_rect[item_index],button_left_adj[item_flag[item_index]],0);
1228 SetTextColor(win_dc,PALETTEINDEX(c[0]));
1230 break;
1232 case 2:
1233 switch (item_flag[item_index]) {
1234 case 0: from_rect.left = 166; from_rect.top = 36; break;
1235 case 1: from_rect.left = 152; from_rect.top = 36; break;
1236 case 2: from_rect.left = 138; from_rect.top = 36; break;
1238 from_rect.right = from_rect.left + 14;
1239 from_rect.bottom = from_rect.top + 10;
1240 rect_draw_some_item( dlg_buttons_gworld,from_rect, win_dc,item_rect[item_index],0,2); break;
1241 break;
1243 case 3: case 4: case 7: case 8: case 9:
1244 cd_erase_item(dlog_num,item_num);
1245 SetTextColor(win_dc,PALETTEINDEX(c[3]));
1246 if ((item_type[item_index] == 3) || (item_type[item_index] == 9))
1247 SelectObject(win_dc,small_bold_font);
1248 if (item_type[item_index] == 4)
1249 SelectObject(win_dc,tiny_font);
1250 if (item_type[item_index] == 7)
1251 SelectObject(win_dc,bold_font);
1252 if (item_flag[item_index] % 10 == 1)
1253 cd_frame_item(dlog_num,item_num,2);
1254 if (item_flag[item_index] >= 10) {
1255 SetTextColor(win_dc,PALETTEINDEX(c[1]));
1258 if (item_rect[item_index].bottom - item_rect[item_index].top < 20) {
1259 item_rect[item_index].left += 3;
1260 DrawText(win_dc,(char *) ((item_index < 10) ? text_long_str[item_index] :
1261 text_short_str[item_index - 10]), -1, &item_rect[item_index],
1262 DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP);
1263 item_rect[item_index].left -= 3;
1265 else {
1266 InflateRect(&item_rect[item_index],-4,-4);
1267 DrawText(win_dc,(char *) ((item_index < 10) ? text_long_str[item_index] :
1268 text_short_str[item_index - 10]), -1, &item_rect[item_index],
1269 DT_LEFT | DT_WORDBREAK | DT_NOCLIP);
1270 InflateRect(&item_rect[item_index],4,4);
1272 SetTextColor(win_dc,PALETTEINDEX(c[0]));
1273 break;
1274 case 5:
1275 if (item_flag[item_index] == -1)
1276 cd_erase_item(dlog_num,item_num);
1277 else draw_dialog_graphic(dlgs[dlg_index], item_rect[item_index],
1278 item_flag[item_index],(item_flag[item_index] >= 2000) ? FALSE : TRUE,0);
1279 break;
1283 if (item_label[item_index] != 0) {
1284 store_label = item_label[item_index];
1285 if (store_label >= 1000) {
1286 store_label -= 1000;
1287 SelectObject(win_dc,bold_font);
1289 else SelectObject(win_dc,tiny_font);
1290 to_rect = item_rect[item_index];
1291 switch (store_label / 100) {
1292 case 0:
1293 to_rect.right = to_rect.left;
1294 to_rect.left -= 2 * (store_label % 100);
1295 break;
1296 case 1:
1297 to_rect.bottom = to_rect.top;
1298 to_rect.top -= 2 * (store_label % 100);
1299 break;
1300 case 2:
1301 to_rect.left = to_rect.right;
1302 to_rect.right += 2 * (store_label % 100);
1303 break;
1304 case 3:
1305 to_rect.top = to_rect.bottom;
1306 to_rect.bottom += 2 * (store_label % 100);
1307 break;
1310 if (to_rect.bottom - to_rect.top < 14) {
1311 to_rect.bottom += (14 - (to_rect.bottom - to_rect.top)) / 2 + 1;
1312 to_rect.top -= (14 - (to_rect.bottom - to_rect.top)) / 2 + 1;
1314 //cd_erase_rect(dlog_num,to_rect);
1315 if (item_active[item_index] != 0) {
1316 SetTextColor(win_dc,PALETTEINDEX(c[3]));
1318 DrawText(win_dc, (char *) labels[item_label_loc[item_index]],
1319 -1, &to_rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
1320 SetTextColor(win_dc,PALETTEINDEX(c[0]));
1325 // hook in special stuff. kludgy
1326 if ((dlog_num == 1098) && ((item_num >= 18) && (item_num <= 23))) {
1327 draw_pc_effects(10 + item_num - 18,win_dc);
1330 SelectObject(win_dc,old_font);
1331 cd_kill_dc(dlg_index,win_dc);
1332 dlg_force_dc = NULL;
1335 void cd_initial_draw(short dlog_num)
1337 short i,which_dlg = -1;
1339 for (i = 0; i < ND; i++)
1340 if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
1341 which_dlg = i;
1342 if (which_dlg < 0)
1343 return;
1344 dlg_draw_ready[which_dlg] = TRUE;
1346 cd_erase_item(dlog_num, 0);
1347 cd_draw(dlog_num);
1350 void cd_draw(short dlog_num)
1352 short i,which_dlg = -1;
1354 for (i = 0; i < ND; i++)
1355 if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
1356 which_dlg = i;
1357 if (which_dlg < 0)
1358 return;
1360 for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++) {
1361 cd_draw_item(dlog_num,i);
1365 void cd_redraw(HWND window)
1367 short which_dlg,dlg_num,dlg_key;
1369 if ((which_dlg = cd_find_dlog(window,&dlg_num,&dlg_key)) < 0)
1370 return;
1371 dlg_draw_ready[which_dlg] = TRUE;
1372 cd_initial_draw(dlg_num);
1375 void cd_frame_item(short dlog_num, short item_num, short width)
1377 short dlg_index,item_index;
1379 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1380 return;
1381 frame_dlog_rect(dlgs[dlg_index], item_rect[item_index], width);
1384 void cd_erase_item(short dlog_num, short item_num)
1385 // if item_num is 0, nail whole window
1386 // item_num + 100 just erase label
1388 short i,dlg_index,item_index,store_label;
1389 RECT to_fry;
1390 HDC win_dc;
1391 HBRUSH old_brush;
1392 HPEN old_pen;
1393 Boolean just_label = FALSE;
1395 if (item_num >= 100) {
1396 item_num -= 100;
1397 just_label = TRUE;
1400 if (item_num == 0) {
1401 for (i = 0; i < ND; i++)
1402 if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
1403 dlg_index = i;
1404 GetWindowRect(dlgs[dlg_index],&to_fry);
1405 OffsetRect(&to_fry,-1 * to_fry.left,-1 * to_fry.top);
1407 else {
1408 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1409 return;
1410 to_fry = item_rect[item_index];
1411 if (just_label == TRUE) {
1412 if (item_label[item_index] != 0) {
1413 store_label = item_label[item_index];
1414 if (store_label >= 1000)
1415 store_label -= 1000;
1417 switch (store_label / 100) {
1418 case 0:
1419 to_fry.right = to_fry.left;
1420 to_fry.left -= 2 * (store_label % 100);
1421 break;
1422 case 1:
1423 to_fry.bottom = to_fry.top;
1424 to_fry.top -= 2 * (store_label % 100);
1425 break;
1426 case 2:
1427 to_fry.left = to_fry.right;
1428 to_fry.right += 2 * (store_label % 100);
1429 break;
1430 case 3:
1431 to_fry.top = to_fry.bottom;
1432 to_fry.bottom += 2 * (store_label % 100);
1433 break;
1435 if ((i = 12 - (to_fry.bottom - to_fry.top)) > 0) {
1436 // adjust rect ... but doesn't work for bold letters
1437 to_fry.bottom += i / 2;
1438 to_fry.bottom++; // extra pixel to get dangly letters
1439 to_fry.top -= i / 2;
1443 InflateRect(&to_fry,1,1);
1446 if (dlg_draw_ready[dlg_index] == FALSE)
1447 return;
1448 win_dc = cd_get_dlog_dc(dlg_index);
1449 /* old_brush = SelectObject(win_dc,bg[4]);
1450 old_pen = SelectObject(win_dc,GetStockObject(NULL_PEN));
1451 Rectangle(win_dc,to_fry.left, to_fry.top,to_fry.right,to_fry.bottom);
1452 SelectObject(win_dc,old_brush);
1453 SelectObject(win_dc,old_pen); */
1454 paint_pattern(win_dc,2,to_fry,0);
1455 cd_kill_dc(dlg_index,win_dc);
1461 void cd_erase_rect(short dlog_num,RECT to_fry)
1463 short i,dlg_index,item_index,store_label;
1464 HDC win_dc;
1465 HBRUSH old_brush;
1466 HPEN old_pen;
1468 if ((dlg_index = cd_get_dlg_index(dlog_num)) < 0)
1469 return;
1470 if (dlg_draw_ready[dlg_index] == FALSE)
1471 return;
1473 win_dc = cd_get_dlog_dc(dlg_index);
1474 /* old_brush = SelectObject(win_dc,bg[4]);
1475 old_pen = SelectObject(win_dc,GetStockObject(NULL_PEN));
1476 Rectangle(win_dc,to_fry.left, to_fry.top,to_fry.right,to_fry.bottom);
1477 SelectObject(win_dc,old_brush);
1478 SelectObject(win_dc,old_pen); */
1479 paint_pattern(win_dc,2,to_fry,0);
1480 cd_kill_dc(dlg_index,win_dc);
1482 // paint_pattern(dlgs[dlg_index],2,to_fry,0);
1485 void cd_press_button(short dlog_num, short item_num)
1487 short dlg_index,item_index;
1488 long dummy;
1489 HDC win_dc;
1490 RECT from_rect,to_rect;
1491 COLORREF colors[3] = {RGB(0,0,0),RGB(0,0,112),RGB(0,255,255)};
1492 UINT c[3];
1494 if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
1495 return;
1496 // no press action for redio buttons
1497 if ((item_type[item_index] == 2) || (item_flag[item_index] == 143)) {
1498 play_sound(34);
1499 return;
1502 c[0] = GetNearestPaletteIndex(hpal,colors[0]);
1503 c[1] = GetNearestPaletteIndex(hpal,colors[1]);
1504 c[2] = GetNearestPaletteIndex(hpal,colors[2]);
1505 win_dc = cd_get_dlog_dc(dlg_index);
1506 /* from_rect.top = button_uly[item_flag[item_index]];
1507 from_rect.left = button_ulx[item_flag[item_index]];
1508 from_rect.bottom = from_rect.top + button_height[item_flag[item_index]];
1509 from_rect.right = from_rect.left + button_width[item_flag[item_index]];
1510 OffsetRect(&from_rect,button_width[item_flag[item_index]],0);
1511 rect_draw_some_item(dlgbtns_gworld,from_rect,win_dc,item_rect[item_index],0,2);
1513 if (play_sounds == TRUE) {
1514 play_sound(37);
1515 Delay(6,&dummy);
1517 else Delay(14,&dummy);
1519 OffsetRect(&from_rect,-1 * button_width[item_flag[item_index]],0);
1520 rect_draw_some_item(dlgbtns_gworld,from_rect,win_dc,item_rect[item_index],0,2);
1523 from_rect.top = button_ul_y[button_type[item_flag[item_index]]];
1524 from_rect.left = button_ul_x[button_type[item_flag[item_index]]];
1525 from_rect.bottom = from_rect.top + button_height[button_type[item_flag[item_index]]];
1526 from_rect.right = from_rect.left + button_width[button_type[item_flag[item_index]]];
1527 OffsetRect(&from_rect,button_width[button_type[item_flag[item_index]]],0);
1529 rect_draw_some_item(dlg_buttons_gworld,from_rect,win_dc,item_rect[item_index],0,2);
1531 SelectObject(win_dc,bold_font);
1532 SetTextColor(win_dc,PALETTEINDEX(c[2]));
1533 if (item_type[item_index] < 2)
1534 OffsetRect(&item_rect[item_index],-1 * button_left_adj[item_flag[item_index]],0);
1535 if (item_type[item_index] < 2) {
1536 char_win_draw_string(win_dc,item_rect[item_index],
1537 (char *) (button_strs[item_flag[item_index]]),1,8);
1539 else {
1540 char_win_draw_string(win_dc,item_rect[item_index],
1541 (char *) ((item_index < 10) ? text_long_str[item_index] :
1542 text_short_str[item_index - 10]),1,8);
1544 if (item_type[item_index] < 2)
1545 OffsetRect(&item_rect[item_index],button_left_adj[item_flag[item_index]],0);
1547 if (play_sounds == TRUE) {
1548 play_sound(37);
1549 Delay(6,&dummy);
1551 else Delay(10,&dummy);
1553 OffsetRect(&from_rect,-1 * button_width[button_type[item_flag[item_index]]],0);
1554 rect_draw_some_item(dlg_buttons_gworld,from_rect,win_dc,item_rect[item_index],0,2);
1556 SelectObject(win_dc,bold_font);
1557 SetTextColor(win_dc,PALETTEINDEX(c[1]));
1558 if (item_type[item_index] < 2)
1559 OffsetRect(&item_rect[item_index],-1 * button_left_adj[item_flag[item_index]],0);
1560 if (item_type[item_index] < 2) {
1561 char_win_draw_string(win_dc,item_rect[item_index],
1562 (char *) (button_strs[item_flag[item_index]]),1,8);
1564 else {
1565 char_win_draw_string(win_dc,item_rect[item_index],
1566 (char *) ((item_index < 10) ? text_long_str[item_index] :
1567 text_short_str[item_index - 10]),1,8);
1569 if (item_type[item_index] < 2)
1570 OffsetRect(&item_rect[item_index],button_left_adj[item_flag[item_index]],0);
1572 SelectObject(win_dc,font);
1573 SetTextColor(win_dc,PALETTEINDEX(c[0]));
1575 cd_kill_dc(dlg_index,win_dc);
1578 // LOW LEVEL
1580 short cd_get_indices(short dlg_num, short item_num, short *dlg_index, short *item_index)
1582 if ((*dlg_index = cd_get_dlg_index(dlg_num)) < 0) {
1583 //print_nums(1234,dlg_num,item_num);
1584 // beep();
1585 return -1;
1587 if ((*item_index = cd_get_item_id(dlg_num,item_num)) < 0) {
1588 // beep();
1589 //print_nums(5678,dlg_num,item_num);
1590 return -1;
1592 return 0;
1595 short cd_get_dlg_index(short dlog_num)
1597 short i;
1599 for (i = 0; i < ND; i++)
1600 if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
1601 return i;
1602 return -1;
1605 short cd_find_dlog(HWND window, short *dlg_num, short *dlg_key)
1607 short i;
1608 for (i = 0; i < ND; i++)
1609 if ((dlg_keys[i] >= 0) && (dlgs[i] == window)) {
1610 *dlg_num = dlg_types[i];
1611 *dlg_key = dlg_keys[i];
1612 return i;
1614 return -1;
1617 short cd_get_item_id(short dlg_num, short item_num)
1619 short i;
1621 for (i = 0; i < NI; i++)
1622 if ((item_dlg[i] == dlg_num) && (item_number[i] == item_num))
1623 return i;
1624 return -1;
1627 HDC cd_get_dlog_dc(short which_slot)
1629 HDC win_dc;
1631 win_dc = GetDC(dlgs[which_slot]);
1632 //SelectObject(win_dc,font);
1633 SelectPalette(win_dc,hpal,0);
1634 SetBkMode(win_dc,TRANSPARENT);
1635 return win_dc;
1638 void cd_kill_dc(short which_slot,HDC hdc)
1640 fry_dc(dlgs[which_slot],hdc);
1643 // External graphics tools (huh huh huh ... tool ... huh huh huh)
1645 void center_window(HWND window)
1647 RECT main_rect,wind_rect;
1648 short width,height;
1650 cursor_shown = TRUE;
1651 showcursor(TRUE);
1653 GetWindowRect(GetDesktopWindow(),&main_rect);
1654 GetWindowRect(window,&wind_rect);
1655 width = wind_rect.right - wind_rect.left;
1656 height = wind_rect.bottom - wind_rect.top;
1657 MoveWindow(window,((main_rect.right - main_rect.left) - width) / 2,
1658 ((main_rect.bottom - main_rect.top) - height) / 2,width,height,TRUE);
1662 RECT get_item_rect(HWND hDlg, short item_num)
1664 HWND item;
1665 RECT big_rect,small_rect;
1667 item = GetDlgItem(hDlg, item_num);
1668 GetWindowRect(hDlg,&big_rect);
1669 GetWindowRect(item,&small_rect);
1670 OffsetRect(&small_rect, -1 * big_rect.left - 7, -1 * big_rect.top - 7);
1671 small_rect.right += 2;
1672 small_rect.bottom += 2;
1673 return small_rect;
1677 void frame_dlog_rect(HWND hDlg, RECT rect, short val)
1679 HDC hdc;
1680 HPEN dpen,lpen,old_pen;
1681 COLORREF x = RGB(0,204,255),y = RGB(0,204,255);//y = RGB(119,119,119);
1682 UINT c;
1683 Boolean keep_dc = FALSE;
1685 InflateRect(&rect,val,val);
1687 if (hDlg == mainPtr) {
1688 keep_dc = TRUE;
1689 hdc = main_dc;
1691 else if (dlg_force_dc != NULL) {
1692 hdc = dlg_force_dc;
1693 keep_dc = TRUE;
1695 else hdc = GetDC(hDlg);
1696 if (hdc == NULL) {
1697 beep();
1698 return;
1700 SelectPalette(hdc,hpal,0);
1701 c = GetNearestPaletteIndex(hpal,x);
1702 lpen = CreatePen(PS_SOLID,1,PALETTEINDEX(c));
1703 c = GetNearestPaletteIndex(hpal,y);
1704 dpen = CreatePen(PS_SOLID,1,PALETTEINDEX(c));
1705 old_pen = SelectObject(hdc,dpen);
1706 MoveTo(hdc,rect.left,rect.top);
1707 LineTo(hdc,rect.right,rect.top);
1708 SelectObject(hdc,lpen);
1709 LineTo(hdc,rect.right,rect.bottom);
1710 LineTo(hdc,rect.left,rect.bottom);
1711 SelectObject(hdc,dpen);
1712 LineTo(hdc,rect.left,rect.top);
1713 SelectObject(hdc,old_pen);
1714 if (keep_dc == FALSE)
1715 fry_dc(hDlg,hdc);
1716 DeleteObject(dpen);
1717 DeleteObject(lpen);
1720 void draw_dialog_graphic(HWND hDlg, RECT rect, short which_g, Boolean do_frame,short win_or_gworld)
1721 // win_or_gworld: 0 - window 1 - an HBITMAP
1722 // 1 means hDlg is actually an HBITMAP variable!
1723 // 0 - 300 number of terrain graphic
1724 // 400 + x - monster graphic num
1725 // 600 + x item graphic
1726 // 700 + x dlog graphic
1727 // 800 + x pc graphic
1728 // 900 + x B&W graphic
1729 // 950 null item
1730 // 1000 + x Talking face
1731 // 1100 - item info help
1732 // 1200 - pc screen help
1733 // 1300 - combat ap
1734 // 1400-1402 - button help
1735 // 1500 - stat symbols help
1736 // 1600 + x - B&W maps
1737 // 1700 + x - anim graphic
1739 short picnum;
1740 RECT from1 = {0,0,36,28},from2 = {0,0,36,36},from3 = {0,0,72,72},tiny_obj_rect = {0,0,18,18};
1741 RECT from_rect = {0,0,28, 36};
1742 RECT face_from = {0,0,32,32};
1743 RECT death_to = {6,6,78,78};
1744 RECT to_rect = {6,6,42,42};
1745 RECT m_to_rect = {10,6,38,42};
1746 RECT bw_from = {0,0,120,120};
1747 RECT map_from = {0,0,240,240};
1749 RECT pc_info_from = {0,127,106,157};
1750 RECT item_info_from = {174,0,312,112};
1751 RECT button_help_from = {0,0,320,100};
1752 RECT combat_ap_from = {0,0,275,100};
1753 RECT stat_symbols_from = {0,0,386,94}; /**/
1754 RECT small_monst_rect = {0,0,14,18};
1755 RECT large_scen_from = {0,0,64,64};
1757 HBITMAP from_gworld;
1758 short draw_dest = 2;
1759 HDC hdc;
1760 HBRUSH old_brush;
1761 short m_start_pic = 0,square_size = 32;
1763 if (win_or_gworld == 1)
1764 draw_dest = 0;
1766 if (which_g < 0)
1767 return;
1769 if (which_g >= 3000)
1770 do_frame = FALSE;
1771 which_g = which_g % 3000;
1773 if (win_or_gworld == 0) {
1774 if (dlg_force_dc != NULL)
1775 hdc = dlg_force_dc;
1776 else hdc = GetDC(hDlg);
1777 SelectPalette(hdc,hpal,0);
1779 if (which_g == 950) { // Empty. Maybe clear space.
1780 if (win_or_gworld == 0) {
1781 paint_pattern(hdc,2,rect,0);
1783 //old_brush = SelectObject(hdc,bg[5]);
1784 //Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
1785 //SelectObject(hdc,old_brush);
1787 //FillCRect(&rect,bg[5]); // don't forget to nail dc!!!
1788 if (dlg_force_dc == NULL)
1789 fry_dc(hDlg, hdc);
1790 return;
1793 switch (which_g / 100) {
1794 case 0: case 1: case 2: // terrain
1795 from_gworld = load_pict(800 + which_g / 50,main_dc);
1796 which_g = which_g % 50;
1797 from_rect = calc_rect(which_g % 10, which_g / 10);
1798 if (rect.right - rect.left != 28) {
1799 rect.left += 1;
1800 rect.right = rect.left + 28;
1802 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP) (hDlg): hdc)
1803 ,rect,0,draw_dest);
1804 DeleteObject(from_gworld);
1805 break;
1806 case 3: // animated terrain
1807 which_g -= 300;
1808 from_gworld = load_pict(820,main_dc);
1809 from_rect = calc_rect(4 * (which_g / 5), which_g % 5);
1810 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
1811 ,rect,0,draw_dest);
1812 DeleteObject(from_gworld);
1813 break;
1814 case 4: case 5: // monster
1815 // There are 4 different ways to draw, depending on size of monster
1816 which_g -= 400;
1817 m_start_pic = m_pic_index[which_g];
1818 if ((m_pic_index_x[which_g] == 1) && (m_pic_index_y[which_g] == 1)) {
1819 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1820 m_start_pic = m_start_pic % 20;
1821 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1822 rect.right = rect.left + 28; rect.bottom = rect.top + 36;
1823 if (win_or_gworld == 0) {
1824 old_brush = SelectObject(hdc,GetStockObject(BLACK_BRUSH));
1825 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
1826 SelectObject(hdc,old_brush);
1828 if (win_or_gworld == 1)
1829 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,rect,0,0);
1830 else rect_draw_some_item(from_gworld,from_rect,hdc,rect,0,draw_dest);
1831 DeleteObject(from_gworld);
1833 if ((m_pic_index_x[which_g] == 2) && (m_pic_index_y[which_g] == 1)) {
1834 rect.right = rect.left + 28; rect.bottom = rect.top + 36;
1835 if (win_or_gworld == 0) {
1836 old_brush = SelectObject(hdc,GetStockObject(BLACK_BRUSH));
1837 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
1838 SelectObject(hdc,old_brush);
1840 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1841 m_start_pic = m_start_pic % 20;
1842 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1843 OffsetRect(&small_monst_rect,rect.left,rect.top + 7);
1845 if (win_or_gworld == 1)
1846 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1847 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1849 m_start_pic = m_pic_index[which_g] + 1;
1850 DeleteObject(from_gworld);
1851 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1852 m_start_pic = m_start_pic % 20;
1853 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1854 OffsetRect(&small_monst_rect,14,0);
1856 if (win_or_gworld == 1)
1857 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1858 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1859 DeleteObject(from_gworld);
1861 if ((m_pic_index_x[which_g] == 1) && (m_pic_index_y[which_g] == 2)) {
1862 rect.right = rect.left + 28; rect.bottom = rect.top + 36;
1863 if (win_or_gworld == 0) {
1864 old_brush = SelectObject(hdc,GetStockObject(BLACK_BRUSH));
1865 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
1866 SelectObject(hdc,old_brush);
1869 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1870 m_start_pic = m_start_pic % 20;
1871 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1872 OffsetRect(&small_monst_rect,rect.left + 7,rect.top);
1874 if (win_or_gworld == 1)
1875 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1876 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1877 m_start_pic = m_pic_index[which_g] + 1;
1878 DeleteObject(from_gworld);
1879 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1880 m_start_pic = m_start_pic % 20;
1881 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1882 OffsetRect(&small_monst_rect,0,18);
1884 if (win_or_gworld == 1)
1885 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1886 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1887 DeleteObject(from_gworld);
1890 if ((m_pic_index_x[which_g] == 2) && (m_pic_index_y[which_g] == 2)) {
1891 rect.right = rect.left + 28; rect.bottom = rect.top + 36;
1892 if (win_or_gworld == 0) {
1893 old_brush = SelectObject(hdc,GetStockObject(BLACK_BRUSH));
1894 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
1895 SelectObject(hdc,old_brush);
1897 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1898 m_start_pic = m_start_pic % 20;
1899 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1900 OffsetRect(&small_monst_rect,rect.left,rect.top);
1902 if (win_or_gworld == 1)
1903 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1904 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1906 m_start_pic = m_pic_index[which_g] + 1;
1907 DeleteObject(from_gworld);
1908 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1909 m_start_pic = m_start_pic % 20;
1910 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1911 OffsetRect(&small_monst_rect,14,0);
1913 if (win_or_gworld == 1)
1914 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1915 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1917 m_start_pic = m_pic_index[which_g] + 2;
1918 DeleteObject(from_gworld);
1919 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1920 m_start_pic = m_start_pic % 20;
1921 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1922 OffsetRect(&small_monst_rect,-14,18);
1924 if (win_or_gworld == 1)
1925 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1926 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1927 m_start_pic = m_pic_index[which_g] + 3;
1928 DeleteObject(from_gworld);
1929 from_gworld = load_pict(1100 + m_start_pic / 20,main_dc);
1930 m_start_pic = m_start_pic % 20;
1931 from_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
1932 OffsetRect(&small_monst_rect,14,0);
1934 if (win_or_gworld == 1)
1935 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,small_monst_rect,0,0);
1936 else rect_draw_some_item(from_gworld,from_rect,hdc,small_monst_rect,0,draw_dest);
1938 DeleteObject(from_gworld);
1939 break;
1940 case 18: case 19: // item
1941 which_g -= 1800;
1942 to_rect = rect;
1943 if (which_g < 45) {
1944 from_gworld = items_gworld;
1945 from_rect = calc_rect(which_g % 5, which_g / 5);
1947 else {
1948 from_gworld = tiny_obj_gworld;
1949 //rect.top += 4; rect.bottom -= 4;
1950 //InflateRect(&to_rect,-5,-9);
1951 to_rect.top += 9;
1952 to_rect.left += 5;
1953 to_rect.right = to_rect.left + 18;
1954 to_rect.bottom = to_rect.top + 18;
1955 from_rect = tiny_obj_rect;
1956 OffsetRect(&from_rect,18 * (which_g % 10), 18 * (which_g / 10));
1958 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
1959 ,to_rect,1,draw_dest);
1960 break;
1961 case 7: // dialog
1962 which_g -= 700;
1963 from_gworld = dlogpics_gworld;
1964 OffsetRect(&from2,36 * (which_g % 4),36 * (which_g / 4));
1965 rect_draw_some_item(from_gworld,from2,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
1966 ,rect,0,draw_dest);
1967 break;
1968 case 8: // PC
1969 if (pcs_gworld != NULL)
1970 from_gworld = pcs_gworld;
1971 else from_gworld = load_pict(902,main_dc);
1972 which_g -= 800;
1973 from_rect = calc_rect(2 * (which_g / 8), which_g % 8);
1974 old_brush = SelectObject(hdc,GetStockObject(BLACK_BRUSH));
1975 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
1976 SelectObject(hdc,old_brush);
1977 //PaintRect(&rect);
1978 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
1979 ,rect,1,draw_dest);
1980 if (pcs_gworld == NULL)
1981 DeleteObject(from_gworld);
1982 break;
1983 case 9: // B&W
1984 which_g -= 900;
1985 from_gworld = load_pict(875,main_dc);
1986 from_rect = bw_from;
1987 OffsetRect(&from_rect,120 * ((which_g) % 3),120 * ((which_g) / 3));
1988 if (win_or_gworld == 1)
1989 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,rect,0,0);
1990 else rect_draw_some_item(from_gworld,from_rect,hdc,rect,0,draw_dest);
1991 DeleteObject(from_gworld);
1992 break;
1993 case 10: // talk face
1994 which_g -= 1000;
1995 from_gworld = load_pict(860,main_dc);
1996 from_rect = face_from;
1997 OffsetRect(&from_rect,32 * ((which_g - 1) % 10),32 * ((which_g - 1) / 10));
1998 if (win_or_gworld == 1)
1999 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) hDlg,rect,0,0);
2000 else rect_draw_some_item(from_gworld,from_rect,hdc,rect,0,draw_dest);
2001 DeleteObject(from_gworld);
2002 break;
2003 case 11: // item info help
2004 from_rect = item_info_from;
2005 rect.right = rect.left + from_rect.right - from_rect.left;
2006 rect.bottom = rect.top + from_rect.bottom - from_rect.top;
2007 rect_draw_some_item(mixed_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
2008 ,rect,0,draw_dest);
2009 break;
2010 case 12: // item info help
2011 from_rect = pc_info_from;
2012 rect.right = rect.left + pc_info_from.right - pc_info_from.left;
2013 rect.bottom = rect.top + pc_info_from.bottom - pc_info_from.top;
2014 rect_draw_some_item(mixed_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
2015 ,rect,0,draw_dest);
2016 break;
2017 case 14: // button help
2018 which_g -= 1400;
2019 if (which_g >= 10) {
2020 from_gworld = load_pict(900 + which_g,main_dc);
2021 from_rect = large_scen_from;
2022 OffsetRect(&from_rect,64 * (which_g % 10),0);
2023 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
2024 ,rect,0,draw_dest);
2025 DeleteObject(from_gworld);
2026 break;
2028 from_gworld = load_pict(1401,main_dc);
2029 from_rect = button_help_from;
2030 rect.top += 10;
2031 rect.right = rect.left + from_rect.right;
2032 rect.bottom = rect.top + from_rect.bottom;
2033 OffsetRect(&from_rect,0,100 * which_g);
2034 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
2035 ,rect,0,draw_dest);
2036 DeleteObject(from_gworld);
2037 break;
2038 case 13: // combat ap help
2039 from_gworld = load_pict(1402,main_dc);
2040 from_rect = combat_ap_from;
2041 rect.right = rect.left + from_rect.right;
2042 rect.bottom = rect.top + from_rect.bottom;
2043 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP) (hDlg): hdc)
2044 ,rect,0,draw_dest);
2045 DeleteObject(from_gworld);
2046 break;
2047 case 15: // stat symbols help
2048 from_gworld = load_pict(1400,main_dc);
2049 from_rect = stat_symbols_from;
2050 rect.right = rect.left + from_rect.right;
2051 rect.bottom = rect.top + from_rect.bottom;
2052 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP) (hDlg): hdc)
2053 ,rect,0,draw_dest);
2054 DeleteObject(from_gworld);
2055 break;
2056 case 16:
2057 which_g -= 1600;
2058 from_gworld = load_pict(851,main_dc);
2059 from_rect.right = 32;
2060 from_rect.bottom = 32;
2061 OffsetRect(&from_rect,32 * (which_g % 5),32 * (which_g / 5));
2062 rect.right = rect.left + 32;
2063 rect.bottom = rect.top + 32;
2064 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP) (hDlg): hdc)
2065 ,rect,0,draw_dest);
2066 DeleteObject(from_gworld);
2067 break;
2068 case 17: // dialog
2069 which_g -= 1700;
2070 from_gworld = fields_gworld;
2071 from_rect = calc_rect(which_g % 8, which_g / 8);
2072 if (win_or_gworld == 0) {
2073 old_brush = SelectObject(hdc,GetStockObject(BLACK_BRUSH));
2074 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
2075 SelectObject(hdc,old_brush);
2077 //PaintRect(&rect);
2079 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP)hDlg: hdc)
2080 ,rect,0,draw_dest);
2081 break;
2082 case 20: case 21: case 22: case 23: // dialog
2083 which_g -= 2000;
2084 rect.right = rect.left + 28;
2085 rect.bottom = rect.top + 36;
2086 from_gworld = spec_scen_g;
2087 from_rect = get_custom_rect(which_g);
2088 if ((win_or_gworld == 0) && (do_frame == TRUE)) {
2089 old_brush = SelectObject(hdc,GetStockObject(BLACK_BRUSH));
2090 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
2091 SelectObject(hdc,old_brush);
2094 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP) (hDlg): hdc)
2095 ,rect,(do_frame == FALSE) ? 1 : 0,draw_dest);
2096 break;
2097 case 24: case 25: case 26: case 27: // dialog
2098 which_g -= 2400;
2099 if (rect.right - rect.left >= 36)
2100 square_size = 36;
2101 from_gworld = spec_scen_g;
2102 from_rect = get_custom_rect(which_g);
2103 to_rect = rect;
2104 to_rect.right = to_rect.left + square_size / 2;
2105 to_rect.bottom = to_rect.top + square_size;
2106 from_rect.right = from_rect.left + square_size / 2;
2107 from_rect.bottom = from_rect.top + square_size;
2108 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP) (hDlg): hdc)
2109 ,to_rect,1,draw_dest);
2110 from_rect = get_custom_rect(which_g + 1);
2111 OffsetRect(&to_rect,square_size / 2,0);
2112 from_rect.right = from_rect.left + square_size / 2;
2113 from_rect.bottom = from_rect.top + square_size;
2114 rect_draw_some_item(from_gworld,from_rect,(HBITMAP) ((win_or_gworld == 1) ? (HBITMAP) (hDlg): hdc)
2115 ,to_rect,1,draw_dest);
2116 break;
2119 if ((win_or_gworld == 0) && (dlg_force_dc == NULL))
2120 fry_dc(hDlg, hdc);
2121 if ((win_or_gworld == 0) && (do_frame == TRUE)){
2122 rect.bottom--; rect.right--;
2123 frame_dlog_rect(hDlg,rect,3);
2127 void showcursor(Boolean a)
2129 short i;
2130 i = ShowCursor(a);
2131 if (a == FALSE)
2132 while (i >= 0)
2133 i = ShowCursor(FALSE);
2134 if (a == TRUE)
2135 while (i < 0)
2136 i = ShowCursor(TRUE);
2139 void ModalDialog()
2141 MSG msg;
2143 while ((dialog_not_toast == TRUE) && (GetMessage(&msg,NULL,0,0))) {
2144 if (!TranslateAccelerator(mainPtr, accel, &msg)) {
2145 TranslateMessage(&msg);
2146 DispatchMessage(&msg);
2151 RECT calc_rect(short i, short j)
2153 RECT base_rect = {0,0,28,36};
2155 OffsetRect(&base_rect,i * 28, j * 36);
2156 return base_rect;