8#ifndef __LIBDRAGON_GRAPHICS_H
9#define __LIBDRAGON_GRAPHICS_H
53typedef struct __attribute__((packed))
66_Static_assert(
sizeof(
color_t) == 4,
"invalid sizeof for color_t");
70#define RGBA16(rx, gx, bx, ax) \
71 (__builtin_constant_p(rx) && \
72 __builtin_constant_p(gx) && \
73 __builtin_constant_p(bx) && \
74 __builtin_constant_p(ax) ? \
76 .r = ((rx) << 3) | ((rx) >> 3), \
77 .g = ((gx) << 3) | ((gx) >> 3), \
78 .b = ((bx) << 3) | ((bx) >> 3), \
79 .a = (ax) ? 0xFF : 0 \
87 .r = (_r << 3) | (_r >> 3), \
88 .g = (_g << 3) | (_g >> 3), \
89 .b = (_b << 3) | (_b >> 3), \
96#define RGBA32(rx,gx,bx,ax) ((color_t){.r=rx, .g=gx, .b=bx, .a=ax})
100 return (((
int)c.
r >> 3) << 11) | (((int)c.
g >> 3) << 6) | (((
int)c.
b >> 3) << 1) | (c.
a >> 7);
105 return *(uint32_t*)&c;
109 int r = (c >> 11) & 0x1F;
110 int g = (c >> 6) & 0x1F;
111 int b = (c >> 1) & 0x1F;
112 return (
color_t){ .
r=(uint8_t)((r << 3) | (r >> 2)), .g=(uint8_t)((g << 3) | (g >> 2)), .b=(uint8_t)((b << 3) | (b >> 2)), .a=(uint8_t)((c&0x1) ? 0xFF : 0) };
117 return (
color_t){ .
r=(uint8_t)(c>>24), .g=(uint8_t)(c>>16), .b=(uint8_t)(c>>8), .a=(uint8_t)c };
uint8_t a
Alpha component.
Definition graphics.h:62
uint8_t g
Green component.
Definition graphics.h:58
uint8_t b
Blue component.
Definition graphics.h:60
uint8_t r
Red component.
Definition graphics.h:56
color_t color_from_packed32(uint32_t c)
Create a color_t from the 32-bit packed format used by a FMT_RGBA32 surface (RGBA 8888)
Definition graphics.h:116
void graphics_draw_pixel(surface_t *surf, int x, int y, uint32_t color)
Draw a pixel to a given display context.
Definition graphics.c:146
void graphics_draw_line(surface_t *surf, int x0, int y0, int x1, int y1, uint32_t color)
Draw a line to a given display context.
Definition graphics.c:211
void graphics_draw_line_trans(surface_t *surf, int x0, int y0, int x1, int y1, uint32_t color)
Draw a line to a given display context with alpha support.
Definition graphics.c:269
void graphics_draw_sprite_trans_stride(surface_t *surf, int x, int y, sprite_t *sprite, int offset)
Draw a sprite from a spritemap to a display context.
Definition graphics.c:752
void graphics_set_font_sprite(sprite_t *font)
Set the current font. Should be set before using any of the draw function.
Definition graphics.c:440
void graphics_draw_pixel_trans(surface_t *surf, int x, int y, uint32_t color)
Draw a pixel to a given display context with alpha support.
Definition graphics.c:163
color_t color_from_packed16(uint16_t c)
Create a color_t from the 16-bit packed format used by a FMT_RGBA16 surface (RGBA 5551)
Definition graphics.h:108
void graphics_set_default_font(void)
Set the font to the default.
Definition graphics.c:433
void graphics_draw_box_trans(surface_t *surf, int x, int y, int width, int height, uint32_t color)
Draw a filled rectangle to a display context.
Definition graphics.c:358
uint32_t color_to_packed32(color_t c)
Convert a color_t to the 32-bit packed format used by a FMT_RGBA32 surface (RGBA 8888)
Definition graphics.h:104
void graphics_draw_sprite(surface_t *surf, int x, int y, sprite_t *sprite)
Draw a sprite to a display context.
Definition graphics.c:631
void graphics_fill_screen(surface_t *surf, uint32_t c)
Fill the entire screen with a particular color.
Definition graphics.c:421
void graphics_draw_sprite_trans(surface_t *surf, int x, int y, sprite_t *sprite)
Draw a sprite to a display context with alpha transparency.
Definition graphics.c:746
void graphics_draw_box(surface_t *surf, int x, int y, int width, int height, uint32_t color)
Draw a filled rectangle to a display context.
Definition graphics.c:327
uint16_t color_to_packed16(color_t c)
Convert a color_t to the 16-bit packed format used by a FMT_RGBA16 surface (RGBA 5551)
Definition graphics.h:99
uint32_t graphics_make_color(int r, int g, int b, int a)
Return a packed 32-bit representation of an RGBA color.
Definition graphics.c:87
void graphics_set_color(uint32_t forecolor, uint32_t backcolor)
Set the current forecolor and backcolor for text operations.
Definition graphics.c:113
uint32_t graphics_convert_color(color_t color)
Convert a color structure to a 32-bit representation of an RGBA color.
Definition graphics.c:99
void graphics_draw_character(surface_t *surf, int x, int y, char ch)
Draw a character to the screen using the built-in font.
Definition graphics.c:447
void graphics_draw_text(surface_t *surf, int x, int y, const char *const msg)
Draw a null terminated string to a display context.
Definition graphics.c:597
void graphics_draw_sprite_stride(surface_t *surf, int x, int y, sprite_t *sprite, int offset)
Draw a sprite from a spritemap to a display context.
Definition graphics.c:637
Generic color structure.
Definition graphics.h:54
Sprite structure.
Definition sprite.h:42
A surface buffer for graphics.
Definition surface.h:140