2 Copyright © 2002-2003 The MorphOS Development Team, All Rights Reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
7 #include <exec/memory.h>
8 #include <graphics/rastport.h>
9 #include <intuition/pointerclass.h>
10 #include <proto/exec.h>
11 #include <proto/graphics.h>
12 #include <proto/intuition.h>
13 #include "intuition_intern.h"
16 struct RastPort
*MyCreateRastPort(struct IntuitionBase
*IntuitionBase
)
18 struct RastPort
*newrp
= AllocMem(sizeof(*newrp
), MEMF_PUBLIC
);
28 struct RastPort
*MyCloneRastPort(struct IntuitionBase
*IntuitionBase
, struct RastPort
*rp
)
30 struct RastPort
*newrp
= NULL
;
34 newrp
= AllocMem(sizeof(*newrp
), MEMF_PUBLIC
);
39 memcpy(newrp
,rp
,sizeof(struct RastPort
));
46 void MyFreeRastPort(struct IntuitionBase
*IntuitionBase
, struct RastPort
*rp
)
48 FreeMem(rp
, sizeof(*rp
));
52 void MySetPointerPos(struct IntuitionBase
*IntuitionBase
, int x
, int y
)
54 struct IntScreen
*scr
= GetPrivScreen(IntuitionBase
->ActiveScreen
);
56 IntuitionBase
->MouseX
= x
;
57 IntuitionBase
->MouseY
= y
;
62 dprintf("MoveSprite Viewport 0x%lx %ld %ld\n",&scr
->Screen
.ViewPort
,x
+ scr
->Pointer
->xoffset
- scr
->Screen
.LeftEdge
,y
+ scr
->Pointer
->yoffset
- scr
->Screen
.TopEdge
);
63 dprintf("MoveSprite data 0x%lx, height %ld, x %ld, y %ld, num %ld, wordwidth, 0x%lx, flags 0x%lx\n",
64 scr
->Pointer
->sprite
->es_SimpleSprite
.posctldata
,
65 scr
->Pointer
->sprite
->es_SimpleSprite
.height
,
66 scr
->Pointer
->sprite
->es_SimpleSprite
.x
,
67 scr
->Pointer
->sprite
->es_SimpleSprite
.y
,
68 scr
->Pointer
->sprite
->es_SimpleSprite
.num
,
69 scr
->Pointer
->sprite
->es_wordwidth
,
70 scr
->Pointer
->sprite
->es_flags
);
72 MoveSprite(&scr
->Screen
.ViewPort
, &scr
->Pointer
->sprite
->es_SimpleSprite
,
73 x
+ scr
->Pointer
->xoffset
,
74 y
+ scr
->Pointer
->yoffset
);
76 dprintf("MoveSprite data 0x%lx, height %ld, x %ld, y %ld, num %ld, wordwidth, 0x%lx, flags 0x%lx\n",
77 scr
->Pointer
->sprite
->es_SimpleSprite
.posctldata
,
78 scr
->Pointer
->sprite
->es_SimpleSprite
.height
,
79 scr
->Pointer
->sprite
->es_SimpleSprite
.x
,
80 scr
->Pointer
->sprite
->es_SimpleSprite
.y
,
81 scr
->Pointer
->sprite
->es_SimpleSprite
.num
,
82 scr
->Pointer
->sprite
->es_wordwidth
,
83 scr
->Pointer
->sprite
->es_flags
);
88 // dprintf("No Screen for mouseptr\n");
93 LONG
IsLayerVisible(struct Layer
*layer
)
98 BOOL
IsLayerHiddenBySibling(struct Layer
*layer
, BOOL xx
)
100 struct Window
*win
= layer
->Window
;
102 /* skip requesters attached to the same window. */
103 while (layer
->front
&& layer
->front
->Window
== win
)
105 layer
= layer
->front
;
108 /* jDc: we need to care for layers that are on
109 ** front of our layer, but don't cover it*/
115 for (lay
= layer
->front
; lay
; lay
= lay
->front
)
117 struct Window
*lwin
= lay
->Window
;
121 if (lwin
->LeftEdge
> win
->LeftEdge
+ win
->Width
- 1) continue;
122 if (lwin
->LeftEdge
+ lwin
->Width
- 1 < win
->LeftEdge
) continue;
123 if (lwin
->TopEdge
> win
->TopEdge
+ win
->Height
- 1) continue;
124 if (lwin
->TopEdge
+ lwin
->Height
- 1 < win
->TopEdge
) continue;
133 /* Only function needed from libc.a. Oh well. */
134 long atol(const char *str
)
139 while (*str
== ' ' || *str
== '\t')
146 while (*str
>= '0' && *str
<= '9')
159 struct TextFont
*SafeReopenFont(struct IntuitionBase
*IntuitionBase
,
160 struct TextFont
**fontptr
)
162 struct TextFont
*ret
= NULL
, *font
;
164 /* Atomically lock the font before, so it can't go away
173 font
->tf_Accessors
++;
176 /* Now really open it
178 ta
.ta_Name
= font
->tf_Message
.mn_Node
.ln_Name
;
179 ta
.ta_YSize
= font
->tf_YSize
;
180 ta
.ta_Style
= font
->tf_Style
;
181 ta
.ta_Flags
= font
->tf_Flags
;
188 font
->tf_Accessors
--;
196 Object
*MakePointerFromData(struct IntuitionBase
*IntuitionBase
,
197 UWORD
*source
, int xOffset
, int yOffset
, int width
, int height
)
199 struct BitMap bitmap
;
201 UWORD plane0
[64], plane1
[64];
205 UWORD mask
= ~((1 << (16 - width
)) - 1);
211 InitBitMap(&bitmap
, 2, 16, height
);
212 bitmap
.Planes
[0] = (PLANEPTR
)plane0
;
213 bitmap
.Planes
[1] = (PLANEPTR
)plane1
;
215 for (k
= 0; k
< height
; ++k
)
222 struct TagItem pointertags
[] =
224 {POINTERA_BitMap
, (IPTR
)&bitmap
},
225 {POINTERA_XOffset
, xOffset
},
226 {POINTERA_YOffset
, yOffset
},
230 retval
= NewObjectA(GetPrivIBase(IntuitionBase
)->pointerclass
, NULL
, pointertags
);
236 Object
*MakePointerFromPrefs(struct IntuitionBase
*IntuitionBase
, struct Preferences
*prefs
)
238 SetPointerColors(IntuitionBase
);
240 return MakePointerFromData(IntuitionBase
,
241 prefs
->PointerMatrix
+ 2, prefs
->XOffset
, prefs
->YOffset
, 16, 16);
244 void InstallPointer(struct IntuitionBase
*IntuitionBase
, Object
**old
, Object
*pointer
)
246 struct IntScreen
*scr
;
248 struct SharedPointer
*oldpointer
;
249 struct SharedPointer
*newpointer
;
251 ULONG lock
= LockIBase(0);
253 GetAttr(POINTERA_SharedPointer
, *old
, (IPTR
*)&oldpointer
);
254 GetAttr(POINTERA_SharedPointer
, pointer
, (IPTR
*)&newpointer
);
256 for (scr
= GetPrivScreen(IntuitionBase
->FirstScreen
); scr
; scr
= GetPrivScreen(scr
->Screen
.NextScreen
))
258 for (win
= scr
->Screen
.FirstWindow
; win
; win
= win
->NextWindow
)
260 if (((struct IntWindow
*)win
)->pointer
== *old
)
262 win
->XOffset
= newpointer
->xoffset
;
263 win
->YOffset
= newpointer
->yoffset
;
267 if (scr
->Pointer
== oldpointer
)
269 DEBUG_POINTER(dprintf("InstallPointer: scr 0x%lx pointer 0x%lx sprite 0x%lx\n",
270 scr
, pointer
, newpointer
->sprite
));
271 if (ChangeExtSpriteA(&scr
->Screen
.ViewPort
,
272 oldpointer
->sprite
, newpointer
->sprite
, NULL
))
274 ObtainSharedPointer(newpointer
, IntuitionBase
);
275 ReleaseSharedPointer(oldpointer
, IntuitionBase
);
276 scr
->Pointer
= newpointer
;
280 DEBUG_POINTER(dprintf("InstallPointer: can't change pointer.\n"));
291 void SetPointerColors(struct IntuitionBase
*IntuitionBase
)
295 ULONG lock
= LockIBase(0);
296 //struct Screen *scr;
298 DEBUG_POINTER(dprintf("SetPointerColors()\n");)
300 p
= &GetPrivIBase(IntuitionBase
)->ActivePreferences
->color17
;
302 DEBUG_POINTER(dprintf("color17 %04lx color18 %04lx color19 %04lx color20 %04lx\n",p
[0],p
[1],p
[2],p
[3]);)
304 if (IntuitionBase
->ActiveScreen
)
306 for (k
= 0; k
< 3; ++k
, ++p
)
308 SetRGB4(&IntuitionBase
->ActiveScreen
->ViewPort
,
309 k
+ 17, *p
>> 8, (*p
>> 4) & 0xf, *p
& 0xf);
315 DEBUG_POINTER(dprintf("SetPointerColors() done\n");)
319 struct SharedPointer
*CreateSharedPointer(struct ExtSprite
*sprite
, int x
, int y
,
320 struct IntuitionBase
*IntuitionBase
)
322 struct SharedPointer
*pointer
;
324 pointer
= AllocMem(sizeof(*pointer
), MEMF_PUBLIC
);
327 pointer
->sprite
= sprite
;
328 pointer
->xoffset
= x
;
329 pointer
->yoffset
= y
;
330 pointer
->ref_count
= 1;
336 void ObtainSharedPointer(struct SharedPointer
*pointer
,
337 struct IntuitionBase
*IntuitionBase
)
339 ULONG lock
= LockIBase(0);
340 ++pointer
->ref_count
;
344 void ReleaseSharedPointer(struct SharedPointer
*pointer
,
345 struct IntuitionBase
*IntuitionBase
)
347 ULONG lock
= LockIBase(0);
348 if (--pointer
->ref_count
== 0)
350 FreeSpriteData(pointer
->sprite
);
351 FreeMem(pointer
, sizeof(*pointer
));