Compare commits

..

10 Commits

2 changed files with 66 additions and 22 deletions

View File

@@ -15,7 +15,7 @@ endif
CC = clang
UFLAGS =
FLAGS = -Wall -Wextra -ggdb -fno-caret-diagnostics -fno-show-column -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable
FLAGS = -Wall -Wextra -ggdb -fno-caret-diagnostics -fno-show-column -Wno-missing-field-initializers -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable
#-std=c99 -pedantic
ifeq ($(DETECTED_OS),macos)

View File

@@ -1,10 +1,10 @@
//////////////////////////////////////////////////////////////////////////
// TODOS: //
// [X] Lower the the time text lower below the activity title. //
// [ ] On timeline, hower, display additional activity chunk info. //
// [X] On timeline, hower, display additional activity chunk info. //
// [X] Display distribution timeline below the activity line. //
// [ ] Better file save error handling. //
// [ ] Make Linux and MacOS libraries for RayLib; store locally. //
// [X] Make Linux and MacOS libraries for RayLib; store locally. //
//////////////////////////////////////////////////////////////////////////
@@ -78,9 +78,7 @@ U64 now()
return (U64)time(NULL);
}
B32 activity_button(Rectangle rect, char *title, char *subtitle,
F32 font_size, Color font_color,
Color background_color)
B32 activity_button(Rectangle rect, char *title, char *subtitle, F32 font_size, Color font_color, Color background_color)
{
B32 button_pressed = false;
@@ -274,7 +272,7 @@ void save_activities(FILE *f, char *file_path, U32 current_activity, activity *a
// NOTE: We use "w+" because want to clear file contents before the next write.
f = freopen(file_path, "w+", f);
if(f) {
char write_buffer[128];
local_persist char write_buffer[128];
for(U32 i = 0; i <= current_activity; i++) {
snprintf(write_buffer, sizeof(write_buffer), "%s %llu %llu\n", activity_type_string_representation[activities[i].type], activities[i].began, activities[i].ended);
@@ -290,7 +288,30 @@ void save_activities(FILE *f, char *file_path, U32 current_activity, activity *a
}
}
int main(int argc, char *argv[])
global B32 dirty = true;
internal void mark_dirty()
{
dirty = true;
}
internal void clear_dirty()
{
dirty = false;
}
internal B32 is_dirty(void)
{
return dirty;
}
internal void poll_input()
{
if(GetMouseDelta().x != 0 || GetMouseDelta().y != 0 || IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsMouseButtonReleased(MOUSE_BUTTON_LEFT) || IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) || GetKeyPressed() != 0 || IsWindowResized())
mark_dirty();
}
S32 main(int argc, char *argv[])
{
// TODO: Move into global state.
activity activities[256]; // TODO: This should be a dynamic array.
@@ -318,15 +339,14 @@ int main(int argc, char *argv[])
state.window_w = 1400;
state.window_h = 300;
SetConfigFlags(FLAG_VSYNC_HINT | FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI);
InitWindow(state.window_w, state.window_h, "Time Tracker");
SetWindowState(FLAG_MSAA_4X_HINT|FLAG_WINDOW_RESIZABLE);
SetTargetFPS(30);
state.font = LoadFontFromMemory(".ttf", opensans_ttf, opensans_ttf_len, 96, NULL, 0);
if(!IsFontValid(state.font)) {
fprintf(stderr, "Unable to load font\n");
return 1;
state.font = GetFontDefault();
}
GenTextureMipmaps(&state.font.texture);
SetTextureFilter(state.font.texture, TEXTURE_FILTER_BILINEAR);
@@ -338,9 +358,14 @@ int main(int argc, char *argv[])
state.font_size = 30;
//DisableEventWaiting();
//EnableEventWaiting();
double last_input_s = now();
SetTargetFPS(30);
while(!WindowShouldClose()) {
poll_input();
U64 now_s = now();
if(now_s >= upper_bound_s) {
@@ -437,12 +462,12 @@ int main(int argc, char *argv[])
DrawTextEx(state.font, index_buf, (Vector2){ rect.x + 10.0f, rect.y + 10.0f }, state.font_size - 5.0f, 2, BLACK);
}
// NOTE: This is rendered last because a popup has to flow above everything else.
// NOTE: This is rendered last because the popups have to float above everything else.
for(U32 i = 0; i <= current_activity; i++) {
F32 start_x = floor((F32)(activities[i].began - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s) * (F32)(state.window_w));
F32 end_x = floor(((F32)(activities[i].ended - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s)) * (F32)(state.window_w));
Rectangle rect = {start_x, 0, end_x - start_x, 40};
Rectangle rect = { start_x, 0, end_x - start_x, 40 };
if(CheckCollisionPointRec(state.mouse_pos, rect)) {
// TOOD: A general popup should be its own component.
char *str_activity_type = activity_type_string_representation[activities[i].type];
@@ -450,16 +475,23 @@ int main(int argc, char *argv[])
Vector2 activity_type_d = MeasureTextEx(state.font, str_activity_type, state.font_size - 5.0f, 2);
Vector2 activity_time_d = MeasureTextEx(state.font, activities_stats[i].seconds_str, state.font_size - 10.0f, 2);
S32 rect_w = (S32)((activity_type_d.x >= activity_time_d.x) ? activity_type_d.x : activity_time_d.x);
DrawRectangleRounded((Rectangle){ start_x, 40, rect_w, (F32)(activity_time_d.y + activity_type_d.y) }, 0.3f, 100, BLACK);
DrawRectangleRoundedLinesEx((Rectangle){ start_x, 40, rect_w, (F32)(activity_time_d.y + activity_type_d.y) }, 0.3f, 100, 2.0f, DARKGRAY);
S32 rect_w = (S32)((activity_type_d.x >= activity_time_d.x) ? activity_type_d.x + 10.0f : activity_time_d.x + 10.0f);
DrawRectangleRounded((Rectangle){ start_x, 40, rect_w, (F32)(activity_time_d.y + activity_type_d.y + 10.0f) }, 0.3f, 100, BLACK);
DrawRectangleRoundedLinesEx((Rectangle){ start_x, 40, rect_w, (F32)(activity_time_d.y + activity_type_d.y + 10.0f) }, 0.3f, 100, 2.0f, DARKGRAY);
// FIXME: We are pulling the aggregate seconds here from the activity statisctics. This is wrong.
// FIXME: The moreover
DrawTextEx(state.font, str_activity_type, (Vector2){ start_x, 40.0f }, state.font_size - 5.0f, 2, WHITE);
DrawTextEx(state.font, activities_stats[activities[i].type].seconds_str, (Vector2){ start_x, 40.0f + (F32)(activity_type_d.y) }, state.font_size - 10.0f, 2, WHITE);
local_persist char buffer[24];
Hours time = break_time(activities[i].ended - activities[i].began);
snprintf(buffer, sizeof(buffer), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds);
// TODO: Display the popup under cursor instead.
DrawTextEx(state.font, str_activity_type, (Vector2){ start_x + 5.0f, 40.0f + 5.0f }, state.font_size - 5.0f, 2, WHITE);
DrawTextEx(state.font, buffer, (Vector2){ start_x + 5.0f, 40.0f + (F32)(activity_type_d.y) }, state.font_size - 10.0f, 2, WHITE);
}
}
DrawRectangle(state.mouse_pos.x, state.mouse_pos.y, 10, 10, WHITE);
DrawFPS(20, 20);
EndDrawing();
// Reset statistics as we will accumulate seconds again.
@@ -472,6 +504,18 @@ int main(int argc, char *argv[])
save_activities(f, file_path, current_activity, activities);
last_save = now_s;
}
#if 0
if(is_dirty()) {
clear_dirty();
SetTargetFPS(120); // FPS cap
} else {
if(now_s - last_input_s > 1) {
SetTargetFPS(20);
last_input_s = now_s;
}
}
#endif
}
save_activities(f, file_path, current_activity, activities);