fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / bgui / vectorclass.c
blob128106b62b8a6e5df1ba1cc2e8793cc7c5a7ffac
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * vectorclass.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.7 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.6 2003/01/18 19:10:03 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.5 2000/08/08 20:57:26 chodorowski
21 * Minor fixes to build on Amiga.
23 * Revision 42.4 2000/05/29 15:42:49 stegerg
24 * fixed some "comparison is always 1 due to limited range of data type"
25 * errors
27 * Revision 42.3 2000/05/29 00:40:24 bergers
28 * Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
30 * Revision 42.2 2000/05/15 19:27:02 stegerg
31 * another hundreds of REG() macro replacements in func headers/protos.
33 * Revision 42.1 2000/05/14 23:32:48 stegerg
34 * changed over 200 function headers which all use register
35 * parameters (oh boy ...), because the simple REG() macro
36 * doesn't work with AROS. And there are still hundreds
37 * of headers left to be fixed :(
39 * Many of these functions would also work with stack
40 * params, but since i have fixed every single one
41 * I encountered up to now, I guess will have to do
42 * the same for the rest.
44 * Revision 42.0 2000/05/09 22:10:34 mlemos
45 * Bumped to revision 42.0 before handing BGUI to AROS team
47 * Revision 41.11 2000/05/09 19:55:23 mlemos
48 * Merged with the branch Manuel_Lemos_fixes.
50 * Revision 41.10.2.1 1998/11/16 20:01:56 mlemos
51 * Replaced AllocVec and FreeVec calls by BGUI_AllocPoolMem and
52 * BGUI_FreePoolMem calls respectively.
53 * Restored prior RastPort AreaInfo and TmpRas after rendering.
55 * Revision 41.10 1998/02/25 21:13:26 mlemos
56 * Bumping to 41.10
58 * Revision 1.1 1998/02/25 17:10:00 mlemos
59 * Ian sources
64 /// Class definitions.
66 #include "include/classdefs.h"
69 * Object instance data.
71 typedef struct {
72 struct TmpRas vd_TmpRas; /* TmpRas for areafill's. */
73 struct AreaInfo vd_AreaInfo; /* AreaInfo for areafill's. */
74 UWORD vd_SizeX; /* Design width. */
75 UWORD vd_SizeY; /* Design height. */
76 UWORD vd_MinWidth; /* Minimum width. */
77 UWORD vd_MinHeight; /* Minimum height. */
78 UWORD vd_BuiltInType; /* Built-in type. */
79 UWORD vd_Flags; /* Flags (see below). */
80 UWORD vd_Pen; /* Pen to use for drawing. */
81 UWORD vd_DriPen; /* DriPen to use for drawing. */
82 struct VectorItem *vd_VectorArray; /* The vector elements. */
83 PLANEPTR vd_AreaPlane; /* Bit-plane for areafills. */
84 WORD *vd_VertexBuffer; /* Buffer for areafills. */
85 UWORD vd_PlaneWidth; /* Width of area-plane. */
86 UWORD vd_PlaneHeight; /* Height of area-plane. */
87 UWORD vd_ErasePen; /* Pen to erase with. */
88 struct TmpRas *vd_OldTmpRas; /* TmpRas before rendering. */
89 struct AreaInfo *vd_OldAreaInfo; /* AreaInfo before rendering. */
90 } VD;
92 #define VDATF_AREA (1<<0) /* We are area filling. */
94 ///
95 /// Built-in images.
98 * Built-in GETPATH image.
100 STATIC struct VectorItem BuiltinGetPath[] = {
101 { 20, 14, VIF_SCALE },
102 { 4, 4, VIF_MOVE | VIF_AREASTART },
103 { 8, 4, VIF_DRAW },
104 { 9, 5, VIF_DRAW },
105 { 5, 5, VIF_DRAW },
106 { 5, 2, VIF_DRAW | VIF_YRELBOTTOM },
107 { 4, 2, VIF_DRAW | VIF_YRELBOTTOM },
108 { 4, 4, VIF_AREAEND },
109 { 8, 4, VIF_MOVE },
110 { 9, 2, VIF_DRAW | VIF_XRELRIGHT },
111 { 6, 2, VIF_DRAW | VIF_XRELRIGHT },
112 { 4, 4, VIF_DRAW | VIF_XRELRIGHT },
113 { 4, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
114 { 4, 2, VIF_DRAW | VIF_YRELBOTTOM },
115 { 9, 5, VIF_MOVE },
116 { 8, 6, VIF_DRAW | VIF_XRELRIGHT },
117 { 4, 6, VIF_DRAW | VIF_XRELRIGHT | VIF_LASTITEM },
121 * Built-in GETFILE image.
123 STATIC struct VectorItem BuiltinGetFile[] = {
124 { 20, 14, VIF_SCALE },
125 { 4, 2, VIF_MOVE | VIF_AREASTART },
126 { 5, 2, VIF_DRAW },
127 { 5, 2, VIF_DRAW | VIF_YRELBOTTOM },
128 { 4, 2, VIF_DRAW | VIF_YRELBOTTOM },
129 { 4, 2, VIF_AREAEND },
130 { 4, 2, VIF_MOVE },
131 { 8, 2, VIF_DRAW | VIF_XRELRIGHT },
132 { 4, 6, VIF_DRAW | VIF_XRELRIGHT },
133 { 8, 6, VIF_DRAW | VIF_XRELRIGHT },
134 { 8, 2, VIF_DRAW | VIF_XRELRIGHT },
135 { 4, 2, VIF_MOVE | VIF_YRELBOTTOM },
136 { 4, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
137 { 5, 6, VIF_MOVE | VIF_XRELRIGHT | VIF_AREASTART },
138 { 4, 6, VIF_DRAW | VIF_XRELRIGHT },
139 { 4, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
140 { 5, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
141 { 5, 6, VIF_LASTITEM | VIF_XRELRIGHT },
145 * Built-in CheckMark image.
147 STATIC struct VectorItem BuiltinCheckMark[] = {
148 { 24, 11, VIF_SCALE },
149 { 6, 5, VIF_MOVE | VIF_AREASTART },
150 { 9, 8, VIF_DRAW },
151 { 11, 8, VIF_DRAW },
152 { 6, 2, VIF_DRAW | VIF_XRELRIGHT },
153 { 5, 2, VIF_DRAW | VIF_XRELRIGHT },
154 { 7, 2, VIF_DRAW | VIF_XRELRIGHT },
155 { 11, 7, VIF_DRAW },
156 { 10, 7, VIF_DRAW },
157 { 8, 5, VIF_DRAW },
158 { 6, 5, VIF_LASTITEM },
162 * Built-in RadioButton image.
164 STATIC struct VectorItem BuiltinRadioButton[] = {
165 { 16, 8, VIF_SCALE },
166 { 4, 3, VIF_MOVE | VIF_AREASTART },
167 { 6, 2, VIF_DRAW },
168 { 6, 2, VIF_DRAW | VIF_XRELRIGHT },
169 { 4, 3, VIF_DRAW | VIF_XRELRIGHT },
170 { 4, 3, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
171 { 6, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
172 { 6, 2, VIF_DRAW | VIF_YRELBOTTOM },
173 { 4, 3, VIF_DRAW | VIF_YRELBOTTOM },
174 { 4, 3, VIF_LASTITEM },
177 #if 0
179 * Built-in PopUp image.
181 STATIC struct VectorItem BuiltInPopUp[] = {
182 { 44, 20, VIF_MOVE | VIF_AREASTART },
183 { 56, 20, VIF_DRAW },
184 { 56, 35, VIF_DRAW },
185 { 73, 35, VIF_DRAW },
186 { 50, 55, VIF_DRAW },
187 { 27, 35, VIF_DRAW },
188 { 44, 35, VIF_DRAW },
189 { 44, 20, VIF_DRAW | VIF_AREAEND },
190 { 27, 70, VIF_MOVE | VIF_AREASTART },
191 { 73, 70, VIF_DRAW },
192 { 73, 77, VIF_DRAW },
193 { 27, 77, VIF_DRAW | VIF_AREAEND },
194 { 18, 14, VIF_MINSIZE },
195 { 100, 100, VIF_SCALE | VIF_LASTITEM },
199 * Built-in Cycle image.
201 STATIC struct VectorItem BuiltInCycle[] = {
202 { 18, 14, VIF_SCALE },
203 { 5, 3, VIF_MOVE | VIF_AREASTART | VIF_YRELBOTTOM },
204 { 6, 3, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
205 { 5, 4, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
206 { 5, 4, VIF_DRAW | VIF_YRELBOTTOM },
207 { 5, 4, VIF_DRAW },
208 { 6, 4, VIF_DRAW | VIF_XRELRIGHT },
209 { 6, 6, VIF_DRAW | VIF_XRELRIGHT },
210 { 8, 6, VIF_DRAW | VIF_XRELRIGHT },
211 { 6, 8, VIF_DRAW | VIF_XRELRIGHT },
212 { 5, 8, VIF_DRAW | VIF_XRELRIGHT },
213 { 3, 6, VIF_DRAW | VIF_XRELRIGHT },
214 { 5, 6, VIF_DRAW | VIF_XRELRIGHT },
215 { 5, 4, VIF_DRAW | VIF_XRELRIGHT },
216 { 6, 3, VIF_DRAW | VIF_XRELRIGHT },
217 { 5, 3, VIF_DRAW },
218 { 4, 4, VIF_DRAW },
219 { 4, 4, VIF_DRAW | VIF_AREAEND | VIF_YRELBOTTOM | VIF_LASTITEM },
223 * Built-in Cycle image - selected.
225 STATIC struct VectorItem BuiltInCycle2[] = {
226 { 18, 14, VIF_SCALE },
227 { 5, 3, VIF_MOVE | VIF_XRELRIGHT | VIF_AREASTART },
228 { 6, 3, VIF_DRAW },
229 { 5, 4, VIF_DRAW },
230 { 5, 4, VIF_DRAW | VIF_XRELRIGHT },
231 { 5, 4, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
232 { 6, 4, VIF_DRAW | VIF_YRELBOTTOM },
233 { 6, 6, VIF_DRAW | VIF_YRELBOTTOM },
234 { 8, 6, VIF_DRAW | VIF_YRELBOTTOM },
235 { 6, 8, VIF_DRAW | VIF_YRELBOTTOM },
236 { 5, 8, VIF_DRAW | VIF_YRELBOTTOM },
237 { 3, 6, VIF_DRAW | VIF_YRELBOTTOM },
238 { 5, 6, VIF_DRAW | VIF_YRELBOTTOM },
239 { 5, 4, VIF_DRAW | VIF_YRELBOTTOM },
240 { 6, 3, VIF_DRAW | VIF_YRELBOTTOM },
241 { 5, 3, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
242 { 4, 4, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
243 { 4, 4, VIF_DRAW | VIF_XRELRIGHT | VIF_AREAEND | VIF_LASTITEM },
245 #endif
248 * Built-in PopUp image.
250 STATIC struct VectorItem BuiltInPopUp[] = {
251 { 15, 13, VIF_SCALE },
252 { 6, 2, VIF_MOVE | VIF_AREASTART },
253 { 8, 2, VIF_DRAW },
254 { 8, 4, VIF_DRAW },
255 { 10, 4, VIF_DRAW },
256 { 7, 7, VIF_DRAW },
257 { 4, 4, VIF_DRAW },
258 { 6, 4, VIF_DRAW },
259 { 6, 2, VIF_DRAW | VIF_AREAEND },
260 { 4, 9, VIF_MOVE | VIF_AREASTART },
261 { 10, 9, VIF_DRAW },
262 { 10, 10, VIF_DRAW },
263 { 4, 10, VIF_DRAW | VIF_AREAEND | VIF_LASTITEM },
267 * Built-in Cycle image.
269 STATIC struct VectorItem BuiltInCycle[] = {
270 { 17, 13, VIF_SCALE },
271 { 4, 10, VIF_MOVE | VIF_AREASTART},
272 { 10, 10, VIF_DRAW },
273 { 11, 9, VIF_DRAW },
274 { 4, 9, VIF_DRAW },
275 { 4, 3, VIF_DRAW },
276 { 10, 3, VIF_DRAW },
277 { 10, 5, VIF_DRAW },
278 { 8, 5, VIF_DRAW },
279 { 10, 7, VIF_DRAW },
280 { 11, 7, VIF_DRAW },
281 { 13, 5, VIF_DRAW },
282 { 11, 5, VIF_DRAW },
283 { 11, 3, VIF_DRAW },
284 { 10, 2, VIF_DRAW },
285 { 4, 2, VIF_DRAW },
286 { 3, 3, VIF_DRAW },
287 { 3, 9, VIF_DRAW | VIF_AREAEND | VIF_LASTITEM },
291 * Built-in Cycle image - selected.
293 STATIC struct VectorItem BuiltInCycle2[] = {
294 { 17, 13, VIF_SCALE },
295 { 11, 2, VIF_MOVE | VIF_AREASTART},
296 { 5, 2, VIF_DRAW },
297 { 4, 3, VIF_DRAW },
298 { 11, 3, VIF_DRAW },
299 { 11, 9, VIF_DRAW },
300 { 5, 9, VIF_DRAW },
301 { 5, 7, VIF_DRAW },
302 { 7, 7, VIF_DRAW },
303 { 5, 5, VIF_DRAW },
304 { 4, 5, VIF_DRAW },
305 { 2, 7, VIF_DRAW },
306 { 4, 7, VIF_DRAW },
307 { 4, 9, VIF_DRAW },
308 { 5, 10, VIF_DRAW },
309 { 11, 10, VIF_DRAW },
310 { 12, 9, VIF_DRAW },
311 { 12, 3, VIF_DRAW | VIF_AREAEND | VIF_LASTITEM },
315 * Built-in arrow up image.
317 STATIC struct VectorItem BuiltInArrowUp[] = {
318 { 16, 9, VIF_SCALE },
319 { 3, 6, VIF_MOVE | VIF_AREASTART },
320 { 8, 2, VIF_DRAW | VIF_XRELRIGHT },
321 { 8, 2, VIF_DRAW },
322 { 3, 6, VIF_DRAW | VIF_XRELRIGHT },
323 { 4, 6, VIF_DRAW | VIF_XRELRIGHT },
324 { 8, 3, VIF_DRAW },
325 { 8, 3, VIF_DRAW | VIF_XRELRIGHT },
326 { 4, 6, VIF_DRAW | VIF_LASTITEM },
330 * Built-in arrow DOWN vector image.
332 STATIC struct VectorItem BuiltInArrowDown[] = {
333 { 16, 9, VIF_SCALE },
334 { 3, 6, VIF_MOVE | VIF_AREASTART | VIF_YRELBOTTOM },
335 { 8, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
336 { 8, 2, VIF_DRAW | VIF_YRELBOTTOM },
337 { 3, 6, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
338 { 4, 6, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
339 { 8, 3, VIF_DRAW | VIF_YRELBOTTOM },
340 { 8, 3, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
341 { 4, 6, VIF_DRAW | VIF_LASTITEM | VIF_YRELBOTTOM },
345 * Built-in arrow LEFT vector image.
347 STATIC struct VectorItem BuiltInArrowLeft[] = {
348 { 10, 12, VIF_SCALE },
349 { 6, 2, VIF_MOVE | VIF_AREASTART },
350 { 3, 6, VIF_DRAW | VIF_YRELBOTTOM },
351 { 3, 6, VIF_DRAW },
352 { 6, 2, VIF_DRAW | VIF_YRELBOTTOM },
353 { 6, 3, VIF_DRAW | VIF_YRELBOTTOM },
354 { 4, 6, VIF_DRAW },
355 { 4, 6, VIF_DRAW | VIF_YRELBOTTOM },
356 { 6, 3, VIF_DRAW | VIF_LASTITEM },
360 * Built-in arrow RIGHT vector image.
362 STATIC struct VectorItem BuiltInArrowRight[] = {
363 { 10, 12, VIF_SCALE },
364 { 6, 2, VIF_MOVE | VIF_AREASTART | VIF_XRELRIGHT },
365 { 3, 6, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
366 { 3, 6, VIF_DRAW | VIF_XRELRIGHT },
367 { 6, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
368 { 6, 3, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
369 { 4, 6, VIF_DRAW | VIF_XRELRIGHT },
370 { 4, 6, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
371 { 6, 3, VIF_DRAW | VIF_LASTITEM | VIF_XRELRIGHT },
375 * Built-in GETFONT image.
377 STATIC struct VectorItem BuiltInGetFont[] = {
378 { 8, 4, VIF_MOVE | VIF_AREASTART },
379 { 10, 4, VIF_DRAW },
380 { 10, 4, VIF_DRAW | VIF_YRELBOTTOM },
381 { 8, 4, VIF_DRAW | VIF_YRELBOTTOM },
382 { 8, 4, VIF_AREAEND },
383 { 8, 4, VIF_MOVE | VIF_AREASTART },
384 { 18, 4, VIF_DRAW },
385 { 20, 6, VIF_DRAW },
386 { 20, 12, VIF_DRAW },
387 { 18, 14, VIF_DRAW },
388 { 20, 12, VIF_DRAW | VIF_YRELBOTTOM },
389 { 20, 6, VIF_DRAW | VIF_YRELBOTTOM },
390 { 18, 4, VIF_DRAW | VIF_YRELBOTTOM },
391 { 9, 4, VIF_DRAW | VIF_YRELBOTTOM },
392 { 9, 6, VIF_DRAW | VIF_YRELBOTTOM },
393 { 17, 6, VIF_DRAW | VIF_YRELBOTTOM },
394 { 18, 7, VIF_DRAW | VIF_YRELBOTTOM },
395 { 18, 12, VIF_DRAW | VIF_YRELBOTTOM },
396 { 17, 13, VIF_DRAW | VIF_YRELBOTTOM },
397 { 9, 13, VIF_DRAW | VIF_YRELBOTTOM },
398 { 9, 13, VIF_DRAW },
399 { 17, 13, VIF_DRAW },
400 { 18, 12, VIF_DRAW },
401 { 18, 7, VIF_DRAW },
402 { 17, 6, VIF_DRAW },
403 { 9, 6, VIF_DRAW | VIF_AREAEND },
405 { 24, 4, VIF_MOVE | VIF_AREASTART },
406 { 26, 4, VIF_DRAW },
407 { 26, 4, VIF_DRAW | VIF_YRELBOTTOM },
408 { 24, 4, VIF_DRAW | VIF_YRELBOTTOM },
409 { 24, 4, VIF_DRAW | VIF_AREAEND },
410 { 25, 13, VIF_MOVE | VIF_AREASTART },
411 { 30, 13, VIF_DRAW },
412 { 32, 13, VIF_DRAW | VIF_YRELBOTTOM },
413 { 32, 6, VIF_DRAW | VIF_YRELBOTTOM },
414 { 30, 4, VIF_DRAW | VIF_YRELBOTTOM },
415 { 25, 4, VIF_DRAW | VIF_YRELBOTTOM },
416 { 25, 6, VIF_DRAW | VIF_YRELBOTTOM },
417 { 29, 6, VIF_DRAW | VIF_YRELBOTTOM },
418 { 30, 7, VIF_DRAW | VIF_YRELBOTTOM },
419 { 30, 12, VIF_DRAW | VIF_YRELBOTTOM },
420 { 29, 13, VIF_DRAW | VIF_YRELBOTTOM },
421 { 25, 13, VIF_DRAW | VIF_YRELBOTTOM | VIF_AREAEND },
423 { 20, 14, VIF_MINSIZE },
424 { 40, 28, VIF_SCALE | VIF_LASTITEM },
428 * Built-in GETSCREEN image.
430 STATIC struct VectorItem BuiltInGetScreen[] = {
431 { 20, 14, VIF_SCALE },
432 { 4, 2, VIF_MOVE | VIF_AREASTART },
433 { 5, 2, VIF_DRAW },
434 { 5, 2, VIF_DRAW | VIF_YRELBOTTOM },
435 { 4, 2, VIF_DRAW | VIF_YRELBOTTOM },
436 { 4, 2, VIF_AREAEND },
437 { 4, 2, VIF_MOVE },
438 { 8, 2, VIF_DRAW | VIF_XRELRIGHT },
439 { 4, 6, VIF_DRAW | VIF_XRELRIGHT },
440 { 8, 6, VIF_DRAW | VIF_XRELRIGHT },
441 { 8, 2, VIF_DRAW | VIF_XRELRIGHT },
442 { 4, 2, VIF_MOVE | VIF_YRELBOTTOM },
443 { 4, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
444 { 5, 6, VIF_MOVE | VIF_XRELRIGHT | VIF_AREASTART },
445 { 4, 6, VIF_DRAW | VIF_XRELRIGHT },
446 { 4, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
447 { 5, 2, VIF_DRAW | VIF_XRELRIGHT | VIF_YRELBOTTOM },
448 { 5, 6, VIF_LASTITEM | VIF_XRELRIGHT },
451 static struct VectorItem *BuiltIn[] =
453 NULL,
454 BuiltinGetPath,
455 BuiltinGetFile,
456 BuiltinCheckMark,
457 BuiltInPopUp,
458 BuiltInArrowUp,
459 BuiltInArrowDown,
460 BuiltInArrowLeft,
461 BuiltInArrowRight,
462 BuiltInCycle,
463 BuiltInCycle2,
464 BuiltinRadioButton,
465 BuiltInGetFont,
466 BuiltInGetScreen,
471 * Deallocate the AreaFill() stuff.
473 STATIC ASM VOID CleanUpArea( REG(a0) struct RastPort *rp, REG(a1) VD *vd )
475 if (vd->vd_Flags & VDATF_AREA)
478 * Don't deallocate to soon.
480 WaitBlit();
482 rp->TmpRas=vd->vd_OldTmpRas;
483 rp->AreaInfo=vd->vd_OldAreaInfo;
486 * Deallocate the buffers.
488 if (vd->vd_AreaPlane)
490 FreeRaster( vd->vd_AreaPlane, vd->vd_PlaneWidth, vd->vd_PlaneHeight );
491 vd->vd_AreaPlane = NULL;
494 if (vd->vd_VertexBuffer)
496 BGUI_FreePoolMem( vd->vd_VertexBuffer );
497 vd->vd_VertexBuffer = NULL;
500 vd->vd_PlaneWidth = vd->vd_PlaneHeight = 0;
503 * Mark us as not area filling.
505 vd->vd_Flags &= ~VDATF_AREA;
510 * Allocate the necessary stuff
511 * for area filling. If this fails
512 * the image areas are not filled.
514 STATIC ULONG SetupArea( struct RastPort *rp, VD *vd, struct VectorItem *vi, UWORD w, UWORD h )
516 UWORD numelem = 0;
517 struct VectorItem *vi2;
520 * Count the number of vector elements
521 ** in the area fill operation.
523 for (vi2 = vi; !(vi2->vi_Flags & (VIF_AREAEND|VIF_LASTITEM)); vi2++);
526 * Safety margins.
528 numelem = vi2 - vi + 2;
530 w <<= 1;
531 h <<= 1;
534 * Allocate and setup the buffers etc.
536 if ((vd->vd_VertexBuffer = (UWORD *)BGUI_AllocPoolMem(numelem * 5)))
538 memset(vd->vd_VertexBuffer,'\0',numelem * 5);
539 if ((vd->vd_AreaPlane = AllocRaster(w, h))) {
541 * Initialize structures.
543 InitTmpRas( &vd->vd_TmpRas, vd->vd_AreaPlane, RASSIZE( w, h ));
544 InitArea( &vd->vd_AreaInfo, vd->vd_VertexBuffer, numelem );
546 * Set them up.
548 vd->vd_OldTmpRas = rp->TmpRas;
549 rp->TmpRas = &vd->vd_TmpRas;
550 vd->vd_OldAreaInfo = rp->AreaInfo;
551 rp->AreaInfo = &vd->vd_AreaInfo;
553 * Mark raster size.
555 vd->vd_PlaneWidth = w;
556 vd->vd_PlaneHeight = h;
558 * Mark us as area filling.
560 vd->vd_Flags |= VDATF_AREA;
562 return 1;
566 * Oops. Screw up somewhere.
568 CleanUpArea(rp, vd);
570 return 0;
573 /// OM_NEW
575 * Create a shiny new object.
577 METHOD(VectorClassNew, struct opSet *, ops)
579 VD *vd;
580 IPTR rc;
583 * First we let the superclass
584 * create a new object.
586 if ((rc = AsmDoSuperMethodA(cl, obj, (Msg)ops)))
589 * Get us the instance data.
591 vd = INST_DATA(cl, rc);
594 * Setup defaults.
596 vd->vd_Pen = vd->vd_DriPen = (UWORD)~0;
599 * Setup the object.
601 AsmCoerceMethod(cl, (Object *)rc, OM_SET, ops->ops_AttrList, NULL);
603 return rc;
605 METHOD_END
607 /// OM_SET
609 * Change one or more attrubutes.
611 METHOD(VectorClassSet, struct opSet *, ops)
613 VD *vd = INST_DATA(cl, obj);
614 IPTR data;
615 struct TagItem *tag;
616 struct TagItem *tstate = ops->ops_AttrList;
617 BOOL resize = FALSE;
618 struct VectorItem *vi;
619 ULONG rc;
622 * First we let the superclass
623 * change the attributes it
624 * knows.
626 rc = AsmDoSuperMethodA(cl, obj, (Msg)ops);
629 * Get the attributes.
631 while ((tag = NextTagItem(&tstate)))
633 data = tag->ti_Data;
634 switch (tag->ti_Tag)
636 case VIT_VectorArray:
637 vd->vd_VectorArray = (struct VectorItem *)data;
638 resize = TRUE;
639 break;
641 case VIT_BuiltIn:
642 vd->vd_VectorArray = BuiltIn[data];
643 vd->vd_BuiltInType = data;
644 resize = TRUE;
645 break;
647 case VIT_Pen:
648 vd->vd_Pen = data;
649 break;
651 case VIT_DriPen:
652 vd->vd_DriPen = data;
653 break;
655 case IMAGE_ErasePen:
656 vd->vd_ErasePen = data;
657 break;
661 if (resize)
664 * Setup the default minimums.
666 vd->vd_MinWidth = 0;
667 vd->vd_MinHeight = 0;
669 for (vi = vd->vd_VectorArray; resize; vi++)
671 if (vi->vi_Flags & VIF_SCALE)
674 * Setup the design size.
676 vd->vd_SizeX = vi->vi_x;
677 vd->vd_SizeY = vi->vi_y;
679 if (vi->vi_Flags & VIF_MINSIZE)
682 * Setup the design size.
684 vd->vd_MinWidth = vi->vi_x;
685 vd->vd_MinHeight = vi->vi_y;
687 if (vi->vi_Flags & VIF_LASTITEM) resize = FALSE;
689 if (!vd->vd_MinWidth) vd->vd_MinWidth = vd->vd_SizeX;
690 if (!vd->vd_MinHeight) vd->vd_MinHeight = vd->vd_SizeY;
692 return rc;
694 METHOD_END
696 /// OM_GET
698 * Give an attribute value.
700 METHOD(VectorClassGet, struct opGet *, opg)
702 VD *vd = INST_DATA( cl, obj );
703 ULONG rc = 1;
704 IPTR *store = opg->opg_Storage;
707 * Firts we see if the attribute
708 * they want is know to us. If not
709 * we pass it onto the superclass.
711 switch (opg->opg_AttrID)
713 case VIT_VectorArray: STORE vd->vd_VectorArray; break;
714 case VIT_BuiltIn: STORE vd->vd_BuiltInType; break;
715 case VIT_Pen: STORE vd->vd_Pen; break;
716 case VIT_DriPen: STORE vd->vd_DriPen; break;
717 case VIT_MinWidth: STORE vd->vd_MinWidth; break;
718 case VIT_MinHeight: STORE vd->vd_MinHeight; break;
719 default:
720 rc = AsmDoSuperMethodA(cl, obj, (Msg)opg);
721 break;
724 return rc;
726 METHOD_END
728 /// BASE_RENDER
730 * Render the vector image.
732 METHOD(VectorClassRender, struct bmRender *, bmr)
734 VD *vd = INST_DATA(cl, obj);
735 struct VectorItem *vi = vd->vd_VectorArray;
736 struct BaseInfo *bi = bmr->bmr_BInfo;
737 struct RastPort *rp = bi->bi_RPort;
738 ULONG rc = 1, f;
739 int l, t, r, b, w, h, x, y;
740 BOOL go = TRUE;
743 * Only render if there are vector
744 * elements to render.
746 if (!vi) return 1;
749 * Get image position and dimensions.
751 l = IMAGE(obj)->LeftEdge;
752 t = IMAGE(obj)->TopEdge;
753 w = IMAGE(obj)->Width;
754 h = IMAGE(obj)->Height;
757 * Get image right and bottom edge coordinates.
759 r = l + w - 1;
760 b = t + h - 1;
763 * Setup the correct startup-pen.
765 if (vd->vd_DriPen != (UWORD)~0)
766 BSetDPenA(bi, vd->vd_DriPen);
767 else if (vd->vd_Pen != (UWORD)~0)
768 BSetPenA(bi, vd->vd_Pen);
769 else
771 switch (bmr->bmr_Flags)
773 case IDS_SELECTED:
774 BSetDPenA(bi, FILLTEXTPEN);
775 break;
777 case IDS_INACTIVESELECTED:
778 default:
779 BSetDPenA(bi, TEXTPEN);
780 break;
785 * Jam only only color.
787 BSetDrMd(bi, JAM1);
790 * Clear rp pattern.
792 BClearAfPt(bi);
793 BNDRYOFF(rp);
796 * Loop through the vector elements.
798 for (; go; vi++)
800 f = vi->vi_Flags;
801 x = vi->vi_x;
802 y = vi->vi_y;
804 go = !(f & VIF_LASTITEM);
806 if (f & (VIF_SCALE|VIF_MINSIZE))
807 continue;
809 if (f & VIF_COLOR)
811 BSetPenA(bi, x);
812 if (f & VIF_BPEN) BSetPenB(bi, y);
813 continue;
815 if (f & VIF_DRIPEN)
817 BSetDPenA(bi, x);
818 if (f & VIF_BPEN) BSetDPenB(bi, y);
819 continue;
821 if (f & VIF_DRAWMODE)
823 BSetDrMd(bi, x);
824 continue;
827 if (f & VIF_LINEPATTERN)
829 SetDrPt(rp, x);
830 BSetDrMd(bi, JAM2);
831 continue;
834 if (f & VIF_AOLPEN) SetOPen(rp, x);
835 else if (f & VIF_ENDOPEN) BNDRYOFF(rp);
837 if (f & VIF_SHADOWPEN) BSetDPenA(bi, SHADOWPEN);
838 else if (f & VIF_SHINEPEN) BSetDPenA(bi, SHINEPEN);
839 else if (f & VIF_FILLPEN) BSetDPenA(bi, FILLPEN);
840 else if (f & VIF_TEXTPEN) BSetDPenA(bi, TEXTPEN);
843 * Do we need to setup an areafill?
845 if (f & VIF_AREASTART) SetupArea(rp, vd, vi, w, h);
848 * Calculate the X and Y coordinates.
850 if (vd->vd_SizeX) x = (x * w) / vd->vd_SizeX;
851 if (vd->vd_SizeY) y = (y * h) / vd->vd_SizeY;
854 * Calculate X from the correct edge.
856 if (f & VIF_XRELRIGHT) x = r - x;
857 else x += l;
860 * Calculate Y from the correct edge.
862 if (f & VIF_YRELBOTTOM) y = b - y;
863 else y += t;
866 * Check that the coordinates do
867 * not go outside the bounding box.
869 if (x < l) x = l;
870 else if (x > r) x = r;
872 if (y < t) y = t;
873 else if (y > b) y = b;
876 * (Area)Move or (Area)Draw to the
877 * coordinates.
879 if (f & VIF_MOVE)
881 if (vd->vd_Flags & VDATF_AREA) AreaMove(rp, x, y);
882 else Move(rp, x, y);
884 else if (f & VIF_DRAW)
886 if (vd->vd_Flags & VDATF_AREA) AreaDraw(rp, x, y);
887 else Draw(rp, x, y);
891 * Are we done area filling?
893 if (f & (VIF_AREAEND|VIF_LASTITEM))
895 if (vd->vd_Flags & VDATF_AREA)
897 AreaEnd(rp);
898 CleanUpArea(rp, vd);
903 * In case a color change or something unexpected gave us a VIF_AREAEND.
905 CleanUpArea(rp, vd);
907 return rc;
909 METHOD_END
912 /// Class initialization.
914 * Class function array.
916 STATIC DPFUNC ClassFunc[] = {
917 { BASE_RENDER, VectorClassRender, },
918 { OM_NEW, VectorClassNew, },
919 { OM_SET, VectorClassSet, },
920 { OM_GET, VectorClassGet, },
921 { DF_END, NULL },
925 * Simple class initialization.
927 makeproto Class *InitVectorClass(void)
929 return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_IMAGE_OBJECT,
930 CLASS_ObjectSize, sizeof(VD),
931 CLASS_DFTable, ClassFunc,
932 TAG_DONE);