[draw] add ax_graphics in geom/graphics.h
This commit is contained in:
parent
7ff4794df7
commit
a53264e4fc
|
@ -0,0 +1,40 @@
|
|||
#include "graphics.h"
|
||||
#include "../util/region.h"
|
||||
|
||||
static size_t INITIAL_CAP = 32;
|
||||
|
||||
struct ax_graphics* ax__graphics_new(struct rgn* dst_rgn)
|
||||
{
|
||||
struct ax_graphics* gr =
|
||||
ralloc_typed(dst_rgn, struct ax_graphics, 1);
|
||||
gr->rgn = rgn_new(dst_rgn, MEDIUM);
|
||||
gr->glyphs.siz = 0;
|
||||
gr->glyphs.cap = 0;
|
||||
ax__graphics_clear(gr, 0x000000);
|
||||
return gr;
|
||||
}
|
||||
|
||||
struct ax_glyph* ax__graphics_push(struct ax_graphics* gr)
|
||||
{
|
||||
if (gr->glyphs.siz >= gr->glyphs.cap) {
|
||||
size_t new_cap = gr->glyphs.cap * 2;
|
||||
struct ax_glyph* new_data =
|
||||
ralloc_typed(gr->rgn, struct ax_glyph, new_cap);
|
||||
memcpy(new_data, gr->glyphs.data, gr->glyphs.siz * sizeof(struct ax_glyph));
|
||||
gr->glyphs.cap = new_cap;
|
||||
gr->glyphs.data = new_data;
|
||||
}
|
||||
return &gr->glyphs.data[gr->glyphs.siz++];
|
||||
}
|
||||
|
||||
void ax__graphics_clear(struct ax_graphics* gr, uint64_t bg)
|
||||
{
|
||||
size_t cap = (gr->glyphs.siz > (INITIAL_CAP / 2))
|
||||
? (gr->glyphs.cap * 2)
|
||||
: INITIAL_CAP;
|
||||
rgn_clear(gr->rgn);
|
||||
gr->bg = bg;
|
||||
gr->glyphs.siz = 0;
|
||||
gr->glyphs.cap = cap;
|
||||
gr->glyphs.data = ralloc_typed(gr->rgn, struct ax_glyph, cap);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
[glyph (AX_GLYPH_RECT "rect")]
|
|
@ -0,0 +1,50 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct rgn;
|
||||
|
||||
enum ax_glyph_type {
|
||||
AX_GLYPH_RECT = 0,
|
||||
AX_GLYPH__COUNT,
|
||||
};
|
||||
|
||||
struct ax_glyph_rect {
|
||||
int32_t x, y;
|
||||
uint32_t w, h;
|
||||
uint64_t f;
|
||||
};
|
||||
|
||||
struct ax_glyph {
|
||||
enum ax_glyph_type ty;
|
||||
union {
|
||||
struct ax_glyph_rect rect;
|
||||
} d;
|
||||
};
|
||||
|
||||
struct ax_graphics {
|
||||
struct rgn* rgn;
|
||||
|
||||
uint64_t bg;
|
||||
struct {
|
||||
size_t siz, cap;
|
||||
struct ax_glyph* data;
|
||||
} glyphs;
|
||||
};
|
||||
|
||||
struct ax_graphics* ax__graphics_new(struct rgn* dst_rgn);
|
||||
void ax__graphics_clear(struct ax_graphics* gr, uint64_t bg);
|
||||
|
||||
struct ax_glyph* ax__graphics_push(struct ax_graphics* gr);
|
||||
|
||||
static inline
|
||||
size_t ax__graphics_glyph_count(const struct ax_graphics* gr) {
|
||||
return gr->glyphs.siz;
|
||||
}
|
||||
|
||||
static inline
|
||||
const struct ax_glyph* ax__graphics_glyph(const struct ax_graphics* gr,
|
||||
size_t i) {
|
||||
return &gr->glyphs.data[i];
|
||||
}
|
Loading…
Reference in New Issue