Commit: d8164ab949eeca69b8633a4c25dd7f6231ce369e
Parent: 1c4bffb78ac513af8620c14d6fd3e6cf9770136f
Author: Randy Palamar
Date: Fri, 7 Jun 2024 21:09:25 -0600
start laying out the window
Diffstat:
3 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/colourpicker.c b/colourpicker.c
@@ -1,12 +1,46 @@
#include <raylib.h>
+#include "util.c"
void
-do_colour_picker(void)
+do_colour_picker(ColourPickerCtx *ctx)
{
- BeginDrawing();
+ ClearBackground(BLACK);
+ DrawFPS(20, 20);
- ClearBackground(BLACK);
- DrawText("Hello World!", 240, 480, 48, BLUE);
+ uv2 ws = ctx->window_size;
- EndDrawing();
+ {
+ v2 cc = { .x = (f32)ws.w / 2, .y = (f32)ws.h / 4 };
+ DrawCircleSector(cc.rv, 0.6 * cc.x, 0, 360, 69, RED);
+ DrawCircleSector(cc.rv, 0.58 * cc.x, 0, 360, 69, BLACK);
+ DrawText("Hello World!", ws.w * 0.3, ws.h / 4, 48, BLUE);
+ }
+
+ {
+ v2 start = { .x = 0, .y = (f32)ws.h / 2 };
+ v2 end = { .x = ws.h, .y = (f32)ws.h / 2 };
+ DrawLineEx(start.rv, end.rv, 8, BLUE);
+ }
+
+ {
+ v2 subregion = {
+ .x = (f32)ws.w * 0.9,
+ .y = (f32)ws.h / 2 * 0.9,
+ };
+
+ v2 starting_pos = {
+ .x = 0.05 * (f32)ws.w,
+ .y = (f32)ws.h / 2 + 0.25 * ((f32)ws.h / 2),
+ };
+
+ v2 size = { .x = subregion.x, .y = 0.15 * subregion.y };
+
+ DrawRectangleV(starting_pos.rv, size.rv, DARKGREEN);
+
+ starting_pos.y += size.y + 0.1 * ((f32)ws.h / 2);
+ DrawRectangleV(starting_pos.rv, size.rv, DARKGREEN);
+
+ starting_pos.y += size.y + 0.1 * ((f32)ws.h / 2);
+ DrawRectangleV(starting_pos.rv, size.rv, DARKGREEN);
+ }
}
diff --git a/main.c b/main.c
@@ -10,7 +10,7 @@ typedef struct timespec Filetime;
static const char *libname = "./libcolourpicker.so";
static void *libhandle;
-typedef void (do_colour_picker_fn)(void);
+typedef void (do_colour_picker_fn)(ColourPickerCtx *);
static do_colour_picker_fn *do_colour_picker;
static Filetime
@@ -31,6 +31,7 @@ compare_filetime(Filetime a, Filetime b)
static void
load_library(const char *lib)
{
+ dlclose(libhandle);
libhandle = dlopen(lib, RTLD_NOW|RTLD_LOCAL);
do_colour_picker = dlsym(libhandle, "do_colour_picker");
}
@@ -38,12 +39,18 @@ load_library(const char *lib)
int
main(void)
{
- InitWindow(720, 960, "Colour Picker");
+ ColourPickerCtx ctx;
+ ctx.window_size = (uv2){.w = 720, .h = 960};
+
+ SetConfigFlags(FLAG_VSYNC_HINT);
+ InitWindow(ctx.window_size.w, ctx.window_size.h, "Colour Picker");
load_library(libname);
Filetime updated_time = get_filetime(libname);
while(!WindowShouldClose()) {
- do_colour_picker();
+ BeginDrawing();
+ do_colour_picker(&ctx);
+ EndDrawing();
Filetime test_time = get_filetime(libname);
if (compare_filetime(test_time, updated_time)) {
diff --git a/util.c b/util.c
@@ -6,3 +6,19 @@ typedef uint32_t u32;
typedef float f32;
typedef double f64;
typedef ptrdiff_t size;
+
+typedef union {
+ struct { u32 w, h; };
+ struct { u32 x, y; };
+ u32 E[2];
+} uv2;
+
+typedef union {
+ struct { f32 x, y; };
+ Vector2 rv;
+ f32 E[2];
+} v2;
+
+typedef struct {
+ uv2 window_size;
+} ColourPickerCtx;