source: abuse/trunk/src/sdl2port/mouse.cpp @ 731

Last change on this file since 731 was 731, checked in by jjsimpso, 4 years ago

sdlport: Add support for SDL2, inculding the game controller API. Configure
script will check for SDL2 and use it if present, otherwise it will fall
back to SDL v1. Some old SDL v1 features not implemented yet on SDL2, such
as saving screenshots.

core: Small change for SDL2 game controller API to disable the game
controller in the save/load game menu.

Summary of game controller API changes:

  • Enable with -gamepad
  • Tested with PS3 dualshock 3.
  • D-pad moves, right analog controls aiming
  • X: change weapon, []: jump, R1: fire, L1: special ability, /\:use/activate
  • All menu navigation requires the mouse, which is disabled during normal game play.
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#if defined HAVE_CONFIG_H
22#   include "config.h"
23#endif
24
25#include <SDL.h>
26
27#include "common.h"
28
29#include "video.h"
30#include "sprite.h"
31#include "image.h"
32#include "filter.h"
33#include "mouse.h"
34
35unsigned char def_mouse[]=
36{
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
47};
48
49//
50// Constructor
51//
52JCMouse::JCMouse( image *Screen, palette *pal )
53{
54    image *im;
55    int br, dr;
56    Filter f;
57    but = 0;
58    cx = cy = 0;
59    here = 1;
60    sp = NULL;
61
62    screen = Screen;
63    br = pal->brightest( 1 );
64    dr = pal->darkest( 1 );
65    f.Set( 1, br );
66    f.Set( 2, dr );
67    im = new image(vec2i(8, 10), def_mouse);
68    f.Apply( im );
69    sp = new sprite(Screen, im, 100, 100);
70    mx = Screen->Size().x / 2;
71    my = Screen->Size().y / 2;
72}
73
74//
75// Destructor
76//
77JCMouse::~JCMouse()
78{
79    if( sp )
80    {
81        delete sp->visual;
82        delete sp;
83    }
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{
92    sp->change_visual( im, 1 );
93    cx = -centerx;
94    cy = -centery;
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{
103    // Make sure the values we are given are sensible.
104    if( new_mx > screen->Size().x - 1 )
105    {
106        new_mx = screen->Size().x - 1;
107    }
108    if( new_my > screen->Size().y - 1 )
109    {
110        new_my = screen->Size().y - 1;
111    }
112
113    // Set the new position
114    mx = new_mx;
115    my = new_my;
116    SDL_WarpMouseInWindow( NULL, new_mx, new_my );
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{
125    if( newx < 0 )
126    {
127        Uint8 mask;
128
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    }
143}
Note: See TracBrowser for help on using the repository browser.