yet another api rework, removal of integer types in public api, optionals at the end, some cleaning
This commit is contained in:
@ -36,8 +36,8 @@ void render_queue_clear(void) {
|
||||
}
|
||||
|
||||
|
||||
void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int border_thickness, Rect rect, Color color) {
|
||||
const float bt = (float)border_thickness; /* i know! */
|
||||
void draw_nine_slice(const char *texture, Vec2 corners, Rect rect, float border_thickness, Color color) {
|
||||
const float bt = border_thickness;
|
||||
const float bt2 = bt * 2; /* combined size of the two borders in an axis */
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, top_left),
|
||||
m_opt(texture_region, ((Rect) { 0, 0, bt, bt })),
|
||||
m_opt(color, color),
|
||||
@ -64,9 +64,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, top_center),
|
||||
m_opt(texture_region, ((Rect) { bt, 0, (float)texture_w - bt2, bt })),
|
||||
m_opt(texture_region, ((Rect) { bt, 0, corners.x - bt2, bt })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
|
||||
@ -79,9 +79,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, top_right),
|
||||
m_opt(texture_region, ((Rect) { (float)texture_w - bt, 0, bt, bt })),
|
||||
m_opt(texture_region, ((Rect) { corners.x - bt, 0, bt, bt })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
|
||||
@ -94,9 +94,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, center_left),
|
||||
m_opt(texture_region, ((Rect) { 0, bt, bt, (float)texture_h - bt2 })),
|
||||
m_opt(texture_region, ((Rect) { 0, bt, bt, corners.y - bt2 })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
|
||||
@ -109,9 +109,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, center_right),
|
||||
m_opt(texture_region, ((Rect) { (float)texture_w - bt, bt, bt, (float)texture_h - bt2 })),
|
||||
m_opt(texture_region, ((Rect) { corners.x - bt, bt, bt, corners.y - bt2 })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
|
||||
@ -124,9 +124,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, bottom_left),
|
||||
m_opt(texture_region, ((Rect) { 0, (float)texture_h - bt, bt, bt })),
|
||||
m_opt(texture_region, ((Rect) { 0, corners.y - bt, bt, bt })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
|
||||
@ -139,9 +139,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, bottom_center),
|
||||
m_opt(texture_region, ((Rect) { bt, (float)texture_h - bt, (float)texture_w - bt2, bt })),
|
||||
m_opt(texture_region, ((Rect) { bt, corners.y - bt, corners.x - bt2, bt })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
|
||||
@ -154,9 +154,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, bottom_right),
|
||||
m_opt(texture_region, ((Rect) { (float)texture_w - bt, (float)texture_h - bt, bt, bt })),
|
||||
m_opt(texture_region, ((Rect) { corners.x - bt, corners.y - bt, bt, bt })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
|
||||
@ -169,9 +169,9 @@ void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int
|
||||
};
|
||||
|
||||
m_sprite(
|
||||
m_set(path, texture_path),
|
||||
m_set(texture, texture),
|
||||
m_set(rect, center),
|
||||
m_opt(texture_region, ((Rect) { bt, bt, (float)texture_w - bt2, (float)texture_h - bt2 })),
|
||||
m_opt(texture_region, ((Rect) { bt, bt, corners.x - bt2, corners.y - bt2 })),
|
||||
m_opt(color, color),
|
||||
);
|
||||
}
|
||||
@ -358,18 +358,18 @@ void render(void) {
|
||||
float ratio = (float)ctx.window_dims.y / (float)ctx.base_render_height;
|
||||
int w = (int)((float)ctx.base_render_width * ratio);
|
||||
setup_viewport(
|
||||
ctx.window_dims.x / 2 - w / 2,
|
||||
(int)ctx.window_dims.x / 2 - w / 2,
|
||||
0,
|
||||
w,
|
||||
ctx.window_dims.y
|
||||
(int)ctx.window_dims.y
|
||||
);
|
||||
} else {
|
||||
float ratio = (float)ctx.window_dims.x / (float)ctx.base_render_width;
|
||||
int h = (int)((float)ctx.base_render_height * ratio);
|
||||
setup_viewport(
|
||||
0,
|
||||
ctx.window_dims.y / 2 - h / 2,
|
||||
ctx.window_dims.x,
|
||||
(int)ctx.window_dims.y / 2 - h / 2,
|
||||
(int)ctx.window_dims.x,
|
||||
h
|
||||
);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ void draw_sprite_args(const DrawSpriteArgs args) {
|
||||
bool const stretch = m_or(args, stretch, false);
|
||||
Rect const *texture_region = m_is_set(args, texture_region) ? &args.texture_region_opt : NULL;
|
||||
|
||||
draw_sprite(args.path, args.rect, texture_region, color, rotation, flip_x, flip_y, stretch);
|
||||
draw_sprite(args.texture, args.rect, texture_region, color, rotation, flip_x, flip_y, stretch);
|
||||
}
|
||||
|
||||
|
||||
@ -216,7 +216,7 @@ void render_sprite_batch(const Primitive2D primitives[],
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
const Vec2 c = center_rect(sprite.rect);
|
||||
const Vec2 c = rect_center(sprite.rect);
|
||||
const Vec2 t = fast_cossine(sprite.rotation + (float)M_PI_4);
|
||||
const Vec2 d = {
|
||||
.x = t.x * sprite.rect.w * (float)M_SQRT1_2,
|
||||
@ -231,7 +231,7 @@ void render_sprite_batch(const Primitive2D primitives[],
|
||||
} else {
|
||||
/* rotated non-square case*/
|
||||
|
||||
const Vec2 c = center_rect(sprite.rect);
|
||||
const Vec2 c = rect_center(sprite.rect);
|
||||
const Vec2 t = fast_cossine(sprite.rotation);
|
||||
|
||||
const Vec2 h = { sprite.rect.w / 2, sprite.rect.h / 2 };
|
||||
|
@ -275,8 +275,8 @@ void text_cache_reset_arena(TextCache *cache) {
|
||||
}
|
||||
|
||||
|
||||
void draw_text(const char *string, Vec2 position, int height_px, Color color, const char *font_path) {
|
||||
ensure_font_cache(font_path, height_px);
|
||||
void draw_text(const char *string, Vec2 position, float height, Color color, const char *font) {
|
||||
ensure_font_cache(font, (int)height);
|
||||
|
||||
/* the original string might not be around by the time it's used, so copy it */
|
||||
size_t str_length = SDL_strlen(string) + 1;
|
||||
@ -290,8 +290,8 @@ void draw_text(const char *string, Vec2 position, int height_px, Color color, co
|
||||
.color = color,
|
||||
.position = position,
|
||||
.text = dup_string,
|
||||
.font = font_path,
|
||||
.height_px = height_px,
|
||||
.font = font,
|
||||
.height_px = (int)height,
|
||||
};
|
||||
|
||||
Primitive2D primitive = {
|
||||
@ -303,9 +303,9 @@ void draw_text(const char *string, Vec2 position, int height_px, Color color, co
|
||||
}
|
||||
|
||||
|
||||
int draw_text_width(const char *string, int height_px, const char *font_path) {
|
||||
ensure_font_cache(font_path, height_px);
|
||||
FontData *font_data = get_font_data(font_path, height_px);
|
||||
float draw_text_width(const char *string, float height, const char *font) {
|
||||
ensure_font_cache(font, (int)height);
|
||||
FontData *font_data = get_font_data(font, (int)height);
|
||||
|
||||
int length = 0;
|
||||
for (const char *p = string; *p != '\0'; ++p) {
|
||||
@ -316,5 +316,5 @@ int draw_text_width(const char *string, int height_px, const char *font_path) {
|
||||
length += advance_width;
|
||||
}
|
||||
|
||||
return (int)((float)length * font_data->scale_factor);
|
||||
return (float)length * font_data->scale_factor;
|
||||
}
|
||||
|
Reference in New Issue
Block a user