2 winnie - an experimental window system
4 Copyright (C) 2013 Eleni Maria Stea
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Author: Eleni Maria Stea <elene.mst@gmail.com>
27 void clear_screen(int r, int g, int b)
29 Rect screen_rect = get_screen_size();
30 fill_rect(screen_rect, r, g, b);
33 void fill_rect(const Rect &rect, int r, int g, int b)
36 Rect screen_rect = get_screen_size();
37 Rect clipping_rect = get_clipping_rect();
39 if(drect.x < clipping_rect.x) {
40 drect.width -= clipping_rect.x - drect.x;
41 drect.x = clipping_rect.x;
44 if(drect.y < clipping_rect.y) {
45 drect.height -= clipping_rect.y - drect.y;
46 drect.y = clipping_rect.y;
49 if(drect.x + drect.width >= clipping_rect.x + clipping_rect.width) {
50 drect.width = clipping_rect.width + clipping_rect.x - drect.x;
53 if(drect.y + drect.height >= clipping_rect.y + clipping_rect.height) {
54 drect.height = clipping_rect.height + clipping_rect.y - drect.y;
57 unsigned char *fb = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4;
58 for(int i=0; i<drect.height; i++) {
59 for(int j=0; j<drect.width; j++) {
64 fb += screen_rect.width * 4;
68 void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
69 const Rect &dest_rect, int dest_x, int dest_y)
71 int red_offs, green_offs, blue_offs;
72 get_rgb_order(&red_offs, &green_offs, &blue_offs);
74 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
76 int width = src_rect.width;
77 int height = src_rect.height;
79 int xoffs = dest_x - irect.x;
85 int yoffs = dest_y - irect.y;
91 int xend = dest_x + width;
92 if(xend >= irect.width) {
93 width -= xend - irect.width;
96 int yend = dest_y + height;
97 if(yend >= irect.height) {
98 height -= yend - irect.height;
101 if(width <= 0 || height <= 0) {
105 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
106 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
108 for(int i=0; i<height; i++) {
109 for(int j=0; j<width; j++) {
110 dptr[j * 4 + red_offs] = sptr[j * 4];
111 dptr[j * 4 + green_offs] = sptr[j * 4 + 1];
112 dptr[j * 4 + blue_offs] = sptr[j * 4 + 2];
114 sptr += src_rect.width * 4;
115 dptr += dest_rect.width * 4;
119 void blit_key(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
120 const Rect &dest_rect, int dest_x, int dest_y, int key_r, int key_g, int key_b)
122 int red_offs, green_offs, blue_offs;
123 get_rgb_order(&red_offs, &green_offs, &blue_offs);
125 Rect irect = rect_intersection(get_clipping_rect(), dest_rect);
127 int width = src_rect.width;
128 int height = src_rect.height;
130 int xoffs = dest_x - irect.x;
136 int yoffs = dest_y - irect.y;
142 int xend = dest_x + width;
143 if(xend >= irect.width) {
144 width -= xend - irect.width;
147 int yend = dest_y + height;
148 if(yend >= irect.height) {
149 height -= yend - irect.height;
152 if(width <= 0 || height <= 0) {
156 unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
157 unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
159 for(int i=0; i<height; i++) {
160 for(int j=0; j<width; j++) {
162 int g = sptr[j * 4 + 1];
163 int b = sptr[j * 4 + 2];
165 if(r != key_r || g != key_g || b != key_b) {
166 dptr[j * 4 + red_offs] = r;
167 dptr[j * 4 + green_offs] = g;
168 dptr[j * 4 + blue_offs] = b;
172 sptr += src_rect.width * 4;
173 dptr += dest_rect.width * 4;