joeylib2/include/joey/draw.h

59 lines
2.7 KiB
C

// Drawing primitives.
//
// All primitives clip to the surface rectangle. Out-of-bounds draws are
// silent no-ops, not errors. jlSamplePixel returns 0 for off-surface reads.
// Primitives operate on color indices; per-scanline palette resolution
// happens only at display time.
#ifndef JOEYLIB_DRAW_H
#define JOEYLIB_DRAW_H
#include "platform.h"
#include "surface.h"
#include "types.h"
// Fill the entire surface with a single color index. Writes color 0 is
// a legitimate clear-to-black and does not skip.
void jlSurfaceClear(jlSurfaceT *s, uint8_t colorIndex);
// Plot a single pixel. Off-surface coordinates are no-ops.
void jlDrawPixel(jlSurfaceT *s, int16_t x, int16_t y, uint8_t colorIndex);
// Read a pixel value. Off-surface coordinates return 0.
uint8_t jlSamplePixel(const jlSurfaceT *s, int16_t x, int16_t y);
// Plot a line from (x0, y0) to (x1, y1) using Bresenham. Endpoints
// are inclusive. Off-surface pixels are skipped per-pixel; lines that
// pass entirely off-surface draw nothing. Horizontal and vertical
// runs hit fast paths.
void jlDrawLine(jlSurfaceT *s, int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t colorIndex);
// Outline a rectangle (1-pixel-wide border). 1xN / Nx1 degenerate
// to vertical / horizontal lines; 1x1 to a single pixel. Negative or
// zero dimensions are no-ops.
void jlDrawRect(jlSurfaceT *s, int16_t x, int16_t y, uint16_t w, uint16_t h, uint8_t colorIndex);
// Fill a solid rectangle. Negative or zero dimensions are no-ops.
void jlFillRect(jlSurfaceT *s, int16_t x, int16_t y, uint16_t w, uint16_t h, uint8_t colorIndex);
// Outline a circle of radius r centered at (cx, cy) using Bresenham
// midpoint. r == 0 plots a single pixel.
void jlDrawCircle(jlSurfaceT *s, int16_t cx, int16_t cy, uint16_t r, uint8_t colorIndex);
// Fill a disk of radius r centered at (cx, cy). r == 0 plots a single
// pixel. Spans are emitted per scanline using midpoint symmetry.
void jlFillCircle(jlSurfaceT *s, int16_t cx, int16_t cy, uint16_t r, uint8_t colorIndex);
// Flood fill a 4-connected region starting at (x, y). Replaces every
// pixel of the original color reached via N/S/E/W steps. No-op if
// (x, y) is off-surface or already matches newColor.
void jlFloodFill(jlSurfaceT *s, int16_t x, int16_t y, uint8_t newColor);
// Flood fill a 4-connected region starting at (x, y), stopping at
// boundary pixels of color boundaryColor. Replaces every reachable
// pixel that is not boundaryColor with newColor. Used for vector-art
// rendering (e.g. Sierra-style picture playback): outline a closed
// region with jlDrawLine in boundaryColor, then fill with this.
void jlFloodFillBounded(jlSurfaceT *s, int16_t x, int16_t y, uint8_t newColor, uint8_t boundaryColor);
#endif