1/**************************************************************************/
2/* style_box.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef STYLE_BOX_H
32#define STYLE_BOX_H
33
34#include "core/io/resource.h"
35#include "core/object/class_db.h"
36#include "core/object/gdvirtual.gen.inc"
37
38class CanvasItem;
39
40class StyleBox : public Resource {
41 GDCLASS(StyleBox, Resource);
42 RES_BASE_EXTENSION("stylebox");
43 OBJ_SAVE_TYPE(StyleBox);
44
45 float content_margin[4];
46
47protected:
48 static void _bind_methods();
49 virtual float get_style_margin(Side p_side) const { return 0; }
50
51 GDVIRTUAL2C(_draw, RID, Rect2)
52 GDVIRTUAL1RC(Rect2, _get_draw_rect, Rect2)
53 GDVIRTUAL0RC(Size2, _get_minimum_size)
54 GDVIRTUAL2RC(bool, _test_mask, Point2, Rect2)
55
56public:
57 virtual Size2 get_minimum_size() const;
58
59 void set_content_margin(Side p_side, float p_value);
60 void set_content_margin_all(float p_value);
61 void set_content_margin_individual(float p_left, float p_top, float p_right, float p_bottom);
62 float get_content_margin(Side p_side) const;
63
64 float get_margin(Side p_side) const;
65 Point2 get_offset() const;
66
67 virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
68 virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
69
70 CanvasItem *get_current_item_drawn() const;
71
72 virtual bool test_mask(const Point2 &p_point, const Rect2 &p_rect) const;
73
74 StyleBox();
75};
76
77class StyleBoxEmpty : public StyleBox {
78 GDCLASS(StyleBoxEmpty, StyleBox);
79 virtual float get_style_margin(Side p_side) const override { return 0; }
80
81public:
82 virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const override {}
83 StyleBoxEmpty() {}
84};
85
86#endif // STYLE_BOX_H
87