diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-11-07 08:46:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 08:46:25 +0100 |
commit | 19d8e36c8e167fb1b27a35ded1245883b97e6541 (patch) | |
tree | 5c6752428b5512a987b7c86bf4419e2025427430 /editor/plugins | |
parent | c4f3b94abf7954d293b847a3a01ef86c8bba4444 (diff) | |
parent | 3de53c8312b45a5511721d1e4f794e8d73f2db8b (diff) |
Merge pull request #68331 from MewPurPur/gradient2d-better-preview
Fix GradientTexture2D's preview
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/gradient_texture_2d_editor_plugin.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/editor/plugins/gradient_texture_2d_editor_plugin.cpp b/editor/plugins/gradient_texture_2d_editor_plugin.cpp index dc01a52bb3..561dca4fc6 100644 --- a/editor/plugins/gradient_texture_2d_editor_plugin.cpp +++ b/editor/plugins/gradient_texture_2d_editor_plugin.cpp @@ -121,13 +121,12 @@ void GradientTexture2DEditorRect::_notification(int p_what) { Size2 rect_size = get_size(); // Get the size and position to draw the texture and handles at. - size = Size2(texture->get_width() * rect_size.height / texture->get_height(), rect_size.height); - if (size.width > rect_size.width) { - size.width = rect_size.width; - size.height = texture->get_height() * size.width / texture->get_width(); - } - offset = ((rect_size - size + handle_size) / 2).round(); - size -= handle_size; + // Subtract handle sizes so they stay inside the preview, but keep the texture's aspect ratio. + Size2 available_size = rect_size - handle_size; + Size2 ratio = available_size / texture->get_size(); + size = MIN(ratio.x, ratio.y) * texture->get_size(); + offset = ((rect_size - size) / 2).round(); + checkerboard->set_rect(Rect2(offset, size)); draw_set_transform(offset); @@ -180,8 +179,9 @@ GradientTexture2DEditorRect::GradientTexture2DEditorRect() { checkerboard = memnew(TextureRect); checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE); + checkerboard->set_ignore_texture_size(true); checkerboard->set_draw_behind_parent(true); - add_child(checkerboard); + add_child(checkerboard, false, INTERNAL_MODE_FRONT); set_custom_minimum_size(Size2(0, 250 * EDSCALE)); } |