source: abuse/trunk/src/sdlport/mouse.cpp @ 28

Last change on this file since 28 was 2, checked in by Sam Hocevar, 18 years ago
  • imported original 0.7.0 tarball
File size: 1.9 KB
Line 
1/************************
2 * mouse.c
3 * SDL port for Abuse
4 * by Anthony Kruize
5 ************************/
6
7#include <SDL.h>
8
9#include "video.hpp"
10#include "sprite.hpp"
11#include "image.hpp"
12#include "filter.hpp"
13#include "mdlread.hpp"
14#include "mouse.hpp"
15
16unsigned char def_mouse[]=
17{
18        0,2,0,0,0,0,0,0,
19        2,1,2,0,0,0,0,0,
20        2,1,1,2,0,0,0,0,
21        2,1,1,1,2,0,0,0,
22        2,1,1,1,1,2,0,0,
23        2,1,1,1,1,1,2,0,
24        0,2,1,1,2,2,0,0,
25        0,0,2,1,1,2,0,0,
26        0,0,2,1,1,2,0,0,
27        0,0,0,2,2,0,0,0
28};
29
30//
31// Constructor
32//
33JCMouse::JCMouse( image *Screen, palette *pal )
34{
35        image *im;
36        int br, dr;
37        filter f;
38        but = 0;
39        cx = cy = 0;
40        here = 1;
41        sp = NULL;
42
43        screen = Screen;
44        br = pal->brightest( 1 );
45        dr = pal->darkest( 1 );
46        f.set( 1, br );
47        f.set( 2, dr );
48        im = new image( 8, 10, def_mouse );
49        f.apply( im );
50        sp = new sprite( Screen, im, 100, 100 );
51        mx = Screen->width() / 2;
52        my = Screen->height() / 2;
53}
54
55//
56// Destructor
57//
58JCMouse::~JCMouse()
59{
60        if( sp )
61        {
62                delete sp->visual;
63                delete sp;
64        }
65}
66
67//
68// set_shape()
69// Set the shape of the mouse cursor
70//
71void JCMouse::set_shape( image *im, int centerx, int centery )
72{
73        sp->change_visual( im, 1 );
74        cx = -centerx;
75        cy = -centery;
76}
77
78//
79// set_position()
80// Set the position of the mouse cursor
81//
82void JCMouse::set_position( int new_mx, int new_my )
83{
84        // Make sure the values we are given are sensible.
85        if( new_mx > 319 )
86        {
87                new_mx = 319;
88        }
89        if( new_my > 199 )
90        {
91                new_my = 199;
92        }
93
94        // Set the new position
95        mx = new_mx;
96        my = new_my;
97        SDL_WarpMouse( new_mx, new_my );
98}
99
100//
101// update()
102// Update the mouses position and buttons states
103//
104void JCMouse::update( int newx, int newy, int new_but )
105{
106        if( newx < 0 )
107        {
108                Uint8 mask;
109
110                lx = mx;
111                ly = my;
112                lbut = but;
113                mask = SDL_GetMouseState( &mx, &my );
114                but = ( ( mask & SDL_BUTTON(1) ) != 0 ) |
115                          ( ( mask & SDL_BUTTON(2) ) != 0 ) << 2 |
116                          ( ( mask & SDL_BUTTON(3) ) != 0 ) << 1;
117        }
118        else
119        {
120                mx = newx;
121                my = newy;
122                but = new_but;
123        }
124}
Note: See TracBrowser for help on using the repository browser.