/* * pointer.c * * Handling of pointer-shape changing * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Steel is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "os.h" #include "sprite.h" #include "swis.h" #include "wimpt.h" #include "pointer.h" static BOOL pointer__notDefault; /* * os_error *pointer__magicSpriteOp(sprite_area *a, * sprite _id *sid, * os_regset *r) * * Use * Performs a sprite op of the appropriate kind for the sprite area given. * * Parameters * sprite_area *a == the sprite area to do the op on * sprite_id *sid == the sprite id to do it to * os_regset r == other registers for the op * * Returns * An error or 0. */ static os_error *pointer__magicSpriteOp(sprite_area *a, sprite_id *sid, os_regset *r) { if (a==(sprite_area *)1) { /* --- The WIMP sprite area --- */ r->r[0]&=~0x300; r->r[2]=(int)sid->s.name; return (os_swix(XWimp_SpriteOp,r)); } else if (!a) { /* --- The nasty system sprite area --- */ r->r[0]&=~0x300; r->r[2]=(int)sid->s.name; return (os_swix(XOS_SpriteOp,r)); } else { /* --- A nice user sprite area --- */ r->r[0]&=~0x300; if (sid->tag) { r->r[0]|=0x200; r->r[2]=(int)sid->s.addr; } else { r->r[0]|=0x100; r->r[2]=(int)sid->s.name; } r->r[1]=(int)a; return (os_swix(XOS_SpriteOp,r)); } } /* * BOOL pointer__spriteExist(sprite_area *a,char *name) * * Use * Returns whether a named sprite exists in the given area * * Parameters * sprite_area *a == the sprite area * char *name == the name of the sprite to test * * Returns * TRUE if the sprite is there */ static BOOL pointer__spriteExist(sprite_area *a,char *name) { os_regset r; sprite_id sid; sid.s.name=name; sid.tag=0; r.r[0]=40; return (!pointer__magicSpriteOp(a,&sid,&r)); } /* * os_error *pointer_set_shape(sprite_area *a,sprite_id *sid,int x,int y) * * Use * Sets the pointer shape to be the pointer specified. If a pointer with * name `name' is found in the sprite area, that's used instead, and * the active point is scaled assuming that the original was specified in * mode-8 type coordinates. * * Parameters * sprite_area *a == the sprite area containing the sprite * sprite_id *sid == pointer to the sprite identifier (dumb idea) * int x,int y == coordinates (in pixels) of the hot-spot */ os_error *pointer_set_shape(sprite_area *a,sprite_id *sid,int x,int y) { char buffer[15]; sprite_id s; os_regset r; if (!sid->tag) { /* --- Try and find a good match for the mode --- */ sprintf(buffer,"%s%i%i",sid->s.name,wimpt_dx(),wimpt_dy()); if (pointer__spriteExist(a,buffer)) { s.s.name=buffer; s.tag=0; sid=&s; x=(x*2)/wimpt_dx(); y=(y*4)/wimpt_dy(); } } /* --- Now set up the pointer shape --- */ r.r[0]=36; r.r[3]=2; /* Set everything up as nicely as possible */ r.r[4]=x; r.r[5]=y; r.r[6]=r.r[7]=0; /* No translation table, no zoom box */ pointer__notDefault=TRUE; return (pointer__magicSpriteOp(a,sid,&r)); } /* * void pointer_reset_shape(void) * * Use * Resets the pointer shape */ void pointer_reset_shape(void) { if (pointer__notDefault) os_cli("%pointer"); pointer__notDefault=FALSE; }