6 static Rect clipping_rect;
8 void set_clipping_rect(const Rect &rect)
10 clipping_rect = rect_intersection(rect, get_screen_size());
13 const Rect &get_clipping_rect()
18 void clear_screen(int r, int g, int b)
20 Rect screen_rect = get_screen_size();
21 fill_rect(screen_rect, r, g, b);
24 void fill_rect(const Rect &rect, int r, int g, int b)
27 Rect screen_rect = get_screen_size();
29 if(drect.x < clipping_rect.x) {
30 drect.width -= clipping_rect.x - drect.x;
31 drect.x = clipping_rect.x;
34 if(drect.y < clipping_rect.y) {
35 drect.height -= clipping_rect.y - drect.y;
36 drect.y = clipping_rect.y;
39 if(drect.x + drect.width >= clipping_rect.x + clipping_rect.width) {
40 drect.width = clipping_rect.width + clipping_rect.x - drect.x;
43 if(drect.y + drect.height >= clipping_rect.y + clipping_rect.height) {
44 drect.height = clipping_rect.height + clipping_rect.y - drect.y;
47 unsigned char *fb = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4;
48 for(int i=0; i<drect.height; i++) {
49 for(int j=0; j<drect.width; j++) {
54 fb += screen_rect.width * 4;
58 void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
59 const Rect &dest_rect, int dest_x, int dest_y)
61 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
63 int width = src_rect.width;
64 int height = src_rect.height;
66 int xoffs = dest_x - irect.x;
72 int yoffs = dest_y - irect.y;
78 int xend = dest_x + width;
79 if(xend >= irect.width) {
80 width -= xend - irect.width;
83 int yend = dest_y + height;
84 if(yend >= irect.height) {
85 height -= yend - irect.height;
88 if(width <= 0 || height <= 0) {
92 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
93 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
95 for(int i=0; i<height; i++) {
96 memcpy(dptr, sptr, width * 4);
97 sptr += src_rect.width * 4;
98 dptr += dest_rect.width * 4;
102 void blit_key(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
103 const Rect &dest_rect, int dest_x, int dest_y, int key_r, int key_g, int key_b)
105 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
107 int width = src_rect.width;
108 int height = src_rect.height;
110 int xoffs = dest_x - irect.x;
116 int yoffs = dest_y - irect.y;
122 int xend = dest_x + width;
123 if(xend >= irect.width) {
124 width -= xend - irect.width;
127 int yend = dest_y + height;
128 if(yend >= irect.height) {
129 height -= yend - irect.height;
132 if(width <= 0 || height <= 0) {
136 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
137 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
139 for(int i=0; i<height; i++) {
140 for(int j=0; j<width; j++) {
142 int g = sptr[j * 4 + 1];
143 int b = sptr[j * 4 + 2];
145 if(r != key_r || g != key_g || b != key_b) {
152 sptr += src_rect.width * 4;
153 dptr += dest_rect.width * 4;