A generic touchscreen calibration program for X.Org
Revisión | 496d4401731c6e5ed550e446cc2fc4b12d999ad8 (tree) |
---|---|
Tiempo | 2010-03-01 07:14:10 |
Autor | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
rudimentary mis-click GUI for x11
@@ -46,6 +46,7 @@ int Calibrator::get_numclicks() | ||
46 | 46 | bool Calibrator::add_click(int x, int y) |
47 | 47 | { |
48 | 48 | // Double-click detection |
49 | + // actually, it is still possible to click on a previous point | |
49 | 50 | if (num_clicks > 0 && threshold_doubleclick > 0 |
50 | 51 | && abs (x - clicked_x[num_clicks-1]) < threshold_doubleclick |
51 | 52 | && abs (y - clicked_y[num_clicks-1]) < threshold_doubleclick) { |
@@ -57,6 +58,8 @@ bool Calibrator::add_click(int x, int y) | ||
57 | 58 | } |
58 | 59 | |
59 | 60 | // Mis-click detection, check second and third point with first point |
61 | + // actually, check that different axes... | |
62 | + // and check that threshold_misclick > 0 | |
60 | 63 | if ((num_clicks == 1 || num_clicks == 2) && |
61 | 64 | (abs (x - clicked_x[0]) > threshold_misclick |
62 | 65 | && abs (x - clicked_y[0]) > threshold_misclick |
@@ -95,6 +95,7 @@ protected: | ||
95 | 95 | |
96 | 96 | // Helper functions |
97 | 97 | void redraw(); |
98 | + void draw_message(const char* msg); | |
98 | 99 | |
99 | 100 | private: |
100 | 101 | static GuiCalibratorX11* instance; |
@@ -261,14 +262,22 @@ bool GuiCalibratorX11::on_timer_signal() | ||
261 | 262 | |
262 | 263 | bool GuiCalibratorX11::on_button_press_event(XEvent event) |
263 | 264 | { |
265 | + // Clear window, maybe a bit overdone, but easiest for me atm. | |
266 | + // (goal is to clear possible message and other clicks) | |
267 | + XClearWindow(display, win); | |
268 | + | |
264 | 269 | // Handle click |
265 | 270 | time_elapsed = 0; |
266 | - calibrator->add_click(event.xbutton.x, event.xbutton.y); | |
271 | + bool success = calibrator->add_click(event.xbutton.x, event.xbutton.y); | |
272 | + | |
273 | + if (!success && calibrator->get_numclicks() == 0) { | |
274 | + draw_message("Mis-click detected, restarting..."); | |
275 | + } | |
267 | 276 | |
268 | 277 | // Are we done yet? |
269 | 278 | if (calibrator->get_numclicks() >= 4) { |
270 | 279 | // Recalibrate |
271 | - bool success = calibrator->finish(display_width, display_height); | |
280 | + success = calibrator->finish(display_width, display_height); | |
272 | 281 | |
273 | 282 | if (success) { |
274 | 283 | exit(0); |
@@ -285,6 +294,21 @@ bool GuiCalibratorX11::on_button_press_event(XEvent event) | ||
285 | 294 | return true; |
286 | 295 | } |
287 | 296 | |
297 | +void GuiCalibratorX11::draw_message(const char* msg) | |
298 | +{ | |
299 | + int text_height = font_info->ascent + font_info->descent; | |
300 | + int text_width = XTextWidth(font_info, msg, strlen(msg)); | |
301 | + | |
302 | + int x = (display_width - text_width) / 2; | |
303 | + int y = (display_height - text_height) / 2 + clock_radius + 60; | |
304 | + XSetForeground(display, gc, pixel[BLACK]); | |
305 | + XSetLineAttributes(display, gc, 2, LineSolid, CapRound, JoinRound); | |
306 | + XDrawRectangle(display, win, gc, x - 10, y - text_height - 10, | |
307 | + text_width + 20, text_height + 25); | |
308 | + | |
309 | + XDrawString(display, win, gc, x, y, msg, strlen(msg)); | |
310 | +} | |
311 | + | |
288 | 312 | void GuiCalibratorX11::give_timer_signal() |
289 | 313 | { |
290 | 314 | if (instance != NULL) { |