From a3142a6b189aa153353fd5a8b90a3557cf09fc44 Mon Sep 17 00:00:00 2001 From: Annika Date: Mon, 6 Jul 2026 17:33:52 -0700 Subject: [PATCH] major refactor --- Makefile | 6 +- datatypes.cpp | 30 ++-- datatypes.h | 9 ++ test | Bin 41280 -> 0 bytes test.cpp | 441 -------------------------------------------------- triangle.cpp | 98 +++++++++++ waymini | Bin 36920 -> 36896 bytes 7 files changed, 119 insertions(+), 465 deletions(-) delete mode 100755 test delete mode 100644 test.cpp diff --git a/Makefile b/Makefile index 459ef17..de58a3d 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,13 @@ LIB_OBJ := $(LIB_SRC:.c=.o) .PHONY: all clean -all: libwaymini.a test waymini +all: libwaymini.a draw waymini libwaymini.a: $(LIB_OBJ) ar rcs $@ $^ -test: test.cpp libwaymini.a - g++ $(CFLAGS) -o $@ test.cpp -L. -lwaymini $(LDFLAGS) +draw: draw.cpp libwaymini.a + g++ $(CFLAGS) -o $@ draw.cpp -L. -lwaymini $(LDFLAGS) 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) diff --git a/datatypes.cpp b/datatypes.cpp index 14fdf67..ac9dd32 100644 --- a/datatypes.cpp +++ b/datatypes.cpp @@ -12,6 +12,12 @@ namespace UwU { this->g = (hex & 0x00ff0000) >> 16; this->r = (hex & 0xff000000) >> 24; } + Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { + this->r = r; + this->g = g; + this->b = b; + this->a = a; + } Color() {} uint8_t r; uint8_t g; @@ -21,13 +27,13 @@ namespace UwU { // Coord2 datatype for xy coordinates, from top-left of surface struct Coord2 { - Coord2(uint32_t x, uint32_t y) { + Coord2(uint16_t x, uint16_t y) { this->x = x; this->y = y; } Coord2() {} - uint32_t x; - uint32_t y; + uint16_t x; + uint16_t y; }; // trapezoid datatype (horizontally constrained) @@ -48,22 +54,4 @@ namespace UwU { uint16_t xr0; uint16_t xr1; }; - - struct Triangle { - Triangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { - this->x0 = x0; - this->y0 = y0; - this->x1 = x1; - this->y1 = y1; - this->x2 = x2; - this->y2 = y2; - } - Triangle() {} - uint16_t x0; - uint16_t y0; - uint16_t x1; - uint16_t y1; - uint16_t x2; - uint16_t y2; - }; } \ No newline at end of file diff --git a/datatypes.h b/datatypes.h index fd19294..a99eee0 100644 --- a/datatypes.h +++ b/datatypes.h @@ -28,4 +28,13 @@ namespace UwU { uint16_t xr0; uint16_t xr1; }; + + struct Buffer { + Buffer(uint8_t* pixels, uint16_t stride, uint16_t height, uint16_t width); + Buffer(); + uint8_t* pixels; + uint16_t stride; + uint16_t height; + uint16_t width; + }; } \ No newline at end of file diff --git a/test b/test deleted file mode 100755 index d71b263ec70d71ad43926e3348697422f72dfe34..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 41280 zcmeHweRx~NmG_nHByKR0fdDRqMr94Pffzf4U;}xv5-E|v0TUbuA3;_uDOMs|LY5P! zA&Y~P;9JGPyW8%jUt4d>w%NCNz}vEf(l*#6F_G<))XnU**%OQ^_;s@@{x75%}+v z*P!zKtXV47>2wt!Ou4*9mG4AY=F{mGWhYav-}T5x?eOPrD$I<_p z+F%+Aqvl(9?Gj@k&{)_!a@xyJ-_}yMZ~B=dcOH6r&Bc-M@;S3Fjs#{#!fhR$Gdrv2 z%$zg3qCHwMOXT|!@{&HX`+A#gL$~eJt%Q~1|6=@?owH^7uYYjf_QHXm9h`jqtaAo# z-!i-U-Q@IxZPf#rbirJA;XSsO*Pj0!i00gWg7`aioV{-W8xLOq{FHIzgD`YF`ENu2 zx#P&M%^`n%4tws+A>Wrn{@-)R@5mv)CI^0g4m}s=kRQt7w|zO}PtT$MmK=KKl|%n&Iq-9! zz^N+%e^Cy6Fo&KW=fK0jPchCmjJstaJbtx;J;gY~Xj1b?ncQt0R(St92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Dswfua)15 z?mJl_B=|ZTkHfT%d@269-aLL{Icd~(q -#include -#include -#include - -#include "datatypes.cpp" -#include "helpers.cpp" -// #include "triangle.cpp" - -// this should be handled elsewhere, eventually, maybe, probably -static void on_key(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); -} - -namespace UwU { - - class Draw { - private: - - uint8_t *pixels; - - void putPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xff) { - size_t i = (size_t)y * waymini_get_stride(wm) + (size_t)x * 4; - uint8_t b0 = pixels[i + 0]; - uint8_t g0 = pixels[i + 1]; - uint8_t r0 = pixels[i + 2]; - b = Helpers::lerp8(b0, b, a); - g = Helpers::lerp8(g0, g, a); - r = Helpers::lerp8(r0, r, a); - pixels[i + 0] = b; // B - pixels[i + 1] = g; // G - pixels[i + 2] = r; // R - pixels[i + 3] = 0xff; // A - } - - // plot lines if m <= 1 - void lineLow(int32_t x0, int32_t y0, int32_t x1, int32_t y1, Color color) { - int32_t dx = x1 - x0; - int32_t dy = y1 - y0; - int32_t yi = 1; - if (dy < 0) { - yi = -1; - dy = -dy; - } - int32_t d = (2 * dy) - dx; - int32_t y = y0; - for (int32_t x = x0; x < x1; x++) { - putPixel(x, y, color.r, color.g, color.b, color.a); - if (d > 0) { - y += yi; - d += (2 * (dy - dx)); - } else { - d += (2 * dy); - } - } - return; - } - - // plot lines if m >1 - void lineHigh(int32_t x0, int32_t y0, int32_t x1, int32_t y1, Color color) { - int32_t dx = x1 - x0; - int32_t dy = y1 - y0; - int32_t xi = 1; - if (dx < 0) { - xi = -1; - dx = -dx; - } - int32_t d = (2 * dx) - dy; - int32_t x = x0; - for (int32_t y = y0; y < y1; y++) { - putPixel(x, y, color.r, color.g, color.b, color.a); - if (d > 0) { - x += xi; - d += (2 * (dx - dy)); - } else { - d += (2 * dx); - } - } - return; - } - - public: - - - Draw(uint32_t width, uint32_t height, waymini_key_cb on_key) { - this->wm = waymini_create(width, height, on_key, NULL); - if (!this->wm) exit(1); - - // this->width = waymini_get_width(this->wm); - // this->height = waymini_get_height(this->wm); - // this->stride = waymini_get_stride(this->wm); - printf("surface: %ux%u stride=%u\n", waymini_get_width(this->wm), waymini_get_height(this->wm), waymini_get_stride(this->wm)); - - this->pixels = (uint8_t *)waymini_get_pixels(this->wm); - if (!this->pixels) { - waymini_destroy(this->wm); - exit(1); - } - } - - struct waymini* wm; - - uint32_t getWidth() { - return waymini_get_width(wm); - } - - uint32_t getHeight() { - return waymini_get_height(wm); - } - - uint32_t getStride() { - return waymini_get_stride(wm); - } - - void present() { - waymini_present(wm); - return; - } - - void destroy() { - waymini_destroy(wm); - return; - } - - // Draw a rectangle (duh) - void rectangle(Coord2 point0, Coord2 point1, Color color) { - if (point0.x > getWidth() || point0.y > getHeight() || point1.x > getWidth() || point1.y > getHeight()) {return;}; - for (uint32_t y = point0.y; y < point1.y; y++) { - for (uint32_t x = point0.x; x < point1.x; x++) { - putPixel(x, y, color.r, color.g, color.b, color.a); - } - } - return; - } - - // Draws a rectangle with a 4-point color gradient - void rectangleGradient(Coord2 point0, Coord2 point1, Color colorUL, Color colorUR, Color colorLL, Color colorLR) { - // convert to int32_t and ensure x1>x0 && y1>y0 - int32_t x0, y0, x1, y1; - if (point0.x > point1.x) { - x0 = (int32_t)point1.x; - x1 = (int32_t)point0.x; - } else { - x0 = (int32_t)point0.x; - x1 = (int32_t)point1.x; - } - if (point0.y > point1.y) { - y0 = (int32_t)point1.y; - y1 = (int32_t)point0.y; - } else { - y0 = (int32_t)point0.y; - y1 = (int32_t)point1.y; - } - - // setup gradient coefficient arrays - int32_t w = x1 - x0 + 1; - int32_t h = y1 - y0 + 1; - int16_t xGrad[w]; - int16_t yGrad[h]; - - // calculate gradient coefficients - Helpers::bresenham(0, 0, w - 1, 255, xGrad); - Helpers::bresenham(0, 0, h - 1, 255, yGrad); - - // for each point calculate, alpha blend and print color - Color Lmix = Color(); - Color Rmix = Color(); - Color Xmix = Color(); - for (int32_t y = y0; y <= y1; y++) { - Lmix = Helpers::lerpColor(colorUL, colorLL, (uint8_t)yGrad[y - y0]); - Rmix = Helpers::lerpColor(colorUR, colorLR, (uint8_t)yGrad[y - y0]); - for (int32_t x = x0; x <= x1; x++) { - Xmix = Helpers::lerpColor(Lmix, Rmix, (uint8_t)xGrad[x - x0]); - putPixel(x, y, Xmix.r, Xmix.g, Xmix.b, Xmix.a); - } - } - return; - } - - // Fill a simple gradient. Each row is stride bytes. - void rainbow() { - for (uint32_t y = 0; y < getHeight(); y++) { - for (uint32_t x = 0; x < getWidth(); x++) { - size_t i = (size_t)y * getStride() + (size_t)x * 4; - pixels[i + 0] = (uint8_t)(y * 255 / getHeight()); // B - pixels[i + 1] = 0x00; // G - pixels[i + 2] = (uint8_t)(x * 255 / getWidth()); // R - pixels[i + 3] = 0xFF; // A - } - } - } - - // Draw a single point - void point (Coord2 point, Color color) { - if (point.x > getWidth() || point.y > getHeight()) {return;}; - putPixel(point.x, point.y, color.r, color.g, color.b, color.a); - } - - // Uses Bresenham's line algorithm to draw line of any slope - void line (Coord2 point0, Coord2 point1, Color color) { - if (point0.x > getWidth() || point0.y > getHeight() || point1.x > getWidth() || point1.y > getHeight()) {return;}; - int32_t x0 = (int32_t)point0.x; - int32_t y0 = (int32_t)point0.y; - int32_t x1 = (int32_t)point1.x; - int32_t y1 = (int32_t)point1.y; - if (abs(y1 - y0) < abs(x1 - x0)) { - if (x0 > x1) { - lineLow(x1, y1, x0, y0, color); - } else { - lineLow(x0, y0, x1, y1, color); - } - } else { - if (y0 > y1) { - lineHigh(x1, y1, x0, y0, color); - } else { - lineHigh(x0, y0, x1, y1, color); - } - } - } - - // Draw a horizontally bounded trapezoid - // coords.y1 >= coords.y0 - // todo move to private and add public checks - void trapezoid (Trapezoid coords, Color color) { - printf("(%u, %u, %u, %u, %u, %u)", coords.y0, coords.y1, coords.xl0, coords.xl1, coords.xr0, coords.xr1); - uint16_t height = 1 + coords.y1 - coords.y0; - int16_t LeftBound[height]; - int16_t RightBound[height]; - - Helpers::bresenham(0, coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound); - Helpers::bresenham(0, coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound); - - printf("leftbound\n"); - for (uint16_t i = 0; i < height; i++) { - printf("(%u, %u)\n", i, LeftBound[i]); - } - printf("rightbound\n"); - for (uint16_t i = 0; i < height; i++) { - printf("(%u, %u)\n", i, RightBound[i]); - } - - for (uint16_t i = 0; i < height; i++) { - for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) { - // printf("(%u, %u)", x, i + coords.y0); - putPixel((uint32_t)x, (uint32_t)i + coords.y0, color.r, color.g, color.b, color.a); - } - } - return; - } - - // Draw a triangle - void triangle (Triangle coords, Color color) { - Coord2 top = Coord2(); - Coord2 mid = Coord2(); - Coord2 btm = Coord2(); - // cases: flat top, flat bottom, left point, right point - if (coords.y0 <= coords.y1 && coords.y0 <= coords.y2) { - top.x = coords.x0; - top.y = coords.y0; - if (coords.y1 < coords.y2) { - mid.x = coords.x1; - mid.y = coords.y1; - btm.x = coords.x2; - btm.y = coords.y2; - } else { - mid.x = coords.x2; - mid.y = coords.y2; - btm.x = coords.x1; - btm.y = coords.y1; - } - } else if (coords.y1 <= coords.y0 && coords.y1 <= coords.y2) { - top.x = coords.x1; - top.y = coords.y1; - if (coords.y0 < coords.y2) { - mid.x = coords.x0; - mid.y = coords.y0; - btm.x = coords.x2; - btm.y = coords.y2; - } else { - mid.x = coords.x2; - mid.y = coords.y2; - btm.x = coords.x0; - btm.y = coords.y0; - } - } else { - top.x = coords.x2; - top.y = coords.y2; - if (coords.y0 < coords.y1) { - mid.x = coords.x0; - mid.y = coords.y0; - btm.x = coords.x1; - btm.y = coords.y1; - } else { - mid.x = coords.x1; - mid.y = coords.y1; - btm.x = coords.x0; - btm.y = coords.y0; - } - } - printf("top: (%u, %u)\n", top.x, top.y); - printf("mid: (%u, %u)\n", mid.x, mid.y); - printf("btm: (%u, %u)\n", btm.x, btm.y); - - uint16_t height = 1 + btm.y - top.y; - int16_t longBound[height]; - int16_t splitBound[height]; - // int16_t rightBound[height]; - Helpers::bresenham(0, top.x, height - 1, btm.x, longBound); - printf("longBound\n"); - if ((int16_t)mid.x < longBound[mid.y - top.y]) { - // left-handed triangle - printf("left-handed\n"); - // rightBound = longBound; - Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound); - printf("splitTop\n"); - Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound); - printf("splitBtm\n"); - for (uint16_t i = 0; i < height; i++) { - printf("(%u, %u)\n", i, splitBound[i]); - } - for (uint32_t i = 0; i < height; i++) { - for (uint32_t x = (uint32_t)splitBound[i]; x <= (uint32_t)longBound[i]; x++) { - putPixel(x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a); - } - } - } else { - // right-handed triangle - printf("right-handed\n"); - // leftBound = longBound; - Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound); - printf("splitTop\n"); - Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound); - printf("splitBtm\n"); - for (uint32_t i = 0; i < height; i++) { - for (uint32_t x = (uint32_t)longBound[i]; x <= (uint32_t)splitBound[i]; x++) { - putPixel(x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a); - } - } - } - - - - // // handle case where top or bottom is flat - // if (mid.y == top.y) { - // // flat top - // if (mid.x < top.x) { - // trapezoid(Trapezoid(top.y, btm.y, mid.x, btm.x, top.x, btm.x), color); - // return; - // } else { - // trapezoid(Trapezoid(top.y, btm.y, top.x, btm.x, mid.x, btm.x), color); - // return; - // } - // } else if (mid.y == btm.y) { - // // flat bottom - // if (mid.x < btm.x) { - // trapezoid(Trapezoid(top.y, btm.y, top.x, mid.x, top.x, btm.x), color); - // return; - // } else { - // trapezoid(Trapezoid(top.y, btm.y, top.x, btm.x, top.x, mid.x), color); - // return; - // } - // } - - // // calculate midpoint of straight line - // int32_t dy = (int32_t)btm.y - (int32_t)top.y; - // if (dy == 0) { - // return; // shouldn't be possible, should be detected earlier - // } - // int32_t dx = (int32_t)btm.x - (int32_t)top.x; - // dx *= (mid.y - top.y); - // dx /= dy; - // dx += top.x; - // uint16_t oppx = (uint16_t)dx; - - // // split triangle into two trapezoids - // if (mid.x < oppx) { - // trapezoid(Trapezoid(top.y, mid.y, top.x, mid.x, top.x, oppx), color); - // trapezoid(Trapezoid(mid.y, btm.y, mid.x, btm.x, oppx, btm.x), color); - // return; - // } else { - // trapezoid(Trapezoid(top.y, mid.y, top.x, oppx, top.x, mid.x), color); - // trapezoid(Trapezoid(mid.y, btm.y, oppx, btm.x, mid.x, btm.x), color); - // return; - // } - return; - } - }; - } - -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, on_key); - - 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, 400), green); - draw.triangle(UwU::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 (!waymini_should_close(draw.wm)) { - if (waymini_dispatch(draw.wm) < 0) break; - } - - draw.destroy(); - return 0; -} diff --git a/triangle.cpp b/triangle.cpp index 8885334..fb7cf1e 100644 --- a/triangle.cpp +++ b/triangle.cpp @@ -4,9 +4,13 @@ #include "datatypes.cpp" #include "helpers.cpp" +#include "buffer.cpp" namespace UwU { class Triangle { + private: + + public: Triangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { this->x0 = x0; @@ -23,5 +27,99 @@ namespace UwU { uint16_t y1; uint16_t x2; uint16_t y2; + + // Draw a triangle + void draw (Buffer buffer, Color color) { + Coord2 top = Coord2(); + Coord2 mid = Coord2(); + Coord2 btm = Coord2(); + // cases: left-handed, right-handed + if (y0 <= y1 && y0 <= y2) { + top.x = x0; + top.y = y0; + if (y1 < y2) { + mid.x = x1; + mid.y = y1; + btm.x = x2; + btm.y = y2; + } else { + mid.x = x2; + mid.y = y2; + btm.x = x1; + btm.y = y1; + } + } else if (y1 <= y0 && y1 <= y2) { + top.x = x1; + top.y = y1; + if (y0 < y2) { + mid.x = x0; + mid.y = y0; + btm.x = x2; + btm.y = y2; + } else { + mid.x = x2; + mid.y = y2; + btm.x = x0; + btm.y = y0; + } + } else { + top.x = x2; + top.y = y2; + if (y0 < y1) { + mid.y = y0; + mid.x = x0; + btm.x = x1; + btm.y = y1; + } else { + mid.x = x1; + mid.y = y1; + btm.x = x0; + btm.y = y0; + } + } + // printf("top: (%u, %u)\n", top.x, top.y); + // printf("mid: (%u, %u)\n", mid.x, mid.y); + // printf("btm: (%u, %u)\n", btm.x, btm.y); + + uint16_t height = 1 + btm.y - top.y; + int16_t longBound[height]; + int16_t splitBound[height]; + // int16_t rightBound[height]; + Helpers::bresenham(0, top.x, height - 1, btm.x, longBound); + // printf("longBound\n"); + if ((int16_t)mid.x < longBound[mid.y - top.y]) { + // left-handed triangle + // printf("left-handed\n"); + // rightBound = longBound; + Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound); + // printf("splitTop\n"); + Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound); + // printf("splitBtm\n"); + // for (uint16_t i = 0; i < height; i++) { + // printf("(%u, %u)\n", i, splitBound[i]); + // } + for (uint16_t i = 0; i < height; i++) { + for (uint16_t x = (uint16_t)splitBound[i]; x <= (uint16_t)longBound[i]; x++) { + // Helpers::putPixel(buffer, x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a); + buffer.drawPixel(Coord2(x, i + (uint16_t)top.y), color); + } + } + } else { + // right-handed triangle + // printf("right-handed\n"); + // leftBound = longBound; + Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound); + // printf("splitTop\n"); + Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound); + // printf("splitBtm\n"); + for (uint16_t i = 0; i < height; i++) { + for (uint16_t x = (uint16_t)longBound[i]; x <= (uint16_t)splitBound[i]; x++) { + // Helpers::putPixel(buffer, x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a); + buffer.drawPixel(Coord2(x, i + (uint16_t)top.y), color); + } + } + } + return; + } }; } \ No newline at end of file diff --git a/waymini b/waymini index 811fb3e1ec99fae163d03b33cd797fbbd7ae0051..351bb7ab0acb30ba2b51061a2ee7714d7453e8c7 100755 GIT binary patch delta 109 zcmdn7fN8-3rU@F13L7=^nMFJKUHN;zgR9ZHuI38Kox+vI6tFlEdP4mB<^E-@f7FfukUGB7!l?{PMhAO!@oEOHbb0XCCCk2e7* VlX;In0uX+ax{p2r28WaSk0ym=C{O?Z