wip prep commit in lieu of gfx subsystem update changes.
[AROS.git] / rom / hidds / graphics / gfx_gcclass.c
blob69a31dc3ccd5358a6867039899fee55524fb90d0
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics gc class implementation.
6 Lang: english
7 */
9 /****************************************************************************************/
11 #include "gfx_debug.h"
13 #include <string.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>
22 #include <oop/oop.h>
24 #include <hidd/gfx.h>
26 #include "gfx_intern.h"
28 /*****************************************************************************************
30 NAME
31 aoHidd_GC_Foreground
33 SYNOPSIS
34 [.SG]
36 LOCATION
37 hidd.gfx.gc
39 FUNCTION
40 Foreground color
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
52 *****************************************************************************************/
54 /*****************************************************************************************
56 NAME
57 aoHidd_GC_Background
59 SYNOPSIS
60 [.SG]
62 LOCATION
63 hidd.gfx.gc
65 FUNCTION
66 Background color
68 NOTES
70 EXAMPLE
72 BUGS
74 SEE ALSO
76 INTERNALS
78 *****************************************************************************************/
80 /*****************************************************************************************
82 NAME
83 aoHidd_GC_DrawMode
85 SYNOPSIS
86 [.SG]
88 LOCATION
89 hidd.gfx.gc
91 FUNCTION
92 Draw mode
94 NOTES
96 EXAMPLE
98 BUGS
100 SEE ALSO
102 INTERNALS
104 *****************************************************************************************/
106 /*****************************************************************************************
108 NAME
109 aoHidd_GC_ColorMask
111 SYNOPSIS
112 [.SG]
114 LOCATION
115 hidd.gfx.gc
117 FUNCTION
118 Prevents some color bits from changing.
120 NOTES
122 EXAMPLE
124 BUGS
126 SEE ALSO
128 INTERNALS
130 *****************************************************************************************/
132 /*****************************************************************************************
134 NAME
135 aoHidd_GC_LinePattern
137 SYNOPSIS
138 [.SG]
140 LOCATION
141 hidd.gfx.gc
143 FUNCTION
144 Pattern for line drawing
146 NOTES
148 EXAMPLE
150 BUGS
152 SEE ALSO
154 INTERNALS
156 *****************************************************************************************/
158 /*****************************************************************************************
160 NAME
161 aoHidd_GC_LinePatternCnt
163 SYNOPSIS
164 [.SG]
166 LOCATION
167 hidd.gfx.gc
169 FUNCTION
170 Pattern start bit for line drawing.
172 NOTES
174 EXAMPLE
176 BUGS
178 SEE ALSO
180 INTERNALS
182 *****************************************************************************************/
184 /*****************************************************************************************
186 NAME
187 aoHidd_GC_ColorExpansionMode
189 SYNOPSIS
190 [.SG]
192 LOCATION
193 hidd.gfx.gc
195 FUNCTION
196 Mode for color expansion
198 NOTES
200 EXAMPLE
202 BUGS
204 SEE ALSO
206 INTERNALS
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);
225 if(obj)
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); */
242 } /* if(obj) */
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;
254 ULONG idx;
256 EnterFunc(bug("GC::Set()\n"));
258 tstate = msg->attrList;
259 while((tag = NextTagItem(&tstate)))
261 if(IS_GC_ATTR(tag->ti_Tag, idx))
263 switch(idx)
265 case aoHidd_GC_Foreground:
266 data->fg = tag->ti_Data;
267 break;
269 case aoHidd_GC_Background:
270 data->bg = tag->ti_Data;
271 break;
273 case aoHidd_GC_DrawMode:
274 data->drMode = tag->ti_Data;
275 break;
277 case aoHidd_GC_ColorMask:
278 data->colMask = tag->ti_Data;
279 break;
281 case aoHidd_GC_LinePattern:
282 data->linePat = (UWORD) tag->ti_Data;
283 break;
285 case aoHidd_GC_LinePatternCnt:
286 data->linePatCnt = (UWORD) tag->ti_Data;
287 break;
289 case aoHidd_GC_ColorExpansionMode:
290 data->colExp = tag->ti_Data;
291 break;
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);
304 ULONG idx;
306 EnterFunc(bug("GC::Get() attrID: %i storage: %p\n", msg->attrID, msg->storage));
308 if(IS_GC_ATTR(msg->attrID, idx))
310 switch(idx)
312 case aoHidd_GC_Foreground:
313 *msg->storage = data->fg;
314 break;
316 case aoHidd_GC_Background:
317 *msg->storage = data->bg;
318 break;
320 case aoHidd_GC_DrawMode:
321 *msg->storage = data->drMode;
322 break;
324 case aoHidd_GC_ColorMask:
325 *msg->storage = data->colMask;
326 break;
328 case aoHidd_GC_LinePattern:
329 *msg->storage = data->linePat;
330 break;
332 case aoHidd_GC_LinePatternCnt:
333 *msg->storage = data->linePatCnt;
334 break;
336 case aoHidd_GC_ColorExpansionMode:
337 *msg->storage = data->colExp;
338 break;
340 default:
341 OOP_DoSuperMethod(cl, obj, (OOP_Msg) msg);
342 break;
345 else
347 OOP_DoSuperMethod(cl, obj, (OOP_Msg) msg);
352 /*****************************************************************************************
354 NAME
355 moHidd_GC_SetClipRect
357 SYNOPSIS
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);
362 LOCATION
363 hidd.gfx.gc
365 FUNCTION
366 Install a clipping rectangle on a GC.
368 INPUTS
369 obj - a GC object
370 x1, y1 - top-left coordinate of the clipping rectangle
371 x2, y2 - bottom-right coordinate of the clipping rectangle
373 RESULT
374 None
376 NOTES
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.
386 EXAMPLE
388 BUGS
390 SEE ALSO
392 INTERNALS
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 /*****************************************************************************************
417 NAME
418 moHidd_GC_UnsetClipRect
420 SYNOPSIS
421 VOID OOP_DoMethod(OOP_Object *obj, struct pHidd_GC_UnsetClipRect *msg);
423 VOID HIDD_GC_UnsetClipRect(OOP_Object *obj);
425 LOCATION
426 hidd.gfx.gc
428 FUNCTION
429 Uninstalls the clipping rectangle (whatever it is) from the GC.
431 INPUTS
432 obj - a GC object
434 RESULT
435 None
437 NOTES
439 EXAMPLE
441 BUGS
443 SEE ALSO
445 INTERNALS
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;