summaryrefslogtreecommitdiff
path: root/lib/libgfx/src
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-03 03:25:59 -0400
committerIan Moffett <ian@osmora.org>2025-08-03 03:25:59 -0400
commita50119daf92b52951c3a68fe70d8d5bf548adf55 (patch)
tree6489cea3332ed6739f9cbeaf859de79005dd7a13 /lib/libgfx/src
parent96d4341a01c9b935d309ccc4b6d31d852a76257b (diff)
libgfx: draw: Add gfx_plot_point() pixel plotting
Implement mechanism that allows one to plot pixels on the screen with a specific color at specific x/y coordinates. Example: -- struct gfx_point p = { .x = 150, .y = 200, .color = GFX_GREEN }; /* Draw green point at (150,200) */ gfx_plot_point(&ctx, &p); -- Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/libgfx/src')
-rw-r--r--lib/libgfx/src/draw.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/libgfx/src/draw.c b/lib/libgfx/src/draw.c
index 8280f8a..9ef8630 100644
--- a/lib/libgfx/src/draw.c
+++ b/lib/libgfx/src/draw.c
@@ -96,6 +96,39 @@ gfx_draw_square(struct gfx_ctx *ctx, const struct gfx_shape *shape)
}
/*
+ * Plot a single pixel (aka point) onto
+ * the screen.
+ *
+ * @ctx: The graphics context pointer
+ * @point: Point to plot
+ *
+ * Returns 0 on success, otherwise a less
+ * than zero value.
+ */
+int
+gfx_plot_point(struct gfx_ctx *ctx, const struct gfx_point *point)
+{
+ uint32_t index;
+
+ if (ctx == NULL || point == NULL) {
+ return -EINVAL;
+ }
+
+ /*
+ * Is this even a valid point on the screen for
+ * us to plot on?
+ */
+ if (gfx_pixel_bounds(ctx, point->x, point->y) < 0) {
+ return -1;
+ }
+
+ /* Plot it !! */
+ index = gfx_io_index(ctx, point->x, point->y);
+ ctx->io[index] = point->rgb;
+ return 0;
+}
+
+/*
* Draw a shape onto the screen
*
* @ctx: libgfx graphics context