diff --git a/.gitignore b/.gitignore index 54dd716..d4e463c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ build/ *~ -*.o \ No newline at end of file +*.o +*#* +adhd \ No newline at end of file diff --git a/Makefile b/Makefile index 83ebac5..5976374 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,24 @@ CC = cc CFLAGS = -g -Wall -Iinclude -SOURCES = $(wildcard src/*.c) -OBJECTS = $(SOURCES:.c=.o) -LDFLAGS = -lraylib +SOURCES = src/main.c src/window_state.c +OBJECTS = src/main.o src/window_state.o +LDFLAGS = -lraylib -lm HEADERS = \ - include/raygui.h + include/raygui.h include/common.h include/window_state.h -adhd: $(OBJECTS) - $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) +# adhd: $(OBJECTS) +# $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) -%.o: %.c $(HEADERS) - $(CC) $(CFLAGS) -c $< -o $@ +# %.o: %.c $(HEADERS) +# $(CC) $(CFLAGS) -c $< -o $@ +adhd: src/main.o src/window_state.o + $(CC) $(CFLAGS) src/main.o src/window_state.o -o $@ $(LDFLAGS) + +src/main.o: src/main.c $(HEADERS) + $(CC) -c $(CFLAGS) src/main.c -o $@ + +src/window_state.o: src/window_state.c $(HEADERS) + $(CC) -c $(CFLAGS) src/window_state.c -o $@ clean: rm -rf $(OBJECTS) adhd diff --git a/TODO.md b/TODO.md index 4db2c59..94fe400 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,8 @@ +- [x] model window state +- [ ] math behind animation engine +- [ ] grid system for win / loss + - [ ] create a slick overlay mode - [ ] create a simple window mode for adjusting the current intention - [ ] remind me by flashing every x minutes (gradient orange) diff --git a/adhd b/adhd deleted file mode 100755 index e87f99e..0000000 Binary files a/adhd and /dev/null differ diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..7b30bc6 --- /dev/null +++ b/include/common.h @@ -0,0 +1,15 @@ +#ifndef COMMON_H +#define COMMON_H + +typedef unsigned int U32; + +struct date { + U32 day; + U32 month; + U32 year; +}; + +struct date to_date(char *); +char *to_string(struct date); + +#endif diff --git a/include/store.h b/include/store.h new file mode 100644 index 0000000..ca00022 --- /dev/null +++ b/include/store.h @@ -0,0 +1,10 @@ +#include +#include "common.h" + +/* persist on disk with compact representation + date representation -> value + */ +void store_result(U32 val, struct date d); +void retrieve_result(U32 val, struct date d); +void retrieve_results_before(int *vals, struct date before); + diff --git a/include/window_state.h b/include/window_state.h new file mode 100644 index 0000000..ebf8dce --- /dev/null +++ b/include/window_state.h @@ -0,0 +1,24 @@ +#ifndef WINDOWSTATE_H +#define WINDOWSTATE_H + +#include "common.h" +#include +#define GRAPH_DAYS 30 + +enum mode_t { + WINDOW = 0, + OVERLAY +}; +typedef enum mode_t Mode; + +void init_window_state(); +void cleanup_window_state(); + +void set_intention(char *intention); +char *get_intention(); +size_t get_intention_size(); + +Mode get_mode(); +void set_mode(Mode mode); + +#endif diff --git a/src/main.c b/src/main.c index a5aa533..f6b7876 100644 --- a/src/main.c +++ b/src/main.c @@ -1,34 +1,78 @@ #include + +#define RAYGUI_IMPLEMENTATION #include #include +#include "window_state.h" #define WINDOW_HEIGHT 700 #define WINDOW_WIDTH 500 #define OVERLAY_HEIGHT 300 #define OVERLAY_WIDTH 700 +bool edit_mode = true; + +void switch_mode(Mode mode) { + set_mode(mode); + + switch (mode) { + case WINDOW: + SetWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); + break; + case OVERLAY: + SetWindowSize(OVERLAY_WIDTH, OVERLAY_HEIGHT); + break; + default: + break; + } +} + void render_window() { ClearBackground(RAYWHITE); DrawFPS(WINDOW_WIDTH - 50, 10); - // draw a button for toggle mode + const Rectangle text_rect = {(WINDOW_WIDTH / 2) - 200, WINDOW_HEIGHT / 2, 400, 50}; + if (GuiTextBox(text_rect, get_intention(), get_intention_size(), &edit_mode)) { + switch_mode(OVERLAY); + } + + char label[2048]; + sprintf(label, "%d / %d characters | Hit enter to set", (int) strlen(get_intention()), (int) get_intention_size()); + GuiLabel((Rectangle){ WINDOW_WIDTH / 2 - 100, (WINDOW_HEIGHT / 2) + 50, 300, 50}, label); + } void render_overlay() { ClearBackground(BLANK); DrawFPS(OVERLAY_WIDTH - 50, 10); - // draw a button to toggle mode + const Rectangle button_rect = {OVERLAY_WIDTH - 100, 10, 100, 25}; + int active = 0; + + if (GuiToggleSlider(button_rect, "Toggle mode", &active)) { + switch_mode(WINDOW); + } + + GuiSetStyle(DEFAULT, TEXT_SIZE, 100); + GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + GuiLabel((Rectangle){0, (OVERLAY_HEIGHT / 2), OVERLAY_WIDTH, 50}, get_intention()); } int main(int argc, char *argv[]) { + init_window_state(); + printf("Welcome to Flowy.adhd\n"); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Flowy.adhd"); - + while (!WindowShouldClose()) { BeginDrawing(); - render_window(); + + GuiSetStyle(DEFAULT, TEXT_SIZE, 15); + + if (get_mode() == WINDOW) render_window(); + else render_overlay(); + EndDrawing(); } diff --git a/src/window_state.c b/src/window_state.c new file mode 100644 index 0000000..d06d44a --- /dev/null +++ b/src/window_state.c @@ -0,0 +1,54 @@ +#include "window_state.h" +#include +#include +#include + +struct state *s = NULL; + +#define INTENTION_MAX_SIZE 2048 + +struct state { + Mode mode; + char intention[INTENTION_MAX_SIZE]; +}; + +void init_window_state() { + s = malloc(sizeof(struct state)); + s->mode = WINDOW; + + memset(s->intention, 0, sizeof(s->intention)); +} + +void cleanup_window_state() { + if (!s) { + return; + } + free(s); + s = NULL; +} + +void set_intention(char *intention) { + assert(s); + + strncpy(s->intention, intention, sizeof(s->intention)); + s->intention[sizeof(s->intention) - 1] = '\0'; +} + +char *get_intention() { + assert(s); + return s->intention; +} + +size_t get_intention_size() { + assert(s); + return sizeof(s->intention); +} + +Mode get_mode() { + assert(s); + return s->mode; +} + +void set_mode(Mode new_mode) { + s->mode = new_mode; +}