Advertisement
Kitomas

gfx.hpp as of 2023-11-16

Nov 17th, 2023
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #ifndef _GAME_GFX_HPP
  2. #define _GAME_GFX_HPP
  3.  
  4. #include <utils/font.hpp>
  5.  
  6.  
  7.  
  8.  
  9. //background and text colors (16 each) should be just different enough
  10.  //to differentiate them if they the palette indexes are the same
  11. extern SDL_Color _gfx_palette_default[32];
  12. typedef enum gfx_colors {
  13.   clr_black   = 0x0,
  14.   clr_dgray   = 0x1,
  15.   clr_lgray   = 0x2,
  16.   clr_white   = 0x3,
  17.   clr_red     = 0x4,
  18.   clr_green   = 0x5,
  19.   clr_blue    = 0x6,
  20.   clr_cyan    = 0x7,
  21.   clr_magenta = 0x8,
  22.   clr_yellow  = 0x9,
  23.   clr_brown   = 0xA,
  24.   clr_moss    = 0xB,
  25.   clr_lblue   = 0xC,
  26.   clr_teal    = 0xD,
  27.   clr_purple  = 0xE,
  28.   clr_orange  = 0xF,
  29. } gfx_colors;
  30.  
  31.  
  32. union gfx_color {
  33.   Uint8  both;
  34.   struct {
  35.     Uint8 txt : 4;
  36.     Uint8  bg : 4;
  37.   };
  38. };
  39.  
  40.  
  41. union gfx_char {
  42.   Uint16       value;
  43.  
  44.   char           chr;
  45.   struct {
  46.     Uint8       _chr : 7;
  47.     Uint8        bgt : 1; //'is background transparent?'
  48.     gfx_color  color;
  49.   };
  50. };
  51.  
  52.  
  53. class gfx_class {
  54.   SDL_bool _valid = SDL_FALSE;
  55.  
  56.   SDL_Renderer* _renderer;
  57.   const SDL_Color* _palette;
  58.  
  59.   font8x8* _colors[256];
  60.  
  61.  
  62. public:
  63.   gfx_char chars[45][80]; //for 80x45 chars
  64.  
  65.  
  66.   SDL_bool isValid(){ return _valid; }
  67.  
  68.   gfx_class(SDL_Renderer* renderer, const SDL_Color* palette = _gfx_palette_default);
  69.  
  70.   ~gfx_class(){
  71.     for(int i=0; i<256; ++i) delete _colors[i];
  72.     _valid = SDL_FALSE;
  73.   }
  74.  
  75.  
  76.   //void setScale(SDL_Point scale);
  77.  
  78.   void present();
  79.   void clear(gfx_colors fillColor = clr_black);
  80.  
  81.   void set(gfx_char newChar, Uint32 column, Uint32 row);
  82.   void box(gfx_color boxColor, SDL_Rect dimensions);
  83.   void print(std::string& txt, Uint32 column, Uint32 row,
  84.              gfx_color color = { .both = 3 },
  85.              SDL_bool bg_transparent = SDL_FALSE);
  86.   //void health();
  87. };
  88.  
  89.  
  90.  
  91.  
  92. #endif /* _GAME_GFX_HPP */
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement