2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: Graphics gc class implementation.
9 /****************************************************************************************/
11 #include "gfx_debug.h"
15 #include <proto/exec.h>
16 #include <proto/utility.h>
17 #include <proto/oop.h>
19 #include <exec/memory.h>
20 #include <graphics/text.h>
21 #include <utility/tagitem.h>
26 #include "gfx_intern.h"
28 /*****************************************************************************************
52 *****************************************************************************************/
54 /*****************************************************************************************
78 *****************************************************************************************/
80 /*****************************************************************************************
104 *****************************************************************************************/
106 /*****************************************************************************************
118 Prevents some color bits from changing.
130 *****************************************************************************************/
132 /*****************************************************************************************
135 aoHidd_GC_LinePattern
144 Pattern for line drawing
156 *****************************************************************************************/
158 /*****************************************************************************************
161 aoHidd_GC_LinePatternCnt
170 Pattern start bit for line drawing.
182 *****************************************************************************************/
184 /*****************************************************************************************
187 aoHidd_GC_ColorExpansionMode
196 Mode for color expansion
208 *****************************************************************************************/
210 VOID
GC__Root__Set(OOP_Class
*cl
, OOP_Object
*obj
, struct pRoot_Set
*msg
);
212 #define IS_GC_ATTR(attr, idx) ( ( (idx) = (attr) - HiddGCAttrBase) < num_Hidd_GC_Attrs)
214 /****************************************************************************************/
216 OOP_Object
*GC__Root__New(OOP_Class
*cl
, OOP_Object
*obj
, struct pRoot_New
*msg
)
218 struct Library
*OOPBase
= CSD(cl
)->cs_OOPBase
;
219 HIDDT_GC_Intern
*data
;
221 EnterFunc(bug("GC::New()\n"));
223 obj
= (OOP_Object
*) OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
) msg
);
227 data
= OOP_INST_DATA(cl
, obj
);
229 /* clear all data and set some default values */
230 data
->fg
= 1; /* foreground color */
231 data
->bg
= 0; /* background color */
232 data
->drMode
= vHidd_GC_DrawMode_Copy
; /* drawmode */
233 data
->colExp
= vHidd_GC_ColExp_Opaque
; /* color expansion mode */
234 data
->colMask
= ~0; /* ColorMask prevents some color bits from changing*/
235 data
->linePat
= ~0; /* LinePattern */
237 /* Override defaults with user suplied attrs */
239 OOP_SetAttrs(obj
, msg
->attrList
);
240 /* GC__Root__Set(cl, obj, &set_msg); */
244 ReturnPtr("GC::New", OOP_Object
*, obj
);
247 /****************************************************************************************/
249 VOID
GC__Root__Set(OOP_Class
*cl
, OOP_Object
*obj
, struct pRoot_Set
*msg
)
251 struct Library
*UtilityBase
= CSD(cl
)->cs_UtilityBase
;
252 HIDDT_GC_Intern
*data
= OOP_INST_DATA(cl
, obj
);
253 struct TagItem
*tag
, *tstate
;
256 EnterFunc(bug("GC::Set()\n"));
258 tstate
= msg
->attrList
;
259 while((tag
= NextTagItem(&tstate
)))
261 if(IS_GC_ATTR(tag
->ti_Tag
, idx
))
265 case aoHidd_GC_Foreground
:
266 data
->fg
= tag
->ti_Data
;
269 case aoHidd_GC_Background
:
270 data
->bg
= tag
->ti_Data
;
273 case aoHidd_GC_DrawMode
:
274 data
->drMode
= tag
->ti_Data
;
277 case aoHidd_GC_ColorMask
:
278 data
->colMask
= tag
->ti_Data
;
281 case aoHidd_GC_LinePattern
:
282 data
->linePat
= (UWORD
) tag
->ti_Data
;
285 case aoHidd_GC_LinePatternCnt
:
286 data
->linePatCnt
= (UWORD
) tag
->ti_Data
;
289 case aoHidd_GC_ColorExpansionMode
:
290 data
->colExp
= tag
->ti_Data
;
296 ReturnVoid("GC::Set");
299 /****************************************************************************************/
301 VOID
GC__Root__Get(OOP_Class
*cl
, OOP_Object
*obj
, struct pRoot_Get
*msg
)
303 HIDDT_GC_Intern
*data
= OOP_INST_DATA(cl
, obj
);
306 EnterFunc(bug("GC::Get() attrID: %i storage: %p\n", msg
->attrID
, msg
->storage
));
308 if(IS_GC_ATTR(msg
->attrID
, idx
))
312 case aoHidd_GC_Foreground
:
313 *msg
->storage
= data
->fg
;
316 case aoHidd_GC_Background
:
317 *msg
->storage
= data
->bg
;
320 case aoHidd_GC_DrawMode
:
321 *msg
->storage
= data
->drMode
;
324 case aoHidd_GC_ColorMask
:
325 *msg
->storage
= data
->colMask
;
328 case aoHidd_GC_LinePattern
:
329 *msg
->storage
= data
->linePat
;
332 case aoHidd_GC_LinePatternCnt
:
333 *msg
->storage
= data
->linePatCnt
;
336 case aoHidd_GC_ColorExpansionMode
:
337 *msg
->storage
= data
->colExp
;
341 OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
) msg
);
347 OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
) msg
);
352 /*****************************************************************************************
355 moHidd_GC_SetClipRect
358 VOID OOP_DoMethod(OOP_Object *obj, struct pHidd_GC_SetClipRect *msg);
360 VOID HIDD_GC_SetClipRect(OOP_Object *obj, LONG x1, LONG y1, LONG x2, LONG y2);
366 Install a clipping rectangle on a GC.
370 x1, y1 - top-left coordinate of the clipping rectangle
371 x2, y2 - bottom-right coordinate of the clipping rectangle
377 Since the GC is just a data container, installing clipping rectangle doesn't magically
378 applies it to all operations. Graphics driver method which uses the GC needs to support
379 it explicitly. Currently clipping is supported only by Draw and DrawEllipse methods.
381 Use this method if and only if the GC object was created by you. graphics.library
382 internally operates on temporary GC objects, which are allocated only partially. They
383 don't have storage space for clipping rectangle data, and attempt to use this
384 method on such a GC will result in memory trashing.
394 *****************************************************************************************/
396 VOID
GC__Hidd_GC__SetClipRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_GC_SetClipRect
*msg
)
398 struct gc_data
*data
= OOP_INST_DATA(cl
, o
);
400 /* A space for struct Rectangle has been allocated together with the object */
401 data
->cr
.MinX
= msg
->x1
;
402 data
->cr
.MinY
= msg
->y1
;
403 data
->cr
.MaxX
= msg
->x2
;
404 data
->cr
.MaxY
= msg
->y2
;
407 * Set clipRect pointer to our own rectangle.
408 * clipRect is intentionally a pointer, not embedded structure. This is done
409 * in order to support temporary GCs embedded in a RastPort for graphics.library.
410 * There's not enough space to hold struct Rectangle in embedded GC.
412 data
->prot
.clipRect
= &data
->cr
;
415 /*****************************************************************************************
418 moHidd_GC_UnsetClipRect
421 VOID OOP_DoMethod(OOP_Object *obj, struct pHidd_GC_UnsetClipRect *msg);
423 VOID HIDD_GC_UnsetClipRect(OOP_Object *obj);
429 Uninstalls the clipping rectangle (whatever it is) from the GC.
447 *****************************************************************************************/
449 VOID
GC__Hidd_GC__UnsetClipRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_GC_UnsetClipRect
*msg
)
451 HIDDT_GC_Intern
*data
= OOP_INST_DATA(cl
, o
);
453 /* Reset clipRect pointer */
454 data
->clipRect
= NULL
;