2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* style_box.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2021-01-02 03:13:46 +08:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 07:50:27 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
#include "style_box.h"
|
2020-03-27 15:44:44 +08:00
|
|
|
|
|
|
|
#include "scene/main/canvas_item.h"
|
2019-01-24 21:21:56 +08:00
|
|
|
|
2017-06-11 15:28:59 +08:00
|
|
|
#include <limits.h>
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const {
|
2014-02-10 09:10:30 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
void StyleBox::set_default_margin(Side p_side, float p_value) {
|
|
|
|
ERR_FAIL_INDEX((int)p_side, 4);
|
2019-10-10 17:48:58 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
margin[p_side] = p_value;
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBox::get_default_margin(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
|
2019-10-10 17:48:58 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
return margin[p_side];
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBox::get_margin(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
|
2019-10-10 17:48:58 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
if (margin[p_side] < 0) {
|
|
|
|
return get_style_margin(p_side);
|
2020-05-14 22:41:43 +08:00
|
|
|
} else {
|
2020-12-23 00:24:29 +08:00
|
|
|
return margin[p_side];
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2019-01-24 21:21:56 +08:00
|
|
|
CanvasItem *StyleBox::get_current_item_drawn() const {
|
|
|
|
return CanvasItem::get_current_item_drawn();
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Size2 StyleBox::get_minimum_size() const {
|
2020-12-23 00:24:29 +08:00
|
|
|
return Size2(get_margin(SIDE_LEFT) + get_margin(SIDE_RIGHT), get_margin(SIDE_TOP) + get_margin(SIDE_BOTTOM));
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Point2 StyleBox::get_offset() const {
|
2020-12-23 00:24:29 +08:00
|
|
|
return Point2(get_margin(SIDE_LEFT), get_margin(SIDE_TOP));
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Size2 StyleBox::get_center_size() const {
|
|
|
|
return Size2();
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:26:30 +08:00
|
|
|
Rect2 StyleBox::get_draw_rect(const Rect2 &p_rect) const {
|
|
|
|
return p_rect;
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
void StyleBox::_bind_methods() {
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("test_mask", "point", "rect"), &StyleBox::test_mask);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_default_margin", "margin", "offset"), &StyleBox::set_default_margin);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_default_margin", "margin"), &StyleBox::get_default_margin);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-02-13 19:47:24 +08:00
|
|
|
//ClassDB::bind_method(D_METHOD("set_default_margin"),&StyleBox::set_default_margin);
|
|
|
|
//ClassDB::bind_method(D_METHOD("get_default_margin"),&StyleBox::get_default_margin);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_margin", "margin"), &StyleBox::get_margin);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_minimum_size"), &StyleBox::get_minimum_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_center_size"), &StyleBox::get_center_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_offset"), &StyleBox::get_offset);
|
2019-01-24 21:21:56 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_current_item_drawn"), &StyleBox::get_current_item_drawn);
|
2015-02-11 10:53:04 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("draw", "canvas_item", "rect"), &StyleBox::draw);
|
2015-02-11 10:53:04 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_GROUP("Content Margin", "content_margin_");
|
2020-12-23 00:24:29 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_left", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_right", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_top", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_TOP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_bottom", PROPERTY_HINT_RANGE, "-1,2048,1"), "set_default_margin", "get_default_margin", SIDE_BOTTOM);
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StyleBox::StyleBox() {
|
2017-03-05 23:44:50 +08:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
margin[i] = -1;
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 02:43:37 +08:00
|
|
|
void StyleBoxTexture::set_texture(Ref<Texture2D> p_texture) {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (texture == p_texture) {
|
2016-06-20 09:16:41 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2017-03-05 23:44:50 +08:00
|
|
|
texture = p_texture;
|
2018-04-27 17:22:42 +08:00
|
|
|
if (p_texture.is_null()) {
|
|
|
|
region_rect = Rect2(0, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
region_rect = Rect2(Point2(), texture->get_size());
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2017-03-31 09:09:25 +08:00
|
|
|
|
2019-06-12 02:43:37 +08:00
|
|
|
Ref<Texture2D> StyleBoxTexture::get_texture() const {
|
2014-02-10 09:10:30 +08:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
void StyleBoxTexture::set_margin_size(Side p_side, float p_size) {
|
|
|
|
ERR_FAIL_INDEX((int)p_side, 4);
|
2018-05-18 05:02:16 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
margin[p_side] = p_size;
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBoxTexture::get_margin_size(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
|
2019-10-10 17:48:58 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
return margin[p_side];
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBoxTexture::get_style_margin(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
|
2019-10-10 17:48:58 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
return margin[p_side];
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2019-11-24 23:26:30 +08:00
|
|
|
Rect2 StyleBoxTexture::get_draw_rect(const Rect2 &p_rect) const {
|
2020-12-23 00:24:29 +08:00
|
|
|
return p_rect.grow_individual(expand_margin[SIDE_LEFT], expand_margin[SIDE_TOP], expand_margin[SIDE_RIGHT], expand_margin[SIDE_BOTTOM]);
|
2019-11-24 23:26:30 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (texture.is_null()) {
|
2014-02-10 09:10:30 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-31 09:09:25 +08:00
|
|
|
Rect2 rect = p_rect;
|
|
|
|
Rect2 src_rect = region_rect;
|
2017-03-31 11:35:57 +08:00
|
|
|
|
2017-03-31 09:09:25 +08:00
|
|
|
texture->get_rect_region(rect, src_rect, rect, src_rect);
|
2017-03-31 11:35:57 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
rect.position.x -= expand_margin[SIDE_LEFT];
|
|
|
|
rect.position.y -= expand_margin[SIDE_TOP];
|
|
|
|
rect.size.x += expand_margin[SIDE_LEFT] + expand_margin[SIDE_RIGHT];
|
|
|
|
rect.size.y += expand_margin[SIDE_TOP] + expand_margin[SIDE_BOTTOM];
|
2017-04-12 21:11:44 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[SIDE_LEFT], margin[SIDE_TOP]), Vector2(margin[SIDE_RIGHT], margin[SIDE_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate);
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 21:11:10 +08:00
|
|
|
void StyleBoxTexture::set_draw_center(bool p_enabled) {
|
|
|
|
draw_center = p_enabled;
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-08-31 21:11:10 +08:00
|
|
|
bool StyleBoxTexture::is_draw_center_enabled() const {
|
2014-02-10 09:10:30 +08:00
|
|
|
return draw_center;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size2 StyleBoxTexture::get_center_size() const {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (texture.is_null()) {
|
2014-02-10 09:10:30 +08:00
|
|
|
return Size2();
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2018-03-29 01:52:55 +08:00
|
|
|
return region_rect.size - get_minimum_size();
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
void StyleBoxTexture::set_expand_margin_size(Side p_side, float p_size) {
|
|
|
|
ERR_FAIL_INDEX((int)p_side, 4);
|
|
|
|
expand_margin[p_side] = p_size;
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-08-22 05:07:08 +08:00
|
|
|
void StyleBoxTexture::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) {
|
2020-12-23 00:24:29 +08:00
|
|
|
expand_margin[SIDE_LEFT] = p_left;
|
|
|
|
expand_margin[SIDE_TOP] = p_top;
|
|
|
|
expand_margin[SIDE_RIGHT] = p_right;
|
|
|
|
expand_margin[SIDE_BOTTOM] = p_bottom;
|
2017-08-22 05:07:08 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxTexture::set_expand_margin_size_all(float p_expand_margin_size) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
expand_margin[i] = p_expand_margin_size;
|
|
|
|
}
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBoxTexture::get_expand_margin_size(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0);
|
|
|
|
return expand_margin[p_side];
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void StyleBoxTexture::set_region_rect(const Rect2 &p_region_rect) {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (region_rect == p_region_rect) {
|
2016-06-05 00:40:53 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2016-06-05 00:40:53 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
region_rect = p_region_rect;
|
2016-06-05 00:40:53 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 StyleBoxTexture::get_region_rect() const {
|
|
|
|
return region_rect;
|
|
|
|
}
|
|
|
|
|
2017-08-12 09:13:19 +08:00
|
|
|
void StyleBoxTexture::set_h_axis_stretch_mode(AxisStretchMode p_mode) {
|
2019-10-10 17:48:58 +08:00
|
|
|
ERR_FAIL_INDEX((int)p_mode, 3);
|
2017-08-12 09:13:19 +08:00
|
|
|
axis_h = p_mode;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleBoxTexture::AxisStretchMode StyleBoxTexture::get_h_axis_stretch_mode() const {
|
|
|
|
return axis_h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxTexture::set_v_axis_stretch_mode(AxisStretchMode p_mode) {
|
2019-10-10 17:48:58 +08:00
|
|
|
ERR_FAIL_INDEX((int)p_mode, 3);
|
2017-08-12 09:13:19 +08:00
|
|
|
axis_v = p_mode;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleBoxTexture::AxisStretchMode StyleBoxTexture::get_v_axis_stretch_mode() const {
|
|
|
|
return axis_v;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void StyleBoxTexture::set_modulate(const Color &p_modulate) {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (modulate == p_modulate) {
|
2016-08-06 09:46:45 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2017-03-05 23:44:50 +08:00
|
|
|
modulate = p_modulate;
|
2016-08-06 09:46:45 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Color StyleBoxTexture::get_modulate() const {
|
|
|
|
return modulate;
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
void StyleBoxTexture::_bind_methods() {
|
2017-08-09 19:19:41 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &StyleBoxTexture::set_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture"), &StyleBoxTexture::get_texture);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_margin_size", "margin", "size"), &StyleBoxTexture::set_margin_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_margin_size", "margin"), &StyleBoxTexture::get_margin_size);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_expand_margin_size", "margin", "size"), &StyleBoxTexture::set_expand_margin_size);
|
2017-08-23 04:11:41 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxTexture::set_expand_margin_size_all);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_expand_margin_individual", "size_left", "size_top", "size_right", "size_bottom"), &StyleBoxTexture::set_expand_margin_size_individual);
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_expand_margin_size", "margin"), &StyleBoxTexture::get_expand_margin_size);
|
2016-06-05 00:40:53 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_region_rect", "region"), &StyleBoxTexture::set_region_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_region_rect"), &StyleBoxTexture::get_region_rect);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_draw_center", "enable"), &StyleBoxTexture::set_draw_center);
|
2017-08-31 21:11:10 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("is_draw_center_enabled"), &StyleBoxTexture::is_draw_center_enabled);
|
2016-08-06 09:46:45 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_modulate", "color"), &StyleBoxTexture::set_modulate);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_modulate"), &StyleBoxTexture::get_modulate);
|
2016-08-06 09:46:45 +08:00
|
|
|
|
2017-08-12 09:13:19 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_h_axis_stretch_mode", "mode"), &StyleBoxTexture::set_h_axis_stretch_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_h_axis_stretch_mode"), &StyleBoxTexture::get_h_axis_stretch_mode);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_v_axis_stretch_mode", "mode"), &StyleBoxTexture::set_v_axis_stretch_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_v_axis_stretch_mode"), &StyleBoxTexture::get_v_axis_stretch_mode);
|
|
|
|
|
2019-06-12 02:43:37 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
|
2018-11-08 22:30:02 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_GROUP("Margin", "margin_");
|
2020-12-23 00:24:29 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_TOP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", SIDE_BOTTOM);
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_GROUP("Expand Margin", "expand_margin_");
|
2020-12-23 00:24:29 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_TOP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", SIDE_BOTTOM);
|
2017-08-12 09:13:19 +08:00
|
|
|
ADD_GROUP("Axis Stretch", "axis_stretch_");
|
2018-11-08 22:30:02 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_stretch_horizontal", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_h_axis_stretch_mode", "get_h_axis_stretch_mode");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_stretch_vertical", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_v_axis_stretch_mode", "get_v_axis_stretch_mode");
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_GROUP("Modulate", "modulate_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate_color"), "set_modulate", "get_modulate");
|
2017-08-31 21:11:10 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_center"), "set_draw_center", "is_draw_center_enabled");
|
2017-08-12 09:13:19 +08:00
|
|
|
|
2017-08-20 23:45:01 +08:00
|
|
|
BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_STRETCH);
|
|
|
|
BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_TILE);
|
|
|
|
BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_TILE_FIT);
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2021-02-10 01:24:36 +08:00
|
|
|
StyleBoxTexture::StyleBoxTexture() {}
|
2017-08-12 09:13:19 +08:00
|
|
|
|
2021-02-10 01:24:36 +08:00
|
|
|
StyleBoxTexture::~StyleBoxTexture() {}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void StyleBoxFlat::set_bg_color(const Color &p_color) {
|
|
|
|
bg_color = p_color;
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
Color StyleBoxFlat::get_bg_color() const {
|
|
|
|
return bg_color;
|
|
|
|
}
|
|
|
|
|
2019-03-19 17:32:13 +08:00
|
|
|
void StyleBoxFlat::set_border_color(const Color &p_color) {
|
|
|
|
border_color = p_color;
|
2017-06-11 02:29:21 +08:00
|
|
|
emit_changed();
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2019-03-19 17:32:13 +08:00
|
|
|
Color StyleBoxFlat::get_border_color() const {
|
|
|
|
return border_color;
|
2017-06-11 02:29:21 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
void StyleBoxFlat::set_border_width_all(int p_size) {
|
|
|
|
border_width[0] = p_size;
|
|
|
|
border_width[1] = p_size;
|
|
|
|
border_width[2] = p_size;
|
|
|
|
border_width[3] = p_size;
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
int StyleBoxFlat::get_border_width_min() const {
|
|
|
|
return MIN(MIN(border_width[0], border_width[1]), MIN(border_width[2], border_width[3]));
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
void StyleBoxFlat::set_border_width(Side p_side, int p_width) {
|
|
|
|
ERR_FAIL_INDEX((int)p_side, 4);
|
|
|
|
border_width[p_side] = p_width;
|
2017-05-03 04:13:12 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
int StyleBoxFlat::get_border_width(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0);
|
|
|
|
return border_width[p_side];
|
2017-05-03 04:13:12 +08:00
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
void StyleBoxFlat::set_border_blend(bool p_blend) {
|
2017-06-11 02:29:21 +08:00
|
|
|
blend_border = p_blend;
|
2014-02-10 09:10:30 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
bool StyleBoxFlat::get_border_blend() const {
|
2017-06-11 02:29:21 +08:00
|
|
|
return blend_border;
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
void StyleBoxFlat::set_corner_radius_all(int radius) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
corner_radius[i] = radius;
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-01-18 11:19:07 +08:00
|
|
|
void StyleBoxFlat::set_corner_radius_individual(const int radius_top_left, const int radius_top_right, const int radius_bottom_right, const int radius_bottom_left) {
|
2017-06-11 02:29:21 +08:00
|
|
|
corner_radius[0] = radius_top_left;
|
|
|
|
corner_radius[1] = radius_top_right;
|
2021-01-18 11:19:07 +08:00
|
|
|
corner_radius[2] = radius_bottom_right;
|
2017-06-11 02:29:21 +08:00
|
|
|
corner_radius[3] = radius_bottom_left;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
void StyleBoxFlat::set_corner_radius(const Corner p_corner, const int radius) {
|
2019-10-10 17:48:58 +08:00
|
|
|
ERR_FAIL_INDEX((int)p_corner, 4);
|
2017-06-11 02:50:01 +08:00
|
|
|
corner_radius[p_corner] = radius;
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
int StyleBoxFlat::get_corner_radius(const Corner p_corner) const {
|
2019-10-10 17:48:58 +08:00
|
|
|
ERR_FAIL_INDEX_V((int)p_corner, 4, 0);
|
2017-06-11 02:50:01 +08:00
|
|
|
return corner_radius[p_corner];
|
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
void StyleBoxFlat::set_expand_margin_size(Side p_side, float p_size) {
|
|
|
|
ERR_FAIL_INDEX((int)p_side, 4);
|
|
|
|
expand_margin[p_side] = p_size;
|
2017-06-11 02:29:21 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2017-08-22 05:07:08 +08:00
|
|
|
|
|
|
|
void StyleBoxFlat::set_expand_margin_size_individual(float p_left, float p_top, float p_right, float p_bottom) {
|
2020-12-23 00:24:29 +08:00
|
|
|
expand_margin[SIDE_LEFT] = p_left;
|
|
|
|
expand_margin[SIDE_TOP] = p_top;
|
|
|
|
expand_margin[SIDE_RIGHT] = p_right;
|
|
|
|
expand_margin[SIDE_BOTTOM] = p_bottom;
|
2017-08-22 05:07:08 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxFlat::set_expand_margin_size_all(float p_expand_margin_size) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
expand_margin[i] = p_expand_margin_size;
|
|
|
|
}
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBoxFlat::get_expand_margin_size(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
|
|
|
|
return expand_margin[p_side];
|
2017-06-11 02:29:21 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-08-31 21:11:10 +08:00
|
|
|
void StyleBoxFlat::set_draw_center(bool p_enabled) {
|
|
|
|
draw_center = p_enabled;
|
2017-06-11 02:29:21 +08:00
|
|
|
emit_changed();
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-08-31 21:11:10 +08:00
|
|
|
bool StyleBoxFlat::is_draw_center_enabled() const {
|
|
|
|
return draw_center;
|
2017-06-11 02:29:21 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
void StyleBoxFlat::set_shadow_color(const Color &p_color) {
|
|
|
|
shadow_color = p_color;
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
Color StyleBoxFlat::get_shadow_color() const {
|
|
|
|
return shadow_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxFlat::set_shadow_size(const int &p_size) {
|
|
|
|
shadow_size = p_size;
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
int StyleBoxFlat::get_shadow_size() const {
|
|
|
|
return shadow_size;
|
|
|
|
}
|
|
|
|
|
2019-03-05 04:35:29 +08:00
|
|
|
void StyleBoxFlat::set_shadow_offset(const Point2 &p_offset) {
|
|
|
|
shadow_offset = p_offset;
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2019-03-05 04:35:29 +08:00
|
|
|
Point2 StyleBoxFlat::get_shadow_offset() const {
|
|
|
|
return shadow_offset;
|
|
|
|
}
|
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
void StyleBoxFlat::set_anti_aliased(const bool &p_anti_aliased) {
|
|
|
|
anti_aliased = p_anti_aliased;
|
|
|
|
emit_changed();
|
2021-03-04 07:51:35 +08:00
|
|
|
notify_property_list_changed();
|
2017-06-11 02:50:01 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
bool StyleBoxFlat::is_anti_aliased() const {
|
|
|
|
return anti_aliased;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxFlat::set_aa_size(const int &p_aa_size) {
|
2017-08-19 21:12:46 +08:00
|
|
|
aa_size = CLAMP(p_aa_size, 1, 5);
|
2017-06-11 02:50:01 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
int StyleBoxFlat::get_aa_size() const {
|
|
|
|
return aa_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxFlat::set_corner_detail(const int &p_corner_detail) {
|
2019-12-15 06:35:01 +08:00
|
|
|
corner_detail = CLAMP(p_corner_detail, 1, 20);
|
2017-06-11 02:50:01 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
int StyleBoxFlat::get_corner_detail() const {
|
|
|
|
return corner_detail;
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Size2 StyleBoxFlat::get_center_size() const {
|
|
|
|
return Size2();
|
|
|
|
}
|
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
inline void set_inner_corner_radius(const Rect2 style_rect, const Rect2 inner_rect, const int corner_radius[4], int *inner_corner_radius) {
|
|
|
|
int border_left = inner_rect.position.x - style_rect.position.x;
|
|
|
|
int border_top = inner_rect.position.y - style_rect.position.y;
|
|
|
|
int border_right = style_rect.size.width - inner_rect.size.width - border_left;
|
|
|
|
int border_bottom = style_rect.size.height - inner_rect.size.height - border_top;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
int rad;
|
|
|
|
//tl
|
|
|
|
rad = MIN(border_top, border_left);
|
|
|
|
inner_corner_radius[0] = MAX(corner_radius[0] - rad, 0);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
//tr
|
2019-03-19 17:32:13 +08:00
|
|
|
rad = MIN(border_top, border_right);
|
2017-06-11 02:29:21 +08:00
|
|
|
inner_corner_radius[1] = MAX(corner_radius[1] - rad, 0);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
//br
|
|
|
|
rad = MIN(border_bottom, border_right);
|
|
|
|
inner_corner_radius[2] = MAX(corner_radius[2] - rad, 0);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
//bl
|
|
|
|
rad = MIN(border_bottom, border_left);
|
|
|
|
inner_corner_radius[3] = MAX(corner_radius[3] - rad, 0);
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-12-20 20:13:47 +08:00
|
|
|
inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color> &colors, const Rect2 &style_rect, const int corner_radius[4],
|
|
|
|
const Rect2 &ring_rect, const Rect2 &inner_rect, const Color &inner_color, const Color &outer_color, const int corner_detail, const bool fill_center = false) {
|
2017-06-11 02:29:21 +08:00
|
|
|
int vert_offset = verts.size();
|
|
|
|
if (!vert_offset) {
|
|
|
|
vert_offset = 0;
|
|
|
|
}
|
2019-03-05 04:35:29 +08:00
|
|
|
|
2017-08-19 20:46:04 +08:00
|
|
|
int adapted_corner_detail = (corner_radius[0] == 0 && corner_radius[1] == 0 && corner_radius[2] == 0 && corner_radius[3] == 0) ? 1 : corner_detail;
|
2017-06-11 02:29:21 +08:00
|
|
|
|
|
|
|
int ring_corner_radius[4];
|
|
|
|
set_inner_corner_radius(style_rect, ring_rect, corner_radius, ring_corner_radius);
|
|
|
|
|
|
|
|
//corner radius center points
|
|
|
|
Vector<Point2> outer_points;
|
|
|
|
outer_points.push_back(ring_rect.position + Vector2(ring_corner_radius[0], ring_corner_radius[0])); //tl
|
|
|
|
outer_points.push_back(Point2(ring_rect.position.x + ring_rect.size.x - ring_corner_radius[1], ring_rect.position.y + ring_corner_radius[1])); //tr
|
|
|
|
outer_points.push_back(ring_rect.position + ring_rect.size - Vector2(ring_corner_radius[2], ring_corner_radius[2])); //br
|
|
|
|
outer_points.push_back(Point2(ring_rect.position.x + ring_corner_radius[3], ring_rect.position.y + ring_rect.size.y - ring_corner_radius[3])); //bl
|
|
|
|
|
|
|
|
int inner_corner_radius[4];
|
2019-03-05 04:35:29 +08:00
|
|
|
set_inner_corner_radius(style_rect, inner_rect, corner_radius, inner_corner_radius);
|
2017-06-11 02:29:21 +08:00
|
|
|
|
|
|
|
Vector<Point2> inner_points;
|
|
|
|
inner_points.push_back(inner_rect.position + Vector2(inner_corner_radius[0], inner_corner_radius[0])); //tl
|
|
|
|
inner_points.push_back(Point2(inner_rect.position.x + inner_rect.size.x - inner_corner_radius[1], inner_rect.position.y + inner_corner_radius[1])); //tr
|
|
|
|
inner_points.push_back(inner_rect.position + inner_rect.size - Vector2(inner_corner_radius[2], inner_corner_radius[2])); //br
|
|
|
|
inner_points.push_back(Point2(inner_rect.position.x + inner_corner_radius[3], inner_rect.position.y + inner_rect.size.y - inner_corner_radius[3])); //bl
|
|
|
|
|
|
|
|
//calculate the vert array
|
|
|
|
for (int corner_index = 0; corner_index < 4; corner_index++) {
|
2017-08-19 20:46:04 +08:00
|
|
|
for (int detail = 0; detail <= adapted_corner_detail; detail++) {
|
2018-10-17 01:48:46 +08:00
|
|
|
for (int inner_outer = 0; inner_outer < 2; inner_outer++) {
|
2017-06-11 02:29:21 +08:00
|
|
|
float radius;
|
|
|
|
Color color;
|
|
|
|
Point2 corner_point;
|
|
|
|
if (inner_outer == 0) {
|
|
|
|
radius = inner_corner_radius[corner_index];
|
2019-03-19 17:32:13 +08:00
|
|
|
color = inner_color;
|
2017-06-11 02:29:21 +08:00
|
|
|
corner_point = inner_points[corner_index];
|
|
|
|
} else {
|
|
|
|
radius = ring_corner_radius[corner_index];
|
2019-03-19 17:32:13 +08:00
|
|
|
color = outer_color;
|
2017-06-11 02:29:21 +08:00
|
|
|
corner_point = outer_points[corner_index];
|
|
|
|
}
|
2020-04-03 17:50:40 +08:00
|
|
|
real_t x = radius * (real_t)cos((corner_index + detail / (double)adapted_corner_detail) * (Math_TAU / 4.0) + Math_PI) + corner_point.x;
|
|
|
|
real_t y = radius * (real_t)sin((corner_index + detail / (double)adapted_corner_detail) * (Math_TAU / 4.0) + Math_PI) + corner_point.y;
|
2017-06-11 02:29:21 +08:00
|
|
|
verts.push_back(Vector2(x, y));
|
|
|
|
colors.push_back(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-03-19 17:32:13 +08:00
|
|
|
int ring_vert_count = verts.size() - vert_offset;
|
2019-03-05 04:35:29 +08:00
|
|
|
|
2018-10-17 01:48:46 +08:00
|
|
|
//fill the indices and the colors for the border
|
2019-03-19 17:32:13 +08:00
|
|
|
for (int i = 0; i < ring_vert_count; i++) {
|
|
|
|
indices.push_back(vert_offset + ((i + 0) % ring_vert_count));
|
|
|
|
indices.push_back(vert_offset + ((i + 2) % ring_vert_count));
|
|
|
|
indices.push_back(vert_offset + ((i + 1) % ring_vert_count));
|
2019-03-05 04:35:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fill_center) {
|
|
|
|
//fill the indices and the colors for the center
|
2019-03-19 17:32:13 +08:00
|
|
|
for (int index = 0; index < ring_vert_count / 2; index += 2) {
|
2019-03-05 04:35:29 +08:00
|
|
|
int i = index;
|
|
|
|
//poly 1
|
|
|
|
indices.push_back(vert_offset + i);
|
2019-03-19 17:32:13 +08:00
|
|
|
indices.push_back(vert_offset + ring_vert_count - 4 - i);
|
2019-03-05 04:35:29 +08:00
|
|
|
indices.push_back(vert_offset + i + 2);
|
|
|
|
//poly 2
|
|
|
|
indices.push_back(vert_offset + i);
|
2019-03-19 17:32:13 +08:00
|
|
|
indices.push_back(vert_offset + ring_vert_count - 2 - i);
|
|
|
|
indices.push_back(vert_offset + ring_vert_count - 4 - i);
|
2019-03-05 04:35:29 +08:00
|
|
|
}
|
2017-06-11 02:29:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 15:28:59 +08:00
|
|
|
inline void adapt_values(int p_index_a, int p_index_b, int *adapted_values, const int *p_values, const real_t p_width, const int p_max_a, const int p_max_b) {
|
|
|
|
if (p_values[p_index_a] + p_values[p_index_b] > p_width) {
|
|
|
|
float factor;
|
|
|
|
int newValue;
|
|
|
|
|
|
|
|
factor = (float)p_width / (float)(p_values[p_index_a] + p_values[p_index_b]);
|
|
|
|
|
|
|
|
newValue = (int)(p_values[p_index_a] * factor);
|
|
|
|
if (newValue < adapted_values[p_index_a]) {
|
|
|
|
adapted_values[p_index_a] = newValue;
|
|
|
|
}
|
|
|
|
newValue = (int)(p_values[p_index_b] * factor);
|
|
|
|
if (newValue < adapted_values[p_index_b]) {
|
|
|
|
adapted_values[p_index_b] = newValue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
adapted_values[p_index_a] = MIN(p_values[p_index_a], adapted_values[p_index_a]);
|
|
|
|
adapted_values[p_index_b] = MIN(p_values[p_index_b], adapted_values[p_index_b]);
|
|
|
|
}
|
|
|
|
adapted_values[p_index_a] = MIN(p_max_a, adapted_values[p_index_a]);
|
|
|
|
adapted_values[p_index_b] = MIN(p_max_b, adapted_values[p_index_b]);
|
|
|
|
}
|
2019-11-24 23:26:30 +08:00
|
|
|
|
|
|
|
Rect2 StyleBoxFlat::get_draw_rect(const Rect2 &p_rect) const {
|
2020-12-23 00:24:29 +08:00
|
|
|
Rect2 draw_rect = p_rect.grow_individual(expand_margin[SIDE_LEFT], expand_margin[SIDE_TOP], expand_margin[SIDE_RIGHT], expand_margin[SIDE_BOTTOM]);
|
2019-11-24 23:26:30 +08:00
|
|
|
|
|
|
|
if (shadow_size > 0) {
|
|
|
|
Rect2 shadow_rect = draw_rect.grow(shadow_size);
|
|
|
|
shadow_rect.position += shadow_offset;
|
|
|
|
draw_rect = draw_rect.merge(shadow_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return draw_rect;
|
|
|
|
}
|
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
|
2017-06-11 02:50:01 +08:00
|
|
|
//PREPARATIONS
|
2019-04-08 04:23:44 +08:00
|
|
|
bool draw_border = (border_width[0] > 0) || (border_width[1] > 0) || (border_width[2] > 0) || (border_width[3] > 0);
|
|
|
|
bool draw_shadow = (shadow_size > 0);
|
|
|
|
if (!draw_border && !draw_center && !draw_shadow) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-11 02:50:01 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
Rect2 style_rect = p_rect.grow_individual(expand_margin[SIDE_LEFT], expand_margin[SIDE_TOP], expand_margin[SIDE_RIGHT], expand_margin[SIDE_BOTTOM]);
|
2019-11-17 22:38:05 +08:00
|
|
|
if (Math::is_zero_approx(style_rect.size.width) || Math::is_zero_approx(style_rect.size.height)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0);
|
|
|
|
bool aa_on = rounded_corners && anti_aliased;
|
2020-01-05 17:54:24 +08:00
|
|
|
float aa_size_grow = 0.5 * ((float)aa_size + 1.0);
|
2017-06-11 02:50:01 +08:00
|
|
|
|
2019-03-19 17:32:13 +08:00
|
|
|
bool blend_on = blend_border && draw_border;
|
|
|
|
|
2019-12-20 20:13:47 +08:00
|
|
|
Color border_color_alpha = Color(border_color.r, border_color.g, border_color.b, 0);
|
|
|
|
Color border_color_blend = (draw_center ? bg_color : border_color_alpha);
|
|
|
|
Color border_color_inner = blend_on ? border_color_blend : border_color;
|
2017-06-11 15:28:59 +08:00
|
|
|
|
2018-02-22 00:30:55 +08:00
|
|
|
//adapt borders (prevent weird overlapping/glitchy drawings)
|
2018-01-21 23:31:59 +08:00
|
|
|
int width = MAX(style_rect.size.width, 0);
|
|
|
|
int height = MAX(style_rect.size.height, 0);
|
2017-06-11 15:28:59 +08:00
|
|
|
int adapted_border[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
|
2020-12-23 00:24:29 +08:00
|
|
|
adapt_values(SIDE_TOP, SIDE_BOTTOM, adapted_border, border_width, height, height, height);
|
|
|
|
adapt_values(SIDE_LEFT, SIDE_RIGHT, adapted_border, border_width, width, width, width);
|
2017-06-11 15:28:59 +08:00
|
|
|
|
2018-02-22 00:30:55 +08:00
|
|
|
//adapt corners (prevent weird overlapping/glitchy drawings)
|
2017-06-11 15:28:59 +08:00
|
|
|
int adapted_corner[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
|
2020-12-23 00:24:29 +08:00
|
|
|
adapt_values(CORNER_TOP_RIGHT, CORNER_BOTTOM_RIGHT, adapted_corner, corner_radius, height, height - adapted_border[SIDE_BOTTOM], height - adapted_border[SIDE_TOP]);
|
|
|
|
adapt_values(CORNER_TOP_LEFT, CORNER_BOTTOM_LEFT, adapted_corner, corner_radius, height, height - adapted_border[SIDE_BOTTOM], height - adapted_border[SIDE_TOP]);
|
|
|
|
adapt_values(CORNER_TOP_LEFT, CORNER_TOP_RIGHT, adapted_corner, corner_radius, width, width - adapted_border[SIDE_RIGHT], width - adapted_border[SIDE_LEFT]);
|
|
|
|
adapt_values(CORNER_BOTTOM_LEFT, CORNER_BOTTOM_RIGHT, adapted_corner, corner_radius, width, width - adapted_border[SIDE_RIGHT], width - adapted_border[SIDE_LEFT]);
|
2017-06-11 15:28:59 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
Rect2 infill_rect = style_rect.grow_individual(-adapted_border[SIDE_LEFT], -adapted_border[SIDE_TOP], -adapted_border[SIDE_RIGHT], -adapted_border[SIDE_BOTTOM]);
|
2017-06-11 02:50:01 +08:00
|
|
|
|
2019-12-20 20:13:47 +08:00
|
|
|
Rect2 border_style_rect = style_rect;
|
|
|
|
if (aa_on) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (border_width[i] > 0) {
|
2020-12-28 17:11:58 +08:00
|
|
|
border_style_rect = border_style_rect.grow_side((Side)i, -aa_size_grow);
|
2019-12-20 20:13:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
Vector<Point2> verts;
|
|
|
|
Vector<int> indices;
|
|
|
|
Vector<Color> colors;
|
2019-09-03 00:48:45 +08:00
|
|
|
Vector<Point2> uvs;
|
2017-06-11 02:29:21 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
//DRAW SHADOW
|
2019-04-08 04:23:44 +08:00
|
|
|
if (draw_shadow) {
|
2019-03-05 04:35:29 +08:00
|
|
|
Rect2 shadow_inner_rect = style_rect;
|
|
|
|
shadow_inner_rect.position += shadow_offset;
|
|
|
|
|
|
|
|
Rect2 shadow_rect = style_rect.grow(shadow_size);
|
|
|
|
shadow_rect.position += shadow_offset;
|
|
|
|
|
2019-03-19 17:32:13 +08:00
|
|
|
Color shadow_color_transparent = Color(shadow_color.r, shadow_color.g, shadow_color.b, 0);
|
2019-03-05 04:35:29 +08:00
|
|
|
|
|
|
|
draw_ring(verts, indices, colors, shadow_inner_rect, adapted_corner,
|
2019-12-20 20:13:47 +08:00
|
|
|
shadow_rect, shadow_inner_rect, shadow_color, shadow_color_transparent, corner_detail);
|
2019-03-05 04:35:29 +08:00
|
|
|
|
|
|
|
if (draw_center) {
|
|
|
|
draw_ring(verts, indices, colors, shadow_inner_rect, adapted_corner,
|
2019-12-20 20:13:47 +08:00
|
|
|
shadow_inner_rect, shadow_inner_rect, shadow_color, shadow_color, corner_detail, true);
|
2019-03-05 04:35:29 +08:00
|
|
|
}
|
2017-06-11 02:50:01 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
//DRAW border
|
2019-03-19 17:32:13 +08:00
|
|
|
if (draw_border) {
|
|
|
|
draw_ring(verts, indices, colors, border_style_rect, adapted_corner,
|
2019-12-20 20:13:47 +08:00
|
|
|
border_style_rect, infill_rect, border_color_inner, border_color, corner_detail);
|
2019-03-19 17:32:13 +08:00
|
|
|
}
|
2017-06-11 02:29:21 +08:00
|
|
|
|
|
|
|
//DRAW INFILL
|
2019-12-20 20:13:47 +08:00
|
|
|
if (draw_center && (!aa_on || blend_on || !draw_border)) {
|
|
|
|
draw_ring(verts, indices, colors, border_style_rect, adapted_corner,
|
|
|
|
infill_rect, infill_rect, bg_color, bg_color, corner_detail, true);
|
2017-06-11 02:29:21 +08:00
|
|
|
}
|
2017-05-03 04:13:12 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
if (aa_on) {
|
2019-03-19 17:32:13 +08:00
|
|
|
int aa_border_width[4];
|
|
|
|
int aa_fill_width[4];
|
|
|
|
if (draw_border) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (border_width[i] > 0) {
|
2019-12-20 20:13:47 +08:00
|
|
|
aa_border_width[i] = aa_size_grow;
|
2019-03-19 17:32:13 +08:00
|
|
|
aa_fill_width[i] = 0;
|
|
|
|
} else {
|
|
|
|
aa_border_width[i] = 0;
|
2019-12-20 20:13:47 +08:00
|
|
|
aa_fill_width[i] = aa_size_grow;
|
2019-03-19 17:32:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2020-01-05 17:54:24 +08:00
|
|
|
aa_border_width[i] = 0;
|
2019-12-20 20:13:47 +08:00
|
|
|
aa_fill_width[i] = aa_size_grow;
|
2019-03-19 17:32:13 +08:00
|
|
|
}
|
2017-06-11 02:50:01 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
Rect2 infill_inner_rect = infill_rect.grow_individual(-aa_border_width[SIDE_LEFT], -aa_border_width[SIDE_TOP],
|
|
|
|
-aa_border_width[SIDE_RIGHT], -aa_border_width[SIDE_BOTTOM]);
|
2019-12-20 20:13:47 +08:00
|
|
|
|
2017-08-31 21:11:10 +08:00
|
|
|
if (draw_center) {
|
2019-12-20 20:13:47 +08:00
|
|
|
if (!blend_on && draw_border) {
|
|
|
|
//DRAW INFILL WITHIN BORDER AA
|
|
|
|
draw_ring(verts, indices, colors, border_style_rect, adapted_corner,
|
|
|
|
infill_inner_rect, infill_inner_rect, bg_color, bg_color, corner_detail, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!blend_on || !draw_border) {
|
2020-12-23 00:24:29 +08:00
|
|
|
Rect2 infill_aa_rect = infill_rect.grow_individual(aa_fill_width[SIDE_LEFT], aa_fill_width[SIDE_TOP],
|
|
|
|
aa_fill_width[SIDE_RIGHT], aa_fill_width[SIDE_BOTTOM]);
|
2019-03-19 17:32:13 +08:00
|
|
|
|
|
|
|
Color alpha_bg = Color(bg_color.r, bg_color.g, bg_color.b, 0);
|
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
//INFILL AA
|
|
|
|
draw_ring(verts, indices, colors, style_rect, adapted_corner,
|
2019-12-20 20:13:47 +08:00
|
|
|
infill_aa_rect, infill_rect, bg_color, alpha_bg, corner_detail);
|
2017-06-11 02:50:01 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-19 17:32:13 +08:00
|
|
|
|
|
|
|
if (draw_border) {
|
|
|
|
if (!blend_on) {
|
|
|
|
//DRAW INNER BORDER AA
|
|
|
|
draw_ring(verts, indices, colors, border_style_rect, adapted_corner,
|
2019-12-20 20:13:47 +08:00
|
|
|
infill_rect, infill_inner_rect, border_color_blend, border_color, corner_detail);
|
2019-03-19 17:32:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//DRAW OUTER BORDER AA
|
|
|
|
draw_ring(verts, indices, colors, border_style_rect, adapted_corner,
|
2019-12-20 20:13:47 +08:00
|
|
|
style_rect, border_style_rect, border_color, border_color_alpha, corner_detail);
|
2017-06-11 02:50:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 00:48:45 +08:00
|
|
|
//COMPUTE UV COORDINATES
|
2020-01-05 17:54:24 +08:00
|
|
|
Rect2 uv_rect = style_rect.grow(aa_on ? aa_size_grow : 0);
|
2019-09-03 00:48:45 +08:00
|
|
|
uvs.resize(verts.size());
|
|
|
|
for (int i = 0; i < verts.size(); i++) {
|
|
|
|
uvs.write[i].x = (verts[i].x - uv_rect.position.x) / uv_rect.size.width;
|
|
|
|
uvs.write[i].y = (verts[i].y - uv_rect.position.y) / uv_rect.size.height;
|
|
|
|
}
|
|
|
|
|
2019-04-08 04:23:44 +08:00
|
|
|
//DRAWING
|
2020-03-28 02:21:27 +08:00
|
|
|
RenderingServer *vs = RenderingServer::get_singleton();
|
2019-09-03 00:48:45 +08:00
|
|
|
vs->canvas_item_add_triangle_array(p_canvas_item, indices, verts, colors, uvs);
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBoxFlat::get_style_margin(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
|
|
|
|
return border_width[p_side];
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-03-04 07:51:35 +08:00
|
|
|
void StyleBoxFlat::_validate_property(PropertyInfo &property) const {
|
|
|
|
if (!anti_aliased && property.name == "anti_aliasing_size") {
|
|
|
|
property.usage = PROPERTY_USAGE_NOEDITOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
void StyleBoxFlat::_bind_methods() {
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bg_color", "color"), &StyleBoxFlat::set_bg_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bg_color"), &StyleBoxFlat::get_bg_color);
|
2017-06-11 02:29:21 +08:00
|
|
|
|
2019-03-19 17:32:13 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_border_color", "color"), &StyleBoxFlat::set_border_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_border_color"), &StyleBoxFlat::get_border_color);
|
2017-06-11 02:29:21 +08:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_border_width_all", "width"), &StyleBoxFlat::set_border_width_all);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_border_width_min"), &StyleBoxFlat::get_border_width_min);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_border_width", "margin", "width"), &StyleBoxFlat::set_border_width);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_border_width", "margin"), &StyleBoxFlat::get_border_width);
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_border_blend", "blend"), &StyleBoxFlat::set_border_blend);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_border_blend"), &StyleBoxFlat::get_border_blend);
|
2017-06-11 02:29:21 +08:00
|
|
|
|
2017-10-14 18:45:26 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_corner_radius_individual", "radius_top_left", "radius_top_right", "radius_bottom_right", "radius_bottom_left"), &StyleBoxFlat::set_corner_radius_individual);
|
2017-06-11 02:29:21 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_corner_radius_all", "radius"), &StyleBoxFlat::set_corner_radius_all);
|
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_corner_radius", "corner", "radius"), &StyleBoxFlat::set_corner_radius);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_corner_radius", "corner"), &StyleBoxFlat::get_corner_radius);
|
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_expand_margin", "margin", "size"), &StyleBoxFlat::set_expand_margin_size);
|
2017-08-22 05:07:08 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_expand_margin_all", "size"), &StyleBoxFlat::set_expand_margin_size_all);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_expand_margin_individual", "size_left", "size_top", "size_right", "size_bottom"), &StyleBoxFlat::set_expand_margin_size_individual);
|
2017-06-11 02:29:21 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_expand_margin", "margin"), &StyleBoxFlat::get_expand_margin_size);
|
|
|
|
|
2017-08-31 21:11:10 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_draw_center", "draw_center"), &StyleBoxFlat::set_draw_center);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_draw_center_enabled"), &StyleBoxFlat::is_draw_center_enabled);
|
2017-03-05 23:44:50 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_color", "color"), &StyleBoxFlat::set_shadow_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_color"), &StyleBoxFlat::get_shadow_color);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_size", "size"), &StyleBoxFlat::set_shadow_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_size"), &StyleBoxFlat::get_shadow_size);
|
|
|
|
|
2019-03-05 04:35:29 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_shadow_offset", "offset"), &StyleBoxFlat::set_shadow_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_shadow_offset"), &StyleBoxFlat::get_shadow_offset);
|
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_anti_aliased", "anti_aliased"), &StyleBoxFlat::set_anti_aliased);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_anti_aliased"), &StyleBoxFlat::is_anti_aliased);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_aa_size", "size"), &StyleBoxFlat::set_aa_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_aa_size"), &StyleBoxFlat::get_aa_size);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_corner_detail", "detail"), &StyleBoxFlat::set_corner_detail);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_corner_detail"), &StyleBoxFlat::get_corner_detail);
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "bg_color"), "set_bg_color", "get_bg_color");
|
2017-06-11 02:29:21 +08:00
|
|
|
|
2017-08-31 21:11:10 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_center"), "set_draw_center", "is_draw_center_enabled");
|
2017-06-11 02:29:21 +08:00
|
|
|
|
|
|
|
ADD_GROUP("Border Width", "border_width_");
|
2020-12-23 00:24:29 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_left", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_top", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_TOP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_right", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "border_width_bottom", PROPERTY_HINT_RANGE, "0,1024,1"), "set_border_width", "get_border_width", SIDE_BOTTOM);
|
2017-06-11 02:29:21 +08:00
|
|
|
|
2017-06-25 10:09:28 +08:00
|
|
|
ADD_GROUP("Border", "border_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "border_color"), "set_border_color", "get_border_color");
|
2017-06-11 02:29:21 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "border_blend"), "set_border_blend", "get_border_blend");
|
2017-06-11 02:29:21 +08:00
|
|
|
|
2017-06-11 02:50:01 +08:00
|
|
|
ADD_GROUP("Corner Radius", "corner_radius_");
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "corner_radius_top_left", PROPERTY_HINT_RANGE, "0,1024,1"), "set_corner_radius", "get_corner_radius", CORNER_TOP_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "corner_radius_top_right", PROPERTY_HINT_RANGE, "0,1024,1"), "set_corner_radius", "get_corner_radius", CORNER_TOP_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "corner_radius_bottom_right", PROPERTY_HINT_RANGE, "0,1024,1"), "set_corner_radius", "get_corner_radius", CORNER_BOTTOM_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "corner_radius_bottom_left", PROPERTY_HINT_RANGE, "0,1024,1"), "set_corner_radius", "get_corner_radius", CORNER_BOTTOM_LEFT);
|
|
|
|
|
2019-12-15 06:35:01 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "corner_detail", PROPERTY_HINT_RANGE, "1,20,1"), "set_corner_detail", "get_corner_detail");
|
2017-06-11 02:50:01 +08:00
|
|
|
|
2017-06-11 02:29:21 +08:00
|
|
|
ADD_GROUP("Expand Margin", "expand_margin_");
|
2020-12-23 00:24:29 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_TOP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin", "get_expand_margin", SIDE_BOTTOM);
|
2017-06-11 02:50:01 +08:00
|
|
|
|
|
|
|
ADD_GROUP("Shadow", "shadow_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color"), "set_shadow_color", "get_shadow_color");
|
2020-09-24 23:41:40 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_size", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_shadow_size", "get_shadow_size");
|
2019-03-05 04:35:29 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "shadow_offset"), "set_shadow_offset", "get_shadow_offset");
|
2017-06-11 02:50:01 +08:00
|
|
|
|
|
|
|
ADD_GROUP("Anti Aliasing", "anti_aliasing_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "anti_aliasing"), "set_anti_aliased", "is_anti_aliased");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "anti_aliasing_size", PROPERTY_HINT_RANGE, "1,5,1"), "set_aa_size", "get_aa_size");
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2021-02-10 01:24:36 +08:00
|
|
|
StyleBoxFlat::StyleBoxFlat() {}
|
2017-06-11 02:50:01 +08:00
|
|
|
|
2021-02-10 01:24:36 +08:00
|
|
|
StyleBoxFlat::~StyleBoxFlat() {}
|
2017-07-18 14:09:19 +08:00
|
|
|
|
|
|
|
void StyleBoxLine::set_color(const Color &p_color) {
|
|
|
|
color = p_color;
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-07-18 14:09:19 +08:00
|
|
|
Color StyleBoxLine::get_color() const {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxLine::set_thickness(int p_thickness) {
|
|
|
|
thickness = p_thickness;
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-07-18 14:09:19 +08:00
|
|
|
int StyleBoxLine::get_thickness() const {
|
|
|
|
return thickness;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxLine::set_vertical(bool p_vertical) {
|
|
|
|
vertical = p_vertical;
|
2019-02-25 23:13:25 +08:00
|
|
|
emit_changed();
|
2017-07-18 14:09:19 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-07-18 14:09:19 +08:00
|
|
|
bool StyleBoxLine::is_vertical() const {
|
|
|
|
return vertical;
|
|
|
|
}
|
|
|
|
|
2018-07-15 05:15:42 +08:00
|
|
|
void StyleBoxLine::set_grow_end(float p_grow_end) {
|
|
|
|
grow_end = p_grow_end;
|
2017-07-18 14:09:19 +08:00
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-07-15 05:15:42 +08:00
|
|
|
float StyleBoxLine::get_grow_end() const {
|
|
|
|
return grow_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxLine::set_grow_begin(float p_grow_begin) {
|
|
|
|
grow_begin = p_grow_begin;
|
|
|
|
emit_changed();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-07-15 05:15:42 +08:00
|
|
|
float StyleBoxLine::get_grow_begin() const {
|
|
|
|
return grow_begin;
|
2017-07-18 14:09:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxLine::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "color"), &StyleBoxLine::set_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &StyleBoxLine::get_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_thickness", "thickness"), &StyleBoxLine::set_thickness);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_thickness"), &StyleBoxLine::get_thickness);
|
2018-07-15 05:15:42 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_grow_begin", "offset"), &StyleBoxLine::set_grow_begin);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_grow_begin"), &StyleBoxLine::get_grow_begin);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_grow_end", "offset"), &StyleBoxLine::set_grow_end);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_grow_end"), &StyleBoxLine::get_grow_end);
|
2017-07-18 14:09:19 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_vertical", "vertical"), &StyleBoxLine::set_vertical);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_vertical"), &StyleBoxLine::is_vertical);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "grow_begin", PROPERTY_HINT_RANGE, "-300,300,1"), "set_grow_begin", "get_grow_begin");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "grow_end", PROPERTY_HINT_RANGE, "-300,300,1"), "set_grow_end", "get_grow_end");
|
2017-07-18 14:09:19 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "thickness", PROPERTY_HINT_RANGE, "0,10"), "set_thickness", "get_thickness");
|
2017-07-20 10:30:39 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertical"), "set_vertical", "is_vertical");
|
2017-07-18 14:09:19 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-12-23 00:24:29 +08:00
|
|
|
float StyleBoxLine::get_style_margin(Side p_side) const {
|
2021-02-16 12:36:51 +08:00
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0);
|
|
|
|
|
|
|
|
if (vertical) {
|
|
|
|
if (p_side == SIDE_LEFT || p_side == SIDE_RIGHT) {
|
|
|
|
return thickness / 2.0;
|
|
|
|
}
|
|
|
|
} else if (p_side == SIDE_TOP || p_side == SIDE_BOTTOM) {
|
|
|
|
return thickness / 2.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-07-18 14:09:19 +08:00
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-07-18 14:09:19 +08:00
|
|
|
Size2 StyleBoxLine::get_center_size() const {
|
|
|
|
return Size2();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleBoxLine::draw(RID p_canvas_item, const Rect2 &p_rect) const {
|
2020-03-28 02:21:27 +08:00
|
|
|
RenderingServer *vs = RenderingServer::get_singleton();
|
2017-07-18 14:09:19 +08:00
|
|
|
Rect2i r = p_rect;
|
|
|
|
|
|
|
|
if (vertical) {
|
2018-07-15 05:15:42 +08:00
|
|
|
r.position.y -= grow_begin;
|
|
|
|
r.size.y += (grow_begin + grow_end);
|
2017-07-18 14:09:19 +08:00
|
|
|
r.size.x = thickness;
|
|
|
|
} else {
|
2018-07-15 05:15:42 +08:00
|
|
|
r.position.x -= grow_begin;
|
|
|
|
r.size.x += (grow_begin + grow_end);
|
2017-07-18 14:09:19 +08:00
|
|
|
r.size.y = thickness;
|
|
|
|
}
|
|
|
|
|
|
|
|
vs->canvas_item_add_rect(p_canvas_item, r, color);
|
|
|
|
}
|
|
|
|
|
2021-02-10 01:24:36 +08:00
|
|
|
StyleBoxLine::StyleBoxLine() {}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2017-07-18 14:09:19 +08:00
|
|
|
StyleBoxLine::~StyleBoxLine() {}
|