Belarusian
[AROS.git] / rom / intuition / pointerclass.c
blob48505f7ab4adfffc9bf85b8434294ac2a445c819
1 /*
2 Copyright © 1995-2010, 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 #undef IntuitionBase
31 #define IntuitionBase ((struct IntuitionBase *)(cl->cl_UserData))
33 /***********************************************************************************/
35 /* Empty sprite */
36 UWORD posctldata[] =
38 0x0000,0x0000, /* posctl */
39 0x0000,0x0000, /* Empty pixels, one line */
40 0x0000,0x0000 /* Reserved */
43 /***********************************************************************************/
45 #define DEF_POINTER_DEPTH 4
47 IPTR PointerClass__OM_NEW(Class *cl, Object *o, struct opSet *msg)
49 D(kprintf("PointerClass: OM_NEW\n"));
51 if (cl)
53 struct TagItem *tags = msg->ops_AttrList;
54 struct BitMap *bitmap = (struct BitMap *)GetTagData(POINTERA_BitMap, (IPTR)NULL, tags);
56 /* Hack: we accept and pass on to AllocSpriteDataA() these attributes in order to
57 provide code reuse. Applications should not rely on it, this is private! */
58 BOOL oldbitmap = GetTagData(SPRITEA_OldDataFormat, FALSE, tags);
59 IPTR width = GetTagData(SPRITEA_Width, 16, tags);
60 IPTR height = GetTagData(SPRITEA_OutputHeight, 0, tags);
62 //ULONG xResolution = GetTagData(POINTERA_XResolution, POINTERXRESN_DEFAULT, tags);
63 //ULONG yResolution = GetTagData(POINTERA_YResolution, POINTERYRESN_DEFAULT, tags);
67 struct TagItem *tagscan=tags;
69 while(tagscan->ti_Tag != 0)
71 kprintf(" 0x%08lx, %08lx\n",tagscan->ti_Tag,tagscan->ti_Data);
72 tagscan++;
77 if (1) // bitmap
79 struct TagItem spritetags[] =
81 {SPRITEA_Width , 0 },
82 {SPRITEA_OutputHeight , 0 },
83 {SPRITEA_OldDataFormat, TRUE},
84 {TAG_DONE }
86 struct ExtSprite *sprite;
87 struct BitMap *spritedata=(struct BitMap *)bitmap;
89 if(spritedata != NULL)
91 if (oldbitmap) {
92 spritetags[0].ti_Data = width;
93 spritetags[1].ti_Data = height;
94 } else {
95 spritetags[0].ti_Data = GetTagData(POINTERA_WordWidth, ((GetBitMapAttr(bitmap, BMA_WIDTH) + 15) & ~15)>>4, tags) * 16;
96 spritetags[1].ti_Tag = TAG_DONE;
99 else
101 D(kprintf("PointerClass: OM_NEW called without bitmap, using dummy sprite !\n"));
103 spritetags[0].ti_Data = 16;
104 spritetags[1].ti_Data = 1;
105 bitmap = (struct BitMap *)posctldata;
109 sprite = AllocSpriteDataA(bitmap, spritetags);
111 D(kprintf("PointerClass: extSprite 0x%lx\n",sprite));
112 D(kprintf("MoveSprite data 0x%lx, height %ld, x %ld, y %ld, num %ld, wordwidth, 0x%lx, flags 0x%lx\n",
113 sprite->es_SimpleSprite.posctldata,
114 sprite->es_SimpleSprite.height,
115 sprite->es_SimpleSprite.x,
116 sprite->es_SimpleSprite.y,
117 sprite->es_SimpleSprite.num,
118 sprite->es_wordwidth,
119 sprite->es_flags));
121 if (sprite)
123 struct SharedPointer *shared;
125 /* If our pointer doesn't already have a user-supplied colormap, we attach it here.
126 This makes the pointer to always have its own colors on hi- and truecolor screens.
127 In addition it gets an alpha channel.
128 Note that this relies on the fact that AllocSpriteDataA() always generates HIDD bitmap
129 in sprite->es_BitMap. */
130 if (!sprite->es_BitMap->Planes[2]) {
131 ULONG i;
132 HIDDT_Color col[DEF_POINTER_DEPTH] = {{0}};
133 struct Color32 *q = GetPrivIBase(IntuitionBase)->Colors;
135 for (i = 1; i < DEF_POINTER_DEPTH; i++ ) {
136 col[i].red = q[i + 7].red >> 16;
137 col[i].green = q[i + 7].green >> 16;
138 col[i].blue = q[i + 7].blue >> 16;
139 col[i].alpha = GetPrivIBase(IntuitionBase)->PointerAlpha;
141 HIDD_BM_SetColors(sprite->es_BitMap->Planes[0], col, 0, DEF_POINTER_DEPTH);
144 shared = CreateSharedPointer(sprite,
145 GetTagData(POINTERA_XOffset, 0, tags),
146 GetTagData(POINTERA_YOffset, 0, tags),
147 IntuitionBase);
149 if (shared)
151 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
153 if (o)
155 struct PointerData *data = INST_DATA(cl, o);
157 data->shared_pointer = shared;
158 //data->xRes = xResolution;
159 //data->yRes = yResolution;
160 D(kprintf("PointerClass: set extSprite 0x%lx and XOffset %ld YOffset %ld\n",shared->sprite,shared->xoffset,shared->yoffset));
162 else
164 D(kprintf("PointerClass: free sprite\n"));
165 ReleaseSharedPointer(shared, IntuitionBase);
168 else
170 D(kprintf("PointerClass: free sprite\n"));
171 FreeSpriteData(sprite);
175 else
177 D(kprintf("PointerClass: OM_NEW called without bitmap !\n"));
181 return (IPTR)o;
184 /***********************************************************************************/
186 IPTR PointerClass__OM_GET(Class *cl, Object *o, struct opGet *msg)
188 struct PointerData *data = INST_DATA(cl, o);
190 D(kprintf("PointerClass: OM_GET\n"));
192 switch (msg->opg_AttrID)
194 case POINTERA_SharedPointer:
195 *msg->opg_Storage = (IPTR)data->shared_pointer;
196 break;
198 case POINTERA_XOffset:
199 *msg->opg_Storage = data->shared_pointer->xoffset;
200 break;
202 case POINTERA_YOffset:
203 *msg->opg_Storage = data->shared_pointer->yoffset;
204 break;
206 default:
207 return DoSuperMethodA(cl, o, (Msg)msg);
209 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));
211 return (IPTR)1;
214 /***********************************************************************************/
216 IPTR PointerClass__OM_DISPOSE(Class *cl, Object *o, Msg msg)
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 /***********************************************************************************/