1 /*
2  * mousedrv.c - Mouse handling for SDL.
3  *
4  * Written by
5  *  Hannu Nuotio <hannu.nuotio@tut.fi>
6  *
7  * Based on code by
8  *  Ettore Perazzoli <ettore@comm2000.it>
9  *  Oliver Schaertel <orschaer@forwiss.uni-erlangen.de>
10  *
11  * This file is part of VICE, the Versatile Commodore Emulator.
12  * See README for copyright notice.
13  *
14  *  This program is free software; you can redistribute it and/or modify
15  *  it under the terms of the GNU General Public License as published by
16  *  the Free Software Foundation; either version 2 of the License, or
17  *  (at your option) any later version.
18  *
19  *  This program is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *  GNU General Public License for more details.
23  *
24  *  You should have received a copy of the GNU General Public License
25  *  along with this program; if not, write to the Free Software
26  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  *
28  */
29 
30 #include "vice.h"
31 
32 #include "vice_sdl.h"
33 
34 #include "mouse.h"
35 #include "mousedrv.h"
36 #include "ui.h"
37 #include "vsyncapi.h"
38 
39 #ifdef ANDROID_COMPILE
40 int mouse_x, mouse_y;
41 #else
42 static int mouse_x, mouse_y;
43 #endif
44 
45 static unsigned long mouse_timestamp = 0;
46 static mouse_func_t mouse_funcs;
47 
mousedrv_mouse_changed(void)48 void mousedrv_mouse_changed(void)
49 {
50     ui_check_mouse_cursor();
51 }
52 
mousedrv_resources_init(mouse_func_t * funcs)53 int mousedrv_resources_init(mouse_func_t *funcs)
54 {
55     mouse_funcs.mbl = funcs->mbl;
56     mouse_funcs.mbr = funcs->mbr;
57     mouse_funcs.mbm = funcs->mbm;
58     mouse_funcs.mbu = funcs->mbu;
59     mouse_funcs.mbd = funcs->mbd;
60     return 0;
61 }
62 
63 /* ------------------------------------------------------------------------- */
64 
mousedrv_cmdline_options_init(void)65 int mousedrv_cmdline_options_init(void)
66 {
67     return 0;
68 }
69 
70 /* ------------------------------------------------------------------------- */
71 
mousedrv_init(void)72 void mousedrv_init(void)
73 {
74 }
75 
76 /* ------------------------------------------------------------------------- */
77 
mouse_button(int bnumber,int state)78 void mouse_button(int bnumber, int state)
79 {
80     switch (bnumber) {
81         case SDL_BUTTON_LEFT:
82             mouse_funcs.mbl(state);
83             break;
84         case SDL_BUTTON_MIDDLE:
85             mouse_funcs.mbm(state);
86             break;
87         case SDL_BUTTON_RIGHT:
88             mouse_funcs.mbr(state);
89             break;
90 /* FIXME: fix for SDL2 */
91 #ifndef USE_SDLUI2
92         case SDL_BUTTON_WHEELUP:
93             mouse_funcs.mbu(state);
94             break;
95         case SDL_BUTTON_WHEELDOWN:
96             mouse_funcs.mbd(state);
97             break;
98 #endif
99         default:
100             break;
101     }
102 }
103 
mousedrv_get_x(void)104 int mousedrv_get_x(void)
105 {
106     return mouse_x;
107 }
108 
mousedrv_get_y(void)109 int mousedrv_get_y(void)
110 {
111     return mouse_y;
112 }
113 
mouse_move(int x,int y)114 void mouse_move(int x, int y)
115 {
116     mouse_x += x;
117     mouse_y -= y;
118     mouse_timestamp = vsyncarch_gettime();
119 }
120 
mousedrv_get_timestamp(void)121 unsigned long mousedrv_get_timestamp(void)
122 {
123     return mouse_timestamp;
124 }
125 
mousedrv_button_left(int pressed)126 void mousedrv_button_left(int pressed)
127 {
128     mouse_funcs.mbl(pressed);
129 }
130 
mousedrv_button_right(int pressed)131 void mousedrv_button_right(int pressed)
132 {
133     mouse_funcs.mbr(pressed);
134 }
135 
mousedrv_button_middle(int pressed)136 void mousedrv_button_middle(int pressed)
137 {
138     mouse_funcs.mbm(pressed);
139 }
140