int glw_scroll_handle_event(glw_scroll_control_t *gs, glw_t *w, event_t *e) { if(event_is_type(e, EVENT_SCROLL)) { event_scroll_t *es = (event_scroll_t *)e; gs->bottom_anchored = 0; gs->target_pos += es->dY; w->glw_flags |= GLW_UPDATE_METRICS; glw_schedule_refresh(w->glw_root, 0); return 1; } return 0; }
void glw_scroll_handle_scroll(glw_scroll_control_t *gsc, glw_t *w, glw_scroll_t *gs) { int top = GLW_MAX(gs->value * (gsc->total_size - gsc->page_size + gsc->scroll_threshold_post), 0); gsc->target_pos = top; glw_schedule_refresh(w->glw_root, 0); if(gsc->chase_focus == 0) return; glw_t *c = w->glw_class->gc_find_visible_child(w); if(c == NULL) return; if(glw_is_focused(w)) { glw_focus_set(w->glw_root, c, GLW_FOCUS_SET_SUGGESTED, "Scroll"); } else { w->glw_focused = c; glw_signal0(w, GLW_SIGNAL_FOCUS_CHILD_INTERACTIVE, c); } }
int glw_scroll_handle_pointer_event_filter(glw_scroll_control_t *gs, glw_t *w, const glw_pointer_event_t *gpe) { glw_root_t *gr = w->glw_root; const int grabbed = gr->gr_pointer_grab_scroll == w; switch(gpe->type) { default: return 0; case GLW_POINTER_TOUCH_START: gr->gr_pointer_grab_scroll = w; gs->initial_pos = gs->target_pos; gs->initial_touch_x = gpe->local_x; gs->initial_touch_y = gpe->local_y; gs->last_touch_x = gpe->local_x; gs->last_touch_y = gpe->local_y; gs->last_touch_time = gpe->ts; gs->touch_velocity = 0; gs->kinetic_scroll = 0; return 0; case GLW_POINTER_TOUCH_END: if(fabsf(gs->touch_velocity) > 10) { gs->kinetic_scroll = gs->touch_velocity; glw_schedule_refresh(w->glw_root, 0); } if(grabbed) gr->gr_pointer_grab_scroll = NULL; return 0; } return 0; }
int glw_scroll_handle_pointer_event(glw_scroll_control_t *gs, glw_t *w, const glw_pointer_event_t *gpe) { glw_root_t *gr = w->glw_root; int64_t dt; const int grabbed = gr->gr_pointer_grab == w; float v; switch(gpe->type) { case GLW_POINTER_SCROLL: gs->target_pos += gs->page_size * gpe->delta_y; w->glw_flags |= GLW_UPDATE_METRICS; glw_schedule_refresh(w->glw_root, 0); return 1; case GLW_POINTER_FINE_SCROLL: gs->target_pos += gpe->delta_y; w->glw_flags |= GLW_UPDATE_METRICS; glw_schedule_refresh(w->glw_root, 0); return 1; case GLW_POINTER_TOUCH_START: gr->gr_pointer_grab = w; gs->initial_pos = gs->target_pos; gs->initial_touch_x = gpe->x; gs->initial_touch_y = gpe->y; gs->last_touch_x = gpe->x; gs->last_touch_y = gpe->y; gs->last_touch_time = gpe->ts; gs->touch_velocity = 0; gs->kinetic_scroll = 0; return 1; case GLW_POINTER_TOUCH_END: if(fabsf(gs->touch_velocity) > 10) gs->kinetic_scroll = gs->touch_velocity; if(grabbed) gr->gr_pointer_grab = NULL; return 1; case GLW_POINTER_TOUCH_CANCEL: if(grabbed) gr->gr_pointer_grab = NULL; return 1; case GLW_POINTER_FOCUS_MOTION: if(!grabbed) return 0; gs->target_pos = (gpe->y - gs->initial_touch_y) * gs->page_size * 0.5 + gs->initial_pos; dt = gpe->ts - gs->last_touch_time; if(dt > 100) { v = 1000000.0 * (gpe->y - gs->last_touch_y) / dt; gs->touch_velocity = v * 10; } gs->last_touch_time = gpe->ts; gs->last_touch_x = gpe->x; gs->last_touch_y = gpe->y; w->glw_flags |= GLW_UPDATE_METRICS; glw_schedule_refresh(w->glw_root, 0); break; default: return 0; } return 0; }
int glw_scroll_handle_pointer_event(glw_scroll_control_t *gs, glw_t *w, const glw_pointer_event_t *gpe) { glw_root_t *gr = w->glw_root; int64_t dt; const int grabbed = gr->gr_pointer_grab_scroll == w; float v; switch(gpe->type) { case GLW_POINTER_SCROLL: gs->bottom_anchored = 0; gs->target_pos += gs->page_size * gpe->delta_y; w->glw_flags |= GLW_UPDATE_METRICS; glw_schedule_refresh(w->glw_root, 0); return 1; case GLW_POINTER_FINE_SCROLL: gs->bottom_anchored = 0; gs->target_pos += gpe->delta_y; w->glw_flags |= GLW_UPDATE_METRICS; glw_schedule_refresh(w->glw_root, 0); return 1; case GLW_POINTER_TOUCH_CANCEL: if(grabbed) gr->gr_pointer_grab_scroll = NULL; return 1; case GLW_POINTER_FOCUS_MOTION: if(!grabbed) return 0; gs->bottom_anchored = 0; gs->target_pos = (gpe->local_y - gs->initial_touch_y) * gs->page_size * 0.5 + gs->initial_pos; const int max_value = MAX(0, gs->total_size - gs->page_size + gs->scroll_threshold_post); gs->target_pos = GLW_CLAMP(gs->target_pos, 0, max_value); if(abs(gs->target_pos - gs->initial_pos) > 15) { if(gr->gr_pointer_press != NULL) { glw_path_modify(gr->gr_pointer_press, 0, GLW_IN_PRESSED_PATH, NULL); gr->gr_pointer_press = NULL; } } dt = gpe->ts - gs->last_touch_time; if(dt > 100) { v = 1000000.0 * (gpe->local_y - gs->last_touch_y) / dt; gs->touch_velocity = v * 10; } gs->last_touch_time = gpe->ts; gs->last_touch_x = gpe->local_x; gs->last_touch_y = gpe->local_y; w->glw_flags |= GLW_UPDATE_METRICS; glw_schedule_refresh(w->glw_root, 0); break; default: return 0; } return 0; }
static void glw_slideshow_layout(glw_t *w, const glw_rctx_t *rc) { glw_root_t *gr = w->glw_root; glw_slideshow_t *s = (glw_slideshow_t *)w; glw_t *c, *p, *n; float delta; int r = 0; glw_reset_screensaver(w->glw_root); delta = s->w.glw_root->gr_frameduration / (float)s->transition_time; if((c = s->w.glw_focused) == NULL) { c = s->w.glw_focused = glw_first_widget(&s->w); if(c) glw_copy_constraints(&s->w, c); } if(c == NULL) return; glw_schedule_refresh(gr, s->deadline); if(s->deadline <= gr->gr_frame_start) { s->deadline = gr->gr_frame_start + s->display_time; c = glw_next_widget(c); if(c == NULL) c = glw_first_widget(&s->w); if(c != NULL) { glw_focus_open_path_close_all_other(c); glw_copy_constraints(&s->w, c); } } glw_layout0(c, rc); r |= update_parent_alpha(c, GLW_MIN(c->glw_parent_alpha + delta, 1.0f)); /** * Keep previous and next images 'hot' (ie, loaded into texture memory) */ p = glw_prev_widget(c); if(p == NULL) p = glw_last_widget(&s->w, 0); if(p != NULL && p != c) { r |= update_parent_alpha(p, GLW_MAX(p->glw_parent_alpha - delta, 0.0f)); glw_layout0(p, rc); } n = glw_next_widget(c); if(n == NULL) n = glw_first_widget(&s->w); if(n != NULL && n != c) { r |= update_parent_alpha(n, GLW_MAX(n->glw_parent_alpha - delta, 0.0f)); glw_layout0(n, rc); } if(r) glw_need_refresh(w->glw_root, 0); }