1 /*
2 * Copyright (c) 2003,2008 NONAKA Kimihiro
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "common.h"
27 #include "winx68k.h"
28 #include "prop.h"
29 #include "scc.h"
30 #include "crtc.h"
31 #include "mouse.h"
32
33 float MouseDX = 0;
34 float MouseDY = 0;
35 BYTE MouseStat = 0;
36 BYTE MouseSW = 0;
37
38 POINT CursorPos;
39 int mousex = 0, mousey = 0;
40
41 #if 0
42 static GdkPixmap *cursor_pixmap;
43 static GdkCursor *cursor;
44
45 static void getmaincenter(GtkWidget *w, POINT *p);
46 void gdk_window_set_pointer(GdkWindow *window, gint x, gint y);
47 #endif
48
Mouse_Init(void)49 void Mouse_Init(void)
50 {
51 if (Config.JoyOrMouse) {
52 Mouse_StartCapture(1);
53 }
54 }
55
56
57 // ----------------------------------
58 // Mouse Event Occured
59 // ----------------------------------
Mouse_Event(int param,float dx,float dy)60 void Mouse_Event(int param, float dx, float dy)
61 {
62 //printf("ME(): %f %f\n", dx, dy);
63
64 if (MouseSW) {
65 switch (param) {
66 case 0: // mouse move
67 MouseDX += dx;
68 MouseDY += dy;
69 break;
70 case 1: // left button
71 if (dx != 0)
72 MouseStat |= 1;
73 else
74 MouseStat &= 0xfe;
75 break;
76 case 2: // right button
77 if (dx != 0)
78 MouseStat |= 2;
79 else
80 MouseStat &= 0xfd;
81 break;
82 default:
83 break;
84 }
85 }
86 }
87
88
89 // ----------------------------------
90 // Mouse Data send to SCC
91 // ----------------------------------
Mouse_SetData(void)92 void Mouse_SetData(void)
93 {
94 POINT pt;
95 int x, y;
96
97 if (MouseSW) {
98
99 x = (int)MouseDX;
100 y = (int)MouseDY;
101
102 MouseDX = MouseDY = 0;
103
104 MouseSt = MouseStat;
105
106 if (x > 127) {
107 MouseSt |= 0x10;
108 MouseX = 127;
109 } else if (x < -128) {
110 MouseSt |= 0x20;
111 MouseX = -128;
112 } else {
113 MouseX = (signed char)x;
114 }
115
116 if (y > 127) {
117 MouseSt |= 0x40;
118 MouseY = 127;
119 } else if (y < -128) {
120 MouseSt |= 0x80;
121 MouseY = -128;
122 } else {
123 MouseY = (signed char)y;
124 }
125
126 } else {
127 MouseSt = 0;
128 MouseX = 0;
129 MouseY = 0;
130 }
131 }
132
133
134 // ----------------------------------
135 // Start Capture
136 // ----------------------------------
Mouse_StartCapture(int flag)137 void Mouse_StartCapture(int flag)
138 {
139 if (flag && !MouseSW) {
140 MouseSW = 1;
141 } else if (!flag && MouseSW) {
142 MouseSW = 0;
143 }
144 }
145
Mouse_ChangePos(void)146 void Mouse_ChangePos(void)
147 {
148 #if 0
149 if (MouseSW) {
150 POINT pt;
151
152 getmaincenter(window, &pt);
153 gdk_window_set_pointer(window->window, pt.x, pt.y);
154 }
155 #endif
156 }
157
158 #if 0
159 static void
160 getmaincenter(GtkWidget *w, POINT *p)
161 {
162
163 p->x = w->allocation.x + w->allocation.width / 2;
164 p->y = w->allocation.y + w->allocation.height / 2;
165 }
166
167 #if GTK_MAJOR_VERSION == 1
168 #include <gdk/gdkprivate.h>
169
170 void
171 gdk_window_set_pointer(GdkWindow *window, gint x, gint y)
172 {
173 GdkWindowPrivate *private;
174
175 if (!window)
176 window = (GdkWindow *)&gdk_root_parent;
177
178 private = (GdkWindowPrivate *)window;
179 if (private->destroyed)
180 return;
181
182 XWarpPointer(private->xdisplay, None, private->xwindow,
183 0, 0, 0, 0, x, y);
184 }
185 #else /* GTK_MAJOR_VERSION != 1 */
186 #include <gdk/gdkx.h>
187
188 void
189 gdk_window_set_pointer(GdkWindow *window, gint x, gint y)
190 {
191 GdkScreen *screen;
192
193 if (window == NULL) {
194 screen = gdk_screen_get_default();
195 window = gdk_screen_get_root_window(screen);
196 }
197 if (GDK_WINDOW_DESTROYED(window))
198 return;
199
200 XWarpPointer(GDK_WINDOW_XDISPLAY(window), None, GDK_WINDOW_XID(window),
201 0, 0, 0, 0, x, y);
202 }
203 #endif /* GTK_MAJOR_VERSION == 1 */
204 #endif
205