- Move imagesoft to templates.
[reactos.git] / rosapps / dflat32 / pictbox.c
1 /* -------------- pictbox.c -------------- */
2
3 #include "dflat.h"
4
5 typedef struct {
6 enum DfVectTypes vt;
7 DFRECT rc;
8 } VECT;
9
10 unsigned char CharInWnd[] = "ijڿÙÀÅôÁÂ";
11
12 unsigned char VectCvt[3][11][2][4] = {
13 { /* --- first character in collision vector --- */
14 /* ( drawing Ä ) ( drawing ³ ) */
15 {{"ÄÄÄ"}, {"ÚÃÀ"}},
16 {{"Ú¿"}, {"³³³"}},
17 {{"ÚÂÂ"}, {"ÚÃÃ"}},
18 {{"¿¿¿"}, {"¿¿¿"}},
19 {{"ÙÙÙ"}, {"ÙÙÙ"}},
20 {{"ÀÁÁ"}, {"ÃÃÀ"}},
21 {{"ÅÅÅ"}, {"ÅÅÅ"}},
22 {{"ÃÅÅ"}, {"ÃÃÃ"}},
23 {{"´´´"}, {"´´´"}},
24 {{"ÁÁÁ"}, {"ÁÁÁ"}},
25 {{"ÂÂÂ"}, {"ÂÅÅ"}} },
26 { /* --- middle character in collision vector --- */
27 /* ( drawing Ä ) ( drawing ³ ) */
28 {{"ÄÄÄ"}, {"ÂÅÁ"}},
29 {{"ÃÅ´"}, {"³³³"}},
30 {{"ÚÚÚ"}, {"ÚÚÚ"}},
31 {{"¿¿¿"}, {"¿¿¿"}},
32 {{"ÙÙÙ"}, {"ÙÙÙ"}},
33 {{"ÀÀÀ"}, {"ÀÀÀ"}},
34 {{"ÅÅÅ"}, {"ÅÅÅ"}},
35 {{"ÃÃÃ"}, {"ÃÃÃ"}},
36 {{"ÅÅ´"}, {"´´´"}},
37 {{"ÁÁÁ"}, {"ÅÅÁ"}},
38 {{"ÂÂÂ"}, {"ÂÂÂ"}} },
39 { /* --- last character in collision vector --- */
40 /* ( drawing Ä ) ( drawing ³ ) */
41 {{"ÄÄÄ"}, {"¿´Ù"}},
42 {{"ÀÁÙ"}, {"³³³"}},
43 {{"ÚÚÚ"}, {"ÚÚÚ"}},
44 {{"¿"}, {"¿´´"}},
45 {{"ÁÁÙ"}, {"´´Ù"}},
46 {{"ÀÀÀ"}, {"ÀÀÀ"}},
47 {{"ÅÅÅ"}, {"ÅÅÅ"}},
48 {{"ÃÃÃ"}, {"ÃÃÃ"}},
49 {{"ÅÅ´"}, {"´´´"}},
50 {{"ÁÁÁ"}, {"ÅÅÁ"}},
51 {{"ÂÂÂ"}, {"ÂÂÂ"}} }
52 };
53
54 /* -- compute whether character is first, middle, or last -- */
55 static int FindVector(DFWINDOW wnd, DFRECT rc, int x, int y)
56 {
57 DFRECT rcc;
58 VECT *vc = wnd->VectorList;
59 int i, coll = -1;
60 for (i = 0; i < wnd->VectorCount; i++) {
61 if ((vc+i)->vt == DF_VECTOR) {
62 rcc = (vc+i)->rc;
63 /* --- skip the colliding vector --- */
64 if (rcc.lf == rc.lf && rcc.rt == rc.rt &&
65 rcc.tp == rc.tp && rc.bt == rcc.bt)
66 continue;
67 if (rcc.tp == rcc.bt) {
68 /* ---- horizontal vector,
69 see if character is in it --- */
70 if (rc.lf+x >= rcc.lf && rc.lf+x <= rcc.rt &&
71 rc.tp+y == rcc.tp) {
72 /* --- it is --- */
73 if (rc.lf+x == rcc.lf)
74 coll = 0;
75 else if (rc.lf+x == rcc.rt)
76 coll = 2;
77 else
78 coll = 1;
79 }
80 }
81 else {
82 /* ---- vertical vector,
83 see if character is in it --- */
84 if (rc.tp+y >= rcc.tp && rc.tp+y <= rcc.bt &&
85 rc.lf+x == rcc.lf) {
86 /* --- it is --- */
87 if (rc.tp+y == rcc.tp)
88 coll = 0;
89 else if (rc.tp+y == rcc.bt)
90 coll = 2;
91 else
92 coll = 1;
93 }
94 }
95 }
96 }
97 return coll;
98 }
99
100 static void PaintVector(DFWINDOW wnd, DFRECT rc)
101 {
102 int i, xi, yi, len;
103 unsigned int ch, nc;
104 unsigned int newch;
105 static int cw, fml, vertvect, coll;
106
107 if (rc.rt == rc.lf) {
108 /* ------ vertical vector ------- */
109 nc = '³';
110 vertvect = 1;
111 len = rc.bt-rc.tp+1;
112 }
113 else {
114 /* ------ horizontal vector ------- */
115 nc = 'Ä';
116 vertvect = 0;
117 len = rc.rt-rc.lf+1;
118 }
119
120 for (i = 0; i < len; i++) {
121 newch = nc;
122 xi = yi = 0;
123 if (vertvect)
124 yi = i;
125 else
126 xi = i;
127 ch = DfVideoChar(DfGetClientLeft(wnd)+rc.lf+xi,
128 DfGetClientTop(wnd)+rc.tp+yi);
129 for (cw = 0; cw < sizeof(CharInWnd); cw++) {
130 if (ch == CharInWnd[cw]) {
131 /* ---- hit another vector character ---- */
132 if ((coll=FindVector(wnd, rc, xi, yi)) != -1) {
133 /* compute first/middle/last subscript */
134 if (i == len-1)
135 fml = 2;
136 else if (i == 0)
137 fml = 0;
138 else
139 fml = 1;
140 newch = VectCvt[coll][cw][vertvect][fml];
141 }
142 }
143 }
144 DfPutWindowChar(wnd, newch, rc.lf+xi, rc.tp+yi);
145 }
146 }
147
148 static void PaintBar(DFWINDOW wnd, DFRECT rc, enum DfVectTypes vt)
149 {
150 int i, vertbar, len;
151 unsigned int tys[] = {219, 178, 177, 176};
152 /* unsigned int tys[] = {'Û', '²', '±', '°'};
153 */
154 unsigned int nc = tys[vt-1];
155
156 if (rc.rt == rc.lf) {
157 /* ------ vertical bar ------- */
158 vertbar = 1;
159 len = rc.bt-rc.tp+1;
160 }
161 else {
162 /* ------ horizontal bar ------- */
163 vertbar = 0;
164 len = rc.rt-rc.lf+1;
165 }
166
167 for (i = 0; i < len; i++) {
168 int xi = 0, yi = 0;
169 if (vertbar)
170 yi = i;
171 else
172 xi = i;
173 DfPutWindowChar(wnd, nc, rc.lf+xi, rc.tp+yi);
174 }
175 }
176
177 static void PaintMsg(DFWINDOW wnd)
178 {
179 int i;
180 VECT *vc = wnd->VectorList;
181 for (i = 0; i < wnd->VectorCount; i++) {
182 if (vc->vt == DF_VECTOR)
183 PaintVector(wnd, vc->rc);
184 else
185 PaintBar(wnd, vc->rc, vc->vt);
186 vc++;
187 }
188 }
189
190 static void DrawVectorMsg(DFWINDOW wnd,DF_PARAM p1,enum DfVectTypes vt)
191 {
192 if (p1) {
193 VECT vc;
194 wnd->VectorList = DfRealloc(wnd->VectorList,
195 sizeof(VECT) * (wnd->VectorCount + 1));
196 vc.vt = vt;
197 vc.rc = *(DFRECT *)p1;
198 *(((VECT *)(wnd->VectorList))+wnd->VectorCount)=vc;
199 wnd->VectorCount++;
200 }
201 }
202
203 static void DrawBoxMsg(DFWINDOW wnd, DF_PARAM p1)
204 {
205 if (p1) {
206 DFRECT rc = *(DFRECT *)p1;
207 rc.bt = rc.tp;
208 DfSendMessage(wnd, DFM_DRAWVECTOR, (DF_PARAM) &rc, TRUE);
209 rc = *(DFRECT *)p1;
210 rc.lf = rc.rt;
211 DfSendMessage(wnd, DFM_DRAWVECTOR, (DF_PARAM) &rc, FALSE);
212 rc = *(DFRECT *)p1;
213 rc.tp = rc.bt;
214 DfSendMessage(wnd, DFM_DRAWVECTOR, (DF_PARAM) &rc, TRUE);
215 rc = *(DFRECT *)p1;
216 rc.rt = rc.lf;
217 DfSendMessage(wnd, DFM_DRAWVECTOR, (DF_PARAM) &rc, FALSE);
218 }
219 }
220
221 int DfPictureProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
222 {
223 switch (msg) {
224 case DFM_PAINT:
225 DfBaseWndProc(DF_PICTUREBOX, wnd, msg, p1, p2);
226 PaintMsg(wnd);
227 return TRUE;
228 case DFM_DRAWVECTOR:
229 DrawVectorMsg(wnd, p1, DF_VECTOR);
230 return TRUE;
231 case DFM_DRAWBOX:
232 DrawBoxMsg(wnd, p1);
233 return TRUE;
234 case DFM_DRAWBAR:
235 DrawVectorMsg(wnd, p1, (enum DfVectTypes)p2);
236 return TRUE;
237 case DFM_CLOSE_WINDOW:
238 if (wnd->VectorList != NULL)
239 free(wnd->VectorList);
240 break;
241 default:
242 break;
243 }
244 return DfBaseWndProc(DF_PICTUREBOX, wnd, msg, p1, p2);
245 }
246
247 static DFRECT PictureRect(int x, int y, int len, int hv)
248 {
249 DFRECT rc;
250 rc.lf = rc.rt = x;
251 rc.tp = rc.bt = y;
252 if (hv)
253 /* ---- horizontal vector ---- */
254 rc.rt += len-1;
255 else
256 /* ---- vertical vector ---- */
257 rc.bt += len-1;
258 return rc;
259 }
260
261 void DfDrawVector(DFWINDOW wnd, int x, int y, int len, int hv)
262 {
263 DFRECT rc = PictureRect(x,y,len,hv);
264 DfSendMessage(wnd, DFM_DRAWVECTOR, (DF_PARAM) &rc, 0);
265 }
266
267 void DfDrawBox(DFWINDOW wnd, int x, int y, int ht, int wd)
268 {
269 DFRECT rc;
270 rc.lf = x;
271 rc.tp = y;
272 rc.rt = x+wd-1;
273 rc.bt = y+ht-1;
274 DfSendMessage(wnd, DFM_DRAWBOX, (DF_PARAM) &rc, 0);
275 }
276
277 void DfDrawBar(DFWINDOW wnd,enum DfVectTypes vt,
278 int x,int y,int len,int hv)
279 {
280 DFRECT rc = PictureRect(x,y,len,hv);
281 DfSendMessage(wnd, DFM_DRAWBAR, (DF_PARAM) &rc, (DF_PARAM) vt);
282 }
283
284 /* EOF */