Fix rendering of Gui.

This commit is contained in:
Tim Schubert 2016-01-24 02:41:50 +01:00
parent a3df4a3189
commit ac0d35e053
10 changed files with 228 additions and 227 deletions

View file

@ -6,7 +6,7 @@
#include <unordered_set>
#include "Exceptions.hpp"
#include "Gameplay.hpp"
//#include "Events.hpp"
#include "Events.hpp"
#include "Gui.hpp"
#ifndef _BOB_H
@ -17,24 +17,13 @@ const int SCREEN_HEIGTH = 600;
const int SIDEBAR_WIDTH = 200;
const std::string TITLE = "Bob - Battles of Bacteria";
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint32 rmask = 0xff000000;
Uint32 gmask = 0x00ff0000;
Uint32 bmask = 0x0000ff00;
Uint32 amask = 0x000000ff;
#else
Uint32 rmask = 0x000000ff;
Uint32 gmask = 0x0000ff00;
Uint32 bmask = 0x00ff0000;
Uint32 amask = 0xff000000;
#endif
class Game
{
public:
Game(SDL_Rect *window_dimensions, Sint16 size)
{
this->event_context = new EventContext(4);
this->layout = new Layout(pointy_orientation, size,
{window_dimensions->w / 2, window_dimensions->h / 2},
{0, 0, window_dimensions->w - SIDEBAR_WIDTH, window_dimensions->h});
@ -46,10 +35,19 @@ public:
this->quit = false;
try
{
this->font = load_font_from_file("/usr/share/fonts/dejavu/DejaVuSans.ttf", 12);
this->window = new Window(TITLE, window_dimensions, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
this->renderer = new Renderer(this->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
this->renderer = new Renderer(this->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
| SDL_RENDERER_TARGETTEXTURE);
SDL_Rect side_bar_dimensions = {window_dimensions->x - SIDEBAR_WIDTH, 0, SIDEBAR_WIDTH,
window_dimensions->y};
this->side_bar = new Container(this->window, this->renderer, side_bar_dimensions);
this->test_box = new TextBox(this->renderer,
{SCREEN_WIDTH - SIDEBAR_WIDTH, 0, SIDEBAR_WIDTH, SCREEN_HEIGTH},
{0x00, 0xff, 0x00, 0xff}, this->font);
this->side_bar->add(test_box);
this->side_bar->set_visible(true);
}
catch (const SDL_Exception &sdl_except)
{
@ -61,13 +59,15 @@ public:
~Game()
{
delete this->test_box;
delete this->move_timer;
delete this->frame_timer;
// delete this->side_bar;
delete this->side_bar;
delete this->grid;
delete this->renderer;
delete this->window;
delete this->layout;
delete this->event_context;
}
void render();
@ -77,11 +77,14 @@ public:
int game_loop();
private:
EventContext *event_context;
TextBox *test_box;
TTF_Font *font;
Window *window;
Renderer *renderer;
HexagonGrid *grid;
Layout *layout;
// SideBar *side_bar;
Container *side_bar;
bool move[4];
bool quit;
Timer *frame_timer;