Merge pull request #8376 from RayKoopa/fix_stylebox_expand_margin
Respect the expand margin for StyleBoxTextures again.
This commit is contained in:
commit
c88f56be64
3 changed files with 33 additions and 33 deletions
|
@ -36,6 +36,8 @@
|
||||||
#include "editor/editor_node.h"
|
#include "editor/editor_node.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// WindowDialog
|
||||||
|
|
||||||
void WindowDialog::_post_popup() {
|
void WindowDialog::_post_popup() {
|
||||||
|
|
||||||
drag_type = DRAG_NONE; // just in case
|
drag_type = DRAG_NONE; // just in case
|
||||||
|
@ -51,11 +53,11 @@ void WindowDialog::_fix_size() {
|
||||||
Size2i viewport_size = get_viewport_rect().size;
|
Size2i viewport_size = get_viewport_rect().size;
|
||||||
|
|
||||||
// Windows require additional padding to keep the window chrome visible.
|
// Windows require additional padding to keep the window chrome visible.
|
||||||
Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
|
Ref<StyleBoxTexture> panel = get_stylebox("panel", "WindowDialog");
|
||||||
float top = panel->get_margin(MARGIN_TOP);
|
float top = panel->get_expand_margin_size(MARGIN_TOP);
|
||||||
float left = panel->get_margin(MARGIN_LEFT);
|
float left = panel->get_expand_margin_size(MARGIN_LEFT);
|
||||||
float bottom = panel->get_margin(MARGIN_BOTTOM);
|
float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM);
|
||||||
float right = panel->get_margin(MARGIN_RIGHT);
|
float right = panel->get_expand_margin_size(MARGIN_RIGHT);
|
||||||
|
|
||||||
pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right));
|
pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right));
|
||||||
pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom));
|
pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom));
|
||||||
|
@ -74,9 +76,9 @@ bool WindowDialog::has_point(const Point2 &p_point) const {
|
||||||
Rect2 r(Point2(), get_size());
|
Rect2 r(Point2(), get_size());
|
||||||
|
|
||||||
// Enlarge upwards for title bar.
|
// Enlarge upwards for title bar.
|
||||||
int titlebar_height = get_constant("titlebar_height", "WindowDialog");
|
int title_height = get_constant("title_height", "WindowDialog");
|
||||||
r.pos.y -= titlebar_height;
|
r.pos.y -= title_height;
|
||||||
r.size.y += titlebar_height;
|
r.size.y += title_height;
|
||||||
|
|
||||||
// Inflate by the resizable border thickness.
|
// Inflate by the resizable border thickness.
|
||||||
if (resizable) {
|
if (resizable) {
|
||||||
|
@ -173,30 +175,21 @@ void WindowDialog::_notification(int p_what) {
|
||||||
|
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
|
|
||||||
RID canvas = get_canvas_item();
|
RID canvas = get_canvas_item();
|
||||||
Size2 size = get_size();
|
|
||||||
|
|
||||||
|
// Draw the background.
|
||||||
Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
|
Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
|
||||||
int margin_left = static_cast<int>(panel->get_margin(MARGIN_LEFT));
|
Size2 size = get_size();
|
||||||
int margin_top = static_cast<int>(panel->get_margin(MARGIN_TOP));
|
panel->draw(canvas, Rect2(0, 0, size.x, size.y));
|
||||||
int margin_right = static_cast<int>(panel->get_margin(MARGIN_RIGHT));
|
|
||||||
int margin_bottom = static_cast<int>(panel->get_margin(MARGIN_BOTTOM));
|
|
||||||
|
|
||||||
Rect2 rect;
|
// Draw the title bar text.
|
||||||
rect.pos.x = -margin_left;
|
Ref<Font> title_font = get_font("title_font", "WindowDialog");
|
||||||
rect.pos.y = -margin_top;
|
|
||||||
rect.size.width = size.width + margin_left + margin_right;
|
|
||||||
rect.size.height = size.height + margin_top + margin_bottom;
|
|
||||||
|
|
||||||
panel->draw(canvas, rect);
|
|
||||||
|
|
||||||
int title_height = get_constant("title_height", "WindowDialog");
|
|
||||||
Color title_color = get_color("title_color", "WindowDialog");
|
Color title_color = get_color("title_color", "WindowDialog");
|
||||||
Ref<Font> font = get_font("title_font", "WindowDialog");
|
int title_height = get_constant("title_height", "WindowDialog");
|
||||||
int ofs = (size.width - font->get_string_size(title).width) / 2;
|
int font_height = title_font->get_height() - title_font->get_descent() * 2;
|
||||||
draw_string(font, Point2(ofs, -title_height + font->get_ascent()), title, title_color, size.width - panel->get_minimum_size().width);
|
int x = (size.x - title_font->get_string_size(title).x) / 2;
|
||||||
|
int y = (-title_height + font_height) / 2;
|
||||||
|
title_font->draw(canvas, Point2(x, y), title, title_color, size.x - panel->get_minimum_size().x);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_THEME_CHANGED:
|
case NOTIFICATION_THEME_CHANGED:
|
||||||
|
@ -238,12 +231,12 @@ int WindowDialog::_drag_hit_test(const Point2 &pos) const {
|
||||||
int drag_type = DRAG_NONE;
|
int drag_type = DRAG_NONE;
|
||||||
|
|
||||||
if (resizable) {
|
if (resizable) {
|
||||||
int titlebar_height = get_constant("titlebar_height", "WindowDialog");
|
int title_height = get_constant("title_height", "WindowDialog");
|
||||||
int scaleborder_size = get_constant("scaleborder_size", "WindowDialog");
|
int scaleborder_size = get_constant("scaleborder_size", "WindowDialog");
|
||||||
|
|
||||||
Rect2 rect = get_rect();
|
Rect2 rect = get_rect();
|
||||||
|
|
||||||
if (pos.y < (-titlebar_height + scaleborder_size))
|
if (pos.y < (-title_height + scaleborder_size))
|
||||||
drag_type = DRAG_RESIZE_TOP;
|
drag_type = DRAG_RESIZE_TOP;
|
||||||
else if (pos.y >= (rect.size.height - scaleborder_size))
|
else if (pos.y >= (rect.size.height - scaleborder_size))
|
||||||
drag_type = DRAG_RESIZE_BOTTOM;
|
drag_type = DRAG_RESIZE_BOTTOM;
|
||||||
|
@ -317,6 +310,8 @@ WindowDialog::WindowDialog() {
|
||||||
WindowDialog::~WindowDialog() {
|
WindowDialog::~WindowDialog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PopupDialog
|
||||||
|
|
||||||
void PopupDialog::_notification(int p_what) {
|
void PopupDialog::_notification(int p_what) {
|
||||||
|
|
||||||
if (p_what == NOTIFICATION_DRAW) {
|
if (p_what == NOTIFICATION_DRAW) {
|
||||||
|
@ -554,6 +549,8 @@ AcceptDialog::AcceptDialog() {
|
||||||
AcceptDialog::~AcceptDialog() {
|
AcceptDialog::~AcceptDialog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfirmationDialog
|
||||||
|
|
||||||
void ConfirmationDialog::_bind_methods() {
|
void ConfirmationDialog::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_cancel:Button"), &ConfirmationDialog::get_cancel);
|
ClassDB::bind_method(D_METHOD("get_cancel:Button"), &ConfirmationDialog::get_cancel);
|
||||||
|
|
|
@ -532,10 +532,8 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
|
||||||
|
|
||||||
// WindowDialog
|
// WindowDialog
|
||||||
|
|
||||||
Ref<StyleBoxTexture> style_pp_win = sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6);
|
t->set_stylebox("panel", "WindowDialog", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6));
|
||||||
t->set_stylebox("panel", "WindowDialog", style_pp_win);
|
t->set_constant("scaleborder_size", "WindowDialog", 4 * scale);
|
||||||
t->set_constant("titlebar_height", "WindowDialog", 20 * scale);
|
|
||||||
t->set_constant("scaleborder_size", "WindowDialog", 4);
|
|
||||||
|
|
||||||
t->set_font("title_font", "WindowDialog", large_font);
|
t->set_font("title_font", "WindowDialog", large_font);
|
||||||
t->set_color("title_color", "WindowDialog", Color(0, 0, 0));
|
t->set_color("title_color", "WindowDialog", Color(0, 0, 0));
|
||||||
|
|
|
@ -138,6 +138,11 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
|
||||||
|
|
||||||
texture->get_rect_region(rect, src_rect, rect, src_rect);
|
texture->get_rect_region(rect, src_rect, rect, src_rect);
|
||||||
|
|
||||||
|
rect.pos.x -= expand_margin[MARGIN_LEFT];
|
||||||
|
rect.pos.y -= expand_margin[MARGIN_TOP];
|
||||||
|
rect.size.x += expand_margin[MARGIN_LEFT] + expand_margin[MARGIN_RIGHT];
|
||||||
|
rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM];
|
||||||
|
|
||||||
VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate);
|
VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue