colourpicker

Simple Colour Picker written in C
git clone anongit@rnpnr.xyz:colourpicker.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: 1c4bffb78ac513af8620c14d6fd3e6cf9770136f
Author: Randy Palamar
Date:   Fri,  7 Jun 2024 20:00:15 -0600

start doing the thing

Diffstat:
Abuild.sh | 10++++++++++
Acolourpicker.c | 12++++++++++++
Amain.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Autil.c | 8++++++++
4 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/build.sh b/build.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +cflags="-march=native -O2 -Wall" +ldflags="-lraylib" + +libcflags="-march=native -Wall -O2 -fPIC" +libldflags="$ldflags -shared" + +cc $libcflags colourpicker.c -o libcolourpicker.so $libldflags +cc $cflags -o colourpicker main.c $ldflags diff --git a/colourpicker.c b/colourpicker.c @@ -0,0 +1,12 @@ +#include <raylib.h> + +void +do_colour_picker(void) +{ + BeginDrawing(); + + ClearBackground(BLACK); + DrawText("Hello World!", 240, 480, 48, BLUE); + + EndDrawing(); +} diff --git a/main.c b/main.c @@ -0,0 +1,54 @@ +#include <dlfcn.h> +#include <fcntl.h> +#include <raylib.h> +#include <sys/stat.h> + +#include "util.c" + +typedef struct timespec Filetime; + +static const char *libname = "./libcolourpicker.so"; +static void *libhandle; + +typedef void (do_colour_picker_fn)(void); +static do_colour_picker_fn *do_colour_picker; + +static Filetime +get_filetime(const char *name) +{ + struct stat sb; + if (stat(name, &sb) < 0) + return (Filetime){0}; + return sb.st_mtim; +} + +static i32 +compare_filetime(Filetime a, Filetime b) +{ + return (a.tv_sec - b.tv_sec) + (a.tv_nsec - b.tv_nsec); +} + +static void +load_library(const char *lib) +{ + libhandle = dlopen(lib, RTLD_NOW|RTLD_LOCAL); + do_colour_picker = dlsym(libhandle, "do_colour_picker"); +} + +int +main(void) +{ + InitWindow(720, 960, "Colour Picker"); + load_library(libname); + + Filetime updated_time = get_filetime(libname); + while(!WindowShouldClose()) { + do_colour_picker(); + + Filetime test_time = get_filetime(libname); + if (compare_filetime(test_time, updated_time)) { + load_library(libname); + updated_time = test_time; + } + } +} diff --git a/util.c b/util.c @@ -0,0 +1,8 @@ +#include <stddef.h> +#include <stdint.h> + +typedef int32_t i32; +typedef uint32_t u32; +typedef float f32; +typedef double f64; +typedef ptrdiff_t size;