#include "base_context_cracking.h" #include "base_core.h" #include #include #include "sourcecodepro.h" #include "third_party/raylib/src/raylib.h" #define TRUE 1 #define FALSE 0 typedef struct { Vector2 mouse_pos; Font font; } global_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; } #if 0 char my_button(int x, int y, int width, int height, int font_size, char *title) { char button_pressed = 0; 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(int x, int y, int width, int height, char *title, F32 font_size, Color color) { char button_pressed = 0; Vector2 font_d = MeasureTextEx(state.font, title, (float)font_size, 2); Rectangle rect = { x, y, width, height }; if(CheckCollisionPointRec(state.mouse_pos, rect)) { if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) button_pressed = 1; } DrawRectangleRounded(rect, 0.2f, 100, color); DrawTextEx(state.font, title, (Vector2){ (rect.x + rect.width / 2.0f - font_d.x / 2.0f), (rect.y + rect.height / 2.0f - font_d.y / 2.0f) }, font_size, 2, BLACK); return button_pressed; } enum activity_type { other, work, projects, gaming, exercise }; typedef struct Activity { enum activity_type activity; Color color; U64 began; U64 ended; } Activity; int main(int argc, char *argv[]) { Activity activities[100]; U32 current_activity = 0; S32 window_w = 800; S32 window_h = 450; InitWindow(window_w, window_h, "Time Tracker"); SetWindowState(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE); SetTargetFPS(60); state.font = LoadFontFromMemory(".ttf", sourcecodepro_ttf, sourcecodepro_ttf_len, 96, NULL, 0); if(!IsFontValid(state.font)) { fprintf(stderr, "Unable to load font\n"); return 1; } 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; int font_size = 30; // DisableEventWaiting(); // EnableEventWaiting(); while(!WindowShouldClose()) { now_ms = millis(); window_w = GetScreenWidth(); window_h = GetScreenHeight(); state.mouse_pos = GetMousePosition(); if(IsKeyPressed(KEY_Q)) break; else if(IsKeyPressed(KEY_UP)) font_size += 2; else if(IsKeyPressed(KEY_DOWN)) font_size -= 2; activities[current_activity].ended = now_ms; BeginDrawing(); ClearBackground(BLACK); DrawRectangleRounded((Rectangle){ 0, 0, window_w, 40 }, 0.0f, 100, 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 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)) { if(activities[current_activity].activity != other) { printf("Activity OTHER\n"); current_activity++; activities[current_activity].activity = other; activities[current_activity].color = RED; activities[current_activity].began = now_ms; activities[current_activity].ended = now_ms; } } if(activity_button((padding_x*2)+(width*1), 60, width, (window_h-70), "Work", font_size, BLUE)) { if(activities[current_activity].activity != work) { printf("Activity WORK\n"); current_activity++; activities[current_activity].activity = work; activities[current_activity].color = BLUE; activities[current_activity].began = now_ms; activities[current_activity].ended = now_ms; } } if(activity_button((padding_x*3)+(width*2), 60, width, (window_h-70), "Projects", font_size, YELLOW)) { if(activities[current_activity].activity != projects) { printf("Activity PROJECTS\n"); current_activity++; activities[current_activity].activity = projects; activities[current_activity].color = YELLOW; activities[current_activity].began = now_ms; activities[current_activity].ended = now_ms; } } if(activity_button((padding_x*4)+(width*3), 60, width, (window_h-70), "Gaming", font_size, GREEN)) { if(activities[current_activity].activity != gaming) { printf("Activity GAMING\n"); current_activity++; activities[current_activity].activity = gaming; activities[current_activity].color = GREEN; activities[current_activity].began = now_ms; activities[current_activity].ended = now_ms; } } if(activity_button((padding_x*5)+(width*4), 60, width, (window_h-70), "Exercise", font_size, PURPLE)) { if(activities[current_activity].activity != exercise) { printf("Activity EXERCISE\n"); current_activity++; activities[current_activity].activity = exercise; activities[current_activity].color = PURPLE; activities[current_activity].began = now_ms; activities[current_activity].ended = now_ms; } } // DrawTextEx(state.font, "Hello, world! && How are you?", (Vector2){100, 400}, font_size, 2, BLUE); EndDrawing(); } CloseWindow(); return 0; }