chiark / gitweb /
Create readable text `.bas' for each tokenized BASIC `,ffb' file.
[ssr] / StraySrc / Libraries / Steel / c / pointer
1 /*
2  * pointer.c
3  *
4  * Handling of pointer-shape changing
5  *
6  * © 1994-1998 Straylight
7  */
8
9 /*----- Licensing note ----------------------------------------------------*
10  *
11  * This file is part of Straylight's Steel library.
12  *
13  * Steel is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * Steel is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with Steel.  If not, write to the Free Software Foundation,
25  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #include <stdio.h>
29
30 #include "os.h"
31 #include "sprite.h"
32 #include "swis.h"
33 #include "wimpt.h"
34 #include "pointer.h"
35
36 static BOOL pointer__notDefault;
37
38 /*
39  * os_error *pointer__magicSpriteOp(sprite_area *a,
40  *                                  sprite _id *sid,
41  *                                  os_regset *r)
42  *
43  * Use
44  *  Performs a sprite op of the appropriate kind for the sprite area given.
45  *
46  * Parameters
47  *  sprite_area *a == the sprite area to do the op on
48  *  sprite_id *sid == the sprite id to do it to
49  *  os_regset r == other registers for the op
50  *
51  * Returns
52  *  An error or 0.
53  */
54
55 static os_error *pointer__magicSpriteOp(sprite_area *a,
56                                         sprite_id *sid,
57                                         os_regset *r)
58 {
59   if (a==(sprite_area *)1)
60   {
61     /* --- The WIMP sprite area --- */
62
63     r->r[0]&=~0x300;
64     r->r[2]=(int)sid->s.name;
65     return (os_swix(XWimp_SpriteOp,r));
66   }
67   else if (!a)
68   {
69     /* --- The nasty system sprite area --- */
70
71     r->r[0]&=~0x300;
72     r->r[2]=(int)sid->s.name;
73     return (os_swix(XOS_SpriteOp,r));
74   }
75   else
76   {
77     /* --- A nice user sprite area --- */
78
79     r->r[0]&=~0x300;
80     if (sid->tag)
81     {
82       r->r[0]|=0x200;
83       r->r[2]=(int)sid->s.addr;
84     }
85     else
86     {
87       r->r[0]|=0x100;
88       r->r[2]=(int)sid->s.name;
89     }
90     r->r[1]=(int)a;
91
92     return (os_swix(XOS_SpriteOp,r));
93   }
94 }
95
96 /*
97  * BOOL pointer__spriteExist(sprite_area *a,char *name)
98  *
99  * Use
100  *  Returns whether a named sprite exists in the given area
101  *
102  * Parameters
103  *  sprite_area *a == the sprite area
104  *  char *name == the name of the sprite to test
105  *
106  * Returns
107  *  TRUE if the sprite is there
108  */
109
110 static BOOL pointer__spriteExist(sprite_area *a,char *name)
111 {
112   os_regset r;
113   sprite_id sid;
114
115   sid.s.name=name;
116   sid.tag=0;
117
118   r.r[0]=40;
119   return (!pointer__magicSpriteOp(a,&sid,&r));
120 }
121
122 /*
123  * os_error *pointer_set_shape(sprite_area *a,sprite_id *sid,int x,int y)
124  *
125  * Use
126  *  Sets the pointer shape to be the pointer specified.  If a pointer with
127  *  name `name<dx><dy>' is found in the sprite area, that's used instead, and
128  *  the active point is scaled assuming that the original was specified in
129  *  mode-8 type coordinates.
130  *
131  * Parameters
132  *  sprite_area *a == the sprite area containing the sprite
133  *  sprite_id *sid == pointer to the sprite identifier (dumb idea)
134  *  int x,int y == coordinates (in pixels) of the hot-spot
135  */
136
137 os_error *pointer_set_shape(sprite_area *a,sprite_id *sid,int x,int y)
138 {
139   char buffer[15];
140   sprite_id s;
141   os_regset r;
142
143   if (!sid->tag)
144   {
145     /* --- Try and find a good match for the mode --- */
146
147     sprintf(buffer,"%s%i%i",sid->s.name,wimpt_dx(),wimpt_dy());
148     if (pointer__spriteExist(a,buffer))
149     {
150       s.s.name=buffer;
151       s.tag=0;
152       sid=&s;
153       x=(x*2)/wimpt_dx();
154       y=(y*4)/wimpt_dy();
155     }
156   }
157
158   /* --- Now set up the pointer shape --- */
159
160   r.r[0]=36;
161   r.r[3]=2;                     /* Set everything up as nicely as possible */
162   r.r[4]=x;
163   r.r[5]=y;
164   r.r[6]=r.r[7]=0;              /* No translation table, no zoom box       */
165   pointer__notDefault=TRUE;
166   return (pointer__magicSpriteOp(a,sid,&r));
167 }
168
169 /*
170  * void pointer_reset_shape(void)
171  *
172  * Use
173  *  Resets the pointer shape
174  */
175
176 void pointer_reset_shape(void)
177 {
178   if (pointer__notDefault)
179     os_cli("%pointer");
180   pointer__notDefault=FALSE;
181 }