Fix some random issues
This commit is contained in:
parent
f6ace83729
commit
9651c88ffe
@ -38,6 +38,10 @@ Rect::Rect(float x, float y, float width, float height) :
|
||||
m_size(width, height)
|
||||
{}
|
||||
|
||||
Rect Rect::constrained(const glm::vec2& pos, const glm::vec2& size) const {
|
||||
return Rect(std::min(m_pos.x, pos.x), std::min(m_pos.y, pos.y), std::min(m_size.x, size.x), std::min(m_size.y, size.y));
|
||||
Rect Rect::constrained(const Rect& other) const {
|
||||
const float x = std::min(std::max(m_pos.x, other.get_x()), other.get_right());
|
||||
const float y = std::min(std::max(m_pos.y, other.get_y()), other.get_bottom());
|
||||
const float width = std::min(x+m_size.x, other.get_right())-x;
|
||||
const float height = std::min(x+m_size.y, other.get_bottom())-y;
|
||||
return Rect(x, y, width, height);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace polygun::math {
|
||||
Rect(float x, float y, float width, float height);
|
||||
~Rect() = default;
|
||||
|
||||
Rect constrained(const glm::vec2& pos, const glm::vec2& size) const;
|
||||
Rect constrained(const Rect& other) const;
|
||||
|
||||
float get_x() const { return m_pos.x; }
|
||||
float get_y() const { return m_pos.y; }
|
||||
|
@ -102,8 +102,8 @@ void TextEdit::render(renderer::GUIRenderer* renderer) {
|
||||
renderer->fill_rect(glm::vec2(get_x(), get_y()), glm::vec2(width, height), add_to_color(Style::get().m_background_color, glm::vec4ub(100, 100, 100, 0)));
|
||||
renderer->fill_rect(glm::vec2(get_x()+extrusion, get_y()+extrusion), glm::vec2(width, height), subtract_from_color(Style::get().m_background_color, glm::vec4ub(30, 30, 30, 0)));
|
||||
renderer->fill_rect(glm::vec2(get_x()+extrusion, get_y()+extrusion), glm::vec2(width-extrusion, height-extrusion), Style::get().m_lower_background_color);
|
||||
renderer->render_cropped_texture(glm::vec2(get_x()+3, get_y()+(height-m_text_texture->get_height())/2), m_text_texture, glm::vec2(1, 1),
|
||||
math::Rect(m_text_offset, 0, width-2, m_text_texture->get_height()));
|
||||
renderer->render_cropped_texture(glm::vec2(get_x()+3, get_y()+height-m_text_texture->get_height()-3), m_text_texture, glm::vec2(1, 1),
|
||||
math::Rect(m_text_offset, 0, width-2, m_text_texture->get_height()*2));
|
||||
if(m_render_cursor)
|
||||
renderer->fill_rect(glm::vec2(get_x()+3+m_cursor_x, get_y()+1), glm::vec2(2, height-3), glm::vec4ub(0, 0, 0, 255));
|
||||
|
||||
@ -231,7 +231,7 @@ void TextEdit::on_style_change() {
|
||||
|
||||
void TextEdit::update_text_texture() {
|
||||
m_glyph_info.clear();
|
||||
Style::get().m_font.render_glyphs(m_text_buffer.empty()?" ":m_text_buffer, 16, Style::get().m_text_color, m_glyph_info);
|
||||
Style::get().m_font.render_glyphs(m_text_buffer.empty()?" ":m_text_buffer, 17, Style::get().m_text_color, m_glyph_info);
|
||||
std::unique_ptr<renderer::Surface> surf = Style::get().m_font.render_text(m_glyph_info);
|
||||
m_text_texture->load_from_surface(*surf);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void GLGUIRenderer::render_cropped_texture(const glm::vec2& pos, Texture* textur
|
||||
|
||||
const glm::vec2 texture_size(glm::vec2(texture->get_width(), texture->get_height()));
|
||||
mesh_renderer->translate(pos);
|
||||
mesh_renderer->scale(scale * crop_rect.constrained(texture_size, texture_size).get_size());
|
||||
mesh_renderer->scale(scale * crop_rect.constrained(math::Rect(glm::vec2(0, 0), texture_size)).get_size());
|
||||
mesh_renderer->rotate(glm::vec2(1, 0), angle);
|
||||
crop_uvs(crop_rect, texture_size);
|
||||
mesh_renderer->render_textured(m_rect_mesh, texture);
|
||||
|
@ -89,16 +89,16 @@ void GUIRenderer::fill_rect(const glm::vec2& pos, const glm::vec2& size, const g
|
||||
}
|
||||
|
||||
void GUIRenderer::crop_uvs(const math::Rect& crop_rect, const glm::vec2& texture_size) {
|
||||
math::Rect constrained_rect = crop_rect.constrained(texture_size, texture_size);
|
||||
math::Rect constrained_rect = crop_rect.constrained(math::Rect(glm::vec2(0, 0), texture_size));
|
||||
const float texture_left = constrained_rect.get_x()/texture_size.x;
|
||||
const float texture_right = constrained_rect.get_right()/texture_size.x;
|
||||
const float texture_top = 1.0f-constrained_rect.get_y()/texture_size.y;
|
||||
const float texture_bottom = 1.0f-constrained_rect.get_bottom()/texture_size.y;
|
||||
const float texture_top = constrained_rect.get_y()/texture_size.y;
|
||||
const float texture_bottom = constrained_rect.get_bottom()/texture_size.y;
|
||||
const std::vector<float> uvs = {
|
||||
texture_left, texture_top,
|
||||
texture_left, texture_bottom,
|
||||
texture_right, texture_bottom,
|
||||
texture_right, texture_top
|
||||
texture_left, texture_top,
|
||||
texture_right, texture_top,
|
||||
texture_right, texture_bottom
|
||||
};
|
||||
m_rect_mesh->load_from_memory(rect_vertices, rect_indices, uvs);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ void LegacyGLGUIRenderer::render_cropped_texture(const glm::vec2& pos, Texture*
|
||||
|
||||
const glm::vec2 texture_size(glm::vec2(texture->get_width(), texture->get_height()));
|
||||
mesh_renderer->translate(pos);
|
||||
mesh_renderer->scale(scale * crop_rect.constrained(texture_size, texture_size).get_size());
|
||||
mesh_renderer->scale(scale * crop_rect.constrained(math::Rect(glm::vec2(0, 0), texture_size)).get_size());
|
||||
mesh_renderer->rotate(glm::vec2(1, 0), angle);
|
||||
crop_uvs(crop_rect, texture_size);
|
||||
mesh_renderer->render_textured(m_rect_mesh, texture);
|
||||
|
Loading…
x
Reference in New Issue
Block a user