-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVanityUI.h
82 lines (74 loc) · 3.62 KB
/
VanityUI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include "Elements.h"
#include "Page.h"
#include <tuple>
#include <SDL_image.h>
#include <iostream>
class Vanity
{
public:
// Library setup methods
static void Setup(int viewWidth, int viewHeight, SDL_Renderer* targetRenderer = nullptr);
static void SetRenderTarget(SDL_Renderer* renderer);
// Element creation methods
static Label* CreateLabel(std::string text = "Label", int x = 0, int y = 0, SDL_Color color = { 0, 0, 0, 255}, int fontSize = 15, std::string fontPath = "fonts/CascadiaCode.ttf");
static Button* CreateButton(std::string label = "Button", int x = 0, int y = 0, int width = 0, int height = 0, int fontSize = 15, std::string fontPath = "fonts/CascadiaCode.ttf");
static Textbox* CreateTextbox(std::string placeholder = "Textbox", int x = 0, int y = 0, int width = 0, int height = 0, int fontSize = 15, int limit = NULL, std::string fontPath = "fonts/CascadiaCode.ttf");
static Checkbox* CreateCheckbox(int x = 0, int y = 0, int size = 20, bool defaultState = false);
static Image* CreateImage(std::string imagePath, int x = 0, int y = 0, int width = 100, int height = 100);
static Slider* CreateSlider(int x = 0, int y = 0, int width = 120, int height = 20, int thumbWidth = 20, int thumbHeight = 20);
static Division* CreateDivision(int x = 0, int y = 0, int width = 100, int height = 100);
// Page related methods
static Page* CreatePage();
static void DisplayPage(Page* page);
// Library utility methods
static void RenderLabel(std::string text, int x, int y, SDL_Color color, TTF_Font* font, int fontSize = 12);
static void DrawCircle(int32_t centreX, int32_t centreY, int32_t radius);
static void Render();
static void Rerender(); // TODO: Only render new frame texture when rerender bool is true!
static SDL_Texture* LoadImage(std::string imagePath);
static bool IsRunning();
static void Prepare();
static SDL_Renderer* CreateRenderingContext(std::string title);
static void EnableVsync();
static void DisableVsync();
static int GetViewportWidth();
static int GetViewportHeight();
static void SetActiveTextbox(Textbox* textbox);
private:
// General library data
static SDL_Renderer* targetRenderer;
static bool leftMousePressed;
static bool leftMouseHeld;
static bool rerender;
static bool isRunning;
static bool vsync;
static int viewportWidth, viewportHeight, mX, mY;
static SDL_Texture* snapshotFrame;
// PAGES - Related data
static Page* currentPage;
// TEXTBOX - Related data
static Textbox* activeTextbox;
static Uint32 textboxCursorDelta, delta;
static char lastPressedKey;
static bool drawTextBoxCursor, capsLockEnabled;
// Private methods
static void UpdateMousePosision();
static bool InheritStateFromParent(Division* parent, int& elementX, int& elementY, bool elementDisplayState);
static void RenderBackgroundImage(SDL_Texture* image, int width, int height, int x, int y);
static void prepareNewSnapshotFrame();
static void finalizeNewSnapshotFrame();
static TTF_Font* OpenFont(std::string fontUrl, int size);
static bool OnMouseHover(int x, int y, int width, int height);
static void UpdateMouseButtonState();
static bool ValidKey(int key);
static void CaptureInputText();
static void RenderButton(Button* button);
static void RenderTextbox(Textbox* textbox);
static void RenderLabel(Label* label);
static void RenderCheckbox(Checkbox* checkbox);
static void RenderImage(Image* image);
static void RenderSlider(Slider* slider);
static void RenderDivision(Division* division);
static void RenderBorder(int x, int y, int width, int height, BorderThickness borderThickness, BorderColors borderColors);
};