6 void clear_screen(int r, int g, int b)
8 Rect screen_rect = get_screen_size();
9 fill_rect(screen_rect, r, g, b);
12 void fill_rect(const Rect &rect, int r, int g, int b)
15 Rect screen_rect = get_screen_size();
16 Rect clipping_rect = get_clipping_rect();
18 if(drect.x < clipping_rect.x) {
19 drect.width -= clipping_rect.x - drect.x;
20 drect.x = clipping_rect.x;
23 if(drect.y < clipping_rect.y) {
24 drect.height -= clipping_rect.y - drect.y;
25 drect.y = clipping_rect.y;
28 if(drect.x + drect.width >= clipping_rect.x + clipping_rect.width) {
29 drect.width = clipping_rect.width + clipping_rect.x - drect.x;
32 if(drect.y + drect.height >= clipping_rect.y + clipping_rect.height) {
33 drect.height = clipping_rect.height + clipping_rect.y - drect.y;
36 unsigned char *fb = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4;
37 for(int i=0; i<drect.height; i++) {
38 for(int j=0; j<drect.width; j++) {
43 fb += screen_rect.width * 4;
47 void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
48 const Rect &dest_rect, int dest_x, int dest_y)
50 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
52 int width = src_rect.width;
53 int height = src_rect.height;
55 int xoffs = dest_x - irect.x;
61 int yoffs = dest_y - irect.y;
67 int xend = dest_x + width;
68 if(xend >= irect.width) {
69 width -= xend - irect.width;
72 int yend = dest_y + height;
73 if(yend >= irect.height) {
74 height -= yend - irect.height;
77 if(width <= 0 || height <= 0) {
81 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
82 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
84 for(int i=0; i<height; i++) {
85 memcpy(dptr, sptr, width * 4);
86 sptr += src_rect.width * 4;
87 dptr += dest_rect.width * 4;
91 void blit_key(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
92 const Rect &dest_rect, int dest_x, int dest_y, int key_r, int key_g, int key_b)
94 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
96 int width = src_rect.width;
97 int height = src_rect.height;
99 int xoffs = dest_x - irect.x;
105 int yoffs = dest_y - irect.y;
111 int xend = dest_x + width;
112 if(xend >= irect.width) {
113 width -= xend - irect.width;
116 int yend = dest_y + height;
117 if(yend >= irect.height) {
118 height -= yend - irect.height;
121 if(width <= 0 || height <= 0) {
125 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
126 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
128 for(int i=0; i<height; i++) {
129 for(int j=0; j<width; j++) {
131 int g = sptr[j * 4 + 1];
132 int b = sptr[j * 4 + 2];
134 if(r != key_r || g != key_g || b != key_b) {
141 sptr += src_rect.width * 4;
142 dptr += dest_rect.width * 4;