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

Last change on this file since 56 was 56, checked in by Sam Hocevar, 15 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 2.6 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
4 *
5 *  This program is free software; you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation; either version 2 of the License, or
8 *  (at your option) any later version.
9 *
10 *  This program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with this program; if not, write to the Free Software Foundation,
17 *  Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
18 */
19
20#include "config.h"
21
22#include <SDL.h>
23
24#include "video.hpp"
25#include "sprite.hpp"
26#include "image.hpp"
27#include "filter.hpp"
28#include "mdlread.hpp"
29#include "mouse.hpp"
30
31unsigned char def_mouse[]=
32{
33        0,2,0,0,0,0,0,0,
34        2,1,2,0,0,0,0,0,
35        2,1,1,2,0,0,0,0,
36        2,1,1,1,2,0,0,0,
37        2,1,1,1,1,2,0,0,
38        2,1,1,1,1,1,2,0,
39        0,2,1,1,2,2,0,0,
40        0,0,2,1,1,2,0,0,
41        0,0,2,1,1,2,0,0,
42        0,0,0,2,2,0,0,0
43};
44
45//
46// Constructor
47//
48JCMouse::JCMouse( image *Screen, palette *pal )
49{
50        image *im;
51        int br, dr;
52        filter f;
53        but = 0;
54        cx = cy = 0;
55        here = 1;
56        sp = NULL;
57
58        screen = Screen;
59        br = pal->brightest( 1 );
60        dr = pal->darkest( 1 );
61        f.set( 1, br );
62        f.set( 2, dr );
63        im = new image( 8, 10, def_mouse );
64        f.apply( im );
65        sp = new sprite( Screen, im, 100, 100 );
66        mx = Screen->width() / 2;
67        my = Screen->height() / 2;
68}
69
70//
71// Destructor
72//
73JCMouse::~JCMouse()
74{
75        if( sp )
76        {
77                delete sp->visual;
78                delete sp;
79        }
80}
81
82//
83// set_shape()
84// Set the shape of the mouse cursor
85//
86void JCMouse::set_shape( image *im, int centerx, int centery )
87{
88        sp->change_visual( im, 1 );
89        cx = -centerx;
90        cy = -centery;
91}
92
93//
94// set_position()
95// Set the position of the mouse cursor
96//
97void JCMouse::set_position( int new_mx, int new_my )
98{
99        // Make sure the values we are given are sensible.
100        if( new_mx > 319 )
101        {
102                new_mx = 319;
103        }
104        if( new_my > 199 )
105        {
106                new_my = 199;
107        }
108
109        // Set the new position
110        mx = new_mx;
111        my = new_my;
112        SDL_WarpMouse( new_mx, new_my );
113}
114
115//
116// update()
117// Update the mouses position and buttons states
118//
119void JCMouse::update( int newx, int newy, int new_but )
120{
121        if( newx < 0 )
122        {
123                Uint8 mask;
124
125                lx = mx;
126                ly = my;
127                lbut = but;
128                mask = SDL_GetMouseState( &mx, &my );
129                but = ( ( mask & SDL_BUTTON(1) ) != 0 ) |
130                          ( ( mask & SDL_BUTTON(2) ) != 0 ) << 2 |
131                          ( ( mask & SDL_BUTTON(3) ) != 0 ) << 1;
132        }
133        else
134        {
135                mx = newx;
136                my = newy;
137                but = new_but;
138        }
139}
Note: See TracBrowser for help on using the repository browser.