|
|
|
@ -16,17 +16,14 @@ namespace guecs { |
|
|
|
text = make_shared<::Text>(); |
|
|
|
text = make_shared<::Text>(); |
|
|
|
text->font_size = size; |
|
|
|
text->font_size = size; |
|
|
|
text->load_font(); |
|
|
|
text->load_font(); |
|
|
|
|
|
|
|
|
|
|
|
if(centered || cell.center) { |
|
|
|
|
|
|
|
// WRONG! Need the scale here...
|
|
|
|
|
|
|
|
auto& ch = text->characters.at('H'); |
|
|
|
auto& ch = text->characters.at('H'); |
|
|
|
|
|
|
|
|
|
|
|
auto text_cell = lel::center(ch.size.x, ch.size.y, cell); |
|
|
|
if(centered || cell.center) { |
|
|
|
|
|
|
|
// BUG: this doesn't center, but need to render the whole text then center it
|
|
|
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
|
|
|
// BUG: lel::center doesn't do what I think it does
|
|
|
|
position = {float(text_cell.x), float(text_cell.y) - text_cell.h / 2}; |
|
|
|
position = {float(cell.x + padding * 2), cell.mid_y + ch.size.y / 2}; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
position = {float(cell.x + padding * 2), float(cell.y + padding * 2)}; |
|
|
|
position = {float(cell.x + padding * 2), float(cell.y + ch.size.y + padding * 2)}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -55,27 +52,24 @@ namespace guecs { |
|
|
|
|
|
|
|
|
|
|
|
// setup the image size and such
|
|
|
|
// setup the image size and such
|
|
|
|
glm::vec2 bounds{image->width, image->height}; // get this from the image
|
|
|
|
glm::vec2 bounds{image->width, image->height}; // get this from the image
|
|
|
|
|
|
|
|
|
|
|
|
if(stretch) { |
|
|
|
|
|
|
|
// handle stretch
|
|
|
|
|
|
|
|
// glm::vec2 bounds{cell.w, cell.h}; // get this from the image
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
float box_width = float(cell.w - padding * 2); |
|
|
|
float box_width = float(cell.w - padding * 2); |
|
|
|
float box_height = float(cell.h - padding * 2); |
|
|
|
float box_height = float(cell.h - padding * 2); |
|
|
|
float scale = std::min(box_width / float(bounds.x), box_height / float(bounds.y)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// no stretch so scale it
|
|
|
|
|
|
|
|
image->scale.x = (bounds.x / float(WINDOW_WIDTH)) * scale; |
|
|
|
|
|
|
|
image->scale.y = (bounds.y / float(WINDOW_HEIGHT)) * scale; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// find center point of cell since origin of image is center (for now)
|
|
|
|
// find center point of cell since origin of image is center (for now)
|
|
|
|
|
|
|
|
// BUG: lel::center doesn't work here, why?
|
|
|
|
image->position.x = (cell.x + box_width / 2); |
|
|
|
image->position.x = (cell.x + box_width / 2); |
|
|
|
image->position.y = (cell.y + box_height / 2); |
|
|
|
image->position.y = (cell.y + box_height / 2); |
|
|
|
|
|
|
|
|
|
|
|
fmt::println("pos: {},{} | bounds: {},{} | box: {},{} | scale: {}", |
|
|
|
if(stretch) { |
|
|
|
image->position.x, image->position.y, bounds.x, bounds.y, box_width, box_height, scale); |
|
|
|
// handle stretch, but should use OpenGL image texture stretch options
|
|
|
|
|
|
|
|
image->scale.x = (box_width / float(WINDOW_WIDTH)); |
|
|
|
|
|
|
|
image->scale.y = (box_height / float(WINDOW_HEIGHT)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// no stretch so scale it
|
|
|
|
|
|
|
|
float scale = std::min(box_width / float(bounds.x), box_height / float(bounds.y)); |
|
|
|
|
|
|
|
image->scale.x = (bounds.x / float(WINDOW_WIDTH)) * scale; |
|
|
|
|
|
|
|
image->scale.y = (bounds.y / float(WINDOW_HEIGHT)) * scale; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// used the center helper here
|
|
|
|
// used the center helper here
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -87,7 +81,10 @@ namespace guecs { |
|
|
|
void Rectangle::init(lel::Cell& cell) { |
|
|
|
void Rectangle::init(lel::Cell& cell) { |
|
|
|
shape = make_shared<Rect>( |
|
|
|
shape = make_shared<Rect>( |
|
|
|
float(cell.x), float(cell.y), |
|
|
|
float(cell.x), float(cell.y), |
|
|
|
float(cell.w) - padding * 2.0f, float(cell.h) - padding * 2.0f); |
|
|
|
float(cell.w) - padding * 2.0f, |
|
|
|
|
|
|
|
float(cell.h) - padding * 2.0f, |
|
|
|
|
|
|
|
color.to_vec4()); |
|
|
|
|
|
|
|
|
|
|
|
shape->init(); |
|
|
|
shape->init(); |
|
|
|
|
|
|
|
|
|
|
|
update(); |
|
|
|
update(); |
|
|
|
|