Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <game/gfx.hpp>
- //contains default palette
- #define _UTILS_GFX_CPP
- #include <utils/_gfx_tables.h>
- #undef _UTILS_GFX_CPP
- gfx_class::gfx_class(SDL_Renderer* renderer, const SDL_Color* palette){
- //some domain checks
- if(renderer == nullptr) throw "renderer = nullptr";
- if(palette == nullptr) throw "palette = nullptr";
- _renderer = renderer;
- _palette = palette;
- //create a font for every palette color combination
- for(int color=0; color<256; ++color){
- SDL_Color txt = palette[ color&15 ];
- SDL_Color bg = palette[16+(color>>4)];
- _colors[color] = new font8x8(renderer, bg, txt);
- }
- _valid = SDL_TRUE;
- clear(clr_black);
- }
- void gfx_class::present(){
- if(!_valid) throw "invalid gfx class";
- for(int yi=0; yi<45; ++yi){
- for(int xi=0; xi<80; ++xi){
- gfx_char chr = chars[yi][xi];
- _colors[chr.color.both]->putChar(chr.chr, xi,yi);
- }
- }
- SDL_RenderPresent(_renderer);
- }
- void gfx_class::clear(gfx_colors fillColor){
- if(!_valid) throw "invalid gfx class";
- gfx_char fillValue = { .chr = ' ' };
- fillValue.color.bg = fillColor;
- for(int yi=0; yi<45; ++yi)
- for(int xi=0; xi<80; ++xi)
- chars[yi][xi].value = fillValue.value;
- }
- void gfx_class::set(gfx_char newChar, Uint32 column, Uint32 row){
- if(!_valid) throw "invalid gfx class";
- if(column<80 && row<45){
- if(newChar.bgt){ //char has a transparent background
- chars[row][column].chr = newChar.chr;
- chars[row][column].color.txt = newChar.color.txt;
- } else { //char has an opaque background
- chars[row][column].value = newChar.value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement