-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputModule.cpp
64 lines (50 loc) · 1.51 KB
/
InputModule.cpp
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
#include "InputModule.hpp"
#include <Graphics/Graphics.hpp>
#include <Graphics/Font.hpp>
#include <Vector/VectorGL.hpp>
#include <sstream>
using std::ostringstream;
namespace {
template< class DATA >
Module *create_inputmodule(const std::string ¶ms) {
return new InputModule< DATA >(params);
}
class Fred {
public:
Fred() {
register_module("input-f", create_inputmodule< float >);
}
} fred;
}
template< class DATA >
Vector2f InputModule< DATA >::size() {
Graphics::FontRef gentium = Graphics::get_font("gentium.txf");
float len = gentium->get_length(prefix + " ", 0.3f);
return make_vector(len, 0.3f);
}
template< class DATA >
void InputModule< DATA >::draw(Box2f viewport, Box2f screen_viewport, float scale, unsigned int recurse) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glBoxToBox(viewport, screen_viewport);
glColor3f(1.0f, 1.0f, 1.0f);
Graphics::FontRef gentium = Graphics::get_font("gentium.txf");
ostringstream msg;
msg << prefix << data();
gentium->draw(msg.str(), make_vector( 0.5f * size().x - gentium->get_length(msg.str(), 0.3f), -0.15f), 0.3f);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
Graphics::gl_errors("Input::draw");
}
template< class DATA >
void InputModule< DATA >::update(float elapsed_time) {
}
template< class DATA >
bool InputModule< DATA >::handle_event(SDL_Event const &event, Vector2f local_mouse) {
if (event.type == SDL_MOUSEMOTION && event.motion.state) {
data() += event.motion.y * 0.01f;
return true;
}
return false;
}