Mercurial > sdl-ios-xcode
comparison src/video/ataricommon/SDL_ataridevmouse.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 2405517b5eab |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
42 static int handle = -1; | 42 static int handle = -1; |
43 static int mouseb, prev_mouseb; | 43 static int mouseb, prev_mouseb; |
44 | 44 |
45 /* Functions */ | 45 /* Functions */ |
46 | 46 |
47 int SDL_AtariDevMouse_Open(void) | 47 int |
48 SDL_AtariDevMouse_Open (void) | |
48 { | 49 { |
49 int r; | 50 int r; |
50 const char *mousedev; | 51 const char *mousedev; |
51 | 52 |
52 /* | 53 /* |
53 TODO: Fix the MiNT device driver, that locks mouse for other | 54 TODO: Fix the MiNT device driver, that locks mouse for other |
54 applications, so this is disabled till fixed | 55 applications, so this is disabled till fixed |
55 */ | 56 */ |
56 return 0; | 57 return 0; |
57 | 58 |
58 /* First, try SDL_MOUSEDEV device */ | 59 /* First, try SDL_MOUSEDEV device */ |
59 mousedev = SDL_getenv("SDL_MOUSEDEV"); | 60 mousedev = SDL_getenv ("SDL_MOUSEDEV"); |
60 if (!mousedev) { | 61 if (!mousedev) { |
61 handle = open(mousedev, 0); | 62 handle = open (mousedev, 0); |
62 } | 63 } |
63 | 64 |
64 /* Failed, try default device */ | 65 /* Failed, try default device */ |
65 if (handle<0) { | 66 if (handle < 0) { |
66 handle = open(DEVICE_NAME, 0); | 67 handle = open (DEVICE_NAME, 0); |
67 } | 68 } |
68 | 69 |
69 if (handle<0) { | 70 if (handle < 0) { |
70 handle = -1; | 71 handle = -1; |
71 return 0; | 72 return 0; |
72 } | 73 } |
73 | 74 |
74 /* Set non blocking mode */ | 75 /* Set non blocking mode */ |
75 r = fcntl(handle, F_GETFL, 0); | 76 r = fcntl (handle, F_GETFL, 0); |
76 if (r<0) { | 77 if (r < 0) { |
77 close(handle); | 78 close (handle); |
78 handle = -1; | 79 handle = -1; |
79 return 0; | 80 return 0; |
80 } | 81 } |
81 | 82 |
82 r |= O_NDELAY; | 83 r |= O_NDELAY; |
83 | 84 |
84 r = fcntl(handle, F_SETFL, r); | 85 r = fcntl (handle, F_SETFL, r); |
85 if (r<0) { | 86 if (r < 0) { |
86 close(handle); | 87 close (handle); |
87 handle = -1; | 88 handle = -1; |
88 return 0; | 89 return 0; |
89 } | 90 } |
90 | 91 |
91 prev_mouseb = 7; | 92 prev_mouseb = 7; |
92 return 1; | 93 return 1; |
93 } | 94 } |
94 | 95 |
95 void SDL_AtariDevMouse_Close(void) | 96 void |
97 SDL_AtariDevMouse_Close (void) | |
96 { | 98 { |
97 if (handle>0) { | 99 if (handle > 0) { |
98 close(handle); | 100 close (handle); |
99 handle = -1; | 101 handle = -1; |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 static int atari_GetButton(int button) | 105 static int |
106 atari_GetButton (int button) | |
104 { | 107 { |
105 switch(button) | 108 switch (button) { |
106 { | 109 case 0: |
107 case 0: | 110 return SDL_BUTTON_RIGHT; |
108 return SDL_BUTTON_RIGHT; | 111 case 1: |
109 case 1: | 112 return SDL_BUTTON_MIDDLE; |
110 return SDL_BUTTON_MIDDLE; | 113 default: |
111 default: | 114 break; |
112 break; | 115 } |
113 } | |
114 | 116 |
115 return SDL_BUTTON_LEFT; | 117 return SDL_BUTTON_LEFT; |
116 } | 118 } |
117 | 119 |
118 void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents) | 120 void |
121 SDL_AtariDevMouse_PostMouseEvents (_THIS, SDL_bool buttonEvents) | |
119 { | 122 { |
120 unsigned char buffer[3]; | 123 unsigned char buffer[3]; |
121 int mousex, mousey; | 124 int mousex, mousey; |
122 | 125 |
123 if (handle<0) { | 126 if (handle < 0) { |
124 return; | 127 return; |
125 } | 128 } |
126 | 129 |
127 mousex = mousey = 0; | 130 mousex = mousey = 0; |
128 while (read(handle, buffer, sizeof(buffer))==sizeof(buffer)) { | 131 while (read (handle, buffer, sizeof (buffer)) == sizeof (buffer)) { |
129 mouseb = buffer[0] & 7; | 132 mouseb = buffer[0] & 7; |
130 mousex += (char) buffer[1]; | 133 mousex += (char) buffer[1]; |
131 mousey += (char) buffer[2]; | 134 mousey += (char) buffer[2]; |
132 | 135 |
133 /* Mouse button events */ | 136 /* Mouse button events */ |
134 if (buttonEvents && (mouseb != prev_mouseb)) { | 137 if (buttonEvents && (mouseb != prev_mouseb)) { |
135 int i; | 138 int i; |
136 | 139 |
137 for (i=0;i<3;i++) { | 140 for (i = 0; i < 3; i++) { |
138 int curbutton, prevbutton; | 141 int curbutton, prevbutton; |
139 | 142 |
140 curbutton = mouseb & (1<<i); | 143 curbutton = mouseb & (1 << i); |
141 prevbutton = prev_mouseb & (1<<i); | 144 prevbutton = prev_mouseb & (1 << i); |
142 | |
143 if (curbutton && !prevbutton) { | |
144 SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0); | |
145 } | |
146 if (!curbutton && prevbutton) { | |
147 SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0); | |
148 } | |
149 } | |
150 | 145 |
151 prev_mouseb = mouseb; | 146 if (curbutton && !prevbutton) { |
152 } | 147 SDL_PrivateMouseButton (SDL_RELEASED, |
153 } | 148 atari_GetButton (i), 0, 0); |
149 } | |
150 if (!curbutton && prevbutton) { | |
151 SDL_PrivateMouseButton (SDL_PRESSED, | |
152 atari_GetButton (i), 0, 0); | |
153 } | |
154 } | |
154 | 155 |
155 /* Mouse motion event */ | 156 prev_mouseb = mouseb; |
156 if (mousex || mousey) { | 157 } |
157 SDL_PrivateMouseMotion(0, 1, mousex, -mousey); | 158 } |
158 } | 159 |
160 /* Mouse motion event */ | |
161 if (mousex || mousey) { | |
162 SDL_PrivateMouseMotion (0, 1, mousex, -mousey); | |
163 } | |
159 } | 164 } |
165 | |
166 /* vi: set ts=4 sw=4 expandtab: */ |