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

Last change on this file since 579 was 579, checked in by Sam Hocevar, 11 years ago

imlib: refactor the Filter and ColorFilter? classes.

File size: 3.0 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]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 */
[2]20
[555]21#if defined HAVE_CONFIG_H
22#   include "config.h"
23#endif
[56]24
[2]25#include <SDL.h>
26
[512]27#include "common.h"
28
[481]29#include "video.h"
30#include "sprite.h"
31#include "image.h"
32#include "filter.h"
33#include "mouse.h"
[2]34
35unsigned char def_mouse[]=
36{
[124]37    0,2,0,0,0,0,0,0,
38    2,1,2,0,0,0,0,0,
39    2,1,1,2,0,0,0,0,
40    2,1,1,1,2,0,0,0,
41    2,1,1,1,1,2,0,0,
42    2,1,1,1,1,1,2,0,
43    0,2,1,1,2,2,0,0,
44    0,0,2,1,1,2,0,0,
45    0,0,2,1,1,2,0,0,
46    0,0,0,2,2,0,0,0
[2]47};
48
49//
50// Constructor
51//
52JCMouse::JCMouse( image *Screen, palette *pal )
53{
[124]54    image *im;
55    int br, dr;
[579]56    Filter f;
[124]57    but = 0;
58    cx = cy = 0;
59    here = 1;
60    sp = NULL;
[2]61
[124]62    screen = Screen;
63    br = pal->brightest( 1 );
64    dr = pal->darkest( 1 );
[579]65    f.Set( 1, br );
66    f.Set( 2, dr );
[513]67    im = new image(vec2i(8, 10), def_mouse);
[579]68    f.Apply( im );
[513]69    sp = new sprite(Screen, im, 100, 100);
[512]70    mx = Screen->Size().x / 2;
71    my = Screen->Size().y / 2;
[2]72}
73
74//
75// Destructor
76//
77JCMouse::~JCMouse()
78{
[124]79    if( sp )
80    {
81        delete sp->visual;
82        delete sp;
83    }
[2]84}
85
86//
87// set_shape()
88// Set the shape of the mouse cursor
89//
90void JCMouse::set_shape( image *im, int centerx, int centery )
91{
[124]92    sp->change_visual( im, 1 );
93    cx = -centerx;
94    cy = -centery;
[2]95}
96
97//
98// set_position()
99// Set the position of the mouse cursor
100//
101void JCMouse::set_position( int new_mx, int new_my )
102{
[124]103    // Make sure the values we are given are sensible.
[512]104    if( new_mx > screen->Size().x - 1 )
[124]105    {
[512]106        new_mx = screen->Size().x - 1;
[124]107    }
[512]108    if( new_my > screen->Size().y - 1 )
[124]109    {
[512]110        new_my = screen->Size().y - 1;
[124]111    }
[2]112
[124]113    // Set the new position
114    mx = new_mx;
115    my = new_my;
116    SDL_WarpMouse( new_mx, new_my );
[2]117}
118
119//
120// update()
121// Update the mouses position and buttons states
122//
123void JCMouse::update( int newx, int newy, int new_but )
124{
[124]125    if( newx < 0 )
126    {
127        Uint8 mask;
[2]128
[124]129        lx = mx;
130        ly = my;
131        lbut = but;
132        mask = SDL_GetMouseState( &mx, &my );
133        but = ( ( mask & SDL_BUTTON(1) ) != 0 ) |
134              ( ( mask & SDL_BUTTON(2) ) != 0 ) << 2 |
135              ( ( mask & SDL_BUTTON(3) ) != 0 ) << 1;
136    }
137    else
138    {
139        mx = newx;
140        my = newy;
141        but = new_but;
142    }
[2]143}
Note: See TracBrowser for help on using the repository browser.