Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _GAME_GFX_HPP
- #define _GAME_GFX_HPP
- #include <utils/font.hpp>
- //background and text colors (16 each) should be just different enough
- //to differentiate them if they the palette indexes are the same
- extern SDL_Color _gfx_palette_default[32];
- typedef enum gfx_colors {
- clr_black = 0x0,
- clr_dgray = 0x1,
- clr_lgray = 0x2,
- clr_white = 0x3,
- clr_red = 0x4,
- clr_green = 0x5,
- clr_blue = 0x6,
- clr_cyan = 0x7,
- clr_magenta = 0x8,
- clr_yellow = 0x9,
- clr_brown = 0xA,
- clr_moss = 0xB,
- clr_lblue = 0xC,
- clr_teal = 0xD,
- clr_purple = 0xE,
- clr_orange = 0xF,
- } gfx_colors;
- union gfx_color {
- Uint8 both;
- struct {
- Uint8 txt : 4;
- Uint8 bg : 4;
- };
- };
- union gfx_char {
- Uint16 value;
- char chr;
- struct {
- Uint8 _chr : 7;
- Uint8 bgt : 1; //'is background transparent?'
- gfx_color color;
- };
- };
- class gfx_class {
- SDL_bool _valid = SDL_FALSE;
- SDL_Renderer* _renderer;
- const SDL_Color* _palette;
- font8x8* _colors[256];
- public:
- gfx_char chars[45][80]; //for 80x45 chars
- SDL_bool isValid(){ return _valid; }
- gfx_class(SDL_Renderer* renderer, const SDL_Color* palette = _gfx_palette_default);
- ~gfx_class(){
- for(int i=0; i<256; ++i) delete _colors[i];
- _valid = SDL_FALSE;
- }
- //void setScale(SDL_Point scale);
- void present();
- void clear(gfx_colors fillColor = clr_black);
- void set(gfx_char newChar, Uint32 column, Uint32 row);
- void box(gfx_color boxColor, SDL_Rect dimensions);
- void print(std::string& txt, Uint32 column, Uint32 row,
- gfx_color color = { .both = 3 },
- SDL_bool bg_transparent = SDL_FALSE);
- //void health();
- };
- #endif /* _GAME_GFX_HPP */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement