Switch to seconds and full day timeline.
This commit is contained in:
86
main.c
86
main.c
@@ -18,12 +18,17 @@ typedef struct {
|
||||
|
||||
global_state state;
|
||||
|
||||
U64 millis()
|
||||
// U64 millis()
|
||||
// {
|
||||
// struct timespec ts;
|
||||
// timespec_get(&ts, TIME_UTC);
|
||||
// U64 ms = (U64)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
||||
// return ms;
|
||||
// }
|
||||
|
||||
U64 now()
|
||||
{
|
||||
struct timespec ts;
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
U64 ms = (U64)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
||||
return ms;
|
||||
return (U64)time(NULL);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -90,6 +95,25 @@ typedef struct Activity {
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
U64 secs = now();
|
||||
struct tm *t = localtime((time_t *)(&secs));
|
||||
t->tm_hour = 0;
|
||||
t->tm_min = 0;
|
||||
t->tm_sec = 0;
|
||||
|
||||
time_t ts = mktime(t);
|
||||
if(ts == (time_t)-1) {
|
||||
fprintf(stderr, "mktime failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
U64 lower_bound_s = (U64)ts;
|
||||
U64 upper_bound_s = lower_bound_s + 86400;
|
||||
// U64 upper_bound_s = lower_bound_s + 3600;
|
||||
|
||||
|
||||
|
||||
Activity activities[100];
|
||||
U32 current_activity = 0;
|
||||
|
||||
@@ -99,7 +123,7 @@ int main(int argc, char *argv[])
|
||||
InitWindow(window_w, window_h, "Time Tracker");
|
||||
SetWindowState(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
SetTargetFPS(60);
|
||||
SetTargetFPS(30);
|
||||
|
||||
state.font = LoadFontFromMemory(".ttf", sourcecodepro_ttf, sourcecodepro_ttf_len, 96, NULL, 0);
|
||||
if(!IsFontValid(state.font)) {
|
||||
@@ -109,24 +133,19 @@ int main(int argc, char *argv[])
|
||||
GenTextureMipmaps(&state.font.texture);
|
||||
SetTextureFilter(state.font.texture, TEXTURE_FILTER_BILINEAR);
|
||||
|
||||
U64 now_ms = millis();
|
||||
U64 lower_bound_ms = now_ms;
|
||||
U64 upper_bound_ms = now_ms + (1800 * 1000);
|
||||
// U64 upper_bound_ms = now_ms + (10 * 1000);
|
||||
|
||||
printf("%u %u\n", lower_bound_ms, upper_bound_ms);
|
||||
|
||||
activities[current_activity].activity = other;
|
||||
activities[current_activity].color = RED;
|
||||
activities[current_activity].began = lower_bound_ms;
|
||||
activities[current_activity].ended = lower_bound_ms;
|
||||
activities[current_activity].began = now();
|
||||
activities[current_activity].ended = lower_bound_s;
|
||||
|
||||
int font_size = 30;
|
||||
|
||||
// DisableEventWaiting();
|
||||
// EnableEventWaiting();
|
||||
while(!WindowShouldClose()) {
|
||||
now_ms = millis();
|
||||
U64 now_s = now();
|
||||
|
||||
// fprintf(stderr, "%lu ... %lu: %lu\n", lower_bound_s, upper_bound_s, now_s);
|
||||
|
||||
window_w = GetScreenWidth();
|
||||
window_h = GetScreenHeight();
|
||||
@@ -140,22 +159,25 @@ int main(int argc, char *argv[])
|
||||
else if(IsKeyPressed(KEY_DOWN))
|
||||
font_size -= 2;
|
||||
|
||||
activities[current_activity].ended = now_ms;
|
||||
activities[current_activity].ended = now_s;
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
DrawRectangleRounded((Rectangle){ 0, 0, window_w, 40 }, 0.0f, 100, GRAY);
|
||||
F32 padding_x = 10.0f;
|
||||
F32 padding_y = 10.0f;
|
||||
|
||||
DrawRectangle(0, 0, window_w, 40, GRAY);
|
||||
|
||||
for(int i = 0; i <= current_activity; i++) {
|
||||
// if((activities[i].ended_on - started_on_ms) <= (ended_on_ms - started_on_ms)) {
|
||||
F32 start_x = (F32)(activities[i].began - lower_bound_ms) / (F32)(upper_bound_ms - lower_bound_ms) * (F32)window_w;
|
||||
F32 end_x = ((F32)(activities[i].ended - lower_bound_ms) / (F32)(upper_bound_ms - lower_bound_ms)) * window_w;
|
||||
DrawRectangleRounded((Rectangle){ start_x, 0, end_x - start_x, 40}, 0.0f, 100, activities[i].color);
|
||||
F32 start_x = (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;
|
||||
// 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);
|
||||
// }
|
||||
}
|
||||
|
||||
F32 padding_x = 10.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)) {
|
||||
@@ -166,8 +188,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
activities[current_activity].activity = other;
|
||||
activities[current_activity].color = RED;
|
||||
activities[current_activity].began = now_ms;
|
||||
activities[current_activity].ended = now_ms;
|
||||
activities[current_activity].began = now_s;
|
||||
activities[current_activity].ended = now_s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,8 +201,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
activities[current_activity].activity = work;
|
||||
activities[current_activity].color = BLUE;
|
||||
activities[current_activity].began = now_ms;
|
||||
activities[current_activity].ended = now_ms;
|
||||
activities[current_activity].began = now_s;
|
||||
activities[current_activity].ended = now_s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,8 +214,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
activities[current_activity].activity = projects;
|
||||
activities[current_activity].color = YELLOW;
|
||||
activities[current_activity].began = now_ms;
|
||||
activities[current_activity].ended = now_ms;
|
||||
activities[current_activity].began = now_s;
|
||||
activities[current_activity].ended = now_s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,8 +227,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
activities[current_activity].activity = gaming;
|
||||
activities[current_activity].color = GREEN;
|
||||
activities[current_activity].began = now_ms;
|
||||
activities[current_activity].ended = now_ms;
|
||||
activities[current_activity].began = now_s;
|
||||
activities[current_activity].ended = now_s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,8 +240,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
activities[current_activity].activity = exercise;
|
||||
activities[current_activity].color = PURPLE;
|
||||
activities[current_activity].began = now_ms;
|
||||
activities[current_activity].ended = now_ms;
|
||||
activities[current_activity].began = now_s;
|
||||
activities[current_activity].ended = now_s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user