diff --git a/apps/scenery/scenes/title.c b/apps/scenery/scenes/title.c index fb0f67f..7014b07 100644 --- a/apps/scenery/scenes/title.c +++ b/apps/scenery/scenes/title.c @@ -24,7 +24,7 @@ static void title_tick(State *state) { char *text_str = cmalloc(text_str_len); snprintf(text_str, text_str_len, "%lu", state->ctx->tick_count); - const char *font = "fonts/kenney-pixel.ttf"; + const char *font = "/fonts/kenney-pixel.ttf"; int text_h = 32; int text_w = text_get_width(text_str, text_h, font); diff --git a/include/twn_rendering.h b/include/twn_rendering.h index d15ed9d..6a64322 100644 --- a/include/twn_rendering.h +++ b/include/twn_rendering.h @@ -38,6 +38,8 @@ TWN_API void push_circle(Vec2 position, float radius, Color color); TWN_API void push_text(char *string, Vec2 position, int height_px, Color color, const char *font_path); TWN_API int text_get_width(char *string, int height_px, const char *font_path); +TWN_API void push_9slice(char *texture_path, int texture_w, int texture_h, int border_thickness, Rect rect, Color color); + /* pushes a textured 3d triangle onto the render queue */ /* vertices are in absolute coordinates, relative to world origin */ /* texture coordinates are in pixels */ diff --git a/src/rendering/twn_rendering.c b/src/rendering/twn_rendering.c index 9031df5..6408a9a 100644 --- a/src/rendering/twn_rendering.c +++ b/src/rendering/twn_rendering.c @@ -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();