X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fsdl%2Fgfx.cc;h=84ab69033a6c0f187dcf504d255cdcf65d657b31;hb=59cd3a77c4517e387f4c2e21e8b62a9017370116;hp=b7576888ee6ec7798dad12b346faea47c67175bc;hpb=6dc42c0e7292d6d94de640ddd7de3ee5c808e9c2;p=winnie diff --git a/src/sdl/gfx.cc b/src/sdl/gfx.cc index b757688..84ab690 100644 --- a/src/sdl/gfx.cc +++ b/src/sdl/gfx.cc @@ -7,8 +7,12 @@ static SDL_Surface *fbsurf; static Rect screen_rect = {0, 0, 1024, 768}; +static Rect clipping_rect; + static int color_depth = 32; // bits per pixel +static Pixmap *pixmap; + bool init_gfx() { if(SDL_Init(SDL_INIT_VIDEO) == -1) { @@ -22,11 +26,20 @@ bool init_gfx() } SDL_ShowCursor(0); + pixmap = new Pixmap; + pixmap->width = screen_rect.width; + pixmap->height = screen_rect.height; + pixmap->pixels = (unsigned char*)fbsurf->pixels; + + set_clipping_rect(screen_rect); + return true; } void destroy_gfx() { + pixmap->pixels = 0; + delete pixmap; SDL_Quit(); } @@ -35,6 +48,11 @@ unsigned char *get_framebuffer() return (unsigned char*)fbsurf->pixels; } +Pixmap *get_framebuffer_pixmap() +{ + return pixmap; +} + Rect get_screen_size() { return screen_rect; @@ -45,6 +63,24 @@ int get_color_depth() return color_depth; } +/*void set_clipping_rect(const Rect &rect) +{ + clipping_rect = rect_intersection(rect, screen_rect); + + SDL_Rect sdl_rect; + sdl_rect.x = clipping_rect.x; + sdl_rect.y = clipping_rect.y; + sdl_rect.w = clipping_rect.width; + sdl_rect.h = clipping_rect.height; + + SDL_SetClipRect(fbsurf, &sdl_rect); +} + +const Rect &get_clipping_rect() +{ + return clipping_rect; +} + void clear_screen(int r, int g, int b) { fill_rect(screen_rect, r, g, b); @@ -61,110 +97,19 @@ void fill_rect(const Rect &rect, int r, int g, int b) sdl_rect.h = rect.height; SDL_FillRect(fbsurf, &sdl_rect, color); -} +}*/ void set_cursor_visibility(bool visible) { } -void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img, - const Rect &dest_rect, int dest_x, int dest_y) -{ - int width = src_rect.width; - int height = src_rect.height; - - int xoffs = dest_x - dest_rect.x; - if(xoffs < 0) { - dest_x = dest_rect.x; - width += xoffs; - } - - int yoffs = dest_y - dest_rect.y; - if(yoffs < 0) { - dest_y = dest_rect.y; - height += yoffs; - } - - int xend = dest_x + width; - if(xend >= dest_rect.width) { - width -= xend - dest_rect.width; - } - - int yend = dest_y + height; - if(yend >= dest_rect.height) { - height -= yend - dest_rect.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= dest_rect.width) { - width -= xend - dest_rect.width; - } - - int yend = dest_y + height; - if(yend >= dest_rect.height) { - height -= yend - dest_rect.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