summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-11-10 15:25:15 +0000
committerThomas Martitz <kugel@rockbox.org>2010-11-10 15:25:15 +0000
commit33af0dec28cf31be0ce7195b90546861efcce76f (patch)
treef106c9118c9191bff00e1468c98540787081c0e8
parente134021e1b05f797cffd28c6b4ee72a963ff3812 (diff)
downloadrockbox-33af0dec28cf31be0ce7195b90546861efcce76f.tar.gz
rockbox-33af0dec28cf31be0ce7195b90546861efcce76f.zip
Touchscreen: Improved scroll threshold
Remove the hardcoded (and way too small) scroll threshold (the distance moved in pixels before we think the users wants to scroll) and replace it with something based on the actual DPI of the screen. On Android we call the API for that, on other touchscreens we reimplemented Android's formula (as of 2.2) and calculate it. Flyspray: 11727 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28548 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--android/src/org/rockbox/RockboxFramebuffer.java19
-rw-r--r--apps/gui/bitmap/list.c12
-rw-r--r--firmware/drivers/touchscreen.c31
-rw-r--r--firmware/export/config/cowond2.h1
-rw-r--r--firmware/export/config/mrobe500.h2
-rw-r--r--firmware/export/config/ondavx747.h1
-rw-r--r--firmware/export/config/ondavx767.h7
-rw-r--r--firmware/export/config/ondavx777.h1
-rw-r--r--firmware/export/config/sim.h1
-rw-r--r--firmware/export/lcd.h10
-rw-r--r--firmware/export/touchscreen.h1
-rw-r--r--firmware/target/hosted/android/lcd-android.c26
-rw-r--r--firmware/target/hosted/sdl/lcd-sdl.c6
13 files changed, 115 insertions, 3 deletions
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index 0a60182502..8c99725e7d 100644
--- a/android/src/org/rockbox/RockboxFramebuffer.java
+++ b/android/src/org/rockbox/RockboxFramebuffer.java
@@ -28,16 +28,20 @@ import org.rockbox.Helper.MediaButtonReceiver;
28import android.content.Context; 28import android.content.Context;
29import android.graphics.Bitmap; 29import android.graphics.Bitmap;
30import android.graphics.Canvas; 30import android.graphics.Canvas;
31import android.util.DisplayMetrics;
31import android.util.Log; 32import android.util.Log;
32import android.view.KeyEvent; 33import android.view.KeyEvent;
33import android.view.MotionEvent; 34import android.view.MotionEvent;
34import android.view.View; 35import android.view.View;
36import android.view.ViewConfiguration;
35 37
36public class RockboxFramebuffer extends View 38public class RockboxFramebuffer extends View
37{ 39{
38 private Bitmap btm; 40 private Bitmap btm;
39 private ByteBuffer native_buf; 41 private ByteBuffer native_buf;
40 private MediaButtonReceiver media_monitor; 42 private MediaButtonReceiver media_monitor;
43 private final DisplayMetrics metrics;
44 private final ViewConfiguration view_config;
41 45
42 public RockboxFramebuffer(Context c, int lcd_width, 46 public RockboxFramebuffer(Context c, int lcd_width,
43 int lcd_height, ByteBuffer native_fb) 47 int lcd_height, ByteBuffer native_fb)
@@ -53,6 +57,9 @@ public class RockboxFramebuffer extends View
53 media_monitor.register(); 57 media_monitor.register();
54 /* the service needs to know the about us */ 58 /* the service needs to know the about us */
55 ((RockboxService)c).set_fb(this); 59 ((RockboxService)c).set_fb(this);
60
61 metrics = c.getResources().getDisplayMetrics();
62 view_config = ViewConfiguration.get(c);
56 } 63 }
57 64
58 public void onDraw(Canvas c) 65 public void onDraw(Canvas c)
@@ -132,6 +139,18 @@ public class RockboxFramebuffer extends View
132 break; 139 break;
133 } 140 }
134 } 141 }
142
143 @SuppressWarnings("unused")
144 private int getDpi()
145 {
146 return metrics.densityDpi;
147 }
148
149 @SuppressWarnings("unused")
150 private int getScrollThreshold()
151 {
152 return view_config.getScaledTouchSlop();
153 }
135 154
136 private native void set_lcd_active(int active); 155 private native void set_lcd_active(int active);
137 private native void touchHandler(boolean down, int x, int y); 156 private native void touchHandler(boolean down, int x, int y);
diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c
index 26e15e7978..268209e1c1 100644
--- a/apps/gui/bitmap/list.c
+++ b/apps/gui/bitmap/list.c
@@ -486,16 +486,26 @@ void _gui_synclist_stop_kinetic_scrolling(void)
486 * otherwise it returns true even if it didn't actually scroll, 486 * otherwise it returns true even if it didn't actually scroll,
487 * but scrolling mode shouldn't be changed 487 * but scrolling mode shouldn't be changed
488 **/ 488 **/
489
490
491static int scroll_begin_threshold;
492static int threshold_accumulation;
489static bool swipe_scroll(struct gui_synclist * gui_list, int line_height, int difference) 493static bool swipe_scroll(struct gui_synclist * gui_list, int line_height, int difference)
490{ 494{
491 /* fixme */ 495 /* fixme */
492 const enum screen_type screen = screens[SCREEN_MAIN].screen_type; 496 const enum screen_type screen = screens[SCREEN_MAIN].screen_type;
493 const int nb_lines = viewport_get_nb_lines(&list_text[screen]); 497 const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
494 498
499 if (UNLIKELY(scroll_begin_threshold == 0))
500 scroll_begin_threshold = touchscreen_get_scroll_threshold();
501
495 /* make selecting items easier */ 502 /* make selecting items easier */
496 if (abs(difference) < SCROLL_BEGIN_THRESHOLD && scroll_mode == SCROLL_NONE) 503 threshold_accumulation += abs(difference);
504 if (threshold_accumulation < scroll_begin_threshold && scroll_mode == SCROLL_NONE)
497 return false; 505 return false;
498 506
507 threshold_accumulation = 0;
508
499 /* does the list even scroll? if no, return but still show 509 /* does the list even scroll? if no, return but still show
500 * the caller that we would scroll */ 510 * the caller that we would scroll */
501 if (nb_lines >= gui_list->nb_items) 511 if (nb_lines >= gui_list->nb_items)
diff --git a/firmware/drivers/touchscreen.c b/firmware/drivers/touchscreen.c
index 9660e0cb9d..823c2e7a92 100644
--- a/firmware/drivers/touchscreen.c
+++ b/firmware/drivers/touchscreen.c
@@ -25,6 +25,7 @@
25#include "touchscreen.h" 25#include "touchscreen.h"
26#include "string.h" 26#include "string.h"
27#include "logf.h" 27#include "logf.h"
28#include "lcd.h"
28 29
29/* Size of the 'dead zone' around each 3x3 button */ 30/* Size of the 'dead zone' around each 3x3 button */
30#define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03) 31#define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03)
@@ -167,3 +168,33 @@ enum touchscreen_mode touchscreen_get_mode(void)
167{ 168{
168 return current_mode; 169 return current_mode;
169} 170}
171
172
173#if ((CONFIG_PLATFORM & PLATFORM_ANDROID) == 0)
174/* android has an API for this */
175
176#define TOUCH_SLOP 16u
177#define REFERENCE_DPI 160
178
179int touchscreen_get_scroll_threshold(void)
180{
181#ifdef LCD_DPI
182 const int dpi = LCD_DPI;
183#else
184 const int dpi = lcd_get_dpi();
185#endif
186
187 /* Inspired by Android calculation
188 *
189 * float density = real dpi / reference dpi (=160)
190 * int threshold = (int) (density * TOUCH_SLOP + 0.5f);(original calculation)
191 *
192 * + 0.5f is for rounding, we use fixed point math to achieve that
193 */
194
195 int result = dpi * (TOUCH_SLOP<<1) / REFERENCE_DPI;
196 result += result & 1; /* round up if needed */
197 return result>>1;
198}
199
200#endif
diff --git a/firmware/export/config/cowond2.h b/firmware/export/config/cowond2.h
index f9de2768bd..ebaa636ac7 100644
--- a/firmware/export/config/cowond2.h
+++ b/firmware/export/config/cowond2.h
@@ -75,6 +75,7 @@
75/* LCD dimensions */ 75/* LCD dimensions */
76#define LCD_WIDTH 320 76#define LCD_WIDTH 320
77#define LCD_HEIGHT 240 77#define LCD_HEIGHT 240
78#define LCD_DPI 160
78#define LCD_DEPTH 16 79#define LCD_DEPTH 16
79#define LCD_PIXELFORMAT 565 80#define LCD_PIXELFORMAT 565
80 81
diff --git a/firmware/export/config/mrobe500.h b/firmware/export/config/mrobe500.h
index 9a201951fc..776b0315f8 100644
--- a/firmware/export/config/mrobe500.h
+++ b/firmware/export/config/mrobe500.h
@@ -87,9 +87,11 @@
87#if _RESOLUTION == _LCD_RES_VGA 87#if _RESOLUTION == _LCD_RES_VGA
88#define LCD_NATIVE_WIDTH 480 88#define LCD_NATIVE_WIDTH 480
89#define LCD_NATIVE_HEIGHT 640 89#define LCD_NATIVE_HEIGHT 640
90#define LCD_DPI 216
90#else 91#else
91#define LCD_NATIVE_WIDTH 240 92#define LCD_NATIVE_WIDTH 240
92#define LCD_NATIVE_HEIGHT 320 93#define LCD_NATIVE_HEIGHT 320
94#define LCD_DPI 108
93#endif 95#endif
94 96
95/* choose the lcd orientation. CONFIG_ORIENTATION defined in config.h */ 97/* choose the lcd orientation. CONFIG_ORIENTATION defined in config.h */
diff --git a/firmware/export/config/ondavx747.h b/firmware/export/config/ondavx747.h
index ae80cac562..1cd9143965 100644
--- a/firmware/export/config/ondavx747.h
+++ b/firmware/export/config/ondavx747.h
@@ -79,6 +79,7 @@
79#define LCD_WIDTH 240 79#define LCD_WIDTH 240
80#define LCD_HEIGHT 400 80#define LCD_HEIGHT 400
81#endif 81#endif
82#define LCD_DPI 155
82 83
83#define LCD_DEPTH 16 /* 16bit colours */ 84#define LCD_DEPTH 16 /* 16bit colours */
84#define LCD_PIXELFORMAT RGB565 /* rgb565 */ 85#define LCD_PIXELFORMAT RGB565 /* rgb565 */
diff --git a/firmware/export/config/ondavx767.h b/firmware/export/config/ondavx767.h
index 19bb7ed580..bf9aaed7c1 100644
--- a/firmware/export/config/ondavx767.h
+++ b/firmware/export/config/ondavx767.h
@@ -65,8 +65,11 @@
65/* LCD dimensions */ 65/* LCD dimensions */
66#define CONFIG_LCD LCD_ONDAVX767 66#define CONFIG_LCD LCD_ONDAVX767
67 67
68#define LCD_WIDTH 320 68/* this are not actually the correct dimensions (480x272 is correct)
69#define LCD_HEIGHT 240 69 * should be fixed once there's a working LCD driver */
70#define LCD_WIDTH 480
71#define LCD_HEIGHT 272
72#define LCD_DPI 128
70 73
71#define LCD_DEPTH 16 /* 16bit colours */ 74#define LCD_DEPTH 16 /* 16bit colours */
72#define LCD_PIXELFORMAT RGB565 /* rgb565 */ 75#define LCD_PIXELFORMAT RGB565 /* rgb565 */
diff --git a/firmware/export/config/ondavx777.h b/firmware/export/config/ondavx777.h
index a2ad15533a..b6e7546590 100644
--- a/firmware/export/config/ondavx777.h
+++ b/firmware/export/config/ondavx777.h
@@ -73,6 +73,7 @@
73#define LCD_WIDTH 240 73#define LCD_WIDTH 240
74#define LCD_HEIGHT 400 74#define LCD_HEIGHT 400
75#endif 75#endif
76#define LCD_DPI 155
76 77
77#define LCD_DEPTH 16 /* 16bit colours */ 78#define LCD_DEPTH 16 /* 16bit colours */
78#define LCD_PIXELFORMAT RGB565 /* rgb565 */ 79#define LCD_PIXELFORMAT RGB565 /* rgb565 */
diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h
index 066201ad08..fc7996e813 100644
--- a/firmware/export/config/sim.h
+++ b/firmware/export/config/sim.h
@@ -19,6 +19,7 @@
19#undef HAVE_ATA_POWER_OFF 19#undef HAVE_ATA_POWER_OFF
20 20
21#undef CONFIG_LCD 21#undef CONFIG_LCD
22#undef LCD_DPI /* likely to be too different on a PC */
22 23
23#undef CONFIG_LED 24#undef CONFIG_LED
24 25
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index 79231d198e..e6e19b1597 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -549,4 +549,14 @@ extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
549 549
550#endif /* HAVE_LCD_BITMAP */ 550#endif /* HAVE_LCD_BITMAP */
551 551
552
553#ifdef HAVE_TOUCHSCREEN
554/* only needed for touchscreen for now, feel free to implement it for others
555 * once needed
556 */
557
558/* returns the pixel density of the display */
559extern int lcd_get_dpi(void);
560#endif
561
552#endif /* __LCD_H__ */ 562#endif /* __LCD_H__ */
diff --git a/firmware/export/touchscreen.h b/firmware/export/touchscreen.h
index 7d1eb4ac8a..a27e60c653 100644
--- a/firmware/export/touchscreen.h
+++ b/firmware/export/touchscreen.h
@@ -50,5 +50,6 @@ void touchscreen_set_mode(enum touchscreen_mode mode);
50enum touchscreen_mode touchscreen_get_mode(void); 50enum touchscreen_mode touchscreen_get_mode(void);
51void touchscreen_disable_mapping(void); 51void touchscreen_disable_mapping(void);
52void touchscreen_reset_mapping(void); 52void touchscreen_reset_mapping(void);
53int touchscreen_get_scroll_threshold(void);
53 54
54#endif /* __TOUCHSCREEN_INCLUDE_H_ */ 55#endif /* __TOUCHSCREEN_INCLUDE_H_ */
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
index 78b1f12f7f..f4ef7b5e75 100644
--- a/firmware/target/hosted/android/lcd-android.c
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -35,6 +35,8 @@ static jmethodID java_lcd_update;
35static jmethodID java_lcd_update_rect; 35static jmethodID java_lcd_update_rect;
36 36
37static bool display_on; 37static bool display_on;
38static int dpi;
39static int scroll_threshold;
38 40
39void lcd_init_device(void) 41void lcd_init_device(void)
40{ 42{
@@ -77,6 +79,20 @@ void lcd_init_device(void)
77 RockboxFramebuffer_class, 79 RockboxFramebuffer_class,
78 "java_lcd_update_rect", 80 "java_lcd_update_rect",
79 "(IIII)V"); 81 "(IIII)V");
82
83 jmethodID get_dpi = e->GetMethodID(env_ptr,
84 RockboxFramebuffer_class,
85 "getDpi", "()I");
86
87 jmethodID get_scroll_threshold
88 = e->GetMethodID(env_ptr,
89 RockboxFramebuffer_class,
90 "getScrollThreshold", "()I");
91
92 dpi = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance,
93 get_dpi);
94 scroll_threshold = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance,
95 get_scroll_threshold);
80 display_on = true; 96 display_on = true;
81} 97}
82 98
@@ -101,6 +117,16 @@ bool lcd_active(void)
101 return display_on; 117 return display_on;
102} 118}
103 119
120int lcd_get_dpi(void)
121{
122 return dpi;
123}
124
125int touchscreen_get_scroll_threshold(void)
126{
127 return scroll_threshold;
128}
129
104/* 130/*
105 * (un)block lcd updates. 131 * (un)block lcd updates.
106 * 132 *
diff --git a/firmware/target/hosted/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c
index 15e4ba95c3..96b1a04aa6 100644
--- a/firmware/target/hosted/sdl/lcd-sdl.c
+++ b/firmware/target/hosted/sdl/lcd-sdl.c
@@ -111,3 +111,9 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
111 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps); 111 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps);
112} 112}
113 113
114int lcd_get_dpi(void)
115{
116 /* TODO: find a way to query it from the OS, SDL doesn't support it
117 * directly; for now assume the more or less standard 96 */
118 return 96;
119}