ComputerGraphik TU WIEN
legend.hpp
Go to the documentation of this file.
1 #ifndef LEGEND_HPP
2 #define LEGEND_HPP
3 
4 #include <glm/vec2.hpp>
5 #include <glm/glm.hpp>
6 #include <glm/gtx/epsilon.hpp>
7 #include <GL/glew.h>
8 #include <GLFW/glfw3.h>
9 
10 #include "sceneObject.hpp"
11 #include "shader.hpp"
12 #include "texture.hpp"
13 #include "mouseSemantics.hpp"
14 
15 #include <ft2build.h>
16 #include FT_FREETYPE_H
17 
18 #define MOUSE_MIN_MOVE 0.3
19 #define MOUSE_MAX_MOVE 3.5
20 #define MOUSE_CUTOFF 200
21 #define STANDARD_TEXTSIZE 15.0f
22 
24 
31 struct Glyph {
32  Glyph(FT_Pos _ax, FT_Pos _ay, unsigned int _bw, unsigned int _bh, FT_Int _bl, FT_Int _bt) {
33  ax = _ax;
34  ay = _ay;
35  bw = _bw;
36  bh = _bh;
37  bl = _bl;
38  bt = _bt;
39  }
40 
41  FT_Pos ax;
42  FT_Pos ay;
43  unsigned int bw;
44  unsigned int bh;
45  FT_Int bl;
46  FT_Int bt;
47 };
48 
50 
58 class LegendBackground : public SceneObject {
59 private:
60  GLuint hudTex;
61  GLuint vboPositions;
63 
64 public:
65  LegendBackground(Scene *_scene, Texture *_texture);
66  virtual ~LegendBackground();
67 
68  void draw();
69  void setShader(Shader *_shader);
70  void renderBackground(float x, float y, float sx, float sy);
71 };
72 
74 
105 class Legend : public SceneObject {
106 private:
107 
108  //Text, HUD alignment
109  float upperleftx;
110  float upperlefty;
111  float ystep;
112  float xstep;
113  float xreset;
114  float yreset;
115  float maxXposText;
116  float maxYposText;
117  float offsetX;
118  float offsetY;
119 
120  std::string selectorText;
121 
122  //Engine
123  glm::vec2 latestPos;
124  GLFWwindow *window;
129  int FPS;
130 
131  //Font
132  FT_Library ft;
133  FT_Face face;
134 
135  //Opengl
136  std::map<char, GLuint> charTexHandleMap;
137  std::map<char, Glyph> charGlyphMap;
138  GLuint vboPositions;
140 
141  float calculateScaleFactor();
142  void renderText(const char *text, float x, float y, float sx, float sy);
143  void updatePosition(bool reset);
144  void calcFPS(double deltaT);
145 
146 public:
147  Legend(Scene* _scene, MouseSemantics *_mouse, Texture *_texture, float upperleftx, float upperlefty, float xstep, float ystep);
148  virtual ~Legend();
149 
150  void setShader(Shader *shader);
151  void draw();
152  void update(double deltaT);
153 
154  void prepareText();
155  void setActiveSelector(std::string _sText) { selectorText = _sText; }
156 };
157 
158 #endif //LEGEND_HPP
std::map< char, Glyph > charGlyphMap
Definition: legend.hpp:137
FT_Library ft
Definition: legend.hpp:132
FT_Pos ax
Definition: legend.hpp:41
Texture * texture
Definition: legend.hpp:62
int FPS
Definition: legend.hpp:129
Displays a Legend that contains text.
Definition: legend.hpp:105
Glyph(FT_Pos _ax, FT_Pos _ay, unsigned int _bw, unsigned int _bh, FT_Int _bl, FT_Int _bt)
Definition: legend.hpp:32
MouseSemantics * mouse
Definition: legend.hpp:125
void prepareText()
Definition: legend - Kopie.cpp:70
void draw()
Definition: legend - Kopie.cpp:322
void draw()
Definition: legend - Kopie.cpp:186
void update(double deltaT)
Definition: legend - Kopie.cpp:133
float calculateScaleFactor()
FT_Int bl
Definition: legend.hpp:45
float yreset
Definition: legend.hpp:114
GLFWwindow * window
Definition: legend.hpp:124
FT_Int bt
Definition: legend.hpp:46
float upperleftx
Definition: legend.hpp:109
GLuint hudTex
Definition: legend.hpp:60
float xstep
Definition: legend.hpp:112
void setShader(Shader *_shader)
Definition: legend - Kopie.cpp:297
LegendBackground * background
Definition: legend.hpp:126
LegendBackground(Scene *_scene, Texture *_texture)
Definition: legend - Kopie.cpp:287
GLuint vboPositions
Definition: legend.hpp:138
FT_Pos ay
Definition: legend.hpp:42
void updatePosition(bool reset)
Definition: legend - Kopie.cpp:175
virtual void reset()
Definition: sceneObject.cpp:108
void renderBackground(float x, float y, float sx, float sy)
Definition: legend - Kopie.cpp:326
float maxXposText
Definition: legend.hpp:115
Texture * texture
Definition: legend.hpp:139
unsigned int bw
Definition: legend.hpp:43
float offsetX
Definition: legend.hpp:117
Encapsulates the Rendering Engine, holds a complete scene and it's assets.
Definition: scene.hpp:71
float xreset
Definition: legend.hpp:113
glm::vec2 latestPos
Definition: legend.hpp:123
Legend(Scene *_scene, MouseSemantics *_mouse, Texture *_texture, float upperleftx, float upperlefty, float xstep, float ystep)
Definition: legend - Kopie.cpp:12
unsigned int bh
Definition: legend.hpp:44
float upperlefty
Definition: legend.hpp:110
virtual ~Legend()
Definition: legend - Kopie.cpp:55
virtual ~LegendBackground()
Definition: legend - Kopie.cpp:293
Encapsulates a texture in the GPU.
Definition: texture.hpp:10
float ystep
Definition: legend.hpp:111
double accumulatedTime
Definition: legend.hpp:128
FT_Face face
Definition: legend.hpp:133
int frameCount
Definition: legend.hpp:127
Encapsulates a shader program.
Definition: shader.hpp:9
float offsetY
Definition: legend.hpp:118
Glyph is used by Legend and contains positional information about characters.
Definition: legend.hpp:31
void setActiveSelector(std::string _sText)
Definition: legend.hpp:155
The base class of the objects which are rendered.
Definition: sceneObject.hpp:30
void setShader(Shader *shader)
Definition: legend - Kopie.cpp:112
void renderText(const char *text, float x, float y, float sx, float sy)
Definition: legend - Kopie.cpp:137
void calcFPS(double deltaT)
Definition: legend - Kopie.cpp:59
Shader * shader
Definition: sceneObject.hpp:70
GLuint vboPositions
Definition: legend.hpp:61
The class which handles the drawing of the cursor as well as the semantic scaling function that trans...
Definition: mouseSemantics.hpp:49
float maxYposText
Definition: legend.hpp:116
Renders a transparent image that can be used as background containing text.
Definition: legend.hpp:58
std::map< char, GLuint > charTexHandleMap
Definition: legend.hpp:136
std::string selectorText
Definition: legend.hpp:120