diff --git a/test b/test index 20acacc..7acbb7d 100755 Binary files a/test and b/test differ diff --git a/test.cpp b/test.cpp index 8ab795d..edcb6f3 100644 --- a/test.cpp +++ b/test.cpp @@ -44,21 +44,62 @@ namespace UwU { // Draw a rectangle (duh) void rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint8_t r, uint8_t g, uint8_t b) { + if (x0 > this->width || y0 > this->height || x1 > this->width || y1 > this->height) {return;}; + for (uint32_t y = y0; y < y1; y++) { + for (uint32_t x = x0; x < x1; x++) { + size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4; + this->pixels[i + 0] = b; // B + this->pixels[i + 1] = g; // G + this->pixels[i + 2] = r; // R + this->pixels[i + 3] = 0xFF; // A + } + } return; } - + // Fill a simple gradient. Each row is stride bytes. void rainbow() { for (uint32_t y = 0; y < this->height; y++) { for (uint32_t x = 0; x < this->width; x++) { size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4; - this->pixels[i + 0] = (uint8_t)(y * 255 / this->height); /* B */ - this->pixels[i + 1] = 0x00; /* G */ - this->pixels[i + 2] = (uint8_t)(x * 255 / this->width); /* R */ - this->pixels[i + 3] = 0xFF; /* A (ignored for XRGB) */ + this->pixels[i + 0] = (uint8_t)(y * 255 / this->height); // B + this->pixels[i + 1] = 0x00; // G + this->pixels[i + 2] = (uint8_t)(x * 255 / this->width); // R + this->pixels[i + 3] = 0xFF; // A } } } + + void point (uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) { + if (x > this->width || y > this->height) {return;}; + size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4; + this->pixels[i + 0] = b; // B + this->pixels[i + 1] = g; // G + this->pixels[i + 2] = r; // R + this->pixels[i + 3] = 0xFF; // A + } + + // // Uses Bresenham's line algorithm to draw line of any slope + // void line (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint8_t r, uint8_t g, uint8_t b) { + // if (x0 > this->width || y0 > this->height || x1 > this->width || y1 > this->height) {return;}; + // int32_t dx = (int32_t)x1 - (int32_t)x0; + // int32_t dy = (int32_t)y1 - (int32_t)y1; + // int32_t yi = 1; + // if (dy < 0) { + // yi = -1; + // dy = -dy; + // } + // int32_t d = (2 * dy) - dx; + // int32_t y = y0 + // for (uint32_t x = x0; x < x1; x++) { + + // } + // size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4; + // this->pixels[i + 0] = b; // B + // this->pixels[i + 1] = g; // G + // this->pixels[i + 2] = r; // R + // this->pixels[i + 3] = 0xFF; // A + // } }; } @@ -71,7 +112,8 @@ int main(void) { draw.rainbow(); waymini_present(draw.wm); - draw.pixels[200001] = 255; + draw.rectangle(69, 69, 420, 420, 0xB0, 0x0B, 0x69); + draw.point(387, 43, 0x00, 0xff, 0x00); while (!waymini_should_close(draw.wm)) { if (waymini_dispatch(draw.wm) < 0) break;