feat: simple overlay and window modes with intention setting
This commit is contained in:
+3
-1
@@ -1,3 +1,5 @@
|
|||||||
build/
|
build/
|
||||||
*~
|
*~
|
||||||
*.o
|
*.o
|
||||||
|
*#*
|
||||||
|
adhd
|
||||||
@@ -1,16 +1,24 @@
|
|||||||
CC = cc
|
CC = cc
|
||||||
CFLAGS = -g -Wall -Iinclude
|
CFLAGS = -g -Wall -Iinclude
|
||||||
SOURCES = $(wildcard src/*.c)
|
SOURCES = src/main.c src/window_state.c
|
||||||
OBJECTS = $(SOURCES:.c=.o)
|
OBJECTS = src/main.o src/window_state.o
|
||||||
LDFLAGS = -lraylib
|
LDFLAGS = -lraylib -lm
|
||||||
HEADERS = \
|
HEADERS = \
|
||||||
include/raygui.h
|
include/raygui.h include/common.h include/window_state.h
|
||||||
|
|
||||||
adhd: $(OBJECTS)
|
# adhd: $(OBJECTS)
|
||||||
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
# $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
%.o: %.c $(HEADERS)
|
# %.o: %.c $(HEADERS)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
# $(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:
|
clean:
|
||||||
rm -rf $(OBJECTS) adhd
|
rm -rf $(OBJECTS) adhd
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
|
||||||
|
- [x] model window state
|
||||||
|
- [ ] math behind animation engine
|
||||||
|
- [ ] grid system for win / loss
|
||||||
|
|
||||||
- [ ] create a slick overlay mode
|
- [ ] create a slick overlay mode
|
||||||
- [ ] create a simple window mode for adjusting the current intention
|
- [ ] create a simple window mode for adjusting the current intention
|
||||||
- [ ] remind me by flashing every x minutes (gradient orange)
|
- [ ] remind me by flashing every x minutes (gradient orange)
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <sqlite3.h>
|
||||||
|
#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);
|
||||||
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef WINDOWSTATE_H
|
||||||
|
#define WINDOWSTATE_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
#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
|
||||||
+48
-4
@@ -1,34 +1,78 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define RAYGUI_IMPLEMENTATION
|
||||||
#include <raygui.h>
|
#include <raygui.h>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
#include "window_state.h"
|
||||||
|
|
||||||
#define WINDOW_HEIGHT 700
|
#define WINDOW_HEIGHT 700
|
||||||
#define WINDOW_WIDTH 500
|
#define WINDOW_WIDTH 500
|
||||||
#define OVERLAY_HEIGHT 300
|
#define OVERLAY_HEIGHT 300
|
||||||
#define OVERLAY_WIDTH 700
|
#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() {
|
void render_window() {
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
DrawFPS(WINDOW_WIDTH - 50, 10);
|
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() {
|
void render_overlay() {
|
||||||
ClearBackground(BLANK);
|
ClearBackground(BLANK);
|
||||||
DrawFPS(OVERLAY_WIDTH - 50, 10);
|
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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
init_window_state();
|
||||||
|
|
||||||
printf("Welcome to Flowy.adhd\n");
|
printf("Welcome to Flowy.adhd\n");
|
||||||
|
|
||||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Flowy.adhd");
|
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Flowy.adhd");
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
render_window();
|
|
||||||
|
GuiSetStyle(DEFAULT, TEXT_SIZE, 15);
|
||||||
|
|
||||||
|
if (get_mode() == WINDOW) render_window();
|
||||||
|
else render_overlay();
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
#include "window_state.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user