-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdGlobal.cpp
executable file
·331 lines (282 loc) · 6.12 KB
/
EdGlobal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include "stdafx.h"
/*
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
*/
#include <math.h>
#include "global.h"
// Gloabl varialbes
// external gloabal variables
extern HINSTANCE store_hInstance;
extern HWND mainPtr;
extern HDC main_dc;
extern HFONT font;
// local variables
Boolean give_delays = TRUE;
// function prototype
void Delay(short val /*,long *dummy */);
// void WinBlackDrawString(char *string,short x,short y);
// void DrawString(char *string,short x,short y,HDC hdc);
// void undo_clip();
// void ClipRect(RECT *rect);
// void force_reprint();
// void MacMoveTo(short x, short y);
// void MoveToDrawString(char *string,HDC hdc);
// void SetControlValue(HWND sbar,short pos);
// void mes_nums(short a, short b, short c, short d);
// void ShowControl(HWND scroll_bar);
// void HideControl(HWND scroll_bar);
short get_ran (short times, short min, short max)
{
short store;
short i, to_ret = 0;
if ((max - min + 1) == 0)
return 0;
for (i = 1; i < times + 1; i++) {
store = (short)(rand() % (max - min + 1));
to_ret = to_ret + min + store;
}
return to_ret;
}
/*
short s_pow(short x,short y)
{
return (short) pow((double) x, (double) y);
}
*/
short dist(location p1,location p2)
{
return (short) sqrt((double)((p1.x - p2.x) * (p1.x - p2.x) +
(p1.y - p2.y) * (p1.y - p2.y)));
}
short smax(short a,short b)
{
if (a > b)
return a;
else return b;
}
short smin(short a,short b)
{
if (a < b)
return a;
else return b;
}
short minmax(short min,short max,short k)
{
if (k < min)
return min;
if (k > max)
return max;
return k;
}
short n_abs(short x)
{
if (x < 0)
return x * -1;
return x;
}
Boolean same_point(location l1,location l2)
{
if ((l1.x == l2.x) && (l1.y == l2.y))
return TRUE;
else return FALSE;
}
void Delay(short val /*,long *dummy */)
{
long then,now,wait_val;
wait_val = (long) val;
wait_val = wait_val * 16;
then = (long)GetCurrentTime();
now = then;
while (now - then < wait_val) {
now = (long) GetCurrentTime();
}
}
void pause(short length)
{
// long dummy;
if (give_delays == 0)
Delay(length /*, &dummy */);
}
void beep()
{
// long dummy;
MessageBeep(MB_OK);
Delay(50 /* ,&dummy */);
}
void SysBeep(/* short a */)
{
MessageBeep(MB_ICONQUESTION);
}
/*
void WinBlackDrawString(char *string,short x,short y)
{
HDC hdc;
hdc = GetDC(mainPtr);
//SelectPalette(hdc,hpal,0);
//SetViewportOrg(hdc,ulx,uly);
SelectObject(hdc,font);
SetBkMode(hdc,TRANSPARENT);
DrawString(string,x,y,hdc);
fry_dc(mainPtr,hdc);
}
*/
/*
void DrawString(char *string,short x,short y,HDC hdc)
{
RECT text_r = {0,0,450,20};
OffsetRect(&text_r,x,y);
DrawText(hdc,string,-1,&text_r,DT_LEFT | DT_SINGLELINE | DT_TOP | DT_NOCLIP);
}
*/
/*
void undo_clip()
{
// RECT overall_rect = {0,0,530,435};
HRGN rgn;
RECT r;
GetClientRect(mainPtr,&r);
//GetWindowRect(GetDesktopWindow(),&r);
rgn = CreateRectRgn(r.left,r.top,r.right,r.bottom);
SelectClipRgn(main_dc,rgn);
DeleteObject(rgn);
}
*/
/*
void ClipRect(RECT *rect)
{
HRGN rgn;
RECT rect2;
rect2 = *rect;
//OffsetRect(&rect2,ulx,uly);
rgn = CreateRectRgn(rect2.left,rect2.top,rect2.right,rect2.bottom);
SelectClipRgn(main_dc,rgn);
DeleteObject(rgn);
}
*/
/*
void StringToNum(char *the_string,long *number_given) {
long store_short;
sscanf(the_string,"%ld",&store_short);
*number_given = (long) store_short;
}
*/
void MacInsetRect(RECT *rect,short x, short y)
{
InflateRect(rect,-1 * x, -1 * y);
}
// Note ... this expects a str len of at most 256 and
// len_array pointing to a 256 long array of shorts
/*
void MeasureText(short str_len,char *str, short *len_array,HDC hdc)
{
short text_len[257];
short i;
char p_str[257];
char *store_array;
short *store2;
SIZE s;
store_array = (char *) len_array;
//text_len = len_array;
for (i = 0; i < 256; i++)
text_len[i] = 0;
for (i = 1; i < str_len; i++) {
strncpy(p_str,str,i);
p_str[i] = 0;
GetTextExtentPoint32(hdc,p_str,i,&s);
text_len[i] = s.cx;
}
for (i = 0; i < 256; i++) {
store2 = (short *) store_array;
*store2 = text_len[i];
store_array += 2;
}
}
*/
// kludgy annoyance
/*
void MacMoveTo(short x, short y)
{//###
//store_text_x = x;
//store_text_y = y - 16;
}
*/
/*
void MoveToDrawString(char *string,HDC hdc)
{
//DrawString(string,store_text_x,store_text_y, hdc);
}
*/
void PaintRect(RECT *rect,HDC hdc,short r, short g, short b)
{
HBRUSH old_brush,new_brush;
HPEN hpen,old_pen;
hpen = CreatePen(PS_SOLID,1,RGB(r,g,b));
old_pen = (HPEN) SelectObject(hdc,hpen);
new_brush = CreateSolidBrush(RGB(r,g,b));
old_brush = (HBRUSH) SelectObject(hdc,new_brush);
Rectangle(hdc,rect->left,rect->top,rect->right,rect->bottom);
SelectObject(hdc,old_brush);
SelectObject(hdc,old_pen);
DeleteObject(new_brush);
DeleteObject(hpen);
}
/*
void SetControlValue(HWND sbar,short pos)
{
SetScrollPos(sbar,SB_CTL,pos,TRUE);
}
*/
short GetControlValue(HWND sbar)
{
return (short) GetScrollPos(sbar,SB_CTL);
}
/*
void mes_nums(short a, short b, short c, short d)
{
char s[100];
sprintf(s,"Debug: %d %d %d %d",(int)a,(int)b,(int)c,(int)d);
MessageBox(NULL,s,"Hey, baby!",MB_OK);
}
*/
void mes_box(const char* str)
{
MessageBox(NULL,str,"Blades of Avernum Error",MB_OK);
}
/*
void ShowControl(HWND scroll_bar)
{
ShowScrollBar(scroll_bar,SB_CTL,TRUE);
}
*/
/*
void HideControl(HWND scroll_bar)
{
ShowScrollBar(scroll_bar,SB_CTL,FALSE);
}
*/
void GetIndString(char *str,short i, short j)
{
UINT resnum = 0,len;
short k;
// extra stupid kludge here
resnum = i * 300 + j;
len = LoadString(store_hInstance,resnum,str,256);
if (len == 0) {
sprintf(str,"");
return;
}
for (k = 0; k < 256; k++) {
if (str[k] == '|')
str[k] = 13;
if (str[k] == '_')
str[k] = 34;
}
}
/*
Boolean point_in_rect(POINT the_point,RECT *world_screen)
{
return (Boolean)PtInRect(world_screen,the_point);
}
*/