diff options
| author | 2026-04-13 17:36:54 -0400 | |
|---|---|---|
| committer | 2026-04-13 17:36:54 -0400 | |
| commit | 4ceadc74f0086168fbc576032ba3e6f23af16e39 (patch) | |
| tree | a542703d78f2b29ac1a756fdceec78e40860bab0 /src/screen | |
| parent | 77b54c35bf9587450cd636e0d7df37e190e28bfb (diff) | |
| download | camu-4ceadc74f0086168fbc576032ba3e6f23af16e39.tar.gz camu-4ceadc74f0086168fbc576032ba3e6f23af16e39.tar.bz2 camu-4ceadc74f0086168fbc576032ba3e6f23af16e39.zip | |
Changes that went uncommitted for too long
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/screen')
| -rw-r--r-- | src/screen/screen.c | 139 | ||||
| -rw-r--r-- | src/screen/screen.h | 9 |
2 files changed, 116 insertions, 32 deletions
diff --git a/src/screen/screen.c b/src/screen/screen.c index 0a0473d..cdc42bf 100644 --- a/src/screen/screen.c +++ b/src/screen/screen.c @@ -3,6 +3,7 @@ #include <al/log.h> #include <al/math.h> #include <nnwt/thread.h> +#include <nnwt/time.h> #include "view.h" #include "screen.h" @@ -15,6 +16,7 @@ #define SCREEN_IS_DRAGGING(scr) ((scr)->flags & CAMU_SCREEN_DRAGGING) #define SCREEN_IS_ZOOMING(scr) ((scr)->flags & CAMU_SCREEN_ZOOMING) +#define SCREEN_IS_FROZEN(scr) ((scr)->flags & CAMU_SCREEN_FROZEN) #define SCREEN_ZOOM_MODE(scr, mode) ((scr)->flags & mode) #define SCREEN_DEFAULT_CURSOR(scr) ((scr->fullscreen || scr->vr_emulation) ? STELA_CURSOR_HIDDEN : STELA_CURSOR_NORMAL) @@ -91,7 +93,7 @@ static bool pointer_pos_callback(void *userdata, f64 x, f64 y) if (SCREEN_IS_DRAGGING(scr)) { #ifdef CAMU_SCREEN_DRAG_SEEK u64 now = nn_get_timestamp(); - if (view && now - scr->last_seek_ts > 110000) { + if (view && now - scr->last_seek_ts > 100000) { seek_to_percent_at_pointer(scr, x); scr->last_seek_ts = now; } @@ -104,7 +106,7 @@ static bool pointer_pos_callback(void *userdata, f64 x, f64 y) view->mode = CAMU_VIEW_DETACHED; queue_refresh = true; } - if (fabs(dx) + fabs(dy) > 3.0) { + if (fabs(dx) + fabs(dy) > 6.0) { scr->last_click_ts = SCREEN_INVALID_TS; } } @@ -120,57 +122,109 @@ static bool scroll_callback(void *userdata, f64 y); static bool touch_callback(void *userdata, s32 index, u8 phase, f64 x, f64 y) { - struct camu_screen *scr = (struct camu_screen *)userdata; // Rough testing stuff. +#define distance(x1, x2, y1, y2) sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1))) + struct camu_screen *scr = (struct camu_screen *)userdata; switch (phase) { case STELA_TOUCH_BEGAN: { if (index == 0) { + scr->last_touch_x[0] = x; + scr->last_touch_y[0] = y; + } else if (index == 1) { + scr->last_touch_x[1] = x; + scr->last_touch_y[1] = y; + } + if (!SCREEN_IS_DRAGGING(scr)) { scr->flags |= CAMU_SCREEN_DRAGGING; scr->last_click_ts = nn_get_timestamp(); - scr->last_pointer_x = x; - scr->last_pointer_y = y; - } else if (index == 1) { - scr->flags &= ~CAMU_SCREEN_DRAGGING; + } else if (!SCREEN_IS_ZOOMING(scr)) { scr->flags |= CAMU_SCREEN_ZOOMING; - } else if (index == 2) { - scr->flags &= ~CAMU_SCREEN_ZOOMING; + f64 lx = scr->last_touch_x[0], lx2 = scr->last_touch_x[1]; + f64 ly = scr->last_touch_y[0], ly2 = scr->last_touch_y[1]; + scr->last_distance = distance(lx, lx2, ly, ly2); + scr->midpoint_x = (lx + lx2) / 2.0; + scr->midpoint_y = (ly + ly2) / 2.0; + } else if (!SCREEN_IS_FROZEN(scr)) { + scr->flags |= CAMU_SCREEN_FROZEN; struct camu_view *view = get_view_from_mouse_pos(scr); - view->mode = CAMU_DEFAULT_VIEW; - camu_view_calculate(view, scr->width, scr->height); + if (view) { + view->mode = CAMU_DEFAULT_VIEW; + camu_view_calculate(view, scr->width, scr->height); + } } break; } case STELA_TOUCH_MOVED: { - if (index == 0) { - if (SCREEN_IS_ZOOMING(scr)) { - f64 dy = (y - scr->last_pointer_y) / 50.0; - scr->last_pointer_x = x; - scr->last_pointer_y = y; - return scroll_callback(scr, dy); - } else if (SCREEN_IS_DRAGGING(scr)) { - return pointer_pos_callback(scr, x, y); + // @TODO: Track current index 1 and 2. On release search for next non-0 index in mask. + if (SCREEN_IS_FROZEN(scr)) { + return false; + } else if (SCREEN_IS_ZOOMING(scr)) { + if (index == 0) { + scr->last_touch_x[0] = x; + scr->last_touch_y[0] = y; + } else if (index == 1) { + scr->last_touch_x[1] = x; + scr->last_touch_y[1] = y; } + f64 lx = scr->last_touch_x[0], lx2 = scr->last_touch_x[1]; + f64 ly = scr->last_touch_y[0], ly2 = scr->last_touch_y[1]; + f64 dist = distance(lx, lx2, ly, ly2); + f64 mx = x = (lx + lx2) / 2.0, my = (ly + ly2) / 2.0; + bool refresh = false; + struct camu_view *view = get_view_from_mouse_pos(scr); + if (view) { + refresh |= camu_view_pan_simple(view, scr->width, scr->height, mx - scr->midpoint_x, my - scr->midpoint_y); + } + scr->midpoint_x = mx; + scr->midpoint_y = my; + scr->last_pointer_x = scr->midpoint_x; + scr->last_pointer_y = scr->midpoint_y; + refresh |= scroll_callback(scr, (dist - scr->last_distance) / 120.0); + scr->last_distance = dist; + return refresh; + } else if (SCREEN_IS_DRAGGING(scr)) { + if (index == 0) { + scr->last_pointer_x = scr->last_touch_x[0]; + scr->last_pointer_y = scr->last_touch_y[0]; + } else if (index == 1) { + scr->last_pointer_x = scr->last_touch_x[1]; + scr->last_pointer_y = scr->last_touch_y[1]; + } + bool refresh = pointer_pos_callback(scr, x, y); + if (index == 0) { + scr->last_touch_x[0] = x; + scr->last_touch_y[0] = y; + } else if (index == 1) { + scr->last_touch_x[1] = x; + scr->last_touch_y[1] = y; + } + return refresh; } break; } case STELA_TOUCH_ENDED: { - if (index == 0) { - scr->flags &= ~(CAMU_SCREEN_DRAGGING | CAMU_SCREEN_ZOOMING); + if (SCREEN_IS_FROZEN(scr)) { + scr->flags &= ~CAMU_SCREEN_FROZEN; + seek_to_percent_at_pointer(scr, x); + } else if (SCREEN_IS_ZOOMING(scr)) { + scr->flags &= ~CAMU_SCREEN_ZOOMING; + } else if (SCREEN_IS_DRAGGING(scr)) { + scr->flags &= ~CAMU_SCREEN_DRAGGING; if (SCREEN_LAST_CLICK_WITHIN(200000)) { - s32 n = (x >= scr->width / 2.0) ? 1 : -1; - scr->callback(scr->userdata, CAMU_SCREEN_SKIP, &n); - } - } else if (index == 1) { - // We want to ignore this if there was a 3rd touch. - if (SCREEN_IS_ZOOMING(scr)) { - scr->flags &= ~CAMU_SCREEN_ZOOMING; - scr->flags |= CAMU_SCREEN_DRAGGING; + f64 third = scr->width / 3.0; + if (x >= third && x <= third * 2.0) { + scr->callback(scr->userdata, CAMU_SCREEN_TOGGLE_PAUSE, NULL); + } else { + s32 n = (x >= third) ? 1 : -1; + scr->callback(scr->userdata, CAMU_SCREEN_SKIP, &n); + } } } break; } } return false; +#undef distance } static bool mouse_button_callback(void *userdata, u8 state, u8 button) @@ -373,6 +427,13 @@ static bool key_callback(void *userdata, u8 state, u16 button) } break; } + case STELA_KEY_T: { + struct camu_view *view = get_view_from_mouse_pos(scr); + if (view) { + scr->window->resize(scr->window, ceil(view->width * view->zoom), ceil(view->height * view->zoom)); + } + break; + } case STELA_KEY_EQUAL: { struct camu_view *view = get_view_from_mouse_pos(scr); if (view) { @@ -455,7 +516,7 @@ static bool key_callback(void *userdata, u8 state, u16 button) return false; } -static void key_immediate_callback(void *userdata, u8 state, u16 button) +static bool key_immediate_callback(void *userdata, u8 state, u16 button) { struct camu_screen *scr = (struct camu_screen *)userdata; switch (state) { @@ -468,17 +529,32 @@ static void key_immediate_callback(void *userdata, u8 state, u16 button) scr->window->set_cursor(scr->window, scr->fullscreen ? STELA_CURSOR_HIDDEN : STELA_CURSOR_NORMAL); } //#ifdef STELA_API_DX11 -#if 0 // Stela's window_win32 fullscreen mode (borderless) is probably more desirable here. +#if 0 // Stela's window_win32 fullscreen mode (borderless) is likely more desirable here. scr->renderer->set(scr->renderer, CAMU_RENDERER_FULLSCREEN, scr->fullscreen); #else scr->window->toggle_fullscreen(scr->window); #endif + return true; + case STELA_KEY_LEFT: + if (scr->touch_mode) { + s32 n = -1; + scr->callback(scr->userdata, CAMU_SCREEN_SKIP, &n); + return true; + } + break; + case STELA_KEY_RIGHT: + if (scr->touch_mode) { + s32 n = 1; + scr->callback(scr->userdata, CAMU_SCREEN_SKIP, &n); + return true; + } break; } break; default: break; } + return false; } bool camu_screen_init(struct camu_screen *scr) @@ -509,6 +585,7 @@ bool camu_screen_init(struct camu_screen *scr) #ifdef CAMU_SCREEN_DRAG_SEEK scr->last_seek_ts = 0; #endif + scr->touch_mode = false; scr->vr_emulation = CAMU_VR_DISABLED; scr->vr_left_eye = false; scr->vr_calibrate_x = 0.5; diff --git a/src/screen/screen.h b/src/screen/screen.h index b92cfe5..0d40a02 100644 --- a/src/screen/screen.h +++ b/src/screen/screen.h @@ -27,7 +27,8 @@ enum { CAMU_SCREEN_MOUSE_MOD = 1 << 3, CAMU_SCREEN_ZOOMING = 1 << 4, CAMU_SCREEN_ZOOM_PAN_SIMPLE = 1 << 5, - CAMU_SCREEN_ZOOM_FOV = 1 << 6 + CAMU_SCREEN_ZOOM_FOV = 1 << 6, + CAMU_SCREEN_FROZEN = 1 << 7 }; enum { @@ -76,9 +77,15 @@ struct camu_screen { u64 last_click_ts; f64 last_pointer_y; f64 last_pointer_x; + f64 last_touch_x[2]; + f64 last_touch_y[2]; + f64 last_distance; + f64 midpoint_x; + f64 midpoint_y; #ifdef CAMU_SCREEN_DRAG_SEEK u64 last_seek_ts; #endif + bool touch_mode; u8 vr_emulation; bool vr_left_eye; f64 vr_calibrate_x; |