2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Graphics gc class implementation.
9 /****************************************************************************************/
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>
22 #include <hidd/graphics.h>
24 #include "graphics_intern.h"
30 #include <aros/debug.h>
32 /*****************************************************************************************
56 *****************************************************************************************/
58 /*****************************************************************************************
82 *****************************************************************************************/
84 /*****************************************************************************************
108 *****************************************************************************************/
110 /*****************************************************************************************
122 Prevents some color bits from changing.
134 *****************************************************************************************/
136 /*****************************************************************************************
139 aoHidd_GC_LinePattern
148 Pattern for line drawing
160 *****************************************************************************************/
162 /*****************************************************************************************
165 aoHidd_GC_LinePatternCnt
174 Pattern start bit for line drawing.
186 *****************************************************************************************/
188 /*****************************************************************************************
191 aoHidd_GC_ColorExpansionMode
200 Mode for color expansion
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
);
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); */
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
;
260 EnterFunc(bug("GC::Set()\n"));
262 tstate
= msg
->attrList
;
263 while((tag
= NextTagItem(&tstate
)))
265 if(IS_GC_ATTR(tag
->ti_Tag
, idx
))
269 case aoHidd_GC_Foreground
:
270 data
->fg
= tag
->ti_Data
;
273 case aoHidd_GC_Background
:
274 data
->bg
= tag
->ti_Data
;
277 case aoHidd_GC_DrawMode
:
278 data
->drMode
= tag
->ti_Data
;
281 case aoHidd_GC_ColorMask
:
282 data
->colMask
= tag
->ti_Data
;
285 case aoHidd_GC_LinePattern
:
286 data
->linePat
= (UWORD
) tag
->ti_Data
;
289 case aoHidd_GC_LinePatternCnt
:
290 data
->linePatCnt
= (UWORD
) tag
->ti_Data
;
293 case aoHidd_GC_ColorExpansionMode
:
294 data
->colExp
= tag
->ti_Data
;
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
);
310 EnterFunc(bug("GC::Get() attrID: %i storage: %p\n", msg
->attrID
, msg
->storage
));
312 if(IS_GC_ATTR(msg
->attrID
, idx
))
316 case aoHidd_GC_Foreground
:
317 *msg
->storage
= data
->fg
;
320 case aoHidd_GC_Background
:
321 *msg
->storage
= data
->bg
;
324 case aoHidd_GC_DrawMode
:
325 *msg
->storage
= data
->drMode
;
328 case aoHidd_GC_ColorMask
:
329 *msg
->storage
= data
->colMask
;
332 case aoHidd_GC_LinePattern
:
333 *msg
->storage
= data
->linePat
;
336 case aoHidd_GC_LinePatternCnt
:
337 *msg
->storage
= data
->linePatCnt
;
340 case aoHidd_GC_ColorExpansionMode
:
341 *msg
->storage
= data
->colExp
;
345 OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
) msg
);
351 OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
) msg
);
356 /*****************************************************************************************
359 moHidd_GC_SetClipRect
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);
370 Install a clipping rectangle on a GC.
374 x1, y1 - top-left coordinate of the clipping rectangle
375 x2, y2 - bottom-right coordinate of the clipping rectangle
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.
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 /*****************************************************************************************
422 moHidd_GC_UnsetClipRect
425 VOID OOP_DoMethod(OOP_Object *obj, struct pHidd_GC_UnsetClipRect *msg);
427 VOID HIDD_GC_UnsetClipRect(OOP_Object *obj);
433 Uninstalls the clipping rectangle (whatever it is) from the GC.
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
;