split out main loop from draw class

This commit is contained in:
2026-07-07 03:49:24 -07:00
parent c9d289f923
commit 19400ed32e
9 changed files with 107 additions and 42 deletions
+4 -4
View File
@@ -12,13 +12,13 @@ LIB_OBJ := $(LIB_SRC:.c=.o)
.PHONY: all clean .PHONY: all clean
all: libwaymini.a draw waymini all: libwaymini.a example waymini
libwaymini.a: $(LIB_OBJ) libwaymini.a: $(LIB_OBJ)
ar rcs $@ $^ ar rcs $@ $^
draw: draw.cpp libwaymini.a example: example.cpp libwaymini.a
g++ $(CFLAGS) -o $@ draw.cpp -L. -lwaymini $(LDFLAGS) g++ $(CFLAGS) -o $@ example.cpp -L. -lwaymini $(LDFLAGS)
waymini: waymini_standalone.c waymini.c xdg-shell-client-protocol.c waymini: waymini_standalone.c waymini.c xdg-shell-client-protocol.c
$(CC) $(CFLAGS) -o $@ waymini_standalone.c waymini.c xdg-shell-client-protocol.c $(LDFLAGS) $(CC) $(CFLAGS) -o $@ waymini_standalone.c waymini.c xdg-shell-client-protocol.c $(LDFLAGS)
@@ -27,7 +27,7 @@ waymini: waymini_standalone.c waymini.c xdg-shell-client-protocol.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
clean: clean:
rm -f $(LIB_OBJ) libwaymini.a test waymini rm -f $(LIB_OBJ) libwaymini.a example waymini
xdg-shell-client-protocol.c xdg-shell-client-protocol.h: gen-protocols.sh xdg-shell-client-protocol.c xdg-shell-client-protocol.h: gen-protocols.sh
bash gen-protocols.sh bash gen-protocols.sh
BIN
View File
Binary file not shown.
+40 -38
View File
@@ -2,6 +2,8 @@
* No external dependencies beyond waymini itself and the C standard library. * No external dependencies beyond waymini itself and the C standard library.
*/ */
#pragma once
#include "waymini.h" #include "waymini.h"
#include <stdint.h> #include <stdint.h>
@@ -16,15 +18,15 @@
#include "surface.cpp" #include "surface.cpp"
// this should be handled elsewhere, eventually, maybe, probably // this should be handled elsewhere, eventually, maybe, probably
static void onKey(void *user, uint32_t keycode, uint32_t state) { // static void onKey(void *user, uint32_t keycode, uint32_t state) {
if (keycode == 1) { // if (keycode == 1) {
exit(1); // exit(1);
} // }
(void)user; // (void)user;
const char *label = state ? "down" : "up "; // const char *label = state ? "down" : "up ";
printf("key %s: %u\n", label, keycode); // printf("key %s: %u\n", label, keycode);
fflush(stdout); // fflush(stdout);
} // }
namespace UwU { namespace UwU {
@@ -273,41 +275,41 @@ namespace UwU {
}; };
} }
int main(void) { // int main(void) {
uint32_t w = 800, h = 480; // uint32_t w = 800, h = 480;
UwU::Color fuchsia = UwU::Color(0xb00b6940); // UwU::Color fuchsia = UwU::Color(0xb00b6940);
UwU::Color red = UwU::Color(0xff0000ff); // UwU::Color red = UwU::Color(0xff0000ff);
UwU::Color green = UwU::Color(0x00ff00ff); // UwU::Color green = UwU::Color(0x00ff00ff);
UwU::Color blue = UwU::Color(0x0000ffff); // UwU::Color blue = UwU::Color(0x0000ffff);
UwU::Color alpha = UwU::Color(0x00000000); // UwU::Color alpha = UwU::Color(0x00000000);
printf("r: %u, g:%u, b:%u, a:%u\n", fuchsia.r, fuchsia.g, fuchsia.b, fuchsia.a); // printf("r: %u, g:%u, b:%u, a:%u\n", fuchsia.r, fuchsia.g, fuchsia.b, fuchsia.a);
// struct waymini *wm = waymini_create(w, h, on_key, NULL); // // struct waymini *wm = waymini_create(w, h, on_key, NULL);
UwU::Draw draw = UwU::Draw(w, h, onKey); // UwU::Draw draw = UwU::Draw(w, h, onKey);
draw.rainbow(); // draw.rainbow();
draw.rectangle(UwU::Coord2(69, 69), UwU::Coord2(420, 420), fuchsia); // draw.rectangle(UwU::Coord2(69, 69), UwU::Coord2(420, 420), fuchsia);
draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red); // draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 400), green); // draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 480), green);
draw.triangle(280, 100, 240, 290, 320, 300, green); // draw.triangle(280, 100, 240, 290, 320, 300, green);
draw.point(UwU::Coord2(387, 43), green); // draw.point(UwU::Coord2(387, 43), green);
draw.line(UwU::Coord2(300, 100), UwU::Coord2(250, 469), green); // draw.line(UwU::Coord2(300, 100), UwU::Coord2(250, 469), green);
draw.line(UwU::Coord2(250, 100), UwU::Coord2(300, 469), green); // draw.line(UwU::Coord2(250, 100), UwU::Coord2(300, 469), green);
draw.line(UwU::Coord2(300, 100), UwU::Coord2(469, 250), green); // draw.line(UwU::Coord2(300, 100), UwU::Coord2(469, 250), green);
draw.line(UwU::Coord2(469, 100), UwU::Coord2(300, 250), green); // draw.line(UwU::Coord2(469, 100), UwU::Coord2(300, 250), green);
draw.line(UwU::Coord2(100, 300), UwU::Coord2(250, 469), green); // draw.line(UwU::Coord2(100, 300), UwU::Coord2(250, 469), green);
draw.line(UwU::Coord2(250, 300), UwU::Coord2(100, 469), green); // draw.line(UwU::Coord2(250, 300), UwU::Coord2(100, 469), green);
draw.line(UwU::Coord2(100, 300), UwU::Coord2(469, 250), green); // draw.line(UwU::Coord2(100, 300), UwU::Coord2(469, 250), green);
draw.line(UwU::Coord2(469, 300), UwU::Coord2(100, 250), green); // draw.line(UwU::Coord2(469, 300), UwU::Coord2(100, 250), green);
draw.present(); // draw.present();
while (!draw.shouldClose()) {} // while (!draw.shouldClose()) {}
draw.destroy(); // draw.destroy();
return 0; // return 0;
} // }
BIN
View File
Binary file not shown.
+63
View File
@@ -0,0 +1,63 @@
// #pragma once
// #include "waymini.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "datatypes.cpp"
#include "draw.cpp"
// #include "triangle.cpp"
// #include "buffer.cpp"
// #include "surface.cpp"
static void onKey(void *user, uint32_t keycode, uint32_t state) {
if (keycode == 1) {
exit(1);
}
(void)user;
const char *label = state ? "down" : "up ";
printf("key %s: %u\n", label, keycode);
fflush(stdout);
}
int main(void) {
uint32_t w = 800, h = 480;
UwU::Color fuchsia = UwU::Color(0xb00b6940);
UwU::Color red = UwU::Color(0xff0000ff);
UwU::Color green = UwU::Color(0x00ff00ff);
UwU::Color blue = UwU::Color(0x0000ffff);
UwU::Color alpha = UwU::Color(0x00000000);
printf("r: %u, g:%u, b:%u, a:%u\n", fuchsia.r, fuchsia.g, fuchsia.b, fuchsia.a);
// struct waymini *wm = waymini_create(w, h, on_key, NULL);
UwU::Draw draw = UwU::Draw(w, h, onKey);
draw.rainbow();
draw.rectangle(UwU::Coord2(69, 69), UwU::Coord2(420, 420), fuchsia);
draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 480), green);
draw.triangle(280, 100, 240, 290, 320, 300, green);
draw.point(UwU::Coord2(387, 43), green);
draw.line(UwU::Coord2(300, 100), UwU::Coord2(250, 469), green);
draw.line(UwU::Coord2(250, 100), UwU::Coord2(300, 469), green);
draw.line(UwU::Coord2(300, 100), UwU::Coord2(469, 250), green);
draw.line(UwU::Coord2(469, 100), UwU::Coord2(300, 250), green);
draw.line(UwU::Coord2(100, 300), UwU::Coord2(250, 469), green);
draw.line(UwU::Coord2(250, 300), UwU::Coord2(100, 469), green);
draw.line(UwU::Coord2(100, 300), UwU::Coord2(469, 250), green);
draw.line(UwU::Coord2(469, 300), UwU::Coord2(100, 250), green);
draw.present();
while (!draw.shouldClose()) {}
draw.destroy();
return 0;
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.