Half-work on totals for each section.
This commit is contained in:
143
main.c
143
main.c
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
#include "sourcecodepro.h"
|
#include "sourcecodepro.h"
|
||||||
#include "third_party/raylib/src/raylib.h"
|
#include "third_party/raylib/src/raylib.h"
|
||||||
@@ -55,11 +56,16 @@ char my_button(int x, int y, int width, int height, int font_size, char *title)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char activity_button(int x, int y, int width, int height, char *title, F32 font_size, Color color)
|
char activity_button(int x, int y, int width, int height, char *title, char *subtitle, F32 font_size, Color color)
|
||||||
{
|
{
|
||||||
char button_pressed = 0;
|
char button_pressed = 0;
|
||||||
|
|
||||||
Vector2 font_d = MeasureTextEx(state.font, title, (float)font_size, 2);
|
F32 subtitle_font_size = font_size - 8.0f;
|
||||||
|
if(subtitle_font_size <= 0.0f)
|
||||||
|
subtitle_font_size = font_size;
|
||||||
|
|
||||||
|
Vector2 title_font_d = MeasureTextEx(state.font, title, (float)font_size, 2);
|
||||||
|
Vector2 subtitle_font_d = MeasureTextEx(state.font, subtitle, (float)subtitle_font_size, 2);
|
||||||
|
|
||||||
Rectangle rect = { x, y, width, height };
|
Rectangle rect = { x, y, width, height };
|
||||||
|
|
||||||
@@ -71,31 +77,45 @@ char activity_button(int x, int y, int width, int height, char *title, F32 font_
|
|||||||
DrawRectangleRounded(rect, 0.2f, 100, color);
|
DrawRectangleRounded(rect, 0.2f, 100, color);
|
||||||
DrawTextEx(state.font, title,
|
DrawTextEx(state.font, title,
|
||||||
(Vector2){
|
(Vector2){
|
||||||
(rect.x + rect.width / 2.0f - font_d.x / 2.0f),
|
(rect.x + rect.width / 2.0f - title_font_d.x / 2.0f),
|
||||||
(rect.y + rect.height / 2.0f - font_d.y / 2.0f)
|
(rect.y + rect.height / 2.0f - title_font_d.y / 2.0f)
|
||||||
}, font_size, 2, BLACK);
|
}, font_size, 2, BLACK);
|
||||||
|
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, BLACK); // WARNING: Substracting from font size like that is unsafe.
|
||||||
|
|
||||||
return button_pressed;
|
return button_pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sleep, exercise, studying, gaming,
|
||||||
|
// entertainment, reading, socializing,
|
||||||
|
// housework, journaling, programmming (or projects?),
|
||||||
|
// break, other
|
||||||
enum activity_type {
|
enum activity_type {
|
||||||
other,
|
other,
|
||||||
work,
|
work,
|
||||||
projects,
|
projects,
|
||||||
gaming,
|
gaming,
|
||||||
exercise
|
exercise,
|
||||||
|
activity_type_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Activity {
|
typedef struct Activity {
|
||||||
enum activity_type activity;
|
enum activity_type activity; // TODO: Rename to kind or type.
|
||||||
Color color;
|
Color color;
|
||||||
U64 began;
|
U64 began;
|
||||||
U64 ended;
|
U64 ended;
|
||||||
} Activity;
|
} Activity;
|
||||||
|
|
||||||
|
typedef struct Activity_Stat {
|
||||||
|
U64 total_seconds;
|
||||||
|
char seconds_str[24];
|
||||||
|
} Activity_Stat;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
U64 secs = now();
|
U64 secs = now();
|
||||||
struct tm *t = localtime((time_t *)(&secs));
|
struct tm *t = localtime((time_t *)(&secs));
|
||||||
t->tm_hour = 0;
|
t->tm_hour = 0;
|
||||||
@@ -117,6 +137,8 @@ int main(int argc, char *argv[])
|
|||||||
Activity activities[100];
|
Activity activities[100];
|
||||||
U32 current_activity = 0;
|
U32 current_activity = 0;
|
||||||
|
|
||||||
|
Activity_Stat activities_stats[activity_type_COUNT];
|
||||||
|
|
||||||
S32 window_w = 800;
|
S32 window_w = 800;
|
||||||
S32 window_h = 450;
|
S32 window_h = 450;
|
||||||
|
|
||||||
@@ -169,21 +191,28 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
DrawRectangle(0, 0, window_w, 40, GRAY);
|
DrawRectangle(0, 0, window_w, 40, GRAY);
|
||||||
|
|
||||||
for(int i = 0; i <= current_activity; i++) {
|
for(U32 i = 0; i <= current_activity; i++) {
|
||||||
// if((activities[i].ended_on - started_on_ms) <= (ended_on_ms - started_on_ms)) {
|
// if((activities[i].ended_on - started_on_ms) <= (ended_on_ms - started_on_ms)) {
|
||||||
F32 start_x = (F32)(activities[i].began - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s) * (F32)window_w;
|
F32 start_x = floor((F32)(activities[i].began - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s) * (F32)window_w);
|
||||||
F32 end_x = ((F32)(activities[i].ended - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s)) * window_w;
|
F32 end_x = floor(((F32)(activities[i].ended - lower_bound_s) / (F32)(upper_bound_s - lower_bound_s)) * window_w);
|
||||||
// DrawRectangleRounded((Rectangle){ start_x, 0, end_x - start_x, 40}, 0.0f, 100, activities[i].color);
|
// DrawRectangleRounded((Rectangle){ start_x, 0, end_x - start_x, 40}, 0.0f, 100, activities[i].color);
|
||||||
DrawRectangle(start_x, 0, end_x - start_x, 40, activities[i].color);
|
DrawRectangle(start_x, 0, end_x - start_x, 40, activities[i].color);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: CLEAN UP.
|
||||||
F32 width = (window_w-padding_x*6.0f) / 5.0f;
|
F32 width = (window_w-padding_x*6.0f) / 5.0f;
|
||||||
|
|
||||||
if(activity_button(padding_x, 60, width, (window_h-70), "Other", font_size, RED)) {
|
for(U32 i = 0; i <= current_activity; i++) {
|
||||||
if(activities[current_activity].activity != other) {
|
activities_stats[activities[i].activity].total_seconds += activities[i].ended - activities[i].began;
|
||||||
printf("Activity OTHER\n");
|
}
|
||||||
|
|
||||||
|
U32 hrs = activities_stats[other].total_seconds / 60 / 60;
|
||||||
|
U32 mins = activities_stats[other].total_seconds / 60;
|
||||||
|
U32 secs = activities_stats[other].total_seconds - (60 * mins);
|
||||||
|
snprintf(activities_stats[other].seconds_str, sizeof(activities_stats[other].seconds_str), "%02lu:%02lu:%02lu", hrs, mins, secs);
|
||||||
|
if(activity_button(padding_x, 60, width, (window_h-70), "Other", activities_stats[other].seconds_str, font_size, RED)) {
|
||||||
|
if(activities[current_activity].activity != other) {
|
||||||
current_activity++;
|
current_activity++;
|
||||||
|
|
||||||
activities[current_activity].activity = other;
|
activities[current_activity].activity = other;
|
||||||
@@ -193,7 +222,11 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(activity_button((padding_x*2)+(width*1), 60, width, (window_h-70), "Work", font_size, BLUE)) {
|
hrs = activities_stats[work].total_seconds / 60 / 60;
|
||||||
|
mins = activities_stats[work].total_seconds / 60;
|
||||||
|
secs = activities_stats[work].total_seconds - (60 * mins);
|
||||||
|
snprintf(activities_stats[work].seconds_str, sizeof(activities_stats[work].seconds_str), "%02lu:%02lu:%02lu", hrs, mins, secs);
|
||||||
|
if(activity_button((padding_x*2)+(width*1), 60, width, (window_h-70), "Work", activities_stats[work].seconds_str, font_size, BLUE)) {
|
||||||
if(activities[current_activity].activity != work) {
|
if(activities[current_activity].activity != work) {
|
||||||
printf("Activity WORK\n");
|
printf("Activity WORK\n");
|
||||||
|
|
||||||
@@ -205,48 +238,52 @@ int main(int argc, char *argv[])
|
|||||||
activities[current_activity].ended = now_s;
|
activities[current_activity].ended = now_s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
if(activity_button((padding_x*3)+(width*2), 60, width, (window_h-70), "Projects", font_size, YELLOW)) {
|
// if(activity_button((padding_x*3)+(width*2), 60, width, (window_h-70), "Projects", font_size, YELLOW)) {
|
||||||
if(activities[current_activity].activity != projects) {
|
// if(activities[current_activity].activity != projects) {
|
||||||
printf("Activity PROJECTS\n");
|
// printf("Activity PROJECTS\n");
|
||||||
|
//
|
||||||
current_activity++;
|
// current_activity++;
|
||||||
|
//
|
||||||
activities[current_activity].activity = projects;
|
// activities[current_activity].activity = projects;
|
||||||
activities[current_activity].color = YELLOW;
|
// activities[current_activity].color = YELLOW;
|
||||||
activities[current_activity].began = now_s;
|
// activities[current_activity].began = now_s;
|
||||||
activities[current_activity].ended = now_s;
|
// activities[current_activity].ended = now_s;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(activity_button((padding_x*4)+(width*3), 60, width, (window_h-70), "Gaming", font_size, GREEN)) {
|
// if(activity_button((padding_x*4)+(width*3), 60, width, (window_h-70), "Gaming", font_size, GREEN)) {
|
||||||
if(activities[current_activity].activity != gaming) {
|
// if(activities[current_activity].activity != gaming) {
|
||||||
printf("Activity GAMING\n");
|
// printf("Activity GAMING\n");
|
||||||
|
//
|
||||||
current_activity++;
|
// current_activity++;
|
||||||
|
//
|
||||||
activities[current_activity].activity = gaming;
|
// activities[current_activity].activity = gaming;
|
||||||
activities[current_activity].color = GREEN;
|
// activities[current_activity].color = GREEN;
|
||||||
activities[current_activity].began = now_s;
|
// activities[current_activity].began = now_s;
|
||||||
activities[current_activity].ended = now_s;
|
// activities[current_activity].ended = now_s;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(activity_button((padding_x*5)+(width*4), 60, width, (window_h-70), "Exercise", font_size, PURPLE)) {
|
// if(activity_button((padding_x*5)+(width*4), 60, width, (window_h-70), "Exercise", font_size, PURPLE)) {
|
||||||
if(activities[current_activity].activity != exercise) {
|
// if(activities[current_activity].activity != exercise) {
|
||||||
printf("Activity EXERCISE\n");
|
// printf("Activity EXERCISE\n");
|
||||||
|
//
|
||||||
current_activity++;
|
// current_activity++;
|
||||||
|
//
|
||||||
activities[current_activity].activity = exercise;
|
// activities[current_activity].activity = exercise;
|
||||||
activities[current_activity].color = PURPLE;
|
// activities[current_activity].color = PURPLE;
|
||||||
activities[current_activity].began = now_s;
|
// activities[current_activity].began = now_s;
|
||||||
activities[current_activity].ended = now_s;
|
// activities[current_activity].ended = now_s;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// DrawTextEx(state.font, "Hello, world! && How are you?", (Vector2){100, 400}, font_size, 2, BLUE);
|
// DrawTextEx(state.font, "Hello, world! && How are you?", (Vector2){100, 400}, font_size, 2, BLUE);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
|
for(U32 i = 0; i <= current_activity; i++) {
|
||||||
|
activities_stats[activities[i].activity].total_seconds = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|||||||
Reference in New Issue
Block a user