summaryrefslogtreecommitdiff
path: root/examples/tablet.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tablet.c')
-rw-r--r--examples/tablet.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/examples/tablet.c b/examples/tablet.c
index 256d8f8..8a1af7e 100644
--- a/examples/tablet.c
+++ b/examples/tablet.c
@@ -43,16 +43,6 @@ static const char *device_name(enum yasl_pointer_device device)
}
}
-static bool is_pen(enum yasl_pointer_device device)
-{
- return device == YASL_PTR_DEV_PEN || device == YASL_PTR_DEV_ERASER;
-}
-
-static double scale(const struct app *app)
-{
- return (double)app->geometry.scale_120 / YASL_SCALE_UNIT;
-}
-
static void cancel_stroke(struct app *app)
{
app->down = app->previous = app->visible = false;
@@ -94,7 +84,9 @@ static void clear_canvas(struct app *app)
static double brush_radius(const struct app *app)
{
- return scale(app) * (is_pen(app->pointer.device) ?
+ return ((double)app->geometry.scale_120 / YASL_SCALE_UNIT) *
+ ((app->pointer.device == YASL_PTR_DEV_PEN ||
+ app->pointer.device == YASL_PTR_DEV_ERASER) ?
2 + 24 * ((double)app->pointer.pen.pressure / 65535) : 6);
}
@@ -121,7 +113,8 @@ static void stroke(struct app *app)
double radius = brush_radius(app);
/* Leaving the canvas breaks the line so re-entry cannot bridge the UI. */
if (x < 0 || x >= app->geometry.size.x ||
- y < HEADER * scale(app) || y >= app->geometry.size.y) {
+ y < HEADER * ((double)app->geometry.scale_120 / YASL_SCALE_UNIT) ||
+ y >= app->geometry.size.y) {
app->previous = false;
return;
}
@@ -234,7 +227,7 @@ static void draw(struct yasl_surface *surface, struct yasl_frame *frame, void *u
}
struct yasl_framebuffer *fb = &frame->target;
memcpy(fb->pixels, app->canvas, (size_t)geometry.size.x * geometry.size.y * sizeof(uint32_t));
- double dpi = scale(app);
+ double dpi = (double)app->geometry.scale_120 / YASL_SCALE_UNIT;
rect(fb, 0, 0, fb->size.x, (int)lround(HEADER * dpi), PANEL);
char line[128];
snprintf(line, sizeof(line), "YASL TABLET / %s / %s / %s", backend_name(app->backend),