122 lines
3.7 KiB
C
122 lines
3.7 KiB
C
#ifndef DRAW_H
|
|
#define DRAW_H
|
|
|
|
#include "gp.h"
|
|
|
|
struct font;
|
|
struct font_startup_receipt;
|
|
|
|
struct draw_startup_receipt { i32 _; };
|
|
struct draw_startup_receipt draw_startup(struct font_startup_receipt *font_sr);
|
|
|
|
/* ========================== *
|
|
* Texture
|
|
* ========================== */
|
|
|
|
#define DRAW_TEXTURE_PARAMS(...) ((struct draw_texture_params) { \
|
|
.tint = COLOR_WHITE, \
|
|
.clip = CLIP_ALL, \
|
|
__VA_ARGS__ \
|
|
})
|
|
|
|
struct draw_texture_params {
|
|
struct xform xf;
|
|
struct gp_resource *texture; /* Overrides sprite if set */
|
|
struct sprite_tag sprite;
|
|
struct clip_rect clip;
|
|
u32 tint;
|
|
f32 emittance;
|
|
};
|
|
|
|
void draw_texture(struct gp_flow *flow, struct draw_texture_params params);
|
|
|
|
/* ========================== *
|
|
* Fill shapes
|
|
* ========================== */
|
|
|
|
void draw_poly_ex(struct gp_flow *flow, struct v2_array vertices, struct gp_indices indices, u32 color);
|
|
|
|
void draw_poly(struct gp_flow *flow, struct v2_array points, u32 color);
|
|
|
|
void draw_circle(struct gp_flow *flow, struct v2 pos, f32 radius, u32 color, u32 detail);
|
|
|
|
void draw_quad(struct gp_flow *flow, struct quad quad, u32 color);
|
|
|
|
/* ========================== *
|
|
* Line shapes
|
|
* ========================== */
|
|
|
|
void draw_gradient_line(struct gp_flow *flow, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
|
|
|
|
void draw_line(struct gp_flow *flow, struct v2 start, struct v2 end, f32 thickness, u32 color);
|
|
|
|
void draw_ray(struct gp_flow *flow, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
|
|
|
|
void draw_poly_line(struct gp_flow *flow, struct v2_array points, b32 loop, f32 thickness, u32 color);
|
|
|
|
void draw_circle_line(struct gp_flow *flow, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
|
|
|
|
void draw_quad_line(struct gp_flow *flow, struct quad quad, f32 thickness, u32 color);
|
|
|
|
void draw_arrow_line(struct gp_flow *flow, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color);
|
|
|
|
void draw_arrow_ray(struct gp_flow *flow, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
|
|
|
|
void draw_collider_line(struct gp_flow *flow, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
|
|
|
/* ========================== *
|
|
* Grid
|
|
* ========================== */
|
|
|
|
void draw_grid(struct gp_flow *flow, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset);
|
|
|
|
/* ========================== *
|
|
* Text
|
|
* ========================== */
|
|
|
|
#define DRAW_TEXT_PARAMS(...) ((struct draw_text_params) { \
|
|
.scale = 1.0, \
|
|
.alignment = DRAW_TEXT_ALIGNMENT_LEFT, \
|
|
.offset_x = DRAW_TEXT_OFFSET_X_LEFT, \
|
|
.offset_y = DRAW_TEXT_OFFSET_Y_TOP, \
|
|
.color = COLOR_WHITE, \
|
|
__VA_ARGS__ \
|
|
})
|
|
|
|
/* How is text aligned within its area */
|
|
enum draw_text_alignment {
|
|
DRAW_TEXT_ALIGNMENT_LEFT, /* Default */
|
|
DRAW_TEXT_ALIGNMENT_CENTER,
|
|
DRAW_TEXT_ALIGNMENT_RIGHT
|
|
};
|
|
|
|
/* How does the specified text position relate to the text area.
|
|
* E.g. BOTTOM & RIGHT means the bottom-right of the text area will snap to
|
|
* the specified position. */
|
|
enum draw_text_offset_x {
|
|
DRAW_TEXT_OFFSET_X_LEFT, /* Default */
|
|
DRAW_TEXT_OFFSET_X_CENTER,
|
|
DRAW_TEXT_OFFSET_X_RIGHT
|
|
};
|
|
|
|
enum draw_text_offset_y {
|
|
DRAW_TEXT_OFFSET_Y_TOP, /* Default */
|
|
DRAW_TEXT_OFFSET_Y_CENTER,
|
|
DRAW_TEXT_OFFSET_Y_BOTTOM
|
|
};
|
|
|
|
struct draw_text_params {
|
|
struct font *font;
|
|
struct v2 pos;
|
|
f32 scale;
|
|
u32 color;
|
|
enum draw_text_alignment alignment;
|
|
enum draw_text_offset_x offset_x;
|
|
enum draw_text_offset_y offset_y;
|
|
struct string str;
|
|
};
|
|
|
|
struct rect draw_text(struct gp_flow *flow, struct draw_text_params params);
|
|
|
|
#endif
|