diff options
Diffstat (limited to 'examples/simple_window.c')
| -rw-r--r-- | examples/simple_window.c | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/examples/simple_window.c b/examples/simple_window.c index a8a2861..a6819f9 100644 --- a/examples/simple_window.c +++ b/examples/simple_window.c @@ -8,6 +8,20 @@ static int mouse_x = -1; static int mouse_y = -1; static bool mouse_down = false; static int color_theme = 0; +static uint16_t pen_pressure = 0; +static int8_t pen_tilt_x = 0; +static int8_t pen_tilt_y = 0; +static enum yasl_pointer_device pointer_device = YASL_PTR_DEV_MOUSE; + +static const char *device_name(enum yasl_pointer_device dev) +{ + switch (dev) { + case YASL_PTR_DEV_PEN: return "Pen/Stylus"; + case YASL_PTR_DEV_ERASER: return "Eraser"; + case YASL_PTR_DEV_TOUCH: return "Touch"; + default: return "Mouse"; + } +} static void on_draw(struct yasl_surface *s, struct yasl_frame *frame, void *ud) { @@ -42,12 +56,20 @@ static void on_draw(struct yasl_surface *s, struct yasl_frame *frame, void *ud) break; } - /* Draw interactive pointer indicator */ + /* Draw interactive pointer / stylus indicator */ if (mouse_x >= 0 && mouse_y >= 0) { int dx = x - mouse_x; int dy = y - mouse_y; int dist_sq = dx * dx + dy * dy; - int radius = mouse_down ? 36 : 20; + + /* Pressure-sensitive radius: scales dynamically from 8px to 64px */ + int radius; + if (pen_pressure > 0) { + radius = 8 + (int)(((uint32_t)pen_pressure * 56) / 65535); + } else { + radius = mouse_down ? 36 : 18; + } + if (dist_sq < radius * radius) { r = (uint8_t)(255 - r / 2); g = (uint8_t)(255 - g / 2); @@ -87,7 +109,6 @@ static void on_quit(void *ud) int main(void) { - /* YASL manages its event loop internally when NULL is passed */ struct yasl_display_cbs disp_cbs = { .quit = on_quit }; struct yasl_display_spec disp_spec = { .app_id = "org.yasl.example", @@ -100,7 +121,7 @@ int main(void) } struct yasl_surface_spec surf_spec = { - .title = "YASL Interactive Window", + .title = "YASL Interactive Window (Pen & Touch Enabled)", .size = { .x = 640, .y = 480 }, }; struct yasl_surface *s = yasl_surface_create_toplevel(d, &surf_spec); @@ -119,9 +140,10 @@ int main(void) yasl_surface_schedule_redraw(s); printf("=== YASL Demo Running ===\n"); - printf(" - Move or Click mouse inside window to interact\n"); - printf(" - Press Space to cycle background themes\n"); - printf(" - Press Escape or close window to exit\n\n"); + printf(" - Stylus/Pen: full pressure (0..65535) and tilt detection\n"); + printf(" - Mouse/Touch: interactive click/motion highlights\n"); + printf(" - Space: cycle background themes\n"); + printf(" - Escape: exit\n\n"); while (running) { yasl_display_dispatch(d); @@ -138,24 +160,34 @@ int main(void) } } } else if (ev.kind == YASL_INPUT_MOUSE) { - if (ev.mouse.kind == YASL_PTR_MOTION) { - mouse_x = ev.mouse.pos.x; - mouse_y = ev.mouse.pos.y; - yasl_surface_schedule_redraw(s); - } else if (ev.mouse.kind == YASL_PTR_PRESS) { + mouse_x = ev.mouse.pos.x; + mouse_y = ev.mouse.pos.y; + pen_pressure = ev.mouse.pen.pressure; + pen_tilt_x = ev.mouse.pen.tilt_x; + pen_tilt_y = ev.mouse.pen.tilt_y; + pointer_device = ev.mouse.device; + + if (ev.mouse.kind == YASL_PTR_PRESS) { mouse_down = true; - mouse_x = ev.mouse.pos.x; - mouse_y = ev.mouse.pos.y; - yasl_surface_schedule_redraw(s); + if (pen_pressure > 0 || pointer_device == YASL_PTR_DEV_PEN) { + printf("[Pen Down] Pressure: %5u/65535 (%.1f%%) | Tilt: (%+3d°, %+3d°) | Device: %s\n", + pen_pressure, (pen_pressure * 100.0) / 65535.0, + pen_tilt_x, pen_tilt_y, device_name(pointer_device)); + } } else if (ev.mouse.kind == YASL_PTR_RELEASE) { mouse_down = false; - yasl_surface_schedule_redraw(s); + pen_pressure = 0; + } else if (ev.mouse.kind == YASL_PTR_MOTION && pen_pressure > 0) { + printf("[Pen Move] Pressure: %5u/65535 (%.1f%%) | Tilt: (%+3d°, %+3d°) | Device: %s\n", + pen_pressure, (pen_pressure * 100.0) / 65535.0, + pen_tilt_x, pen_tilt_y, device_name(pointer_device)); } else if (ev.mouse.kind == YASL_PTR_LEAVE) { mouse_x = -1; mouse_y = -1; mouse_down = false; - yasl_surface_schedule_redraw(s); + pen_pressure = 0; } + yasl_surface_schedule_redraw(s); } } |
