X-Git-Url: http://git.mutantstargoat.com?p=winnie;a=blobdiff_plain;f=src%2Fgfx.cc;fp=src%2Fgfx.cc;h=1da29539767792a7823f303ad0bc70abed2473a9;hp=0000000000000000000000000000000000000000;hb=59cd3a77c4517e387f4c2e21e8b62a9017370116;hpb=695cf39b73ecc76cbbc39e54f844ae55f4a9f938 diff --git a/src/gfx.cc b/src/gfx.cc new file mode 100644 index 0000000..1da2953 --- /dev/null +++ b/src/gfx.cc @@ -0,0 +1,155 @@ +#include + +#include "geom.h" +#include "gfx.h" + +static Rect clipping_rect; + +void set_clipping_rect(const Rect &rect) +{ + clipping_rect = rect_intersection(rect, get_screen_size()); +} + +const Rect &get_clipping_rect() +{ + return clipping_rect; +} + +void clear_screen(int r, int g, int b) +{ + Rect screen_rect = get_screen_size(); + fill_rect(screen_rect, r, g, b); +} + +void fill_rect(const Rect &rect, int r, int g, int b) +{ + Rect drect = rect; + Rect screen_rect = get_screen_size(); + + if(drect.x < clipping_rect.x) { + drect.width -= clipping_rect.x - drect.x; + drect.x = clipping_rect.x; + } + + if(drect.y < clipping_rect.y) { + drect.height -= clipping_rect.y - drect.y; + drect.y = clipping_rect.y; + } + + if(drect.x + drect.width >= clipping_rect.x + clipping_rect.width) { + drect.width = clipping_rect.width + clipping_rect.x - drect.x; + } + + if(drect.y + drect.height >= clipping_rect.y + clipping_rect.height) { + drect.height = clipping_rect.height + clipping_rect.y - drect.y; + } + + unsigned char *fb = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4; + for(int i=0; i= irect.width) { + width -= xend - irect.width; + } + + int yend = dest_y + height; + if(yend >= irect.height) { + height -= yend - irect.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= irect.width) { + width -= xend - irect.width; + } + + int yend = dest_y + height; + if(yend >= irect.height) { + height -= yend - irect.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