mirror of
https://github.com/IllusionMan1212/cudoku.git
synced 2026-10-24 02:12:25 +00:00
redid the win overlay
This commit is contained in:
@@ -47,48 +47,31 @@ static const char *help_texts[HELP_TEXT_SIZE] = {
|
|||||||
"Ctrl+Q/Esc - Quit"
|
"Ctrl+Q/Esc - Quit"
|
||||||
};
|
};
|
||||||
|
|
||||||
void draw_win() {
|
void draw_win(Cudoku *game) {
|
||||||
Size window = zephr_get_window_size();
|
Size window = zephr_get_window_size();
|
||||||
Color bg_color = {233.f, 84.f, 32.f, 200.f};
|
Color bg_color = {0, 0, 0, 180.f};
|
||||||
Color text_color = {237.f, 225.f, 215.f, 255.f};
|
Color text_color = {237.f, 225.f, 215.f, 255.f};
|
||||||
|
|
||||||
|
char time_text[64];
|
||||||
|
|
||||||
|
float time_elapsed = game->win_time - game->timer.time;
|
||||||
|
snprintf(time_text, 64, "Solved in: %02dm%02ds", (int)time_elapsed / 60, (int)time_elapsed % 60);
|
||||||
|
|
||||||
UIConstraints constraints = {0};
|
UIConstraints constraints = {0};
|
||||||
/* set_x_constraint(&constraints, 0, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* set_y_constraint(&constraints, 0, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* set_width_constraint(&constraints, window.width, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* set_height_constraint(&constraints, window.height, UI_CONSTRAINT_FIXED); */
|
|
||||||
|
|
||||||
Alignment align = ALIGN_TOP_LEFT;
|
|
||||||
int font_size = 72.0f;
|
|
||||||
|
|
||||||
/* Sizef text_size = calculate_text_size(win_text, font_size); */
|
|
||||||
|
|
||||||
set_x_constraint(&constraints, 0, UI_CONSTRAINT_FIXED);
|
set_x_constraint(&constraints, 0, UI_CONSTRAINT_FIXED);
|
||||||
set_y_constraint(&constraints, 0, UI_CONSTRAINT_FIXED);
|
set_y_constraint(&constraints, 0, UI_CONSTRAINT_FIXED);
|
||||||
/* set_width_constraint(&constraints, text_size.width, UI_CONSTRAINT_FIXED); */
|
set_width_constraint(&constraints, window.width, UI_CONSTRAINT_FIXED);
|
||||||
/* set_height_constraint(&constraints, text_size.height, UI_CONSTRAINT_FIXED); */
|
set_height_constraint(&constraints, window.height, UI_CONSTRAINT_FIXED);
|
||||||
/* set_rotation_constraint(&constraints, 0); */
|
|
||||||
|
|
||||||
/* UIConstraints circle_const; */
|
draw_quad(constraints, &bg_color, 0.0, ALIGN_CENTER);
|
||||||
/* set_x_constraint(&circle_const, 50, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* set_y_constraint(&circle_const, 0, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* set_width_constraint(&circle_const, 70, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* set_height_constraint(&circle_const, 90, UI_CONSTRAINT_FIXED); */
|
|
||||||
|
|
||||||
/* draw_circle(circle_const, NULL, ALIGN_LEFT_CENTER); */
|
|
||||||
/* draw_quad(constraints, &bg_color, 0.0, align); */
|
|
||||||
/* set_x_constraint(&constraints, -50, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* draw_quad(constraints, &bg_color, 25.0, ALIGN_TOP_RIGHT); */
|
|
||||||
/* set_x_constraint(&constraints, 0, UI_CONSTRAINT_FIXED); */
|
|
||||||
/* draw_quad(constraints, &bg_color, 0.5, ALIGN_BOTTOM_RIGHT); */
|
|
||||||
/* draw_quad(constraints, &bg_color, 0.0, align); */
|
|
||||||
|
|
||||||
/* draw_triangle(constraints, &bg_color, ALIGN_CENTER); */
|
|
||||||
|
|
||||||
set_width_constraint(&constraints, 1, UI_CONSTRAINT_FIXED);
|
set_width_constraint(&constraints, 1, UI_CONSTRAINT_FIXED);
|
||||||
set_height_constraint(&constraints, 1, UI_CONSTRAINT_FIXED);
|
set_height_constraint(&constraints, 1, UI_CONSTRAINT_FIXED);
|
||||||
/* set_rotation_constraint(&constraints, 0); */
|
|
||||||
draw_text(win_text, font_size, constraints, &text_color, align);
|
set_y_constraint(&constraints, -30, UI_CONSTRAINT_FIXED);
|
||||||
|
draw_text(win_text, 72.f, constraints, &text_color, ALIGN_CENTER);
|
||||||
|
set_y_constraint(&constraints, 30, UI_CONSTRAINT_FIXED);
|
||||||
|
draw_text(time_text, 48.f, constraints, &text_color, ALIGN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_scale_factor(int width, int height, float *x, float *y) {
|
void set_scale_factor(int width, int height, float *x, float *y) {
|
||||||
@@ -186,50 +169,6 @@ void draw_numbers(Shader shader, unsigned int vao, unsigned int vbo, float *tran
|
|||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int prepare_win_overlay() {
|
|
||||||
unsigned int vbo, vao, ebo;
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
glGenBuffers(1, &ebo);
|
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quad_vertices), quad_vertices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quad_indices), quad_indices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *)0);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
return vao;
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_win_overlay(Shader win_shader, Shader font_shader, unsigned int vao, unsigned int font_vao, unsigned int font_vbo, float *transform, Cudoku *game) {
|
|
||||||
use_shader(win_shader);
|
|
||||||
|
|
||||||
set_mat4f(win_shader, "transform", transform);
|
|
||||||
set_vec4f(win_shader, "aColor", 0.0, 0.0, 0.0, 0.8);
|
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
char time_text[64];
|
|
||||||
float time_elapsed = game->win_time - game->timer.time;
|
|
||||||
snprintf(time_text, 64, "Solved in: %02dm%02ds", (int)time_elapsed / 60, (int)time_elapsed % 60);
|
|
||||||
|
|
||||||
/* Size win_text_size = calculate_text_size(win_text, 1.0f); */
|
|
||||||
/* Size time_text_size = calculate_text_size(time_text, 1.0f); */
|
|
||||||
/* draw_text_center(font_shader, win_text, win_text_size, 1.5f, font_vao, font_vbo, transform, 0.0, 75.0); */
|
|
||||||
/* draw_text_center(font_shader, time_text, time_text_size, 0.8f, font_vao, font_vbo, transform, 0.0, -75.0); */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* void draw_pause_overlay(Cudoku *game) { */
|
/* void draw_pause_overlay(Cudoku *game) { */
|
||||||
/* timer_pause(&game->timer); */
|
/* timer_pause(&game->timer); */
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ unsigned int prepare_bg(bool use_texture, unsigned int *texture);
|
|||||||
void draw_bg_grid_shader(Shader shader, unsigned int vao, float* transform, float resolution);
|
void draw_bg_grid_shader(Shader shader, unsigned int vao, float* transform, float resolution);
|
||||||
void draw_bg_grid_texture(Shader shader, unsigned int vao, unsigned int texture, float* transform);
|
void draw_bg_grid_texture(Shader shader, unsigned int vao, unsigned int texture, float* transform);
|
||||||
void draw_numbers(Shader shader, unsigned int vao, unsigned int vbo, float *transform, Cell board[9][9]);
|
void draw_numbers(Shader shader, unsigned int vao, unsigned int vbo, float *transform, Cell board[9][9]);
|
||||||
unsigned int prepare_win_overlay();
|
|
||||||
void draw_win_overlay(Shader win_shader, Shader font_shader, unsigned int vao, unsigned int font_vao, unsigned int font_vbo, float *transform, Cudoku *game);
|
void draw_win_overlay(Shader win_shader, Shader font_shader, unsigned int vao, unsigned int font_vao, unsigned int font_vbo, float *transform, Cudoku *game);
|
||||||
void prepare_selection_box(unsigned int *vao, unsigned int *vbo);
|
void prepare_selection_box(unsigned int *vao, unsigned int *vbo);
|
||||||
void draw_selection_box(Shader shader, unsigned int vao, unsigned int vbo, int x, int y, float *transform, Color color);
|
void draw_selection_box(Shader shader, unsigned int vao, unsigned int vbo, int x, int y, float *transform, Color color);
|
||||||
@@ -55,4 +54,4 @@ void draw_help_overlay(
|
|||||||
Timer *timer
|
Timer *timer
|
||||||
);
|
);
|
||||||
void draw_timer(Shader shader, unsigned int vao, unsigned int vbo, float *projection, Timer *timer, int win_width);
|
void draw_timer(Shader shader, unsigned int vao, unsigned int vbo, float *projection, Timer *timer, int win_width);
|
||||||
void draw_win();
|
void draw_win(Cudoku *game);
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ int main(int argc, char *argv[]) {
|
|||||||
prepare_selection_box(&selection_vao, &selection_vbo);
|
prepare_selection_box(&selection_vao, &selection_vbo);
|
||||||
|
|
||||||
Shader win_shader = create_shader("shaders/board_v.vert", "shaders/quad.frag");
|
Shader win_shader = create_shader("shaders/board_v.vert", "shaders/quad.frag");
|
||||||
unsigned int win_vao = prepare_win_overlay();
|
|
||||||
|
|
||||||
float delta_t, last_t = 0.0;
|
float delta_t, last_t = 0.0;
|
||||||
timer_start(&game.help_timer, 5.0f);
|
timer_start(&game.help_timer, 5.0f);
|
||||||
@@ -181,7 +180,7 @@ int main(int argc, char *argv[]) {
|
|||||||
height = window_size.height;
|
height = window_size.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_win();
|
draw_win(&game);
|
||||||
|
|
||||||
/* draw_quad( */
|
/* draw_quad( */
|
||||||
/* (Vec2){0.0, 0.0}, */
|
/* (Vec2){0.0, 0.0}, */
|
||||||
|
|||||||
Reference in New Issue
Block a user