Date:2011-06-14 23:51:46 (12 years 9 months ago)
Author:David Kühling
Commit:5c9e2b87a337c6493407d01f598b9ffb98030636
Message:ase: hack gui to emulate mouse via keyboard; change keymap to not interfere.

Files: ase/patches/090-keyboard-mouse.patch (1 diff)

Change Details

ase/patches/090-keyboard-mouse.patch
1Index: ase-0.8.2/src/jinete/jsystem.cpp
2===================================================================
3--- ase-0.8.2.orig/src/jinete/jsystem.cpp 2011-06-14 22:25:51.681509956 +0200
4@@ -29,6 +29,8 @@
5  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6  */
7
8+// #include <stdio.h>
9+
10 #include "config.h"
11
12 #include <allegro.h>
13@@ -355,6 +357,9 @@
14   return mouse_scares == 0;
15 }
16
17+/* used by keyboard-mouse code by david */
18+static int key_mouse_b = 0;
19+
20 /**
21  * Updates the mouse information (position, wheel and buttons).
22  *
23@@ -369,7 +374,7 @@
24
25   poll_mouse();
26
27- m_b[0] = mouse_b;
28+ m_b[0] = mouse_b | key_mouse_b;
29   m_z[0] = mouse_z;
30
31   update_mouse_position();
32@@ -438,8 +443,130 @@
33     return false;
34 }
35
36+
37+/* keyboard mouse emulation code inserted by david <dvdkhlng TA gmx TOD de> */
38+static void keyboard_mouse()
39+{
40+ static int last_clock = ji_clock;
41+ static int speed_x = 0;
42+ static int speed_y = 0;
43+ static int delta_x = 0;
44+ static int delta_y = 0;
45+
46+ const int scale = 1000;
47+ const int max_speed = 1000; // [scale]*px/ms
48+
49+ int now = ji_clock;
50+ int delta_t = now - last_clock;
51+ int ak = 1;
52+ int ad = 10;
53+
54+ if (delta_t == 0)
55+ {
56+ return;
57+ }
58+
59+ if (key[KEY_LEFT]) {
60+ speed_x -= ak*delta_t;
61+ }
62+ else if (key[KEY_RIGHT]) {
63+ speed_x += ak*delta_t;
64+ }
65+ else {
66+ if (speed_x < 0)
67+ {
68+ speed_x = speed_x + ad*delta_t;
69+ speed_x = speed_x > 0 ? 0 : speed_x;
70+ }
71+ else
72+ {
73+ speed_x = speed_x - ad*delta_t;
74+ speed_x = speed_x < 0 ? 0 : speed_x;
75+ }
76+ }
77+
78+ if (key[KEY_UP]) {
79+ speed_y -= ak*delta_t;
80+ }
81+ else if (key[KEY_DOWN]) {
82+ speed_y += ak*delta_t;
83+ }
84+ else {
85+ if (speed_y < 0)
86+ {
87+ speed_y = speed_y + ad*delta_t;
88+ speed_y = speed_y > 0 ? 0 : speed_y;
89+ }
90+ else
91+ {
92+ speed_y = speed_y - ad*delta_t;
93+ speed_y = speed_y < 0 ? 0 : speed_y;
94+ }
95+ }
96+
97+ if (speed_x > max_speed)
98+ speed_x = max_speed;
99+ if (speed_x < -max_speed)
100+ speed_x = -max_speed;
101+ if (speed_y > max_speed)
102+ speed_y = max_speed;
103+ if (speed_y < -max_speed)
104+ speed_y = -max_speed;
105+
106+ delta_x += delta_t*speed_x;
107+ delta_y += delta_t*speed_y;
108+
109+ // fprintf (stderr, "%i %i %i %i %i\n", delta_t, speed_x, speed_y, delta_x, delta_y);
110+ // fprintf (stderr, "now %i %i then %i %i %i\n", mouse_x, mouse_y,
111+ // mouse_x+delta_x/scale, mouse_y+delta_y/scale);
112+
113+ int int_delta_x = delta_x/scale;
114+ int int_delta_y = delta_y/scale;
115+ delta_x %= scale;
116+ delta_y %= scale;
117+
118+ if (int_delta_x || int_delta_y) {
119+ int pos = mouse_pos;
120+ int x = (pos>>16) + int_delta_x;
121+ int y = (pos&0xffff) + int_delta_y;
122+
123+ if (x >= screen->w)
124+ {
125+ speed_x = 0;
126+ x = screen->w;
127+ }
128+ if (x < 0)
129+ {
130+ speed_x = 0;
131+ x = 0;
132+ }
133+ if (y >= screen->h)
134+ {
135+ speed_y = 0;
136+ y = screen->h;
137+ }
138+ if (y < 0)
139+ {
140+ speed_y = 0;
141+ y = 0;
142+ }
143+
144+ position_mouse(x, y);
145+ }
146+
147+ /* mouse buttons */
148+ key_mouse_b = 0;
149+ if (key[KEY_F1]) key_mouse_b |= 1; /* left */
150+ if (key[KEY_F2]) key_mouse_b |= 4; /* middle */
151+ if (key[KEY_F3]) key_mouse_b |= 2; /* right */
152+
153+ last_clock = now;
154+}
155+
156 static void update_mouse_position()
157 {
158+ keyboard_mouse();
159+
160   if (ji_screen == screen) {
161     m_x[0] = mouse_x;
162     m_y[0] = mouse_y;
163Index: ase-0.8.2/data/gui.xml
164===================================================================
165--- ase-0.8.2.orig/data/gui.xml 2011-06-14 23:37:49.391508728 +0200
166@@ -45,14 +45,14 @@
167       <!-- Layer -->
168       <key command="layer_properties" shortcut="Shift+P" />
169       <key command="new_layer" shortcut="Shift+N" />
170- <key command="goto_previous_layer" shortcut="Down" />
171- <key command="goto_next_layer" shortcut="Up" />
172+ <key command="goto_previous_layer" shortcut="\" />
173+ <key command="goto_next_layer" shortcut="/" />
174       <!-- Frame -->
175       <key command="new_frame" shortcut="N" />
176       <key command="frame_properties" shortcut="P" />
177       <key command="goto_first_frame" shortcut="Home" />
178- <key command="goto_previous_frame" shortcut="Left" />
179- <key command="goto_next_frame" shortcut="Right" />
180+ <key command="goto_previous_frame" shortcut="," />
181+ <key command="goto_next_frame" shortcut="." />
182       <key command="goto_last_frame" shortcut="End" />
183       <key command="play_animation" shortcut="Enter" />
184       <!-- Select -->

Archive Download the corresponding diff file



interactive