Root/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+++ ase-0.8.2/src/jinete/jsystem.cpp 2011-06-16 12:39:33.218215092 +0200
5@@ -29,6 +29,8 @@
6  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7  */
8 
9+// #include <stdio.h>
10+
11 #include "config.h"
12 
13 #include <allegro.h>
14@@ -355,6 +357,9 @@
15   return mouse_scares == 0;
16 }
17 
18+/* used by keyboard-mouse code by david */
19+static int key_mouse_b = 0;
20+
21 /**
22  * Updates the mouse information (position, wheel and buttons).
23  *
24@@ -369,7 +374,7 @@
25 
26   poll_mouse();
27 
28- m_b[0] = mouse_b;
29+ m_b[0] = mouse_b | key_mouse_b;
30   m_z[0] = mouse_z;
31 
32   update_mouse_position();
33@@ -438,8 +443,135 @@
34     return false;
35 }
36 
37+
38+/* keyboard mouse emulation code inserted by david <dvdkhlng TA gmx TOD de> */
39+static void keyboard_mouse()
40+{
41+ static int last_clock = ji_clock;
42+ static int speed_x = 0;
43+ static int speed_y = 0;
44+ static int delta_x = 0;
45+ static int delta_y = 0;
46+
47+ const int scale = 1000;
48+ const int max_speed = 1000; // [scale]*px/ms
49+
50+ int now = ji_clock;
51+ int delta_t = now - last_clock;
52+ int ak = 1;
53+ int ad = 10;
54+
55+ if (delta_t == 0)
56+ {
57+ return;
58+ }
59+
60+ /* The patched jmessage.cpp filters out all arrow key messages, unless the
61+ shift key is held, so it's better to disable the keyboard mouse on shift
62+ key */
63+ int shift = key_shifts&KB_SHIFT_FLAG;
64+
65+ if (!shift && key[KEY_LEFT]) {
66+ speed_x -= ak*delta_t;
67+ }
68+ else if (!shift && key[KEY_RIGHT]) {
69+ speed_x += ak*delta_t;
70+ }
71+ else {
72+ if (speed_x < 0)
73+ {
74+ speed_x = speed_x + ad*delta_t;
75+ speed_x = speed_x > 0 ? 0 : speed_x;
76+ }
77+ else
78+ {
79+ speed_x = speed_x - ad*delta_t;
80+ speed_x = speed_x < 0 ? 0 : speed_x;
81+ }
82+ }
83+
84+ if (!shift && key[KEY_UP]) {
85+ speed_y -= ak*delta_t;
86+ }
87+ else if (!shift && key[KEY_DOWN]) {
88+ speed_y += ak*delta_t;
89+ }
90+ else {
91+ if (speed_y < 0)
92+ {
93+ speed_y = speed_y + ad*delta_t;
94+ speed_y = speed_y > 0 ? 0 : speed_y;
95+ }
96+ else
97+ {
98+ speed_y = speed_y - ad*delta_t;
99+ speed_y = speed_y < 0 ? 0 : speed_y;
100+ }
101+ }
102+
103+ if (speed_x > max_speed)
104+ speed_x = max_speed;
105+ if (speed_x < -max_speed)
106+ speed_x = -max_speed;
107+ if (speed_y > max_speed)
108+ speed_y = max_speed;
109+ if (speed_y < -max_speed)
110+ speed_y = -max_speed;
111+
112+ delta_x += delta_t*speed_x;
113+ delta_y += delta_t*speed_y;
114+
115+ // fprintf (stderr, "%i %i %i %i %i\n", delta_t, speed_x, speed_y, delta_x, delta_y);
116+ // fprintf (stderr, "now %i %i then %i %i %i\n", mouse_x, mouse_y,
117+ // mouse_x+delta_x/scale, mouse_y+delta_y/scale);
118+
119+ int int_delta_x = delta_x/scale;
120+ int int_delta_y = delta_y/scale;
121+ delta_x %= scale;
122+ delta_y %= scale;
123+
124+ if (int_delta_x || int_delta_y) {
125+ int pos = mouse_pos;
126+ int x = (pos>>16) + int_delta_x;
127+ int y = (pos&0xffff) + int_delta_y;
128+
129+ if (x >= screen->w)
130+ {
131+ speed_x = 0;
132+ x = screen->w;
133+ }
134+ if (x < 0)
135+ {
136+ speed_x = 0;
137+ x = 0;
138+ }
139+ if (y >= screen->h)
140+ {
141+ speed_y = 0;
142+ y = screen->h;
143+ }
144+ if (y < 0)
145+ {
146+ speed_y = 0;
147+ y = 0;
148+ }
149+
150+ position_mouse(x, y);
151+ }
152+
153+ /* mouse buttons */
154+ key_mouse_b = 0;
155+ if (key[KEY_F1]) key_mouse_b |= 1; /* left */
156+ if (key[KEY_F2]) key_mouse_b |= 4; /* middle */
157+ if (key[KEY_F3]) key_mouse_b |= 2; /* right */
158+
159+ last_clock = now;
160+}
161+
162 static void update_mouse_position()
163 {
164+ keyboard_mouse();
165+
166   if (ji_screen == screen) {
167     m_x[0] = mouse_x;
168     m_y[0] = mouse_y;
169Index: ase-0.8.2/data/gui.xml
170===================================================================
171--- ase-0.8.2.orig/data/gui.xml 2011-06-14 23:37:49.391508728 +0200
172+++ ase-0.8.2/data/gui.xml 2011-06-14 23:44:56.211508608 +0200
173@@ -45,14 +45,14 @@
174       <!-- Layer -->
175       <key command="layer_properties" shortcut="Shift+P" />
176       <key command="new_layer" shortcut="Shift+N" />
177- <key command="goto_previous_layer" shortcut="Down" />
178- <key command="goto_next_layer" shortcut="Up" />
179+ <key command="goto_previous_layer" shortcut="\" />
180+ <key command="goto_next_layer" shortcut="/" />
181       <!-- Frame -->
182       <key command="new_frame" shortcut="N" />
183       <key command="frame_properties" shortcut="P" />
184       <key command="goto_first_frame" shortcut="Home" />
185- <key command="goto_previous_frame" shortcut="Left" />
186- <key command="goto_next_frame" shortcut="Right" />
187+ <key command="goto_previous_frame" shortcut="," />
188+ <key command="goto_next_frame" shortcut="." />
189       <key command="goto_last_frame" shortcut="End" />
190       <key command="play_animation" shortcut="Enter" />
191       <!-- Select -->
192Index: ase-0.8.2/src/jinete/jmessage.cpp
193===================================================================
194--- ase-0.8.2.orig/src/jinete/jmessage.cpp 2011-06-16 12:43:59.718215107 +0200
195+++ ase-0.8.2/src/jinete/jmessage.cpp 2011-06-19 12:35:11.813186277 +0200
196@@ -81,6 +81,22 @@
197   msg->key.propagate_to_children = false;
198   msg->key.propagate_to_parent = true;
199 
200+ /* ignore keys used for mouse emuliation unless shift is pressed, to not
201+ * interfere with the keyboard-mouse (some menus would close when
202+ * receiveing key events) */
203+ switch (msg->key.scancode)
204+ {
205+ case KEY_UP:
206+ case KEY_DOWN:
207+ case KEY_LEFT:
208+ case KEY_RIGHT:
209+ case KEY_F1:
210+ case KEY_F2:
211+ case KEY_F3:
212+ if (!(msg->any.shifts&KB_SHIFT_FLAG))
213+ msg->any.used = true;
214+ }
215+
216 #if 0
217   printf("%i: %i %i [%c]\n", type, msg->key.scancode,
218      msg->key.ascii, msg->key.ascii);
219

Archive Download this file



interactive