-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI_system.h
More file actions
102 lines (83 loc) · 2.94 KB
/
UI_system.h
File metadata and controls
102 lines (83 loc) · 2.94 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include "glm/gtx/hash.hpp"
#include <string>
class Program;
class UIElement{
public:
UIElement(Program* program, float posX, float posY, float setWidth, float setHeight, float posU, float posV, float setDU, float setDH);
void moveTo(float newX, float newY);
void calcTransform();
std::vector<glm::mat4x4> getTransform() const {return transform;};
// to set func pass the returned value from a std::bind()
void setClickOnFunc(std::function<void()> boundFunc) {func = boundFunc;};
void clickOn();
bool onElement(float xpos, float ypos);
int getNumTextures() const {return numTextures;};
void setText(std::string s, float size);
bool getActive() const {return active;};
void setActive(bool newVal);
void changeTexture(float posU, float posV, float setDU, float setDH);
void calcTextureTransform();
std::vector<glm::mat4x4> getTextureTransform() const {return texTransform;};
private:
Program* p;
int numTextures;
// used for on element function
float mainX,mainY;// top left location [-1,1],[-1,1]
float mainWidth,mainHeight;// width and height
// used for rendering
std::vector<float> x,y;// texture location
std::vector<float> width,height;
std::vector<glm::mat4x4> transform;
std::vector<float> u,v;// top left location of texture
std::vector<float> du,dv;// width and height in texture coordinates
std::vector<glm::mat4x4> texTransform;
std::function<void()> func;
bool active;
};
class TextInputUIElement{
public:
TextInputUIElement(Program* program);
~TextInputUIElement();
void setActive(bool newVal);
void setTarget(float* setOutputFloat, UIElement* setUpdateTextWhenDone, std::function<void()> setUpdateFuncWhenDone, float givenSetTextSize);
void update(GLFWwindow* window);
private:
Program* p;// buttons and Program to render them
UIElement* cancelButton;
UIElement* textDisplay;
UIElement* doneButton;
UIElement* background;
std::string s;// stored input
std::unordered_map<int,bool> releasedKeyMap;// prevent pressing key every frame
bool active;// is it currently being used
float* outputFloat;// store pointers to where results are sent
UIElement* updateTextWhenDone;
std::function<void()> updateFuncWhenDone;
float setTextSize;
};
class Camera{
public:
Camera();
void moveTo(glm::vec3 newPos);
glm::mat4x4 getViewMatrix();
glm::mat4x4 getPerspectiveMatrix();
glm::mat4x4 getInverseViewMatrix();
void getUserInput(GLFWwindow* window);
glm::vec3 getPos() const {return pos;};
private:
glm::vec3 pos;
glm::vec3 lookDir;
double theta;
double phi;
glm::mat4x4 perspective;
};