crocparty/sys/sys_graphics.h

201 lines
4.6 KiB
C
Raw Permalink Normal View History

2024-02-26 01:54:57 +00:00
// Corresponds roughly to section 6.2 of the Pico 8 manual
//
// However, all ranges are now half-open.
//
// https://www.lexaloffle.com/dl/docs/pico-8_manual.html
//
#ifndef CROCPARTY_SYS_GRAPHICS_H
#define CROCPARTY_SYS_GRAPHICS_H
#include <stdbool.h>
#include <stdint.h>
#include "sys_data.h"
/**
* Set the clipping rectangle in pixels.
*
* All drawing operations will be clipped to this rectangle.
*/
void sys_clip_set(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1);
/**
* Reset the clipping rectangle.
*/
void sys_clip_reset();
2024-02-26 01:54:57 +00:00
/**
* Set the clipping rectangle in pixels.
*
* This is the same as `sys_clip_set`, but you can pass clip_previous in order
* to clip to the previous region.
*/
void sys_clip_set_ext(
sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1,
bool clip_previous
);
/**
* Set the color of the pixel `(x, y)`.
*/
void sys_pixel_set(
sys_i32 x, sys_i32 y,
sys_color c
);
/**
* Get the color of the pixel `(x, y)`.
*
* Returns SYS_COLOR_TRANSPARENT if the pixel is out of bounds.
2024-02-26 01:54:57 +00:00
*/
sys_color sys_pixel_get(
sys_i32 x, sys_i32 y
);
// TODO: SSET/SGET
// TODO: FGET/FSET
2024-02-29 04:48:22 +00:00
/**
* Output the dimensions of the text (x and y)
*/
void sys_measure_text(const char* str, sys_i32* x, sys_i32* y);
2024-02-26 20:42:07 +00:00
/**
* Print a string `str` in the color `col`
*/
2024-02-29 04:48:22 +00:00
void sys_print(const char* str, sys_i32 x, sys_i32 y, sys_color col);
2024-02-26 01:54:57 +00:00
// TODO: CURSOR? COLOR?
/**
* Fill the entire screen with color `c`.
*/
void sys_cls(sys_color c);
/**
* Create a screen offset of `(-x, -y)` for all drawing operations.
*/
void sys_camera_set(sys_i32 x, sys_i32 y);
/**
* Reset the camera's offset to `(0, 0)`.
*/
void sys_camera_reset();
/**
* Draw or fill a circle at `(x, y)` with radius `r`.
*
2024-02-26 06:10:21 +00:00
* The circle is centered at the center of the pixel, not at the junction
* between pixels.
2024-02-26 01:54:57 +00:00
*
* If r is negative, the circle is not drawn.
*
* This is a special case of sys_oval_draw_ext.
2024-02-26 01:54:57 +00:00
*/
void sys_circ_draw(sys_i32 x, sys_i32 y, sys_i32 r, sys_color c);
2024-02-26 20:42:07 +00:00
void sys_circ_fill(sys_i32 x, sys_i32 y, sys_i32 r, sys_color c);
2024-02-26 06:10:21 +00:00
void sys_circ_draw_ext(sys_i32 x, sys_i32 y, sys_i32 r, sys_color c, bool fill);
2024-02-26 01:54:57 +00:00
/**
* Draw or fill an oval in the rectangle from `(x0, y0)` to `(x1, y1)`
*/
void sys_oval_draw(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1, sys_color c);
void sys_oval_fill(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1, sys_color c);
2024-02-26 06:10:21 +00:00
void sys_oval_draw_ext(
sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1, sys_color c, bool fill
);
2024-02-26 01:54:57 +00:00
/**
* Draw a line from x0 to y0.
2024-02-26 06:23:43 +00:00
*
* The point `(x1, y1)` is not drawn. (because the line is a half-open interval)
2024-02-26 01:54:57 +00:00
*/
void sys_line_draw(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1, sys_color c);
/**
* Draw or fill a rectangle `(x, y, w, h)`
*/
void sys_rect_draw(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1, sys_color c);
void sys_rect_fill(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1, sys_color c);
2024-02-26 06:10:21 +00:00
void sys_rect_draw_ext(
sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1, sys_color c, bool fill
);
2024-02-26 01:54:57 +00:00
/**
* Set screen palette.
*
* After calling this function, virtual color `c0` will be rendered as
* real color `rc1`.
*/
void sys_spal_set(sys_color c0, sys_screen_color rc1);
2024-02-26 01:54:57 +00:00
/**
* Reset screen palette.
*
* After calling this function, all screen colors are (0, 0, 0).
*/
void sys_spal_reset();
/**
* Set draw palette.
*
* After calling this function, draws using color `c0` will be performed
* using color `c1` instead.
*
* Any color mapped to `SYS_COLOR_TRANSPARENT` will not actually be drawn.
2024-02-26 01:54:57 +00:00
*/
void sys_dpal_set(sys_color c0, sys_color c1);
2024-02-26 01:54:57 +00:00
/**
* Reset draw palette.
*
* All colors are mapped to themselves. SYS_COLOR_TRANSPARENT is transparent.
2024-02-26 01:54:57 +00:00
*/
void sys_dpal_reset();
/**
* Draw a given sprite.
*
* w, h default to 1.
* flip_x and flip_y default to false.
*/
void sys_sprite_draw(
sys_spritesheet spritesheet,
sys_i32 n,
sys_i32 x, sys_i32 y
);
void sys_sprite_draw_ext(
sys_spritesheet spritesheet,
sys_i32 n,
sys_i32 x, sys_i32 y,
sys_i32 w, sys_i32 h,
bool flip_x, bool flip_y
);
2024-02-26 01:54:57 +00:00
// TODO: SSPR
// TODO: FILLP?
2024-02-27 04:19:22 +00:00
void sys_map_draw(
// NOTE: not the same order of args
// as on pico 8
// but: more consistent!
sys_map map,
sys_spritesheet spritesheet,
sys_i32 sx, sys_i32 sy,
sys_i32 tile_x, sys_i32 tile_y,
sys_i32 tile_w, sys_i32 tile_h
// TODO: Layers?
);
2024-02-26 01:54:57 +00:00
2024-02-28 05:49:20 +00:00
/**
* Get a single map tile, putting whether the coords were invalid into
* flag_invalid.
*
* (flag_invalid may be null)
*/
sys_maptile sys_map_get(
sys_map map,
sys_i32 tile_x, sys_i32 tile_y,
bool* flag_invalid
);
2024-02-26 01:54:57 +00:00
#endif // CROCPARTY_SYS_GRAPHICS_H