1 /** \file mousedrv.c
2 * \brief Native GTK3 UI mouse driver stuff.
3 *
4 * \author Marco van den Heuvel <blackystardust68@yahoo.com>
5 */
6
7 /*
8 * This file is part of VICE, the Versatile Commodore Emulator.
9 * See README for copyright notice.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 * 02111-1307 USA.
25 *
26 */
27
28 #include "vice.h"
29
30 #include <stdio.h>
31
32 #include "debug_gtk3.h"
33
34 #include "vsyncapi.h"
35 #include "mouse.h"
36 #include "mousedrv.h"
37 #include "uimachinewindow.h"
38
39
40 /** \brief The callbacks registered for mouse buttons being pressed or
41 * released.
42 * \sa mousedrv_resources_init which sets these values properly
43 * \sa mouse_button which uses them
44 */
45 static mouse_func_t mouse_funcs = {
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL
51 };
52
53 /** \brief Current mouse X value.
54 *
55 * This is a dead-reckoning sum of left and right motions and does
56 * not necessarily bear any connection to any actual X coordinates.
57 *
58 * \sa mousedrv_get_x
59 */
60 static float mouse_x = 0.0;
61
62 /** \brief Current mouse Y value.
63 *
64 * This is a dead-reckoning sum of left and right motions and does
65 * not necessarily bear any connection to any actual X coordinates.
66 *
67 * \sa mousedrv_get_y
68 */
69 static float mouse_y = 0.0;
70
71 /** \brief Last time the mouse was moved.
72 *
73 * \sa mousedrv_get_timestamp
74 */
75 static unsigned long mouse_timestamp = 0;
76
mousedrv_cmdline_options_init(void)77 int mousedrv_cmdline_options_init(void)
78 {
79 return 0;
80 }
81
mousedrv_get_timestamp(void)82 unsigned long mousedrv_get_timestamp(void)
83 {
84 return mouse_timestamp;
85 }
86
mousedrv_get_x(void)87 int mousedrv_get_x(void)
88 {
89 return (int)mouse_x;
90 }
91
mousedrv_get_y(void)92 int mousedrv_get_y(void)
93 {
94 return (int)mouse_y;
95 }
96
97
mouse_move(float dx,float dy)98 void mouse_move(float dx, float dy)
99 {
100 #if 0
101 mouse_x += dx;
102 mouse_y -= dy; /* why ? */
103
104 /* can't this be done with int modulo ? */
105 while (mouse_x < 0.0) {
106 mouse_x += 65536.0;
107 }
108 while (mouse_x >= 65536.0) {
109 mouse_x -= 65536.0;
110 }
111 while (mouse_y < 0.0) {
112 mouse_y += 65536.0;
113 }
114 while (mouse_y >= 65536.0) {
115 mouse_y -= 65536.0;
116 }
117 #endif
118
119 mouse_x = (float)((int)(mouse_x + dx) % 0xffff);
120 mouse_y = (float)((int)(mouse_y - dy) % 0xffff);
121
122 mouse_timestamp = vsyncarch_gettime();
123 }
124
mouse_button(int bnumber,int state)125 void mouse_button(int bnumber, int state)
126 {
127 switch(bnumber) {
128 case 0:
129 if (mouse_funcs.mbl) {
130 mouse_funcs.mbl(state);
131 }
132 break;
133 case 1:
134 if (mouse_funcs.mbm) {
135 mouse_funcs.mbm(state);
136 }
137 break;
138 case 2:
139 if (mouse_funcs.mbr) {
140 mouse_funcs.mbr(state);
141 }
142 break;
143 case 3:
144 if (mouse_funcs.mbu) {
145 mouse_funcs.mbu(state);
146 }
147 break;
148 case 4:
149 if (mouse_funcs.mbd) {
150 mouse_funcs.mbd(state);
151 }
152 break;
153 default:
154 fprintf(stderr, "GTK3MOUSE: Warning: Strange mouse button %d\n", bnumber);
155 }
156 }
157
mousedrv_init(void)158 void mousedrv_init(void)
159 {
160 /* This does not require anything special to be done */
161 }
162
mousedrv_mouse_changed(void)163 void mousedrv_mouse_changed(void)
164 {
165 /** \todo Tell UI level to capture mouse cursor if necessary and
166 * permitted */
167 fprintf(stderr, "GTK3MOUSE: Status changed: %d (%s)\n",
168 _mouse_enabled, _mouse_enabled ? "enabled" : "disabled");
169 if (_mouse_enabled) {
170 ui_mouse_grab_pointer();
171 } else {
172 ui_mouse_ungrab_pointer();
173 }
174 }
175
mousedrv_resources_init(mouse_func_t * funcs)176 int mousedrv_resources_init(mouse_func_t *funcs)
177 {
178 mouse_funcs.mbl = funcs->mbl;
179 mouse_funcs.mbr = funcs->mbr;
180 mouse_funcs.mbm = funcs->mbm;
181 mouse_funcs.mbu = funcs->mbu;
182 mouse_funcs.mbd = funcs->mbd;
183 return 0;
184 }
185
186
187