-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLL_Code.cpp
More file actions
132 lines (117 loc) · 3.23 KB
/
LL_Code.cpp
File metadata and controls
132 lines (117 loc) · 3.23 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "LL_Code.hpp"
#include "LL_Regions.hpp"
#include <cassert>
namespace {
Module *create_module(const std::string ¶ms_in) {
return new Code();
}
class Fred {
public:
Fred() {
register_module("ll_code", create_module, "");
}
} fred;
}
namespace {
void draw_nothing(const PortData *, const Connection &, void *) {
}
}
Code::Code() {
in_ports.push_back(&state);
state.name = "state";
state.position = make_vector(0.0f, 0.0f);
state.draw_fn_data = NULL;
state.draw_fn = draw_nothing;
state() = NULL;
code = Graphics::get_texture("ll_siggraph/flip-up.png", false, false);
assert(code.ref);
}
Code::~Code() {
}
Vector2f Code::size() {
return make_vector(1.0f, code->h / float(code->w));
}
void Code::draw(Box2f viewport, Box2f screen_viewport, float scale, unsigned int recurse) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glBoxToBox(viewport, screen_viewport);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
assert(code.ref);
glBindTexture(GL_TEXTURE_2D, code->obj);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-size().x*0.5f, -size().y*0.5f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f( size().x*0.5f, -size().y*0.5f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f( size().x*0.5f, size().y*0.5f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-size().x*0.5f, size().y*0.5f);
glEnd();
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
Box2f draw;
draw.min = draw.max = make_vector(0.0f, 0.0f);
if (state()) {
switch( state()->state ) {
case INIT:
draw.min = make_vector< float >(65, 7);
draw.max = draw.min + make_vector< float >(283, 39);
break;
case CHECK:
draw.min = make_vector< float >(114, 45);
draw.max = draw.min + make_vector< float >(276, 42);
break;
case CHECK_RETURN:
draw.min = make_vector< float >(391, 47);
draw.max = draw.min + make_vector< float >(109, 38);
break;
case WHILE:
draw.min = make_vector< float >(114, 87);
draw.max = draw.min + make_vector< float >(285, 42);
break;
case WHILE_RETURN:
// draw.min = make_vector< float >( , );
// draw.max = draw.min + make_vector< float >( , );
break;
case SWAP:
case SWAP_ACTION:
case SWAP_AFTER:
draw.min = make_vector< float >(163, 165);
draw.max = draw.min + make_vector< float >(285, 42);
break;
case RECURSE:
case RECURSE_AFTER:
draw.min = make_vector< float >(157, 206);
draw.max = draw.min + make_vector< float >(346, 81);
break;
default:
break;
}
}
if (draw.min != draw.max) {
draw.min.x = (draw.min.x / float(code->w) - 0.5f) * size().x;
draw.max.x = (draw.max.x / float(code->w) - 0.5f) * size().x;
draw.min.y = (1.0f - draw.min.y / float(code->h) - 0.5f) * size().y;
draw.max.y = (1.0f - draw.max.y / float(code->h) - 0.5f) * size().y;
glBegin(GL_QUADS);
glColor4f(1.0f, 1.0f, 0.2f, 0.5f);
glVertex2f(draw.min.x, draw.min.y);
glVertex2f(draw.min.x, draw.max.y);
glVertex2f(draw.max.x, draw.max.y);
glVertex2f(draw.max.x, draw.min.y);
glEnd();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void Code::update(float elapsed_time) {
}
bool Code::handle_event(SDL_Event const &event, Vector2f local_mouse) {
return false;
}