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 int red_offs, green_offs, blue_offs;
51 get_rgb_order(&red_offs, &green_offs, &blue_offs);
53 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
55 int width = src_rect.width;
56 int height = src_rect.height;
58 int xoffs = dest_x - irect.x;
64 int yoffs = dest_y - irect.y;
70 int xend = dest_x + width;
71 if(xend >= irect.width) {
72 width -= xend - irect.width;
75 int yend = dest_y + height;
76 if(yend >= irect.height) {
77 height -= yend - irect.height;
80 if(width <= 0 || height <= 0) {
84 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
85 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
87 for(int i=0; i<height; i++) {
88 for(int j=0; j<width; j++) {
89 dptr[j * 4 + red_offs] = sptr[j * 4];
90 dptr[j * 4 + green_offs] = sptr[j * 4 + 1];
91 dptr[j * 4 + blue_offs] = sptr[j * 4 + 2];
93 sptr += src_rect.width * 4;
94 dptr += dest_rect.width * 4;
98 void blit_key(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
99 const Rect &dest_rect, int dest_x, int dest_y, int key_r, int key_g, int key_b)
101 int red_offs, green_offs, blue_offs;
102 get_rgb_order(&red_offs, &green_offs, &blue_offs);
104 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
106 int width = src_rect.width;
107 int height = src_rect.height;
109 int xoffs = dest_x - irect.x;
115 int yoffs = dest_y - irect.y;
121 int xend = dest_x + width;
122 if(xend >= irect.width) {
123 width -= xend - irect.width;
126 int yend = dest_y + height;
127 if(yend >= irect.height) {
128 height -= yend - irect.height;
131 if(width <= 0 || height <= 0) {
135 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
136 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
138 for(int i=0; i<height; i++) {
139 for(int j=0; j<width; j++) {
141 int g = sptr[j * 4 + 1];
142 int b = sptr[j * 4 + 2];
144 if(r != key_r || g != key_g || b != key_b) {
145 dptr[j * 4 + red_offs] = r;
146 dptr[j * 4 + green_offs] = g;
147 dptr[j * 4 + blue_offs] = b;
151 sptr += src_rect.width * 4;
152 dptr += dest_rect.width * 4;