feature/imgui-sdl
|
Last change
on this file since 8b823e7 was e1f88a9, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 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 |
|
|---|
| 5 | Screen::Screen(SDL_Renderer& renderer, VulkanGame& gameInfo) :
|
|---|
| 6 | renderer(renderer),
|
|---|
| 7 | gameInfo(gameInfo) {
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | Screen::~Screen() {
|
|---|
| 11 | for (UIElement*& uiElement : this->uiElements) {
|
|---|
| 12 | delete uiElement;
|
|---|
| 13 | }
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | void Screen::init() {
|
|---|
| 17 | for (UIElement*& uiElement : this->uiElements) {
|
|---|
| 18 | uiElement->init();
|
|---|
| 19 | }
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | void 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 |
|
|---|
| 31 | void Screen::handleEvent(UIEvent& e) {
|
|---|
| 32 | for (UIElement*& uiElement : this->uiElements) {
|
|---|
| 33 | uiElement->handleEvent(e);
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | void Screen::addUIElement(UIElement* element) {
|
|---|
| 38 | this->uiElements.push_back(element);
|
|---|
| 39 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.