void rot_bitmap_layer_update_func (Layer* l,GContext* ctx) { ROT_BITMAP_GET; GPoint topOffset=getTopOffset (); setTopOffset(GPoint(0,0)); GRect rect=GRect(0,0,l->frame.size.w,l->frame.size.h); SDL_Surface* sur=createSurface(rotbitmap->bitmap->bounds.size.w,rotbitmap->bitmap->bounds.size.h); SDL_FillRect(sur,0,0); graphics_context_set_compositing_mode (ctx,GCompOpAssign); graphics_draw_bitmap_in_rect_to (ctx,rotbitmap->bitmap,rect,sur); double angle=(double)rotbitmap->rotation/TRIG_MAX_ANGLE*360.0; SDL_Surface* rotated=rotozoomSurface(sur,-angle,1.0,SMOOTHING_OFF); SDL_FreeSurface(sur); GPoint offset=getPivotRotationOffset(rotbitmap->bitmap->bounds.size,GSize(rotated->w,rotated->h),rotbitmap->src_ic,angle); rotbitmap->dest_ic.x=l->frame.size.w/2; //TODO: Verify this rotbitmap->dest_ic.y=l->frame.size.h/2; setTopOffset(topOffset); if (rotbitmap->corner_clip_color!=GColorClear) { graphics_context_set_fill_color(ctx,rotbitmap->corner_clip_color); graphics_fill_rect(ctx,GRect(0,0,l->frame.size.w,l->frame.size.h),0,0); } graphics_context_set_compositing_mode (ctx,rotbitmap->compositing_mode); graphics_draw_surface_in_rect (ctx,rotated,GRect(rotbitmap->dest_ic.x-offset.x,rotbitmap->dest_ic.y-offset.y,rotated->w,rotated->h)); SDL_FreeSurface(rotated); }
void graphics_fill_rect(GContext *ctx, GRect rect, uint8_t corner_radius, GCornerMask corner_mask) { //TODO: corner_mask GPoint topOffset=getTopOffset (); if (corner_radius>0) roundedBoxColor (getTopScreen(),topOffset.x+rect.origin.x,topOffset.y+rect.origin.y,topOffset.x+rect.origin.x+rect.size.w,topOffset.y+rect.origin.y+rect.size.h,corner_radius,getRawColor(ctx->fill_color)); else boxColor (getTopScreen(),topOffset.x+rect.origin.x,topOffset.y+rect.origin.y,topOffset.x+rect.origin.x+rect.size.w,topOffset.y+rect.origin.y+rect.size.h,getRawColor(ctx->fill_color)); }
void graphics_draw_something_in_rect_to(GContext *ctx, void* what,graphics_draw_something_callback callback, GRect rect,SDL_Surface* screen) { // TODO: verify composite mode implementations // TODO: bitmap->info_flags? GCompOp compositing_mode = ctx->compositing_mode; GPoint topOffset=getTopOffset (); SDL_Rect clipRect; SDL_GetClipRect(screen,&clipRect); LOCK(screen); int16_t x,y; callback (what,-1,0); for(x=0; x < rect.size.w; x++) { int16_t dst_x = x + rect.origin.x+topOffset.x; if(dst_x < clipRect.x) continue; else if(dst_x >= clipRect.x+clipRect.w) break; for(y=0; y < rect.size.h; y++) { int16_t dst_y = y + rect.origin.y+topOffset.y; if(dst_y < clipRect.y) continue; else if(dst_y >= clipRect.y+clipRect.h) break; uint32_t src_c = callback(what,x,y); uint32_t *dst_c = (uint32_t *)(((uint8_t*)screen->pixels) + screen->pitch * dst_y + 4 * dst_x); switch(compositing_mode) { case GCompOpAssign: *dst_c = src_c; break; case GCompOpAssignInverted: *dst_c = ~(src_c) | 0x000000ff; break; case GCompOpOr: if (src_c == r_white) *dst_c = r_white; break; case GCompOpAnd: if (src_c == r_black) *dst_c = r_black; break; case GCompOpClear: if (src_c == r_white) *dst_c = r_black; break; case GCompOpSet: if (src_c == r_black) *dst_c = r_white; break; } } } callback(what,0,-1); UNLOCK(screen); }
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 rotbmp_layer_update_func (Layer* me,GContext* ctx) { GPoint topOffset=getTopOffset (); setTopOffset(GPoint(0,0)); GRect rect=GRect(0,0,me->frame.size.w,me->frame.size.h); RotBitmapLayer* bitmapLayer=(RotBitmapLayer*)me; SDL_Surface* bitmap=createSurface(bitmapLayer->bitmap->bounds.size.w,bitmapLayer->bitmap->bounds.size.h); SDL_FillRect(bitmap,0,0); graphics_context_set_compositing_mode (ctx,GCompOpAssign); graphics_draw_bitmap_in_rect_to (ctx,bitmapLayer->bitmap,rect,bitmap); double angle=(double)bitmapLayer->rotation/TRIG_MAX_ANGLE*360.0; SDL_Surface* rotated=rotozoomSurface(bitmap,-angle,1.0,SMOOTHING_OFF); SDL_FreeSurface(bitmap); GPoint offset=getPivotRotationOffset(bitmapLayer->bitmap->bounds.size,GSize(rotated->w,rotated->h),bitmapLayer->src_ic,angle); setTopOffset(topOffset); graphics_context_set_compositing_mode (ctx,bitmapLayer->compositing_mode); graphics_draw_surface_in_rect (ctx,rotated,GRect(bitmapLayer->dest_ic.x-offset.x,bitmapLayer->dest_ic.y-offset.y,rotated->w,rotated->h)); SDL_FreeSurface(rotated); }
void _gpath_to_sdl(GPath *path,Sint16** pointsX,Sint16** pointsY) { GPoint topOffset=getTopOffset (); *pointsX=(Sint16*)malloc(sizeof(Sint16)*path->num_points); *pointsY=(Sint16*)malloc(sizeof(Sint16)*path->num_points); double s = sin(((double)path->rotation/TRIG_MAX_ANGLE) * 2*PI ); double c = cos(((double)path->rotation/TRIG_MAX_ANGLE) * 2*PI); int p; for(p=0; p<path->num_points; p++) { double x, y, nx; x = path->points[p].x+0.5; y = path->points[p].y+0.5; nx = x * c - y * s; y = x * s + y * c; x = nx; x += path->offset.x; y += path->offset.y; (*pointsX)[p] = (Sint16)(x+topOffset.x); (*pointsY)[p] = (Sint16)(y+topOffset.y); } }
long PANEElement::getBottomOffset(){ return getTopOffset() + getActualHeight( getAvailableWidth() ); }
void graphics_draw_round_rect(GContext *ctx, GRect rect, int radius) { GPoint topOffset=getTopOffset (); roundedRectangleColor(getTopScreen(),topOffset.x+rect.origin.x,topOffset.y+rect.origin.y,topOffset.x+rect.origin.x+rect.size.w,topOffset.y+rect.origin.y+rect.size.h,radius,getRawColor(ctx->stroke_color)); }
void graphics_fill_circle(GContext *ctx, GPoint p, int radius) { GPoint topOffset=getTopOffset (); filledCircleColor(getTopScreen(), topOffset.x+p.x, topOffset.y+p.y, radius, getRawColor(ctx->fill_color)); }
void graphics_draw_circle(GContext *ctx, GPoint p, int radius) { GPoint topOffset=getTopOffset (); circleColor(getTopScreen(), topOffset.x+p.x, topOffset.y+p.y, radius, getRawColor(ctx->stroke_color)); }
void graphics_draw_line(GContext *ctx, GPoint p0, GPoint p1) { GPoint topOffset=getTopOffset (); lineColor(getTopScreen(), topOffset.x+p0.x, topOffset.y+p0.y, topOffset.x+p1.x, topOffset.y+p1.y, getRawColor(ctx->stroke_color)); }
void graphics_draw_pixel(GContext *ctx, GPoint point) { GPoint topOffset=getTopOffset (); pixelColor(getTopScreen(), topOffset.x+point.x, topOffset.y+point.y, getRawColor(ctx->stroke_color)); }
//#verify #verify #verify !!!!!!!!!! void graphics_text_draw(GContext *ctx, const char *text, const GFont font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextLayoutCacheRef layout) { char buffer [256]; //SHIT!! I need to mark the end of the string but I can't use the original parameter... TextWrapper textWrapper=(overflow_mode==GTextOverflowModeWordWrap?wrap_words:wrap_points); int lineHeight=0,usedHeight=0; SDL_Surface* lineSurface,*lineSurfaceTemp; SDL_Surface* textSurface=SDL_CreateRGBSurface (SDL_SWSURFACE|SDL_SRCALPHA,box.size.w,box.size.h,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff); SDL_FillRect (textSurface,0,0); SDL_Surface* pointsSurface=0; //this will only be initalised when it's needed SDL_Rect dstRect,srcRect; SDL_Color color=getColor(ctx->text_color); GPoint topOffset=getTopOffset (); _WrapResult wrap; if (text==0) return; while (*text!=0&&usedHeight<box.size.h) { wrap=textWrapper (text,box.size.w,font); memcpy(buffer,text,wrap.lineLen); buffer[wrap.lineLen]=0; text=wrap.newString; if (wrap.lineLen==0) { usedHeight+=lineHeight; continue; } lineSurfaceTemp=TTF_RenderText_Solid ((TTF_Font*)font,buffer,color); if (lineSurfaceTemp==0) { printf("[WARN] TTF_RenderText_Solid: %s\n",TTF_GetError ()); return; } lineSurface=SDL_ConvertSurface(lineSurfaceTemp,textSurface->format,SDL_SWSURFACE|SDL_SRCALPHA); SDL_FreeSurface(lineSurfaceTemp); if (lineHeight==0) lineHeight=lineSurface->h; //prepare blitting srcRect=((SDL_Rect) { 0,0,lineSurface->w,lineSurface->h }); if (srcRect.h+usedHeight>box.size.h) srcRect.h=box.size.h-usedHeight; dstRect=srcRect; dstRect.y=usedHeight; //set text alignment if (alignment==GTextAlignmentCenter) dstRect.x=box.size.w/2-(dstRect.w+wrap.addPoints)/2; else if (alignment==GTextAlignmentRight) dstRect.x=box.size.w-(dstRect.w+wrap.addPoints); //else // srcRect.x=0; //blit line to text SDL_gfxBlitRGBA(lineSurface,&srcRect,textSurface,&dstRect); SDL_FreeSurface(lineSurface); if (wrap.addPoints>0) { if (pointsSurface==0) { pointsSurface=TTF_RenderText_Solid ((TTF_Font*)font,"...",color); if (pointsSurface==0) { printf("[WARN] TTF_RenderText_Solid: %s\n",TTF_GetError ()); return; } } srcRect.x=0; srcRect.w=pointsSurface->w; dstRect.x+=dstRect.w; dstRect.w=pointsSurface->w; SDL_BlitSurface(pointsSurface,&srcRect,textSurface,&dstRect); } usedHeight+=lineHeight; } srcRect=((SDL_Rect) { 0,0,box.size.w,box.size.h }); dstRect=((SDL_Rect) { box.origin.x+topOffset.x,box.origin.y+topOffset.y,box.size.w,box.size.h }); SDL_gfxBlitRGBA(textSurface,&srcRect,getTopScreen(),&dstRect); SDL_FreeSurface(textSurface); if (pointsSurface!=0) SDL_FreeSurface(pointsSurface); }