void scroll_layer_set_content_offset(ScrollLayer *l, GPoint offset, bool animated) { SCROLL_GET; if (gpoint_equal(&scroll->content_sublayer->frame.origin,&offset)) return; offset.x=0; GPoint oldOffset=scroll_layer_get_content_offset(l); GRect to=scroll_layer_get_new_content_rect(l,offset); if (animated) { if (scroll->animation) property_animation_destroy(scroll->animation); scroll->animation=property_animation_create_layer_frame(scroll->content_sublayer,0,&to); double duration=to.origin.y-oldOffset.y; if (duration<25||duration>-25) duration=abs(duration)*SCROLL_LAYER_SCROLL_SPEED; else duration=1; animation_set_duration((Animation*)scroll->animation,duration); animation_schedule((Animation*)scroll->animation); } else { scroll->content_sublayer->frame.origin=offset; layer_mark_dirty(scroll_layer); } if (scroll->callbacks.content_offset_changed_handler!=0) scroll->callbacks.content_offset_changed_handler(l,scroll->context); }
static void thread_offset_changed_handler(ScrollLayer *scroll_layer, void *context) { GPoint offset = scroll_layer_get_content_offset(scroll_layer); bool hide = (scroll_layer_size.h + offset.y - window_frame.size.h) > THREAD_WINDOW_HEIGHT; if(thread_inverter_hidden != hide) { thread_inverter_hidden = hide; layer_set_hidden(inverter_layer_get_layer(thread_inverter_layer), thread_inverter_hidden); if(!hide) { layer_set_frame(inverter_layer_get_layer(thread_inverter_layer), layer_get_frame(text_layer_get_layer(thread_view_comments_layer))); } } }
void scroll_layer_shadow_layer_update_func (Layer* me,GContext* ctx) { ScrollLayer* scroll_layer=(ScrollLayer*)me->parent; SDL_Surface* scroll_shadow=getSimulatorImage(SIM_IMG_SCROLL_SHADOW); GPoint topOffset=getTopOffset(); SDL_Surface* screen=getTopScreen (); GPoint offset=scroll_layer_get_content_offset (scroll_layer); GSize size=scroll_layer_get_content_size (scroll_layer); GSize frameSize=me->frame.size; SDL_Rect src,dst; if (offset.y<0) { src=(SDL_Rect){0,15,144,15}; dst=(SDL_Rect){topOffset.x,topOffset.y,144,15}; SDL_gfxBlitRGBA(scroll_shadow,&src,screen,&dst); } if (offset.y-((Layer*)scroll_layer)->frame.size.h!=-size.h) { src=(SDL_Rect){0,0,144,15}; dst=(SDL_Rect){topOffset.x,topOffset.y+frameSize.h-15,144,15}; SDL_gfxBlitRGBA(scroll_shadow,&src,screen,&dst); } }
void scroll_layer_scroll_down_click_handler(ClickRecognizerRef recognizer, void *l) { ScrollLayer* scroll_layer=(ScrollLayer*)l; GPoint offset=scroll_layer_get_content_offset(scroll_layer); offset.y-=SCROLL_LAYER_SCROLL_AMOUNT; scroll_layer_set_content_offset(scroll_layer,offset,true); }
void scroll_layer_scroll_up_click_handler(ClickRecognizerRef recognizer, ScrollLayer *scroll_layer) { GPoint offset=scroll_layer_get_content_offset(scroll_layer); offset.y+=SCROLL_LAYER_SCROLL_AMOUNT; scroll_layer_set_content_offset(scroll_layer,offset,true); }