Some updates.
This commit is contained in:
114
main.c
114
main.c
@@ -1,7 +1,7 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// TODOS: //
|
// TODOS: //
|
||||||
// [ ] Lower the the time text lower below the activity title. //
|
// [X] Lower the the time text lower below the activity title. //
|
||||||
// [ ] On timeline hower, display additional activity chunk info. //
|
// [ ] On timeline, hower, display additional activity chunk info. //
|
||||||
// [ ] Display distribution timeline below the activity line. //
|
// [ ] Display distribution timeline below the activity line. //
|
||||||
// [ ] Better file save error handling. //
|
// [ ] Better file save error handling. //
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@@ -98,7 +98,7 @@ 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, (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);
|
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);
|
||||||
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);
|
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) + 22.0f }, subtitle_font_size, 2, font_color);
|
||||||
|
|
||||||
return button_pressed;
|
return button_pressed;
|
||||||
}
|
}
|
||||||
@@ -213,6 +213,62 @@ char *get_file(char *dir, struct tm *t)
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILE *load_activities(char *file_path, activity *activities, U32 *current_activity)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(file_path, "a+");
|
||||||
|
if(!f) {
|
||||||
|
fprintf(stderr, "fopen(%s) failed: %s\n", file_path, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
local_persist char line[4096];
|
||||||
|
if(file_size(f) > 0) {
|
||||||
|
while(fgets(line, sizeof line, f)) {
|
||||||
|
size_t n = strcspn(line, "\r\n");
|
||||||
|
line[n] = '\0';
|
||||||
|
|
||||||
|
char activity_name[64];
|
||||||
|
U64 lower;
|
||||||
|
U64 upper;
|
||||||
|
int l = sscanf(line, "%s %llu %llu", activity_name, &lower, &upper);
|
||||||
|
if(l != 3)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(lower > upper)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
activity_type type = other;
|
||||||
|
if(strcmp(activity_name, activity_type_string_representation[other]) == 0)
|
||||||
|
type = other;
|
||||||
|
else if(strcmp(activity_name, activity_type_string_representation[studying]) == 0)
|
||||||
|
type = studying;
|
||||||
|
else if(strcmp(activity_name, activity_type_string_representation[projects]) == 0)
|
||||||
|
type = projects;
|
||||||
|
else if(strcmp(activity_name, activity_type_string_representation[gaming]) == 0)
|
||||||
|
type = gaming;
|
||||||
|
else if(strcmp(activity_name, activity_type_string_representation[exercise]) == 0)
|
||||||
|
type = exercise;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
activities[*current_activity].type = type;
|
||||||
|
activities[*current_activity].color = activity_type_color_representation[type];
|
||||||
|
activities[*current_activity].began = lower;
|
||||||
|
activities[*current_activity].ended = upper;
|
||||||
|
|
||||||
|
(*current_activity)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Do we really need this?
|
||||||
|
if(ferror(f)) {
|
||||||
|
fprintf(stderr, "read error: %s\n", strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
void save_activities(FILE *f, char *file_path, U32 current_activity, activity *activities)
|
void save_activities(FILE *f, char *file_path, U32 current_activity, activity *activities)
|
||||||
{
|
{
|
||||||
// NOTE: We use "w+" because want to clear file contents before the next write.
|
// NOTE: We use "w+" because want to clear file contents before the next write.
|
||||||
@@ -256,56 +312,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *f;
|
// NOTE: Not sure this is great, but that is what we'll go with for now.
|
||||||
f = fopen(file_path, "a+");
|
FILE *f = load_activities(file_path, activities, ¤t_activity);
|
||||||
if(!f) {
|
|
||||||
fprintf(stderr, "fopen(%s) failed: %s\n", file_path, strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char line[4096];
|
|
||||||
if(file_size(f) > 0) {
|
|
||||||
while(fgets(line, sizeof line, f)) {
|
|
||||||
size_t n = strcspn(line, "\r\n");
|
|
||||||
line[n] = '\0';
|
|
||||||
|
|
||||||
char activity_name[64];
|
|
||||||
U64 lower;
|
|
||||||
U64 upper;
|
|
||||||
int l = sscanf(line, "%s %llu %llu", activity_name, &lower, &upper);
|
|
||||||
if(l != 3)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(lower > upper)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
activity_type type = other;
|
|
||||||
if(strcmp(activity_name, activity_type_string_representation[other]) == 0)
|
|
||||||
type = other;
|
|
||||||
else if(strcmp(activity_name, activity_type_string_representation[studying]) == 0)
|
|
||||||
type = studying;
|
|
||||||
else if(strcmp(activity_name, activity_type_string_representation[projects]) == 0)
|
|
||||||
type = projects;
|
|
||||||
else if(strcmp(activity_name, activity_type_string_representation[gaming]) == 0)
|
|
||||||
type = gaming;
|
|
||||||
else if(strcmp(activity_name, activity_type_string_representation[exercise]) == 0)
|
|
||||||
type = exercise;
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
|
|
||||||
activities[current_activity].type = type;
|
|
||||||
activities[current_activity].color = activity_type_color_representation[type];
|
|
||||||
activities[current_activity].began = lower;
|
|
||||||
activities[current_activity].ended = upper;
|
|
||||||
|
|
||||||
current_activity++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ferror(f)) {
|
|
||||||
fprintf(stderr, "read error: %s\n", strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
U64 last_save = 0;
|
U64 last_save = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user