~mil/mepo

0328af71821a1eb81da30a2b0f07850f8c7806c1 — Miles Alan 2 years ago 5b75b59 drag-test
Debounce drawing / drag based on interval
1 files changed, 10 insertions(+), 2 deletions(-)

M src/Mepo.zig
M src/Mepo.zig => src/Mepo.zig +10 -2
@@ 859,11 859,19 @@ pub fn sdl_event_loop(mepo: *@This()) !void {
    var pending: types.Pending = .None;
    var e: sdl.SDL_Event = undefined;

    var last_drag_redraw_ticks : ?usize = null;
    const drag_redraw_ms = 5;

    while (true) {
        // Redraw

        const has_pending_motion_events = (sdl.SDL_bool.SDL_TRUE == sdl.SDL_HasEvent(@enumToInt(sdl.SDL_EventType.SDL_MOUSEMOTION)));
        if ((!has_pending_motion_events and pending == .Drag) or pending == .Redraw) {
        // Redraw
        if (
            (pending == .Drag and !has_pending_motion_events and (last_drag_redraw_ticks == null or  sdl.SDL_GetTicks() > last_drag_redraw_ticks.? + drag_redraw_ms)) or 
            pending == .Redraw
        ) {
            try blit(mepo);
            last_drag_redraw_ticks = if (pending == .Drag) sdl.SDL_GetTicks() else null;
        }

        mepo.click_hold_check_dispatch();