add the long awaited push_9slice

This commit is contained in:
2024-10-02 14:18:07 -03:00
parent 452ecd72fe
commit dbbf6e25f0
3 changed files with 144 additions and 1 deletions

View File

@ -50,6 +50,147 @@ void push_rectangle(Rect rect, Color color) {
}
void push_9slice(char *texture_path, int texture_w, int texture_h, int border_thickness, Rect rect, Color color) {
const float bt = (float)border_thickness; /* i know! */
const float bt2 = bt * 2; /* combined size of the two borders in an axis */
Rect top_left = {
.x = rect.x,
.y = rect.y,
.w = bt,
.h = bt,
};
m_sprite(
m_set(path, texture_path),
m_set(rect, top_left),
m_opt(texture_region, ((Rect) { 0, 0, bt, bt })),
m_opt(color, color),
);
Rect top_center = {
.x = rect.x + bt,
.y = rect.y,
.w = rect.w - bt2, /* here bt2 represents the top left and right corners */
.h = bt,
};
m_sprite(
m_set(path, texture_path),
m_set(rect, top_center),
m_opt(texture_region, ((Rect) { bt, 0, (float)texture_w - bt2, bt })),
m_opt(color, color),
);
Rect top_right = {
.x = rect.x + (rect.w - bt),
.y = rect.y,
.w = bt,
.h = bt,
};
m_sprite(
m_set(path, texture_path),
m_set(rect, top_right),
m_opt(texture_region, ((Rect) { (float)texture_w - bt, 0, bt, bt })),
m_opt(color, color),
);
Rect center_left = {
.x = rect.x,
.y = rect.y + bt,
.w = bt,
.h = rect.h - bt2, /* here bt2 represents the top and bottom left corners */
};
m_sprite(
m_set(path, texture_path),
m_set(rect, center_left),
m_opt(texture_region, ((Rect) { 0, bt, bt, (float)texture_h - bt2 })),
m_opt(color, color),
);
Rect center_right = {
.x = rect.x + (rect.w - bt),
.y = rect.y + bt,
.w = bt,
.h = rect.h - bt2, /* here bt2 represents the top and bottom right corners */
};
m_sprite(
m_set(path, texture_path),
m_set(rect, center_right),
m_opt(texture_region, ((Rect) { (float)texture_w - bt, bt, bt, (float)texture_h - bt2 })),
m_opt(color, color),
);
Rect bottom_left = {
.x = rect.x,
.y = rect.y + (rect.h - bt),
.w = bt,
.h = bt,
};
m_sprite(
m_set(path, texture_path),
m_set(rect, bottom_left),
m_opt(texture_region, ((Rect) { 0, (float)texture_h - bt, bt, bt })),
m_opt(color, color),
);
Rect bottom_center = {
.x = rect.x + bt,
.y = rect.y + (rect.h - bt),
.w = rect.w - bt2, /* here bt2 represents the bottom left and right corners */
.h = bt,
};
m_sprite(
m_set(path, texture_path),
m_set(rect, bottom_center),
m_opt(texture_region, ((Rect) { bt, (float)texture_h - bt, (float)texture_w - bt2, bt })),
m_opt(color, color),
);
Rect bottom_right = {
.x = rect.x + (rect.w - bt),
.y = rect.y + (rect.h - bt),
.w = bt,
.h = bt,
};
m_sprite(
m_set(path, texture_path),
m_set(rect, bottom_right),
m_opt(texture_region, ((Rect) { (float)texture_w - bt, (float)texture_h - bt, bt, bt })),
m_opt(color, color),
);
Rect center = {
.x = rect.x + bt,
.y = rect.y + bt,
.w = rect.w - bt2,
.h = rect.h - bt2,
};
m_sprite(
m_set(path, texture_path),
m_set(rect, center),
m_opt(texture_region, ((Rect) { bt, bt, (float)texture_w - bt2, (float)texture_h - bt2 })),
m_opt(color, color),
);
}
static void render_2d(void) {
use_2d_pipeline();