Added a fix for opening files and moved font size into global state.
This commit is contained in:
32
main.c
32
main.c
@@ -25,6 +25,7 @@ typedef struct {
|
|||||||
Vector2 mouse_pos;
|
Vector2 mouse_pos;
|
||||||
|
|
||||||
Font font;
|
Font font;
|
||||||
|
S32 font_size;
|
||||||
} global_state;
|
} global_state;
|
||||||
|
|
||||||
global_state state;
|
global_state state;
|
||||||
@@ -76,10 +77,8 @@ B32 activity_button(Rectangle rect, char *title, char *subtitle,
|
|||||||
if(subtitle_font_size <= 0.0f)
|
if(subtitle_font_size <= 0.0f)
|
||||||
subtitle_font_size = font_size;
|
subtitle_font_size = font_size;
|
||||||
|
|
||||||
Vector2 title_font_d =
|
Vector2 title_font_d = MeasureTextEx(state.font, title, (float)font_size, 2);
|
||||||
MeasureTextEx(state.font, title, (float)font_size, 2);
|
Vector2 subtitle_font_d = MeasureTextEx(state.font, subtitle, (float)subtitle_font_size, 2);
|
||||||
Vector2 subtitle_font_d =
|
|
||||||
MeasureTextEx(state.font, subtitle, (float)subtitle_font_size, 2);
|
|
||||||
|
|
||||||
if(CheckCollisionPointRec(state.mouse_pos, rect)) {
|
if(CheckCollisionPointRec(state.mouse_pos, rect)) {
|
||||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||||
@@ -87,16 +86,8 @@ B32 activity_button(Rectangle rect, char *title, char *subtitle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DrawRectangleRounded(rect, 0.2f, 100, background_color);
|
DrawRectangleRounded(rect, 0.2f, 100, background_color);
|
||||||
DrawTextEx(state.font, title,
|
DrawTextEx(state.font, title, (Vector2){ (rect.x + rect.width / 2.0f - title_font_d.x / 2.0f), (rect.y + rect.height / 2.0f - title_font_d.y / 2.0f) }, font_size, 2, font_color);
|
||||||
(Vector2){
|
DrawTextEx(state.font, subtitle, (Vector2){ (rect.x + rect.width / 2.0f - subtitle_font_d.x / 2.0f), (rect.y + rect.height / 2.0f - subtitle_font_d.y / 2.0f) + 20.0f }, subtitle_font_size, 2, font_color);
|
||||||
(rect.x + rect.width / 2.0f - title_font_d.x / 2.0f),
|
|
||||||
(rect.y + rect.height / 2.0f - title_font_d.y / 2.0f)
|
|
||||||
}, font_size, 2, font_color);
|
|
||||||
DrawTextEx(state.font, subtitle,
|
|
||||||
(Vector2){
|
|
||||||
(rect.x + rect.width / 2.0f - subtitle_font_d.x / 2.0f),
|
|
||||||
(rect.y + rect.height / 2.0f - subtitle_font_d.y / 2.0f) + 20.0f
|
|
||||||
}, subtitle_font_size, 2, font_color);
|
|
||||||
|
|
||||||
return button_pressed;
|
return button_pressed;
|
||||||
}
|
}
|
||||||
@@ -235,7 +226,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
f = fopen(file_path, "r+");
|
f = fopen(file_path, "a+");
|
||||||
if(!f) {
|
if(!f) {
|
||||||
fprintf(stderr, "fopen(%s) failed: %s\n", file_path, strerror(errno));
|
fprintf(stderr, "fopen(%s) failed: %s\n", file_path, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
@@ -296,7 +287,7 @@ int main(int argc, char *argv[])
|
|||||||
S32 window_h = 500;
|
S32 window_h = 500;
|
||||||
|
|
||||||
InitWindow(window_w, window_h, "Time Tracker");
|
InitWindow(window_w, window_h, "Time Tracker");
|
||||||
SetWindowState(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
SetWindowState(FLAG_MSAA_4X_HINT|FLAG_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
SetTargetFPS(30);
|
SetTargetFPS(30);
|
||||||
|
|
||||||
@@ -310,15 +301,12 @@ int main(int argc, char *argv[])
|
|||||||
SetTextureFilter(state.font.texture, TEXTURE_FILTER_BILINEAR);
|
SetTextureFilter(state.font.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
|
||||||
// Initialize to default activity at the start.
|
// Initialize to default activity at the start.
|
||||||
// NOTE: We can potentially make the default a non-state, so the users
|
|
||||||
// choose themselves.
|
|
||||||
activities[current_activity].type = other;
|
activities[current_activity].type = other;
|
||||||
activities[current_activity].color = RED;
|
activities[current_activity].color = RED;
|
||||||
activities[current_activity].began = now();
|
activities[current_activity].began = now();
|
||||||
activities[current_activity].ended = lower_bound_s;
|
activities[current_activity].ended = lower_bound_s;
|
||||||
|
|
||||||
// TODO: Move into game state.
|
state.font_size = 30;
|
||||||
int font_size = 30;
|
|
||||||
|
|
||||||
// DisableEventWaiting();
|
// DisableEventWaiting();
|
||||||
// EnableEventWaiting();
|
// EnableEventWaiting();
|
||||||
@@ -394,7 +382,7 @@ int main(int argc, char *argv[])
|
|||||||
snprintf(activities_stats[i].seconds_str, sizeof(activities_stats[i].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
|
snprintf(activities_stats[i].seconds_str, sizeof(activities_stats[i].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
|
||||||
|
|
||||||
Rectangle rect = { (padding_x*(i+1))+(width*i), 60, width, (window_h-70) };
|
Rectangle rect = { (padding_x*(i+1))+(width*i), 60, width, (window_h-70) };
|
||||||
if(activity_button(rect, activity_type_string_representation[i], activities_stats[i].seconds_str, font_size, (activities[current_activity].type == i ? WHITE : BLACK), activity_type_color_representation[i])) {
|
if(activity_button(rect, activity_type_string_representation[i], activities_stats[i].seconds_str, state.font_size, (activities[current_activity].type == i ? WHITE : BLACK), activity_type_color_representation[i])) {
|
||||||
if(activities[current_activity].type != i) {
|
if(activities[current_activity].type != i) {
|
||||||
switch_activity(activities, ¤t_activity, i, now_s);
|
switch_activity(activities, ¤t_activity, i, now_s);
|
||||||
}
|
}
|
||||||
@@ -404,7 +392,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
char index_buf[8];
|
char index_buf[8];
|
||||||
snprintf(index_buf, sizeof(index_buf), "%d", i + 1);
|
snprintf(index_buf, sizeof(index_buf), "%d", i + 1);
|
||||||
DrawTextEx(state.font, index_buf, (Vector2){ rect.x + 10.0f, rect.y + 10.0f }, font_size - 5.0f, 2, BLACK);
|
DrawTextEx(state.font, index_buf, (Vector2){ rect.x + 10.0f, rect.y + 10.0f }, state.font_size - 5.0f, 2, BLACK);
|
||||||
}
|
}
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user