forked from osuripple/oppai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview_window.cc
123 lines (97 loc) · 2.47 KB
/
preview_window.cc
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
#ifdef SLIDERTEST
#include "preview_window.h"
#include "common.h"
#if NEEDS_TO_INSTALL_GENTOO
#include <Windows.h>
#define FREEGLUT_STATIC
#else
#include <unistd.h>
#endif
#include <GL/gl.h>
#include <GL/freeglut.h>
#include <stdio.h>
#include <string.h>
#include "preview_window.h"
#include "beatmap.h"
// TODO: just use gl's privitives to draw lines which is quicker and cleaner
namespace {
// yes this is extremely bad and slow but I don't care, it's just for testin
const i32 screen_w = 512, screen_h = 384;
u8 pixels[screen_w * screen_h][3];
void slider_display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawPixels(screen_w, screen_h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
glutSwapBuffers();
}
bool showing_slider;
void slider_keyboard(u8, i32, i32) {
showing_slider = false;
}
u8* p_get_px(const v2f& pos) {
i32 int_x = (int)pos.x;
i32 int_y = (int)pos.y;
if (int_x < 0 || int_x >= screen_w || int_y < 0 || int_y >= screen_h) {
return nullptr;
}
return (u8*)pixels[(screen_h - (i32)int_y - 1)
* screen_w + (i32)int_x];
}
void p_cls() {
memset(pixels, 0, screen_w * screen_h * sizeof(pixels[0][0]) * 3);
}
void p_put_px(const v2f& pos, u8 r, u8 g, u8 b) {
auto px = p_get_px(pos);
if (!px) {
return;
}
px[0] = r;
px[1] = g;
px[2] = b;
}
void shigeZZZ(u64 ms) {
#if NEEDS_TO_INSTALL_GENTOO
puts("INSTALL GENTOO");
Sleep((DWORD)ms);
#else
usleep(ms * 1000);
#endif
}
}
void p_init(int& argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(screen_w, screen_h);
glutCreateWindow("preview");
glutDisplayFunc(slider_display);
glutIdleFunc(slider_display);
glutKeyboardFunc(slider_keyboard);
glClearColor(0.f, 0.f, 0.f, 1.f);
}
void p_show(hit_object& ho) {
auto& sl = ho.slider;
puts("\n-- TEST SLIDER SIMULATION --");
p_cls();
// draw slider curve
i64 duration = ho.end_time - ho.time;
for (i64 ms = 0; ms <= duration; ms++) {
v2f p = ho.at(ms);
if (ms % 50 == 0 || ms == duration) {
printf("%" fi64 "ms %s\n", ms, p.str());
}
p_put_px(p, 255, 0, 0);
}
// draw slider points
for (size_t j = 0; j < sl.points.size(); j++) {
p_put_px(sl.points[j], 0, 255, 0);
}
// run glut main loop until a key is pressed
puts("Press any key in the slider window to continue...");
showing_slider = true;
while (showing_slider) {
glutMainLoopEvent();
glutPostRedisplay();
shigeZZZ(50);
}
puts("----------------------------\n");
}
#endif