annotate src/events/SDL_mouse.c @ 1670:eef792d31de8 SDL-1.3

Work in progress. :)
author Sam Lantinga <slouken@libsdl.org>
date Wed, 07 Jun 2006 16:10:28 +0000
parents 4da1ee79c9af
children 89f7510fe17a
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1283
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1283
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1283
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1283
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1283
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1283
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1283
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* General mouse handling code for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include "SDL_events.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include "SDL_events_c.h"
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
28 #include "SDL_mouse_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
31 static int SDL_num_mice;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
32 static int SDL_current_mouse;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
33 static SDL_Mouse *SDL_mice;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 /* Public functions */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
37 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
38 SDL_MouseInit(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
40 return (0);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
41 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
42
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
43 int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
44 SDL_AddMouse(SDL_WindowID focus, int x, int y, Uint8 buttonstate)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
45 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
46 SDL_Mouse *new_mice;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
47 int index;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
48 SDL_Mouse *mouse;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
49
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
50 new_mice =
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
51 (SDL_Mouse *) SDL_realloc(SDL_mice,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
52 (SDL_num_mice + 1) * sizeof(*new_mice));
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
53 if (!new_mice) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
54 SDL_OutOfMemory();
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
55 return -1;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
56 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
58 index = SDL_num_mice++;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
59 mouse = &SDL_mice[index];
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
60 mouse->focus = focus;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
61 mouse->x = x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
62 mouse->y = y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
63 mouse->xdelta = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
64 mouse->ydelta = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
65 mouse->buttonstate = buttonstate;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
66
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
67 return index;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
68 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
69
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
70 SDL_Mouse *
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
71 SDL_GetMouse(int index)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
72 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
73 if (index < 0 || index >= SDL_num_mice) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
74 return NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
75 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
76 return &SDL_mice[index];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
78
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
79 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
80 SDL_MouseQuit(void)
1123
28ac87a38c17 Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents: 943
diff changeset
81 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
82 SDL_num_mice = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
83 SDL_current_mouse = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
84
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
85 if (SDL_mice) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
86 SDL_free(SDL_mice);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
87 SDL_mice = NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
88 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
89 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
90
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
91 int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
92 SDL_GetNumMice(void)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
93 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
94 return SDL_num_mice;
1123
28ac87a38c17 Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents: 943
diff changeset
95 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
97 int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
98 SDL_SelectMouse(int index)
460
a888b3ae31ff Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
99 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
100 if (index >= 0 && index < SDL_num_mice) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
101 SDL_current_mouse = index;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
102 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
103 return SDL_current_mouse;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
104 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
105
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
106 SDL_WindowID
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
107 SDL_GetMouseFocusWindow()
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
108 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
109 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
110
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
111 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
112 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
113 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
114 return mouse->focus;
460
a888b3ae31ff Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
115 }
a888b3ae31ff Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
116
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
117 Uint8
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
118 SDL_GetMouseState(int *x, int *y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
120 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
121
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
122 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
123 if (x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
124 *x = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
125 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
126 if (y) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
127 *y = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
128 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
129 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
130 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
131
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
132 if (x) {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
133 *x = mouse->x;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
134 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
135 if (y) {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
136 *y = mouse->y;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
137 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
138 return mouse->buttonstate;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
141 Uint8
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
142 SDL_GetRelativeMouseState(int *x, int *y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
144 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
145
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
146 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
147 if (x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
148 *x = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
149 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
150 if (y) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
151 *y = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
152 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
153 return 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
154 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
156 if (x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
157 *x = mouse->xdelta;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
158 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
159 if (y) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
160 *y = mouse->ydelta;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
161 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
162 mouse->xdelta = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
163 mouse->ydelta = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
164 return mouse->buttonstate;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
165 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
167 int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
168 SDL_SendMouseMotion(int index, SDL_WindowID windowID, int relative, int x,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
169 int y)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
170 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
171 SDL_Mouse *mouse = SDL_GetMouse(index);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
172 int posted;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
173 int xrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
174 int yrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
175
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
176 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
177 return 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
178 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
180 if (windowID) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
181 mouse->focus = windowID;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
182 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
184 if (relative) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
185 /* Push the cursor around */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
186 xrel = x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
187 yrel = y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
188 x = (mouse->x + xrel);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
189 y = (mouse->y + yrel);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
190 } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
191 xrel = x - mouse->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
192 yrel = y - mouse->y;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
193 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
195 /* Drop events that don't change state */
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
196 if (!xrel && !yrel) {
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
197 #if 0
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
198 printf("Mouse event didn't change state - dropped!\n");
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
199 #endif
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
200 return 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
201 }
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
202
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
203 /* Update internal mouse state */
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
204 mouse->xdelta += xrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
205 mouse->ydelta += yrel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
207 /* Post the event, if desired */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
208 posted = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
209 if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
210 SDL_Event event;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
211 event.motion.type = SDL_MOUSEMOTION;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
212 event.motion.which = (Uint8) index;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
213 event.motion.state = mouse->buttonstate;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
214 event.motion.x = mouse->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
215 event.motion.y = mouse->y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
216 event.motion.xrel = xrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
217 event.motion.yrel = yrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
218 event.motion.windowID = mouse->focus;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
219 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
220 posted = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
221 SDL_PushEvent(&event);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
222 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
223 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
224 return posted;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
227 int
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
228 SDL_PrivateMouseButton(int index, SDL_WindowID windowID, Uint8 state,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
229 Uint8 button)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
231 SDL_Mouse *mouse = SDL_GetMouse(index);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
232 int posted;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
233 Uint8 type;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
235 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
236 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
237 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
239 if (windowID) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
240 mouse->focus = windowID;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
241 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
243 /* Figure out which event to perform */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
244 switch (state) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
245 case SDL_PRESSED:
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
246 if (mouse->buttonstate & SDL_BUTTON(button)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
247 /* Ignore this event, no state change */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
248 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
249 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
250 type = SDL_MOUSEBUTTONDOWN;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
251 mouse->buttonstate |= SDL_BUTTON(button);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
252 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
253 case SDL_RELEASED:
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
254 if (!(mouse->buttonstate & SDL_BUTTON(button))) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
255 /* Ignore this event, no state change */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
256 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
257 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
258 type = SDL_MOUSEBUTTONUP;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
259 mouse->buttonstate &= ~SDL_BUTTON(button);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
260 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
261 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
262 /* Invalid state -- bail */
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
263 return 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
264 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
266 /* Post the event, if desired */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
267 posted = 0;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
268 if (SDL_ProcessEvents[type] == SDL_ENABLE) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
269 SDL_Event event;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
270 event.type = type;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
271 event.button.which = (Uint8) index;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
272 event.button.state = state;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
273 event.button.button = button;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
274 event.button.x = mouse->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
275 event.button.y = mouse->y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
276 event.button.windowID = windowID;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
277 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
278 posted = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
279 SDL_PushEvent(&event);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
280 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
281 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
282 return posted;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1525
diff changeset
285 /* vi: set ts=4 sw=4 expandtab: */