disable debug
[AROS.git] / rom / hidds / graphics / GC_Class.c
bloba2a71f4e4758eae2e4f7909eb57d36d3fc4938f4
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics gc class implementation.
6 Lang: english
7 */
9 /****************************************************************************************/
11 #include <string.h>
13 #include <proto/exec.h>
14 #include <proto/utility.h>
15 #include <proto/oop.h>
17 #include <exec/memory.h>
18 #include <graphics/text.h>
19 #include <utility/tagitem.h>
20 #include <oop/oop.h>
22 #include <hidd/graphics.h>
24 #include "graphics_intern.h"
26 #undef SDEBUG
27 #define SDEBUG 0
28 #undef DEBUG
29 #define DEBUG 0
30 #include <aros/debug.h>
32 /*****************************************************************************************
34 NAME
35 aoHidd_GC_Foreground
37 SYNOPSIS
38 [.SG]
40 LOCATION
41 hidd.graphics.gc
43 FUNCTION
44 Foreground color
46 NOTES
48 EXAMPLE
50 BUGS
52 SEE ALSO
54 INTERNALS
56 *****************************************************************************************/
58 /*****************************************************************************************
60 NAME
61 aoHidd_GC_Background
63 SYNOPSIS
64 [.SG]
66 LOCATION
67 hidd.graphics.gc
69 FUNCTION
70 Background color
72 NOTES
74 EXAMPLE
76 BUGS
78 SEE ALSO
80 INTERNALS
82 *****************************************************************************************/
84 /*****************************************************************************************
86 NAME
87 aoHidd_GC_DrawMode
89 SYNOPSIS
90 [.SG]
92 LOCATION
93 hidd.graphics.gc
95 FUNCTION
96 Draw mode
98 NOTES
100 EXAMPLE
102 BUGS
104 SEE ALSO
106 INTERNALS
108 *****************************************************************************************/
110 /*****************************************************************************************
112 NAME
113 aoHidd_GC_ColorMask
115 SYNOPSIS
116 [.SG]
118 LOCATION
119 hidd.graphics.gc
121 FUNCTION
122 Prevents some color bits from changing.
124 NOTES
126 EXAMPLE
128 BUGS
130 SEE ALSO
132 INTERNALS
134 *****************************************************************************************/
136 /*****************************************************************************************
138 NAME
139 aoHidd_GC_LinePattern
141 SYNOPSIS
142 [.SG]
144 LOCATION
145 hidd.graphics.gc
147 FUNCTION
148 Pattern for line drawing
150 NOTES
152 EXAMPLE
154 BUGS
156 SEE ALSO
158 INTERNALS
160 *****************************************************************************************/
162 /*****************************************************************************************
164 NAME
165 aoHidd_GC_LinePatternCnt
167 SYNOPSIS
168 [.SG]
170 LOCATION
171 hidd.graphics.gc
173 FUNCTION
174 Pattern start bit for line drawing.
176 NOTES
178 EXAMPLE
180 BUGS
182 SEE ALSO
184 INTERNALS
186 *****************************************************************************************/
188 /*****************************************************************************************
190 NAME
191 aoHidd_GC_ColorExpansionMode
193 SYNOPSIS
194 [.SG]
196 LOCATION
197 hidd.graphics.gc
199 FUNCTION
200 Mode for color expansion
202 NOTES
204 EXAMPLE
206 BUGS
208 SEE ALSO
210 INTERNALS
212 *****************************************************************************************/
214 VOID GC__Root__Set(OOP_Class *cl, OOP_Object *obj, struct pRoot_Set *msg);
216 #define IS_GC_ATTR(attr, idx) ( ( (idx) = (attr) - HiddGCAttrBase) < num_Hidd_GC_Attrs)
218 /****************************************************************************************/
220 OOP_Object *GC__Root__New(OOP_Class *cl, OOP_Object *obj, struct pRoot_New *msg)
222 struct Library *OOPBase = CSD(cl)->cs_OOPBase;
223 HIDDT_GC_Intern *data;
225 EnterFunc(bug("GC::New()\n"));
227 obj = (OOP_Object *) OOP_DoSuperMethod(cl, obj, (OOP_Msg) msg);
229 if(obj)
231 data = OOP_INST_DATA(cl, obj);
233 /* clear all data and set some default values */
234 data->fg = 1; /* foreground color */
235 data->bg = 0; /* background color */
236 data->drMode = vHidd_GC_DrawMode_Copy; /* drawmode */
237 data->colExp = vHidd_GC_ColExp_Opaque; /* color expansion mode */
238 data->colMask = ~0; /* ColorMask prevents some color bits from changing*/
239 data->linePat = ~0; /* LinePattern */
241 /* Override defaults with user suplied attrs */
243 OOP_SetAttrs(obj, msg->attrList);
244 /* GC__Root__Set(cl, obj, &set_msg); */
246 } /* if(obj) */
248 ReturnPtr("GC::New", OOP_Object *, obj);
251 /****************************************************************************************/
253 VOID GC__Root__Set(OOP_Class *cl, OOP_Object *obj, struct pRoot_Set *msg)
255 struct Library *UtilityBase = CSD(cl)->cs_UtilityBase;
256 HIDDT_GC_Intern *data = OOP_INST_DATA(cl, obj);
257 struct TagItem *tag, *tstate;
258 ULONG idx;
260 EnterFunc(bug("GC::Set()\n"));
262 tstate = msg->attrList;
263 while((tag = NextTagItem(&tstate)))
265 if(IS_GC_ATTR(tag->ti_Tag, idx))
267 switch(idx)
269 case aoHidd_GC_Foreground:
270 data->fg = tag->ti_Data;
271 break;
273 case aoHidd_GC_Background:
274 data->bg = tag->ti_Data;
275 break;
277 case aoHidd_GC_DrawMode:
278 data->drMode = tag->ti_Data;
279 break;
281 case aoHidd_GC_ColorMask:
282 data->colMask = tag->ti_Data;
283 break;
285 case aoHidd_GC_LinePattern:
286 data->linePat = (UWORD) tag->ti_Data;
287 break;
289 case aoHidd_GC_LinePatternCnt:
290 data->linePatCnt = (UWORD) tag->ti_Data;
291 break;
293 case aoHidd_GC_ColorExpansionMode:
294 data->colExp = tag->ti_Data;
295 break;
300 ReturnVoid("GC::Set");
303 /****************************************************************************************/
305 VOID GC__Root__Get(OOP_Class *cl, OOP_Object *obj, struct pRoot_Get *msg)
307 HIDDT_GC_Intern *data = OOP_INST_DATA(cl, obj);
308 ULONG idx;
310 EnterFunc(bug("GC::Get() attrID: %i storage: %p\n", msg->attrID, msg->storage));
312 if(IS_GC_ATTR(msg->attrID, idx))
314 switch(idx)
316 case aoHidd_GC_Foreground:
317 *msg->storage = data->fg;
318 break;
320 case aoHidd_GC_Background:
321 *msg->storage = data->bg;
322 break;
324 case aoHidd_GC_DrawMode:
325 *msg->storage = data->drMode;
326 break;
328 case aoHidd_GC_ColorMask:
329 *msg->storage = data->colMask;
330 break;
332 case aoHidd_GC_LinePattern:
333 *msg->storage = data->linePat;
334 break;
336 case aoHidd_GC_LinePatternCnt:
337 *msg->storage = data->linePatCnt;
338 break;
340 case aoHidd_GC_ColorExpansionMode:
341 *msg->storage = data->colExp;
342 break;
344 default:
345 OOP_DoSuperMethod(cl, obj, (OOP_Msg) msg);
346 break;
349 else
351 OOP_DoSuperMethod(cl, obj, (OOP_Msg) msg);
356 /*****************************************************************************************
358 NAME
359 moHidd_GC_SetClipRect
361 SYNOPSIS
362 VOID OOP_DoMethod(OOP_Object *obj, struct pHidd_GC_SetClipRect *msg);
364 VOID HIDD_GC_SetClipRect(OOP_Object *obj, LONG x1, LONG y1, LONG x2, LONG y2);
366 LOCATION
367 hidd.graphics.gc
369 FUNCTION
370 Install a clipping rectangle on a GC.
372 INPUTS
373 obj - a GC object
374 x1, y1 - top-left coordinate of the clipping rectangle
375 x2, y2 - bottom-right coordinate of the clipping rectangle
377 RESULT
378 None
380 NOTES
381 Since the GC is just a data container, installing clipping rectangle doesn't magically
382 applies it to all operations. Graphics driver method which uses the GC needs to support
383 it explicitly. Currently clipping is supported only by Draw and DrawEllipse methods.
385 Use this method if and only if the GC object was created by you. graphics.library
386 internally operates on temporary GC objects, which are allocated only partially. They
387 don't have storage space for clipping rectangle data, and attempt to use this
388 method on such a GC will result in memory trashing.
390 EXAMPLE
392 BUGS
394 SEE ALSO
396 INTERNALS
398 *****************************************************************************************/
400 VOID GC__Hidd_GC__SetClipRect(OOP_Class *cl, OOP_Object *o, struct pHidd_GC_SetClipRect *msg)
402 struct gc_data *data = OOP_INST_DATA(cl, o);
404 /* A space for struct Rectangle has been allocated together with the object */
405 data->cr.MinX = msg->x1;
406 data->cr.MinY = msg->y1;
407 data->cr.MaxX = msg->x2;
408 data->cr.MaxY = msg->y2;
411 * Set clipRect pointer to our own rectangle.
412 * clipRect is intentionally a pointer, not embedded structure. This is done
413 * in order to support temporary GCs embedded in a RastPort for graphics.library.
414 * There's not enough space to hold struct Rectangle in embedded GC.
416 data->prot.clipRect = &data->cr;
419 /*****************************************************************************************
421 NAME
422 moHidd_GC_UnsetClipRect
424 SYNOPSIS
425 VOID OOP_DoMethod(OOP_Object *obj, struct pHidd_GC_UnsetClipRect *msg);
427 VOID HIDD_GC_UnsetClipRect(OOP_Object *obj);
429 LOCATION
430 hidd.graphics.gc
432 FUNCTION
433 Uninstalls the clipping rectangle (whatever it is) from the GC.
435 INPUTS
436 obj - a GC object
438 RESULT
439 None
441 NOTES
443 EXAMPLE
445 BUGS
447 SEE ALSO
449 INTERNALS
451 *****************************************************************************************/
453 VOID GC__Hidd_GC__UnsetClipRect(OOP_Class *cl, OOP_Object *o, struct pHidd_GC_UnsetClipRect *msg)
455 HIDDT_GC_Intern *data = OOP_INST_DATA(cl, o);
457 /* Reset clipRect pointer */
458 data->clipRect = NULL;