source: opengl-game/gui/screen.cpp@ 670c09a

feature/imgui-sdl
Last change on this file since 670c09a was e1f88a9, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Create a system to draw and switch between different screens, a Screen class, a MainScreen class that extends it, and some classes for UI elements that can be added to screens.

  • Property mode set to 100644
File size: 829 bytes
Line 
1#include "screen.hpp"
2
3#include "../vulkan-game.hpp"
4
5Screen::Screen(SDL_Renderer& renderer, VulkanGame& gameInfo) :
6 renderer(renderer),
7 gameInfo(gameInfo) {
8}
9
10Screen::~Screen() {
11 for (UIElement*& uiElement : this->uiElements) {
12 delete uiElement;
13 }
14}
15
16void Screen::init() {
17 for (UIElement*& uiElement : this->uiElements) {
18 uiElement->init();
19 }
20}
21
22void Screen::renderUI() {
23 SDL_SetRenderDrawColor(&this->renderer, 0x00, 0x00, 0x00, 0x00);
24 SDL_RenderClear(&this->renderer);
25
26 for (UIElement*& uiElement : this->uiElements) {
27 uiElement->render(0, 0);
28 }
29}
30
31void Screen::handleEvent(UIEvent& e) {
32 for (UIElement*& uiElement : this->uiElements) {
33 uiElement->handleEvent(e);
34 }
35}
36
37void Screen::addUIElement(UIElement* element) {
38 this->uiElements.push_back(element);
39}
Note: See TracBrowser for help on using the repository browser.