return rects_overlap(
camera_rect(
camera,
- sprite_font_boundary_box(position, size, strlen(text))),
+ sprite_font_boundary_box(position, size, text)),
rect_from_sdl(&view_port));
}
sprite_font_boundary_box(
position,
LABELS_SIZE,
- strlen(texts + i * LABEL_LAYER_TEXT_MAX_SIZE)),
+ texts + i * LABEL_LAYER_TEXT_MAX_SIZE),
sprite_font_boundary_box(
vec_sum(
position,
vec(0.0f, FONT_CHAR_HEIGHT),
LABELS_SIZE)),
vec(1.0f, 1.0f),
- strlen(ids + i * LABEL_LAYER_ID_MAX_SIZE)));
+ ids + i * LABEL_LAYER_ID_MAX_SIZE));
}
int label_layer_render(const LabelLayer *label_layer,
sprite_font_boundary_box(
current_position,
LEVEL_PICKER_LIST_FONT_SCALE,
- strlen(item_text)));
+ item_text));
if (SDL_SetRenderDrawColor(camera->renderer, 255, 255, 255, 255) < 0) {
return -1;
}
Rect boundary_box = sprite_font_boundary_box(
vec(0.0f, 0.0f),
LEVEL_PICKER_LIST_FONT_SCALE,
- strlen(item_text));
+ item_text);
result.x = fmaxf(result.x, boundary_box.w);
result.y += boundary_box.y + LEVEL_PICKER_LIST_PADDING_BOTTOM;
Rect boundary_box = sprite_font_boundary_box(
position,
LEVEL_PICKER_LIST_FONT_SCALE,
- strlen(item_text));
+ item_text);
if (rect_contains_point(boundary_box, mouse_pos)) {
level_picker->cursor = i;
Rect boundary_box = sprite_font_boundary_box(
position,
LEVEL_PICKER_LIST_FONT_SCALE,
- strlen(item_text));
+ item_text);
const Vec2f mouse_pos = vec((float) event->motion.x, (float) event->motion.y);
if (rect_contains_point(boundary_box, mouse_pos)) {
const char *text);
static inline
-Rect sprite_font_boundary_box(Vec2f position, Vec2f size, size_t text_size)
+Rect sprite_font_boundary_box(Vec2f position, Vec2f size, const char *text)
{
+ size_t num_max_col = 1, num_row = 1;
+ for (size_t i = 0, num_col = 1; text[i] != '\0'; i++){
+ if (text[i] == '\n'){
+ num_col = 1;
+ num_row++;
+ continue;
+ }
+ if (num_col > num_max_col)
+ num_max_col = num_col;
+ num_col++;
+ }
return rect(
position.x, position.y,
- size.x * FONT_CHAR_WIDTH * (float) text_size,
- size.y * FONT_CHAR_HEIGHT);
+ size.x * FONT_CHAR_WIDTH * (float) num_max_col,
+ size.y * FONT_CHAR_HEIGHT * (float) num_row);
}
#endif // SPRITE_FONT_H_
const Rect boundary = sprite_font_boundary_box(
vec(0.0f, 0.0f),
wiggly_text->scale,
- strlen(wiggly_text->text));
+ wiggly_text->text);
return vec(boundary.w, boundary.h);
}