A little bit of clean up.
This commit is contained in:
86
main.c
86
main.c
@@ -13,8 +13,13 @@
|
|||||||
#include "sourcecodepro.h"
|
#include "sourcecodepro.h"
|
||||||
#include "third_party/raylib/src/raylib.h"
|
#include "third_party/raylib/src/raylib.h"
|
||||||
|
|
||||||
#define TRUE 1
|
#ifndef true
|
||||||
#define FALSE 0
|
#define true 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef false
|
||||||
|
#define false 0
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vector2 mouse_pos;
|
Vector2 mouse_pos;
|
||||||
@@ -24,14 +29,6 @@ typedef struct {
|
|||||||
|
|
||||||
global_state state;
|
global_state state;
|
||||||
|
|
||||||
// U64 millis()
|
|
||||||
// {
|
|
||||||
// struct timespec ts;
|
|
||||||
// timespec_get(&ts, TIME_UTC);
|
|
||||||
// U64 ms = (U64)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
|
||||||
// return ms;
|
|
||||||
// }
|
|
||||||
|
|
||||||
B32 path_exists(const char *path)
|
B32 path_exists(const char *path)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@@ -68,33 +65,9 @@ U64 now()
|
|||||||
return (U64)time(NULL);
|
return (U64)time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
B32 activity_button(Rectangle rect, char *title, char *subtitle, F32 font_size, Color font_color, Color background_color)
|
||||||
char my_button(int x, int y, int width, int height, int font_size, char *title)
|
|
||||||
{
|
{
|
||||||
char button_pressed = 0;
|
B32 button_pressed = false;
|
||||||
|
|
||||||
Vector2 font_dimensions = MeasureTextEx(state.font, title, (float)font_size, 2);
|
|
||||||
|
|
||||||
int padding = 10;
|
|
||||||
Rectangle rect = { x, y, font_dimensions.x + (padding * 2), font_dimensions.y };
|
|
||||||
Color background_color = LIGHTGRAY;
|
|
||||||
|
|
||||||
if(CheckCollisionPointRec(state.mouse_pos, rect)) {
|
|
||||||
background_color = GRAY;
|
|
||||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
|
||||||
button_pressed = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawRectangleRounded(rect, 0.7f, 96, background_color);
|
|
||||||
DrawTextEx(state.font, title, (Vector2){ x + padding, y }, font_size, 2, BLUE);
|
|
||||||
|
|
||||||
return button_pressed;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char activity_button(Rectangle rect, char *title, char *subtitle, F32 font_size, Color font_color, Color background_color)
|
|
||||||
{
|
|
||||||
char button_pressed = 0;
|
|
||||||
|
|
||||||
F32 subtitle_font_size = font_size - 8.0f;
|
F32 subtitle_font_size = font_size - 8.0f;
|
||||||
if(subtitle_font_size <= 0.0f)
|
if(subtitle_font_size <= 0.0f)
|
||||||
@@ -105,7 +78,7 @@ char activity_button(Rectangle rect, char *title, char *subtitle, F32 font_size,
|
|||||||
|
|
||||||
if(CheckCollisionPointRec(state.mouse_pos, rect)) {
|
if(CheckCollisionPointRec(state.mouse_pos, rect)) {
|
||||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||||
button_pressed = 1;
|
button_pressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawRectangleRounded(rect, 0.2f, 100, background_color);
|
DrawRectangleRounded(rect, 0.2f, 100, background_color);
|
||||||
@@ -123,10 +96,6 @@ char activity_button(Rectangle rect, char *title, char *subtitle, F32 font_size,
|
|||||||
return button_pressed;
|
return button_pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sleep, exercise, studying, gaming,
|
|
||||||
// entertainment, reading, socializing,
|
|
||||||
// housework, journaling, programmming (or projects?),
|
|
||||||
// break, other
|
|
||||||
typedef enum activity_type {
|
typedef enum activity_type {
|
||||||
other,
|
other,
|
||||||
studying,
|
studying,
|
||||||
@@ -139,17 +108,27 @@ typedef enum activity_type {
|
|||||||
} activity_type;
|
} activity_type;
|
||||||
|
|
||||||
char *activity_type_string_representation[activity_type_COUNT] = {
|
char *activity_type_string_representation[activity_type_COUNT] = {
|
||||||
"Other", "Studying", "Programming", "Projects", "Gaming", "Exercise", "Reading"
|
"Other",
|
||||||
|
"Studying",
|
||||||
|
"Programming",
|
||||||
|
"Projects",
|
||||||
|
"Gaming",
|
||||||
|
"Exercise",
|
||||||
|
"Reading"
|
||||||
};
|
};
|
||||||
|
|
||||||
Color activity_type_color_representation[activity_type_COUNT] = {
|
Color activity_type_color_representation[activity_type_COUNT] = {
|
||||||
RED, GREEN, BLUE, ORANGE, MAROON, PURPLE, BROWN
|
RED,
|
||||||
|
GREEN,
|
||||||
|
BLUE,
|
||||||
|
ORANGE,
|
||||||
|
MAROON,
|
||||||
|
PURPLE,
|
||||||
|
BROWN
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: String representation.
|
|
||||||
|
|
||||||
typedef struct activity {
|
typedef struct activity {
|
||||||
activity_type type; // TODO: Rename to kind or type.
|
activity_type type;
|
||||||
Color color;
|
Color color;
|
||||||
U64 began;
|
U64 began;
|
||||||
U64 ended;
|
U64 ended;
|
||||||
@@ -198,6 +177,8 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Clean up.
|
||||||
|
// TODO: Clean up.
|
||||||
// TODO: Clean up.
|
// TODO: Clean up.
|
||||||
|
|
||||||
// Check if 2025-02-10 available
|
// Check if 2025-02-10 available
|
||||||
@@ -276,8 +257,6 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "read error: %s\n", strerror(errno));
|
fprintf(stderr, "read error: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 0; */
|
|
||||||
|
|
||||||
U64 last_save = 0;
|
U64 last_save = 0;
|
||||||
|
|
||||||
U64 lower_bound_s = (U64)ts;
|
U64 lower_bound_s = (U64)ts;
|
||||||
@@ -300,11 +279,15 @@ int main(int argc, char *argv[])
|
|||||||
GenTextureMipmaps(&state.font.texture);
|
GenTextureMipmaps(&state.font.texture);
|
||||||
SetTextureFilter(state.font.texture, TEXTURE_FILTER_BILINEAR);
|
SetTextureFilter(state.font.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
|
||||||
|
// Initialize to default activity at the start.
|
||||||
|
// NOTE: We can potentially make the default a non-state, so the users
|
||||||
|
// choos 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.
|
||||||
int font_size = 30;
|
int font_size = 30;
|
||||||
|
|
||||||
// DisableEventWaiting();
|
// DisableEventWaiting();
|
||||||
@@ -319,10 +302,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(IsKeyPressed(KEY_Q))
|
if(IsKeyPressed(KEY_Q))
|
||||||
break;
|
break;
|
||||||
else if(IsKeyPressed(KEY_UP))
|
|
||||||
font_size += 2;
|
|
||||||
else if(IsKeyPressed(KEY_DOWN))
|
|
||||||
font_size -= 2;
|
|
||||||
|
|
||||||
activities[current_activity].ended = now_s;
|
activities[current_activity].ended = now_s;
|
||||||
|
|
||||||
@@ -368,10 +347,9 @@ int main(int argc, char *argv[])
|
|||||||
if(activities[current_activity].type == i)
|
if(activities[current_activity].type == i)
|
||||||
DrawRectangleRoundedLinesEx(rect, 0.2f, 100, 5.0f, WHITE);
|
DrawRectangleRoundedLinesEx(rect, 0.2f, 100, 5.0f, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawTextEx(state.font, "Hello, world! && How are you?", (Vector2){100, 400}, font_size, 2, BLUE);
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
|
// Reset statistics as we will accumulate seconds again.
|
||||||
for(U32 i = 0; i <= current_activity; i++) {
|
for(U32 i = 0; i <= current_activity; i++) {
|
||||||
activities_stats[activities[i].type].total_seconds = 0;
|
activities_stats[activities[i].type].total_seconds = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user