X-Git-Url: http://git.mutantstargoat.com?p=winnie;a=blobdiff_plain;f=src%2Fgfx.cc;h=5c04d1edb3b2856719071f2f0ea75d1d34842cf0;hp=226d26954369b37c945bfe69dd6494bcb0b4a1d2;hb=5449bf8fbca1d2cfbefa0386df7109afb2a5aa34;hpb=094e53b80e5576db6c86bb7dc6141b0cff7fa665 diff --git a/src/gfx.cc b/src/gfx.cc index 226d269..5c04d1e 100644 --- a/src/gfx.cc +++ b/src/gfx.cc @@ -113,17 +113,97 @@ void set_cursor_visibility(bool visible) } } -void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img, int dest_x, int dest_y) +void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img, + const Rect &dest_rect, int dest_x, int dest_y) { - Rect dest_rect; + int width = src_rect.width; + int height = src_rect.height; - if(dest_x < screen_rect.x) { - dest_rect.x = screen_rect.x; + int xoffs = dest_x - dest_rect.x; + if(xoffs < 0) { + dest_x = dest_rect.x; + width += xoffs; } - if(dest_y < screen_rect.y) { - dest_rect.y = screen_rect.y; + int yoffs = dest_y - dest_rect.y; + if(yoffs < 0) { + dest_y = dest_rect.y; + height += yoffs; } - //TODO :p zzz + int xend = dest_x + width; + if(xend >= dest_rect.width) { + width -= xend - dest_rect.width; + } + + int yend = dest_y + height; + if(yend >= dest_rect.height) { + height -= yend - dest_rect.height; + } + + if(width <= 0 || height <= 0) { + return; + } + + unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4; + unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4; + + for(int i=0; i= dest_rect.width) { + width -= xend - dest_rect.width; + } + + int yend = dest_y + height; + if(yend >= dest_rect.height) { + height -= yend - dest_rect.height; + } + + if(width <= 0 || height <= 0) { + return; + } + + unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4; + unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4; + + for(int i=0; i