Minor fixes to comments.
[AROS.git] / rom / intuition / pointerclass.c
blobb4eb1e172fb92ae3c05d582c6c495c28f9270795
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <hidd/graphics.h>
8 #include <intuition/intuition.h>
9 #include <intuition/intuitionbase.h>
10 #include <intuition/classes.h>
11 #include <intuition/classusr.h>
12 #include <intuition/pointerclass.h>
13 #include <graphics/sprite.h>
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <proto/graphics.h>
18 #include <proto/utility.h>
20 #include "intuition_intern.h"
22 #undef DEBUG
23 #define DEBUG 0
24 #include <aros/debug.h>
26 #include <aros/asmcall.h>
28 /***********************************************************************************/
30 /* Empty sprite */
31 const UWORD posctldata[] =
33 0x0000,0x0000, /* posctl */
34 0x0000,0x0000, /* Empty pixels, one line */
35 0x0000,0x0000 /* Reserved */
38 /***********************************************************************************/
40 #define DEF_POINTER_DEPTH 4
42 IPTR PointerClass__OM_NEW(Class *cl, Object *o, struct opSet *msg)
44 struct IntuitionBase *IntuitionBase = (struct IntuitionBase *)cl->cl_UserData;
45 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
46 struct Library *UtilityBase = GetPrivIBase(IntuitionBase)->UtilityBase;
47 OOP_MethodID HiddBitMapBase = ((struct IntIntuitionBase *)IntuitionBase)->ib_HiddBitMapBase;
48 D(kprintf("PointerClass: OM_NEW\n"));
50 if (cl)
52 struct TagItem *tags = msg->ops_AttrList;
53 struct BitMap *bitmap = (struct BitMap *)GetTagData(POINTERA_BitMap, (IPTR)NULL, tags);
55 /* Hack: we accept and pass on to AllocSpriteDataA() these attributes in order to
56 provide code reuse. Applications should not rely on it, this is private! */
57 BOOL oldbitmap = GetTagData(SPRITEA_OldDataFormat, FALSE, tags);
58 IPTR width = GetTagData(SPRITEA_Width, 16, tags);
59 IPTR height = GetTagData(SPRITEA_OutputHeight, 0, tags);
61 //ULONG xResolution = GetTagData(POINTERA_XResolution, POINTERXRESN_DEFAULT, tags);
62 //ULONG yResolution = GetTagData(POINTERA_YResolution, POINTERYRESN_DEFAULT, tags);
66 struct TagItem *tagscan=tags;
68 while(tagscan->ti_Tag != 0)
70 kprintf(" 0x%08lx, %08lx\n",tagscan->ti_Tag,tagscan->ti_Data);
71 tagscan++;
76 if (1) // bitmap
78 struct TagItem spritetags[] =
80 {SPRITEA_Width , 0 },
81 {SPRITEA_OutputHeight , 0 },
82 {SPRITEA_OldDataFormat, TRUE},
83 {TAG_DONE }
85 struct ExtSprite *sprite;
86 struct BitMap *spritedata=(struct BitMap *)bitmap;
88 if(spritedata != NULL)
90 if (oldbitmap) {
91 spritetags[0].ti_Data = width;
92 spritetags[1].ti_Data = height;
93 } else {
94 spritetags[0].ti_Data = GetTagData(POINTERA_WordWidth, ((GetBitMapAttr(bitmap, BMA_WIDTH) + 15) & ~15)>>4, tags) * 16;
95 spritetags[1].ti_Tag = TAG_DONE;
98 else
100 D(kprintf("PointerClass: OM_NEW called without bitmap, using dummy sprite !\n"));
102 spritetags[0].ti_Data = 16;
103 spritetags[1].ti_Data = 1;
104 bitmap = (struct BitMap *)posctldata;
108 sprite = AllocSpriteDataA(bitmap, spritetags);
110 D(kprintf("PointerClass: extSprite 0x%lx\n",sprite));
111 D(kprintf("MoveSprite data 0x%lx, height %ld, x %ld, y %ld, num %ld, wordwidth, 0x%lx, flags 0x%lx\n",
112 sprite->es_SimpleSprite.posctldata,
113 sprite->es_SimpleSprite.height,
114 sprite->es_SimpleSprite.x,
115 sprite->es_SimpleSprite.y,
116 sprite->es_SimpleSprite.num,
117 sprite->es_wordwidth,
118 sprite->es_flags));
120 if (sprite)
122 struct SharedPointer *shared;
124 /* If our pointer doesn't already have a user-supplied colormap, we attach it here.
125 This makes the pointer to always have its own colors on hi- and truecolor screens.
126 In addition it gets an alpha channel.
127 Note that this relies on the fact that AllocSpriteDataA() always generates HIDD bitmap
128 in sprite->es_BitMap. */
129 if (!sprite->es_BitMap->Planes[2]) {
130 ULONG i;
131 HIDDT_Color col[DEF_POINTER_DEPTH] = {{0}};
132 struct Color32 *q = GetPrivIBase(IntuitionBase)->Colors;
134 for (i = 1; i < DEF_POINTER_DEPTH; i++ ) {
135 col[i].red = q[i + 7].red >> 16;
136 col[i].green = q[i + 7].green >> 16;
137 col[i].blue = q[i + 7].blue >> 16;
138 col[i].alpha = GetPrivIBase(IntuitionBase)->PointerAlpha;
140 HIDD_BM_SetColors((OOP_Object *)sprite->es_BitMap->Planes[0], col, 0, DEF_POINTER_DEPTH);
143 shared = CreateSharedPointer(sprite,
144 GetTagData(POINTERA_XOffset, 0, tags),
145 GetTagData(POINTERA_YOffset, 0, tags),
146 IntuitionBase);
148 if (shared)
150 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
152 if (o)
154 struct PointerData *data = INST_DATA(cl, o);
156 data->shared_pointer = shared;
157 //data->xRes = xResolution;
158 //data->yRes = yResolution;
159 D(kprintf("PointerClass: set extSprite 0x%lx and XOffset %ld YOffset %ld\n",shared->sprite,shared->xoffset,shared->yoffset));
161 else
163 D(kprintf("PointerClass: free sprite\n"));
164 ReleaseSharedPointer(shared, IntuitionBase);
167 else
169 D(kprintf("PointerClass: free sprite\n"));
170 FreeSpriteData(sprite);
174 else
176 D(kprintf("PointerClass: OM_NEW called without bitmap !\n"));
180 return (IPTR)o;
183 /***********************************************************************************/
185 IPTR PointerClass__OM_GET(Class *cl, Object *o, struct opGet *msg)
187 struct PointerData *data = INST_DATA(cl, o);
189 D(kprintf("PointerClass: OM_GET\n"));
191 switch (msg->opg_AttrID)
193 case POINTERA_SharedPointer:
194 *msg->opg_Storage = (IPTR)data->shared_pointer;
195 break;
197 case POINTERA_XOffset:
198 *msg->opg_Storage = data->shared_pointer->xoffset;
199 break;
201 case POINTERA_YOffset:
202 *msg->opg_Storage = data->shared_pointer->yoffset;
203 break;
205 default:
206 return DoSuperMethodA(cl, o, (Msg)msg);
208 D(kprintf("PointerClass: current extSprite 0x%lx and XOffset %ld YOffset %ld\n",data->shared_pointer->sprite,data->shared_pointer->xoffset,data->shared_pointer->yoffset));
210 return (IPTR)1;
213 /***********************************************************************************/
215 IPTR PointerClass__OM_DISPOSE(Class *cl, Object *o, Msg msg)
217 struct IntuitionBase *IntuitionBase = (struct IntuitionBase *)cl->cl_UserData;
218 struct PointerData *data = INST_DATA(cl, o);
220 D(kprintf("PointerClass: OM_DISPOSE\n"));
221 D(kprintf("PointerClass: extSprite 0x%lx\n",data->shared_pointer->sprite));
222 ReleaseSharedPointer(data->shared_pointer, IntuitionBase);
224 return DoSuperMethodA(cl, o, msg);
227 /***********************************************************************************/