diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libgfx/include/libgfx/draw.h | 13 | ||||
-rw-r--r-- | lib/libgfx/src/draw.c | 33 |
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/libgfx/include/libgfx/draw.h b/lib/libgfx/include/libgfx/draw.h index 3bd013a..9f56f6c 100644 --- a/lib/libgfx/include/libgfx/draw.h +++ b/lib/libgfx/include/libgfx/draw.h @@ -89,7 +89,20 @@ struct gfx_shape { dimm_t height; }; +/* + * A point or single pixel that + * may be plotted onto the screen. + * + * @x,y: Position of the point on the screen + * @rgb: Color of the point (RGB) + */ +struct gfx_point { + scrpos_t x, y; + color_t rgb; +}; + int gfx_draw_shape(struct gfx_ctx *ctx, const struct gfx_shape *shape); +int gfx_plot_point(struct gfx_ctx *ctx, const struct gfx_point *point); __always_inline static inline size_t gfx_io_index(struct gfx_ctx *ctx, scrpos_t x, scrpos_t y) 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 |