mirror of
https://github.com/IllusionMan1212/cudoku.git
synced 2026-10-24 02:12:25 +00:00
calculate help overlay width from text instead of hardcoding it
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
|
|
||||||
#define HELP_TEXT_SIZE 13
|
#define HELP_TEXT_SIZE 13
|
||||||
#define HELP_OVERLAY_WIDTH 700
|
|
||||||
|
|
||||||
static const float quad_vertices[] = {
|
static const float quad_vertices[] = {
|
||||||
// positions // texture coords
|
// positions // texture coords
|
||||||
@@ -623,12 +622,14 @@ void draw_help_overlay(Shader overlay_shader, Shader font_shader, unsigned int o
|
|||||||
int const text_padding = 10;
|
int const text_padding = 10;
|
||||||
float const text_scale = 0.3f;
|
float const text_scale = 0.3f;
|
||||||
int overlay_height = 0;
|
int overlay_height = 0;
|
||||||
|
int overlay_width = 0;
|
||||||
|
|
||||||
for (int i = 0; i < HELP_TEXT_SIZE; i++) {
|
for (int i = 0; i < HELP_TEXT_SIZE; i++) {
|
||||||
Size text_size = calculate_text_size(help_texts[i], text_scale);
|
Size text_size = calculate_text_size(help_texts[i], text_scale);
|
||||||
overlay_height += text_size.height + text_padding;
|
overlay_height += text_size.height + text_padding;
|
||||||
|
overlay_width = max(overlay_width, text_size.width + text_padding * 2);
|
||||||
}
|
}
|
||||||
Size size = {.width = HELP_OVERLAY_WIDTH, .height = overlay_height + 20};
|
Size size = {.width = overlay_width, .height = overlay_height + text_padding * 2};
|
||||||
Vec2 pos = {
|
Vec2 pos = {
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = window_height - size.height
|
.y = window_height - size.height
|
||||||
@@ -656,7 +657,7 @@ Size size = {.width = HELP_OVERLAY_WIDTH, .height = overlay_height + 20};
|
|||||||
snprintf(closing_in_text, sizeof(closing_in_text), "Hiding in %ds", (int)timer_remaining(timer) + 1);
|
snprintf(closing_in_text, sizeof(closing_in_text), "Hiding in %ds", (int)timer_remaining(timer) + 1);
|
||||||
Size closing_in_text_size = calculate_text_size(closing_in_text, text_scale / 2.0);
|
Size closing_in_text_size = calculate_text_size(closing_in_text, text_scale / 2.0);
|
||||||
Vec2 closing_in_text_pos = {
|
Vec2 closing_in_text_pos = {
|
||||||
.x = HELP_OVERLAY_WIDTH - closing_in_text_size.width,
|
.x = overlay_width - closing_in_text_size.width,
|
||||||
.y = window_height - closing_in_text_size.height - text_padding,
|
.y = window_height - closing_in_text_size.height - text_padding,
|
||||||
};
|
};
|
||||||
Color closing_in_text_color = {
|
Color closing_in_text_color = {
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
|
|
||||||
Matrix4x4 orthographic_projection_2d(float left, float right, float bottom, float top) {
|
Matrix4x4 identity() {
|
||||||
Matrix4x4 result;
|
Matrix4x4 result = {0};
|
||||||
|
|
||||||
// Identity matrix
|
result.m[0][0] = 1.0f;
|
||||||
for (int i = 0; i < 4; i++) {
|
result.m[1][1] = 1.0f;
|
||||||
for (int j = 0; j < 4; j++) {
|
result.m[2][2] = 1.0f;
|
||||||
result.m[i][j] = 0.0f;
|
result.m[3][3] = 1.0f;
|
||||||
}
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix4x4 orthographic_projection_2d(float left, float right, float bottom, float top) {
|
||||||
|
Matrix4x4 result = identity();
|
||||||
|
|
||||||
result.m[0][0] = 2.0f / (right - left);
|
result.m[0][0] = 2.0f / (right - left);
|
||||||
result.m[3][0] = -(right + left) / (right - left);
|
result.m[3][0] = -(right + left) / (right - left);
|
||||||
result.m[1][1] = 2.0f / (top - bottom);
|
result.m[1][1] = 2.0f / (top - bottom);
|
||||||
@@ -19,3 +23,7 @@ Matrix4x4 orthographic_projection_2d(float left, float right, float bottom, floa
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int max(int a, int b) {
|
||||||
|
return a > b ? a : b;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user