File: MouseLinux.cpp

package info (click to toggle)
between 6%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,532 kB
  • sloc: cpp: 28,110; php: 718; ansic: 638; objc: 245; sh: 236; makefile: 97; perl: 67
file content (73 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Modification History
 *
 * 2000-November-28		Jason Rohrer
 * Created.
 *
 * 2001-May-2   Jason Rohrer
 * Changed to use more standard SDL include location.
 */
 
#include "minorGems/ui/Mouse.h"

#include <SDL/SDL.h>

/**
 * Note:  Linux implementation:
 * Requires that a ScreenGraphics be constructed before accessing the mouse.
 */



void Mouse::getLocation( int *outX, int *outY ) {
	SDL_PumpEvents();
	SDL_GetMouseState( outX, outY );
	/*
	SDL_PumpEvents( void );
	
	int numEventsToGet = 99;
	
	SDL_Event *events = new SDL_Event[numEventsToGet];
	
	// get events from the queue
	int numEventsRetrieved = SDL_PeepEvents( events, numEventsToGet,
		SDL_GETEVENT, SDL_MOUSEMOTIONMASK ); 
	
	// for mouse motion, we only care about the last event
	SDL_Event lastEvent = events[ numEventsRetrieved - 1 ];
	
	delete [] events;
	*/
	}
	
	
char Mouse::isButtonDown( int inButtonNumber ) {
	SDL_PumpEvents();
	
	int x, y;
	
	Uint8 buttonState = SDL_GetMouseState( &x, &y );
	
	if( inButtonNumber == 0 ) {
		return( buttonState & SDL_BUTTON_LMASK );
		}
	
	if( mNumButtons >=3 ) {	
		// if we care about 3 buttons, then count the middle button
		// as button 1
		if( inButtonNumber == 1 ) {
			return( buttonState & SDL_BUTTON_MMASK );
			}
		if( inButtonNumber == 2 ) {
			return( buttonState & SDL_BUTTON_RMASK );
			}
		}
	else {
		// we care about 2 or fewer buttons 
		if( inButtonNumber == 1 ) {
			return( buttonState & SDL_BUTTON_RMASK );
			}
		}
		
	return false;
	}