virtualx-engine/scene/resources/style_box.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
5.9 KiB
C++
Raw Normal View History

2014-02-10 02:10:30 +01:00
/**************************************************************************/
/* style_box.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
2014-02-10 02:10:30 +01:00
#include "style_box.h"
#include "scene/main/canvas_item.h"
Size2 StyleBox::get_minimum_size() const {
Size2 min_size = Size2(get_margin(SIDE_LEFT) + get_margin(SIDE_RIGHT), get_margin(SIDE_TOP) + get_margin(SIDE_BOTTOM));
Size2 custom_size;
GDVIRTUAL_CALL(_get_minimum_size, custom_size);
if (min_size.x < custom_size.x) {
min_size.x = custom_size.x;
}
if (min_size.y < custom_size.y) {
min_size.y = custom_size.y;
}
2014-02-10 02:10:30 +01:00
return min_size;
}
void StyleBox::set_content_margin(Side p_side, float p_value) {
2020-12-22 17:24:29 +01:00
ERR_FAIL_INDEX((int)p_side, 4);
2019-10-10 11:48:58 +02:00
content_margin[p_side] = p_value;
2014-02-10 02:10:30 +01:00
emit_changed();
}
void StyleBox::set_content_margin_all(float p_value) {
for (int i = 0; i < 4; i++) {
content_margin[i] = p_value;
}
emit_changed();
}
void StyleBox::set_content_margin_individual(float p_left, float p_top, float p_right, float p_bottom) {
content_margin[SIDE_LEFT] = p_left;
content_margin[SIDE_TOP] = p_top;
content_margin[SIDE_RIGHT] = p_right;
content_margin[SIDE_BOTTOM] = p_bottom;
emit_changed();
}
float StyleBox::get_content_margin(Side p_side) const {
2020-12-22 17:24:29 +01:00
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
2019-10-10 11:48:58 +02:00
return content_margin[p_side];
2014-02-10 02:10:30 +01:00
}
2020-12-22 17:24:29 +01:00
float StyleBox::get_margin(Side p_side) const {
ERR_FAIL_INDEX_V((int)p_side, 4, 0.0);
2019-10-10 11:48:58 +02:00
if (content_margin[p_side] < 0) {
2020-12-22 17:24:29 +01:00
return get_style_margin(p_side);
} else {
return content_margin[p_side];
}
2014-02-10 02:10:30 +01:00
}
Point2 StyleBox::get_offset() const {
2020-12-22 17:24:29 +01:00
return Point2(get_margin(SIDE_LEFT), get_margin(SIDE_TOP));
2014-02-10 02:10:30 +01:00
}
void StyleBox::draw(RID p_canvas_item, const Rect2 &p_rect) const {
GDVIRTUAL_REQUIRED_CALL(_draw, p_canvas_item, p_rect);
2014-02-10 02:10:30 +01:00
}
Rect2 StyleBox::get_draw_rect(const Rect2 &p_rect) const {
Rect2 ret;
if (GDVIRTUAL_CALL(_get_draw_rect, p_rect, ret)) {
return ret;
}
return p_rect;
}
CanvasItem *StyleBox::get_current_item_drawn() const {
return CanvasItem::get_current_item_drawn();
}
bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const {
bool ret = true;
GDVIRTUAL_CALL(_test_mask, p_point, p_rect, ret);
return ret;
}
2014-02-10 02:10:30 +01:00
void StyleBox::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_minimum_size"), &StyleBox::get_minimum_size);
2014-02-10 02:10:30 +01:00
ClassDB::bind_method(D_METHOD("set_content_margin", "margin", "offset"), &StyleBox::set_content_margin);
ClassDB::bind_method(D_METHOD("set_content_margin_all", "offset"), &StyleBox::set_content_margin_all);
ClassDB::bind_method(D_METHOD("get_content_margin", "margin"), &StyleBox::get_content_margin);
2014-02-10 02:10:30 +01:00
ClassDB::bind_method(D_METHOD("get_margin", "margin"), &StyleBox::get_margin);
ClassDB::bind_method(D_METHOD("get_offset"), &StyleBox::get_offset);
ClassDB::bind_method(D_METHOD("draw", "canvas_item", "rect"), &StyleBox::draw);
ClassDB::bind_method(D_METHOD("get_current_item_drawn"), &StyleBox::get_current_item_drawn);
ClassDB::bind_method(D_METHOD("test_mask", "point", "rect"), &StyleBox::test_mask);
ADD_GROUP("Content Margins", "content_margin_");
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_left", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_LEFT);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_top", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_right", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_RIGHT);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "content_margin_bottom", PROPERTY_HINT_RANGE, "-1,2048,1,suffix:px"), "set_content_margin", "get_content_margin", SIDE_BOTTOM);
GDVIRTUAL_BIND(_draw, "to_canvas_item", "rect")
GDVIRTUAL_BIND(_get_draw_rect, "rect")
GDVIRTUAL_BIND(_get_minimum_size)
GDVIRTUAL_BIND(_test_mask, "point", "rect")
2014-02-10 02:10:30 +01:00
}
StyleBox::StyleBox() {
for (int i = 0; i < 4; i++) {
content_margin[i] = -1;
2014-02-10 02:10:30 +01:00
}
}