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

Last change on this file since 494 was 494, checked in by Sam Hocevar, 12 years ago

style: remove trailing spaces, fix copyright statements.

File size: 3.0 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This program is free software; you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation; either version 2 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program; if not, write to the Free Software Foundation,
18 *  Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 */
20
21#include "config.h"
22
23#include <SDL.h>
24
25#include "video.h"
26#include "sprite.h"
27#include "image.h"
28#include "filter.h"
29#include "mouse.h"
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 > screen->width() - 1 )
101    {
102        new_mx = screen->width() - 1;
103    }
104    if( new_my > screen->height() - 1 )
105    {
106        new_my = screen->height() - 1;
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.