annotate src/events/SDL_mouse.c @ 1671:89f7510fe17a SDL-1.3

Moved the cursor handling into the mouse code. Added support for multiple mice, potentially dynamically added and removed.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 09 Jun 2006 06:42:42 +0000
parents eef792d31de8
children 7688a73b25b1
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"
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
29 #include "default_cursor.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
32 static int SDL_num_mice;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
33 static int SDL_current_mouse;
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
34 static SDL_Mouse **SDL_mice;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 /* 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
38 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
39 SDL_MouseInit(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
41 return (0);
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
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
44 SDL_Mouse *
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
45 SDL_GetMouse(int index)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
46 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
47 if (index < 0 || index >= SDL_num_mice) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
48 return NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
49 }
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
50 return SDL_mice[index];
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
51 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
52
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
53 int
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
54 SDL_AddMouse(const SDL_Mouse * mouse, int index)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
55 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
56 SDL_Mouse **mice;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
57 SDL_Cursor *cursor;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
58 int selected_mouse;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
59
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
60 /* Add the mouse to the list of mice */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
61 if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
62 mice =
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
63 (SDL_Mouse **) SDL_realloc(SDL_mice,
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
64 (SDL_num_mice + 1) * sizeof(*mice));
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
65 if (!mice) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
66 SDL_OutOfMemory();
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
67 return -1;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
68 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
69
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
70 SDL_mice = mice;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
71 index = SDL_num_mice++;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
72 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
73 SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
74 if (!SDL_mice[index]) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
75 SDL_OutOfMemory();
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
76 return -1;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
77 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
78 *SDL_mice[index] = *mouse;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
79
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
80 /* Create the default cursor for the mouse */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
81 SDL_mice[index]->cursor_shown = SDL_TRUE;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
82 selected_mouse = SDL_SelectMouse(index);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
83 SDL_mice[index]->cur_cursor = NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
84 SDL_mice[index]->def_cursor =
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
85 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
86 DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
87 SDL_SetCursor(SDL_mice[index]->def_cursor);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
88 SDL_SelectMouse(selected_mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
89
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
90 return index;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
91 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
92
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
93 void
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
94 SDL_DelMouse(int index)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
95 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
96 SDL_Mouse *mouse = SDL_GetMouse(index);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
97
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
98 if (!mouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
99 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
100 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
101
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
102 mouse->def_cursor = NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
103 while (mouse->cursors) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
104 SDL_FreeCursor(mouse->cursors);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
105 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
106
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
107 if (mouse->FreeMouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
108 mouse->FreeMouse(mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
109 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
110 SDL_free(mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
111
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
112 SDL_mice[index] = NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
113 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
114
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
115 void
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
116 SDL_ResetMouse(int index)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
117 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
118 SDL_Mouse *mouse = SDL_GetMouse(index);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
119
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
120 if (!mouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
121 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
122 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
123
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
124 /* FIXME */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 }
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
126
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
127 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
128 SDL_MouseQuit(void)
1123
28ac87a38c17 Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents: 943
diff changeset
129 {
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
130 int i;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
131
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
132 for (i = 0; i < SDL_num_mice; ++i) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
133 SDL_DelMouse(i);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
134 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
135 SDL_num_mice = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
136 SDL_current_mouse = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
137
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
138 if (SDL_mice) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
139 SDL_free(SDL_mice);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
140 SDL_mice = NULL;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
141 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
142 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
143
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
144 int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
145 SDL_GetNumMice(void)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
146 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
147 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
148 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
150 int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
151 SDL_SelectMouse(int index)
460
a888b3ae31ff Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
152 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
153 if (index >= 0 && index < SDL_num_mice) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
154 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
155 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
156 return SDL_current_mouse;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
157 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
158
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
159 SDL_WindowID
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
160 SDL_GetMouseFocusWindow()
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 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
163
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
164 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
165 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
166 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
167 return mouse->focus;
460
a888b3ae31ff Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
168 }
a888b3ae31ff Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
169
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
170 Uint8
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
171 SDL_GetMouseState(int *x, int *y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
173 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
174
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
175 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
176 if (x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
177 *x = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
178 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
179 if (y) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
180 *y = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
181 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
182 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
183 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
184
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
185 if (x) {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
186 *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
187 }
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
188 if (y) {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
189 *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
190 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
191 return mouse->buttonstate;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193
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
194 Uint8
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
195 SDL_GetRelativeMouseState(int *x, int *y)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
197 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
198
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
199 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
200 if (x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
201 *x = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
202 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
203 if (y) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
204 *y = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
205 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
206 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
207 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
209 if (x) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
210 *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
211 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
212 if (y) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
213 *y = mouse->ydelta;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
214 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
215 mouse->xdelta = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
216 mouse->ydelta = 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
217 return mouse->buttonstate;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
218 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
220 int
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
221 SDL_SendMouseMotion(int index, SDL_WindowID windowID, int relative, int x,
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
222 int y)
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
223 {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
224 SDL_Mouse *mouse = SDL_GetMouse(index);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
225 int posted;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
226 int xrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
227 int yrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
228
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
229 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
230 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
231 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
233 if (windowID) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
234 mouse->focus = windowID;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
235 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
237 if (relative) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
238 /* Push the cursor around */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
239 xrel = x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
240 yrel = y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
241 x = (mouse->x + xrel);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
242 y = (mouse->y + yrel);
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
243 } else {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
244 xrel = x - mouse->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
245 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
246 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247
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
248 /* Drop events that don't change state */
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
249 if (!xrel && !yrel) {
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
250 #if 0
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
251 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
252 #endif
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
253 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
254 }
1283
f214b6fae45a Date: Fri, 14 Jan 2005 21:52:46 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 1123
diff changeset
255
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
256 /* Update internal mouse state */
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
257 mouse->x = x;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
258 mouse->y = y;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
259 mouse->xdelta += xrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
260 mouse->ydelta += yrel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
262 /* Move the mouse cursor, if needed */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
263 if (mouse->MoveCursor && mouse->cur_cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
264 mouse->MoveCursor(mouse->cur_cursor);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
265 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
266
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
267 /* 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
268 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
269 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
270 SDL_Event event;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
271 event.motion.type = SDL_MOUSEMOTION;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
272 event.motion.which = (Uint8) index;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
273 event.motion.state = mouse->buttonstate;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
274 event.motion.x = mouse->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
275 event.motion.y = mouse->y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
276 event.motion.xrel = xrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
277 event.motion.yrel = yrel;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
278 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
279 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
280 posted = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
281 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
282 }
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
283 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
284 return posted;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286
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
287 int
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
288 SDL_SendMouseButton(int index, SDL_WindowID windowID, Uint8 state,
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
289 Uint8 button)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 {
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
291 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
292 int posted;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
293 Uint8 type;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
295 if (!mouse) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
296 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
297 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
299 if (windowID) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
300 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
301 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302
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
303 /* 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
304 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
305 case SDL_PRESSED:
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
306 if (mouse->buttonstate & SDL_BUTTON(button)) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
307 /* Ignore this event, no state change */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
308 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
309 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
310 type = SDL_MOUSEBUTTONDOWN;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
311 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
312 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
313 case SDL_RELEASED:
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
314 if (!(mouse->buttonstate & SDL_BUTTON(button))) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
315 /* Ignore this event, no state change */
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
316 return 0;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
317 }
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
318 type = SDL_MOUSEBUTTONUP;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
319 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
320 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
321 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
322 /* Invalid state -- bail */
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
323 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
324 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325
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
326 /* 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
327 posted = 0;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
328 if (SDL_ProcessEvents[type] == SDL_ENABLE) {
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
329 SDL_Event event;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
330 event.type = type;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
331 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
332 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
333 event.button.button = button;
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
334 event.button.x = mouse->x;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
335 event.button.y = mouse->y;
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
336 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
337 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
338 posted = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
339 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
340 }
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
341 }
1670
eef792d31de8 Work in progress. :)
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
342 return posted;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344
1671
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
345 void
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
346 SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
347 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
348 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
349
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
350 if (!mouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
351 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
352 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
353
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
354 if (mouse->WarpMouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
355 mouse->WarpMouse(mouse, windowID, x, y);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
356 } else {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
357 SDL_SendMouseMotion(SDL_current_mouse, windowID, 0, x, y);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
358 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
359 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
360
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
361 SDL_Cursor *
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
362 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
363 int w, int h, int hot_x, int hot_y)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
364 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
365 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
366 SDL_Surface *surface;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
367 SDL_Cursor *cursor;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
368 int x, y;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
369 Uint32 *pixel;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
370 Uint8 datab, maskb;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
371 const Uint32 black = 0xFF000000;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
372 const Uint32 white = 0xFFFFFFFF;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
373 const Uint32 transparent = 0x00000000;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
374
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
375 if (!mouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
376 SDL_SetError("No mice are initialized");
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
377 return NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
378 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
379
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
380 if (!mouse->CreateCursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
381 SDL_SetError("Current mouse doesn't have cursor support");
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
382 return NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
383 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
384
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
385 /* Sanity check the hot spot */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
386 if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
387 SDL_SetError("Cursor hot spot doesn't lie within cursor");
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
388 return NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
389 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
390
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
391 /* Make sure the width is a multiple of 8 */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
392 w = ((w + 7) & ~7);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
393
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
394 /* Create the surface from a bitmap */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
395 surface =
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
396 SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
397 0xFF000000);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
398 if (!surface) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
399 return NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
400 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
401 for (y = 0; y < h; ++y) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
402 pixel =
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
403 (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch +
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
404 x * 4);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
405 for (x = 0; x < w; ++x) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
406 if ((x % 8) == 0) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
407 datab = *data++;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
408 maskb = *mask++;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
409 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
410 if (maskb & 0x80) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
411 *pixel++ = (datab & 0x80) ? black : white;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
412 } else {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
413 *pixel++ = (datab & 0x80) ? black : transparent;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
414 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
415 datab <<= 1;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
416 maskb <<= 1;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
417 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
418 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
419
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
420 cursor = mouse->CreateCursor(surface, hot_x, hot_y);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
421 if (cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
422 cursor->mouse = mouse;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
423 cursor->next = mouse->cursors;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
424 mouse->cursors = cursor;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
425 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
426
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
427 SDL_FreeSurface(surface);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
428
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
429 return cursor;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
430 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
431
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
432 /* SDL_SetCursor(NULL) can be used to force the cursor redraw,
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
433 if this is desired for any reason. This is used when setting
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
434 the video mode and when the SDL window gains the mouse focus.
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
435 */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
436 void
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
437 SDL_SetCursor(SDL_Cursor * cursor)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
438 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
439 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
440
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
441 if (!mouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
442 SDL_SetError("No mice are initialized");
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
443 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
444 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
445
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
446 /* Set the new cursor */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
447 if (cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
448 /* Make sure the cursor is still valid for this mouse */
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
449 SDL_Cursor *found;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
450 for (found = mouse->cursors; found; found = found->next) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
451 if (found == cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
452 break;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
453 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
454 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
455 if (!found) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
456 SDL_SetError("Cursor not associated with the current mouse");
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
457 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
458 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
459 mouse->cur_cursor = cursor;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
460 } else {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
461 cursor = mouse->cur_cursor;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
462 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
463
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
464 if (cursor && mouse->cursor_shown) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
465 if (mouse->ShowCursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
466 mouse->ShowCursor(cursor);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
467 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
468 } else {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
469 if (mouse->ShowCursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
470 mouse->ShowCursor(NULL);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
471 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
472 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
473 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
474
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
475 SDL_Cursor *
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
476 SDL_GetCursor(void)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
477 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
478 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
479
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
480 if (!mouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
481 return NULL;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
482 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
483 return mouse->cur_cursor;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
484 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
485
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
486 void
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
487 SDL_FreeCursor(SDL_Cursor * cursor)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
488 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
489 SDL_Mouse *mouse;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
490 SDL_Cursor *curr, *prev;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
491
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
492 if (!cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
493 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
494 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
495 mouse = cursor->mouse;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
496
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
497 if (cursor == mouse->def_cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
498 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
499 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
500 if (cursor == mouse->cur_cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
501 SDL_SetCursor(mouse->def_cursor);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
502 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
503
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
504 for (prev = NULL, curr = mouse->cursors; curr;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
505 prev = curr, curr = curr->next) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
506 if (curr == cursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
507 if (prev) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
508 prev->next = curr->next;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
509 } else {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
510 mouse->cursors = curr->next;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
511 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
512
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
513 if (mouse->FreeCursor) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
514 mouse->FreeCursor(curr);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
515 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
516 return;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
517 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
518 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
519 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
520
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
521 int
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
522 SDL_ShowCursor(int toggle)
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
523 {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
524 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
525 SDL_bool shown;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
526
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
527 if (!mouse) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
528 return 0;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
529 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
530
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
531 shown = mouse->cursor_shown;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
532 if (toggle >= 0) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
533 if (toggle) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
534 mouse->cursor_shown = SDL_TRUE;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
535 } else {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
536 mouse->cursor_shown = SDL_FALSE;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
537 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
538 if (mouse->cursor_shown != shown) {
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
539 SDL_SetCursor(NULL);
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
540 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
541 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
542 return shown;
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
543 }
89f7510fe17a Moved the cursor handling into the mouse code.
Sam Lantinga <slouken@libsdl.org>
parents: 1670
diff changeset
544
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
545 /* vi: set ts=4 sw=4 expandtab: */