added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / amiga / workbench / hidds / graphics / intuition / BM_Class.c
blob9d7184f400ec52b4ca4a418a6205006b5984a3d5
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics-amiga-intui bitmap class implementation.
6 Lang: english
7 */
9 #include <string.h>
11 #include <proto/exec.h>
12 #include <proto/utility.h>
13 #include <proto/intuition.h>
14 #include <proto/oop.h>
16 #include <exec/memory.h>
17 #include <utility/tagitem.h>
18 #include <intuition/screens.h>
20 #include <oop/oop.h>
22 #include <hidd/graphics.h>
23 #include <hidd/graphics-amiga-intuition.h>
25 #include "graphics_intern.h"
27 #undef SDEBUG
28 #undef DEBUG
29 #define DEBUG 1
30 #include <aros/debug.h>
32 #define IS_BM_ATTR(attr, idx) ( ( (idx) = (attr) - HiddBitMapAttrBase) < num_Hidd_BitMap_Attrs)
34 static AttrBase HiddBitMapAttrBase = 0;
36 /*** BitMap::New() ************************************************************/
38 static Object *bitmap_new(Class *cl, Object *obj, struct pRoot_New *msg)
40 struct TagItem tags[] = {
41 {aHidd_BitMap_AllocBuffer, FALSE },
42 {TAG_MORE , (IPTR) NULL}
45 struct HIDDBitMapAmigaIntuiData *data;
46 struct TagItem *tag, *tstate, *newTagList;
47 BOOL ok = FALSE;
49 struct pRoot_New new_msg;
50 struct pHidd_BitMap_PrivateSet private_set_msg;
52 ULONG width, height, depth, format;
53 BOOL displayable;
55 EnterFunc(bug("BitMapAmigaIntui::New()\n"));
57 new_msg.mID = GetMethodID(IID_Root, moRoot_New);
58 private_set_msg.mID = GetMethodID(IID_Hidd_BitMap, moHidd_BitMap_PrivateSet);
61 displayable = (BOOL) GetTagData(aHidd_BitMap_Displayable, 0, msg->attrList);
62 if(!displayable)
64 /* let the superclass do all work */
66 obj = (Object *) DoSuperMethod(cl, obj, (Msg) msg);
67 if(obj) ok = TRUE;
69 else
72 aHidd_BitMap_AllocBuffer and aHidd_BitMap_Displayable must be
73 FALSE. To make this easy first a copy of the taglist is
74 created. In the new list Hidd_BitMap_Displayable is set to
75 FALSE. If the taglist contains a "aHidd_BitMap_AllocBuffer"
76 tag then ti_Data is set to FALSE else tags(see above) is
77 connected with the new list.
79 NOTE: If msg.attrList contains more than one
80 "aHidd_BitMap_AllocBuffer" we have a problem.
83 newTagList = CloneTagItems(msg->attrList);
84 if(newTagList)
86 tag = FindTagItem(aHidd_BitMap_Displayable, newTagList);
87 if(tag)
89 tag->ti_Data = FALSE;
92 tag = FindTagItem(aHidd_BitMap_AllocBuffer, newTagList);
93 if(tag)
95 tag->ti_Data = FALSE;
96 new_msg.attrList = newTagList;
98 else
100 tags[1].ti_Data = (IPTR) newTagList;
101 new_msg.attrList = tags;
104 obj = (Object *) DoSuperMethod(cl, obj, (Msg) &new_msg);
106 FreeTagItems(newTagList);
109 if(obj)
111 data = INST_DATA(cl, obj);
113 /* clear all data and set some default values */
114 memset(data, 0, sizeof(struct HIDDBitMapAmigaIntuiData));
116 GetAttr(obj, aHidd_BitMap_Width, &width);
117 GetAttr(obj, aHidd_BitMap_Height, &height);
118 GetAttr(obj, aHidd_BitMap_Depth, &depth);
119 GetAttr(obj, aHidd_BitMap_Format, &format);
121 if(format == vHIDD_BitMap_Format_Planar)
123 /* only displayable support for planar format */
125 struct TagItem tags[] =
127 {SA_Left , 0},
128 {SA_Top , 0},
129 {SA_Width , width},
130 {SA_Height , height},
131 {SA_Depth , depth},
132 {TAG_SKIP , 1}, /* Use SA_DisplayID only wenn a display mode */
133 {SA_DisplayID, 0}, /* is specified */
134 {SA_Title , (ULONG) "AROS graphics hidd"},
135 {SA_Type , CUSTOMSCREEN},
137 /* Will be use later */
138 /* SA_Quiet , TRUE, */
139 /* SA_BitMap , 0 On V37 double buffering could only
140 implemented with a custom bitmap */
141 {TAG_DONE, 0}
144 data->screen = OpenScreenTagList(NULL, tags);
145 if(data->screen)
147 struct TagItem set[] =
149 {aHidd_BitMap_BaseAddress, (IPTR) &data->screen->RastPort.BitMap->Planes[0]},
150 {aHidd_BitMap_Format , vHIDD_BitMap_Format_Planar},
151 {aHidd_BitMap_Displayable, TRUE },
152 {aHidd_BitMap_BytesPerRow, data->screen->RastPort.BitMap->BytesPerRow},
153 {TAG_END , 0 }
156 private_set_msg.attrList = set;
157 DoSuperMethod(cl, obj, (Msg) &private_set_msg);
158 ok = TRUE;
159 } /* if(data->screen) */
160 } /* if(format == vHIDD_BitMap_Format_Planar) */
161 } /* if(obj) */
162 } /* if(!displayable) */
164 /* free all on error */
165 if(ok == FALSE)
167 if(obj) DisposeObject(obj);
168 obj = NULL;
171 ReturnPtr("BitMapAmigaIntui::New", Object *, obj);
175 /*** BitMap::Dispose() ********************************************************/
177 static void bitmap_dispose(Class *cl, Object *obj, Msg *msg)
179 struct HIDDBitMapAmigaIntuiData *data = INST_DATA(cl, obj);
181 struct pHidd_BitMap_PrivateSet private_set_msg;
184 EnterFunc(bug("BitMapAmigaIntui::Dispose()\n"));
186 if(data->screen)
189 We use an own buffer so set the BaseAddress to NULL to prevent
190 the superclass to free our own buffer.
193 struct TagItem set[] =
195 {aHidd_BitMap_BaseAddress, NULL},
196 {TAG_END , 0 }
199 CloseScreen(data->screen);
201 private_set_msg.mID = GetMethodID(IID_Hidd_BitMap, moHidd_BitMap_PrivateSet);
202 private_set_msg.attrList = set;
203 DoSuperMethod(cl, obj, (Msg) &private_set_msg);
206 DoSuperMethod(cl, obj, (Msg) msg);
208 ReturnVoid("BitMapAmigaIntui::Dispose");
212 /*** init_bitmapclass *********************************************************/
214 #undef OOPBase
215 #undef SysBase
217 #define OOPBase (csd->oopbase)
218 #define SysBase (csd->sysbase)
220 #define NUM_ROOT_METHODS 2
221 #define NUM_BITMAP_METHODS 0
223 Class *init_bitmapclass(struct class_static_data *csd)
225 struct MethodDescr root_descr[NUM_ROOT_METHODS + 1] =
227 {(IPTR (*)())bitmap_new , moRoot_New },
228 {(IPTR (*)())bitmap_dispose, moRoot_Dispose},
229 {NULL, 0UL}
232 struct MethodDescr bitMap_descr[NUM_BITMAP_METHODS + 1] =
234 {NULL, 0UL}
237 struct InterfaceDescr ifdescr[] =
239 {root_descr, IID_Root , NUM_ROOT_METHODS},
240 {bitMap_descr, IID_Hidd_BitMap, NUM_BITMAP_METHODS},
241 {NULL, NULL, 0}
244 AttrBase MetaAttrBase = GetAttrBase(IID_Meta);
246 struct TagItem tags[] =
248 {aMeta_SuperID, (IPTR) CLID_Hidd_BitMap},
249 {aMeta_InterfaceDescr, (IPTR) ifdescr},
250 {aMeta_ID, (IPTR) CLID_Hidd_BitMapAmigaIntui},
251 {aMeta_InstSize, (IPTR) sizeof(struct HIDDBitMapAmigaIntuiData)},
252 {TAG_DONE, 0UL}
255 Class *cl = NULL;
257 EnterFunc(bug("init_bitmapclassAmigaIntui(csd=%p)\n", csd));
259 if(MetaAttrBase)
261 cl = NewObject(NULL, CLID_HiddMeta, tags);
262 if(cl)
264 D(bug("BitMap class ok\n"));
265 csd->bitmapclass = cl;
266 cl->UserData = (APTR) csd;
268 /* Get attrbase for the BitMap interface */
269 HiddBitMapAttrBase = ObtainAttrBase(IID_Hidd_BitMap);
270 if(HiddBitMapAttrBase)
272 AddClass(cl);
274 else
276 free_bitmapclass(csd);
277 cl = NULL;
280 } /* if(MetaAttrBase) */
282 ReturnPtr("init_bitmapclassAmigaIntui", Class *, cl);
286 /*** free_bitmapclass *********************************************************/
288 void free_bitmapclass(struct class_static_data *csd)
290 EnterFunc(bug("free_bitmapclassAmigaIntui(csd=%p)\n", csd));
292 if(csd)
294 RemoveClass(csd->bitmapclass);
295 DisposeObject((Object *) csd->bitmapclass);
296 csd->bitmapclass = NULL;
297 if(HiddBitMapAttrBase) ReleaseAttrBase(IID_Hidd_BitMap);
300 ReturnVoid("free_bitmapclassAmigaIntui");