diff options
| -rw-r--r-- | src/mtview.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/mtview.c b/src/mtview.c index b8c3e37..a733dde 100644 --- a/src/mtview.c +++ b/src/mtview.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #include <stdio.h> | 2 | #include <stdio.h> |
| 3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
| 4 | #include <grail-touch.h> | 4 | #include <grail-touch.h> |
| 5 | #include <math.h> | ||
| 5 | 6 | ||
| 6 | #define XMARG 64 | 7 | #define XMARG 64 |
| 7 | #define YMARG 64 | 8 | #define YMARG 64 |
| @@ -15,6 +16,11 @@ struct windata { | |||
| 15 | unsigned long white, black, color[DIM_TOUCH]; | 16 | unsigned long white, black, color[DIM_TOUCH]; |
| 16 | }; | 17 | }; |
| 17 | 18 | ||
| 19 | static inline float max(float a, float b) | ||
| 20 | { | ||
| 21 | return b > a ? b : a; | ||
| 22 | } | ||
| 23 | |||
| 18 | static unsigned long new_color() | 24 | static unsigned long new_color() |
| 19 | { | 25 | { |
| 20 | return lrand48(); | 26 | return lrand48(); |
| @@ -29,15 +35,27 @@ static void clear_screen(struct windata *w) | |||
| 29 | static void output_touch(struct touch_dev *dev, struct windata *w, | 35 | static void output_touch(struct touch_dev *dev, struct windata *w, |
| 30 | const struct touch *t) | 36 | const struct touch *t) |
| 31 | { | 37 | { |
| 38 | float a = touch_angle(dev, t->orientation); | ||
| 39 | float ac = fabs(cos(a)); | ||
| 40 | float as = fabs(sin(a)); | ||
| 41 | float mx = max(t->touch_minor * ac, t->touch_major * as); | ||
| 42 | float my = max(t->touch_major * ac, t->touch_minor * as); | ||
| 43 | float ux = t->x - 0.5 * mx; | ||
| 44 | float uy = t->y - 0.5 * my; | ||
| 45 | float vx = t->x + 0.5 * mx; | ||
| 46 | float vy = t->y + 0.5 * my; | ||
| 47 | |||
| 32 | float x1 = dev->caps.min_x, y1 = dev->caps.min_y; | 48 | float x1 = dev->caps.min_x, y1 = dev->caps.min_y; |
| 33 | float x2 = dev->caps.max_x, y2 = dev->caps.max_y; | 49 | float x2 = dev->caps.max_x, y2 = dev->caps.max_y; |
| 34 | int x = (t->x - x1) / (x2 - x1) * w->width; | 50 | float dx = x2 - x1, dy = y2 - y1; |
| 35 | int y = (t->y - y1) / (y2 - y1) * w->height; | 51 | float px = (ux - x1) / dx * w->width; |
| 36 | int d = t->touch_major / (x2 - x1) * w->width * WSCALE; | 52 | float py = (uy - y1) / dy * w->height; |
| 53 | float qx = (vx - x1) / dx * w->width; | ||
| 54 | float qy = (vy - y1) / dy * w->height; | ||
| 37 | if (t->id > w->lastid) | 55 | if (t->id > w->lastid) |
| 38 | w->color[t->slot] = new_color(); | 56 | w->color[t->slot] = new_color(); |
| 39 | XSetForeground(w->dsp, w->gc, w->color[t->slot]); | 57 | XSetForeground(w->dsp, w->gc, w->color[t->slot]); |
| 40 | XFillArc(w->dsp, w->win, w->gc, x, y, d, d, 0, 360 * 64); | 58 | XFillArc(w->dsp, w->win, w->gc, px, py, qx - px, qy - py, 0, 360 * 64); |
| 41 | } | 59 | } |
| 42 | 60 | ||
| 43 | static void tp_event(struct touch_dev *dev, | 61 | static void tp_event(struct touch_dev *dev, |
| @@ -69,13 +87,20 @@ static void event_loop(struct touch_dev *dev, int fd, struct windata *w) | |||
| 69 | dev->priv = w; | 87 | dev->priv = w; |
| 70 | w->lastid = -1; | 88 | w->lastid = -1; |
| 71 | 89 | ||
| 72 | XSelectInput(w->dsp, w->win, ButtonPressMask | ButtonReleaseMask); | 90 | XSelectInput(w->dsp, w->win, ButtonPress | ButtonRelease); |
| 91 | clear_screen(w); | ||
| 92 | XFlush(w->dsp); | ||
| 93 | |||
| 73 | while (1) { | 94 | while (1) { |
| 74 | XNextEvent(w->dsp, &ev); | 95 | if (XEventsQueued(w->dsp, QueuedAlready)) { |
| 75 | clear_screen(w); | 96 | XNextEvent(w->dsp, &ev); |
| 76 | XNextEvent(w->dsp, &ev); | 97 | if (ev.type == ButtonRelease) |
| 77 | while (!touch_dev_idle(dev, fd, 1000)) | 98 | break; |
| 99 | } | ||
| 100 | if(!touch_dev_idle(dev, fd, 100)) { | ||
| 78 | touch_dev_pull(dev, fd); | 101 | touch_dev_pull(dev, fd); |
| 102 | XFlush(w->dsp); | ||
| 103 | } | ||
| 79 | } | 104 | } |
| 80 | } | 105 | } |
| 81 | 106 | ||
