-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
224 lines (191 loc) · 4.45 KB
/
main.cpp
File metadata and controls
224 lines (191 loc) · 4.45 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include "linmath.h"
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <ctime>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include "list_item.h"
#include "list_item_grid.h"
#include "api_source.h"
#include "Texture2D.h"
using namespace std;
#define SCROLL_INTERVAL 0.4f
#define KEY_ESC 27
void init_gl(int argc, char** argv);
void display();
void idle();
void special_down_callback(int key, int x, int y);
void special_up_callback(int key, int x, int y);
void key_callback(unsigned char key, int x, int y);
bool timer_check(clock_t timer, float interval);
bool handle_pic_change();
bool handle_day_change();
bool right_press = false;
bool left_press = false;
bool up_press = false;
bool down_press = false;
clock_t right_timer = 0;
clock_t left_timer = 0;
list_item_grid* game_list;
Texture2D background;
api_source api;
/*GL initialization*/
void init_gl(int argc, char** argv)
{
ilInit(); //Intialize DevIL
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutFullScreen();
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutIdleFunc(idle); // Register display callback handler for window re-paint
glutSpecialFunc(special_down_callback);
glutSpecialUpFunc(special_up_callback);
glutKeyboardFunc(key_callback);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
background.LoadTexture("Resources/background.jpg");
}
/* GL display function*/
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)
background.Draw(-1.0f, -1.0f, 2.0f);
game_list->draw();
glFlush(); // Render now
}
/* GL idle function*/
void idle()
{
bool change = false;
change = handle_pic_change();
change = change || handle_day_change();
//Drawing
if(change)
display();
}
int main(int argc, char** argv) {
time_t source_day = time(0);
tm ltm;
init_gl(argc, argv);
localtime_s(<m, &source_day);
ltm.tm_mday--; //use yesterday to give time to upload pics
mktime(<m); //Nomralize time
api.set_source_day(ltm);
api.refresh_source();
game_list = new list_item_grid(api.get_num_games(), -0.85f, 0.0f, 0.2f, 0.1f, &api);
glutMainLoop(); // Enter the event-processing loop
game_list->remove_files();
delete game_list;
}
/* handle press down key */
void special_down_callback(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_RIGHT:
right_press = true;
break;
case GLUT_KEY_LEFT:
left_press = true;
break;
case GLUT_KEY_UP:
up_press = true;
break;
case GLUT_KEY_DOWN:
down_press = true;
break;
default:
break;
}
}
/* handle key release */
void special_up_callback(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_RIGHT:
right_press = false;
break;
case GLUT_KEY_LEFT:
left_press = false;
break;
default:
break;
}
}
/* handle escape key */
void key_callback(unsigned char key, int x, int y)
{
switch(key)
{
case KEY_ESC:
glutFullScreenToggle();
break;
default:
break;
}
}
/* timer check for press and hold of left/right arrow keys */
bool timer_check( clock_t timer, float interval )
{
return(timer == 0 || (clock() - timer) > (long)(interval * CLOCKS_PER_SEC));
}
/* moving to new picture */
bool handle_pic_change()
{
bool change = false;
if (right_press && !left_press)
{
if (timer_check(right_timer, SCROLL_INTERVAL))
{
game_list->select_next();
change = true;
right_timer = clock() + (clock_t)(CLOCKS_PER_SEC * (right_timer == 0 ? SCROLL_INTERVAL : 0.0f));
}
}
else if (left_press && !right_press)
{
if (timer_check(left_timer, SCROLL_INTERVAL))
{
game_list->select_prev();
change = true;
left_timer = clock() + (clock_t)(CLOCKS_PER_SEC * (left_timer == 0 ? SCROLL_INTERVAL : 0.0f));
}
}
else
{
right_timer = 0;
left_timer = 0;
}
return(change);
}
/* moving to new day */
bool handle_day_change()
{
bool change = false;
if(up_press)
{
api.move_source_day(true);
change = true;
up_press = false;
}
else if(down_press)
{
api.move_source_day(false);
change = true;
down_press = false;
}
if (change)
{
api.refresh_source();
*game_list = list_item_grid(api.get_num_games(), -0.85f, 0.0f, 0.2f, 0.1f, &api);
}
return(change);
}