forked from alexfru/dflat20
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pictbox.c
284 lines (265 loc) · 7.86 KB
/
pictbox.c
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
/* -------------- pictbox.c -------------- */
#include "dflat.h"
#ifdef INCLUDE_PICTUREBOX
typedef struct {
enum VectTypes vt;
RECT rc;
} VECT;
unsigned char CharInWnd[] = "ijڿÙÀÅôÁÂ";
unsigned char VectCvt[3][11][2][4] = {
{ /* --- first character in collision vector --- */
/* ( drawing Ä ) ( drawing ³ ) */
{{"ÄÄÄ"}, {"ÚÃÀ"}},
{{"Ú¿"}, {"³³³"}},
{{"ÚÂÂ"}, {"ÚÃÃ"}},
{{"¿¿¿"}, {"¿¿¿"}},
{{"ÙÙÙ"}, {"ÙÙÙ"}},
{{"ÀÁÁ"}, {"ÃÃÀ"}},
{{"ÅÅÅ"}, {"ÅÅÅ"}},
{{"ÃÅÅ"}, {"ÃÃÃ"}},
{{"´´´"}, {"´´´"}},
{{"ÁÁÁ"}, {"ÁÁÁ"}},
{{"ÂÂÂ"}, {"ÂÅÅ"}} },
{ /* --- middle character in collision vector --- */
/* ( drawing Ä ) ( drawing ³ ) */
{{"ÄÄÄ"}, {"ÂÅÁ"}},
{{"ÃÅ´"}, {"³³³"}},
{{"ÚÚÚ"}, {"ÚÚÚ"}},
{{"¿¿¿"}, {"¿¿¿"}},
{{"ÙÙÙ"}, {"ÙÙÙ"}},
{{"ÀÀÀ"}, {"ÀÀÀ"}},
{{"ÅÅÅ"}, {"ÅÅÅ"}},
{{"ÃÃÃ"}, {"ÃÃÃ"}},
{{"ÅÅ´"}, {"´´´"}},
{{"ÁÁÁ"}, {"ÅÅÁ"}},
{{"ÂÂÂ"}, {"ÂÂÂ"}} },
{ /* --- last character in collision vector --- */
/* ( drawing Ä ) ( drawing ³ ) */
{{"ÄÄÄ"}, {"¿´Ù"}},
{{"ÀÁÙ"}, {"³³³"}},
{{"ÚÚÚ"}, {"ÚÚÚ"}},
{{"¿"}, {"¿´´"}},
{{"ÁÁÙ"}, {"´´Ù"}},
{{"ÀÀÀ"}, {"ÀÀÀ"}},
{{"ÅÅÅ"}, {"ÅÅÅ"}},
{{"ÃÃÃ"}, {"ÃÃÃ"}},
{{"ÅÅ´"}, {"´´´"}},
{{"ÁÁÁ"}, {"ÅÅÁ"}},
{{"ÂÂÂ"}, {"ÂÂÂ"}} }
};
/* -- compute whether character is first, middle, or last -- */
static int FindVector(WINDOW wnd, RECT rc, int x, int y)
{
RECT rcc;
VECT *vc = wnd->VectorList;
int i, coll = -1;
for (i = 0; i < wnd->VectorCount; i++) {
if ((vc+i)->vt == VECTOR) {
rcc = (vc+i)->rc;
/* --- skip the colliding vector --- */
if (rcc.lf == rc.lf && rcc.rt == rc.rt &&
rcc.tp == rc.tp && rc.bt == rcc.bt)
continue;
if (rcc.tp == rcc.bt) {
/* ---- horizontal vector,
see if character is in it --- */
if (rc.lf+x >= rcc.lf && rc.lf+x <= rcc.rt &&
rc.tp+y == rcc.tp) {
/* --- it is --- */
if (rc.lf+x == rcc.lf)
coll = 0;
else if (rc.lf+x == rcc.rt)
coll = 2;
else
coll = 1;
}
}
else {
/* ---- vertical vector,
see if character is in it --- */
if (rc.tp+y >= rcc.tp && rc.tp+y <= rcc.bt &&
rc.lf+x == rcc.lf) {
/* --- it is --- */
if (rc.tp+y == rcc.tp)
coll = 0;
else if (rc.tp+y == rcc.bt)
coll = 2;
else
coll = 1;
}
}
}
}
return coll;
}
static void PaintVector(WINDOW wnd, RECT rc)
{
int i, xi, yi, len;
unsigned int ch, nc;
unsigned int newch;
static int cw, fml, vertvect, coll;
if (rc.rt == rc.lf) {
/* ------ vertical vector ------- */
nc = '³';
vertvect = 1;
len = rc.bt-rc.tp+1;
}
else {
/* ------ horizontal vector ------- */
nc = 'Ä';
vertvect = 0;
len = rc.rt-rc.lf+1;
}
for (i = 0; i < len; i++) {
newch = nc;
xi = yi = 0;
if (vertvect)
yi = i;
else
xi = i;
ch = videochar(GetClientLeft(wnd)+rc.lf+xi,
GetClientTop(wnd)+rc.tp+yi);
for (cw = 0; cw < sizeof(CharInWnd); cw++) {
if (ch == CharInWnd[cw]) {
/* ---- hit another vector character ---- */
if ((coll=FindVector(wnd, rc, xi, yi)) != -1) {
/* compute first/middle/last subscript */
if (i == len-1)
fml = 2;
else if (i == 0)
fml = 0;
else
fml = 1;
newch = VectCvt[coll][cw][vertvect][fml];
}
}
}
PutWindowChar(wnd, newch, rc.lf+xi, rc.tp+yi);
}
}
static void PaintBar(WINDOW wnd, RECT rc, enum VectTypes vt)
{
int i, vertbar, len;
unsigned int tys[] = {219, 178, 177, 176};
/* unsigned int tys[] = {'Û', '²', '±', '°'};
*/
unsigned int nc = tys[vt-1];
if (rc.rt == rc.lf) {
/* ------ vertical bar ------- */
vertbar = 1;
len = rc.bt-rc.tp+1;
}
else {
/* ------ horizontal bar ------- */
vertbar = 0;
len = rc.rt-rc.lf+1;
}
for (i = 0; i < len; i++) {
int xi = 0, yi = 0;
if (vertbar)
yi = i;
else
xi = i;
PutWindowChar(wnd, nc, rc.lf+xi, rc.tp+yi);
}
}
static void PaintMsg(WINDOW wnd)
{
int i;
VECT *vc = wnd->VectorList;
for (i = 0; i < wnd->VectorCount; i++) {
if (vc->vt == VECTOR)
PaintVector(wnd, vc->rc);
else
PaintBar(wnd, vc->rc, vc->vt);
vc++;
}
}
static void DrawVectorMsg(WINDOW wnd,PARAM p1,enum VectTypes vt)
{
if (p1) {
VECT vc;
wnd->VectorList = DFrealloc(wnd->VectorList,
sizeof(VECT) * (wnd->VectorCount + 1));
vc.vt = vt;
vc.rc = *(RECT *)p1;
*(((VECT *)(wnd->VectorList))+wnd->VectorCount)=vc;
wnd->VectorCount++;
}
}
static void DrawBoxMsg(WINDOW wnd, PARAM p1)
{
if (p1) {
RECT rc = *(RECT *)p1;
rc.bt = rc.tp;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, TRUE);
rc = *(RECT *)p1;
rc.lf = rc.rt;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, FALSE);
rc = *(RECT *)p1;
rc.tp = rc.bt;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, TRUE);
rc = *(RECT *)p1;
rc.rt = rc.lf;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, FALSE);
}
}
int PictureProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case PAINT:
BaseWndProc(PICTUREBOX, wnd, msg, p1, p2);
PaintMsg(wnd);
return TRUE;
case DRAWVECTOR:
DrawVectorMsg(wnd, p1, VECTOR);
return TRUE;
case DRAWBOX:
DrawBoxMsg(wnd, p1);
return TRUE;
case DRAWBAR:
DrawVectorMsg(wnd, p1, (enum VectTypes)p2);
return TRUE;
case CLOSE_WINDOW:
if (wnd->VectorList != NULL)
free(wnd->VectorList);
break;
default:
break;
}
return BaseWndProc(PICTUREBOX, wnd, msg, p1, p2);
}
static RECT PictureRect(int x, int y, int len, int hv)
{
RECT rc;
rc.lf = rc.rt = x;
rc.tp = rc.bt = y;
if (hv)
/* ---- horizontal vector ---- */
rc.rt += len-1;
else
/* ---- vertical vector ---- */
rc.bt += len-1;
return rc;
}
void DrawVector(WINDOW wnd, int x, int y, int len, int hv)
{
RECT rc = PictureRect(x,y,len,hv);
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, 0);
}
void DrawBox(WINDOW wnd, int x, int y, int ht, int wd)
{
RECT rc;
rc.lf = x;
rc.tp = y;
rc.rt = x+wd-1;
rc.bt = y+ht-1;
SendMessage(wnd, DRAWBOX, (PARAM) &rc, 0);
}
void DrawBar(WINDOW wnd,enum VectTypes vt,
int x,int y,int len,int hv)
{
RECT rc = PictureRect(x,y,len,hv);
SendMessage(wnd, DRAWBAR, (PARAM) &rc, (PARAM) vt);
}
#endif