1/**************************************************************************/
2/* style_box_texture.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_TEXTURE_H
32#define STYLE_BOX_TEXTURE_H
33
34#include "scene/resources/style_box.h"
35#include "scene/resources/texture.h"
36
37class StyleBoxTexture : public StyleBox {
38 GDCLASS(StyleBoxTexture, StyleBox);
39
40public:
41 enum AxisStretchMode {
42 AXIS_STRETCH_MODE_STRETCH,
43 AXIS_STRETCH_MODE_TILE,
44 AXIS_STRETCH_MODE_TILE_FIT,
45 };
46
47private:
48 float expand_margin[4] = {};
49 float texture_margin[4] = {};
50 Rect2 region_rect;
51 Ref<Texture2D> texture;
52 bool draw_center = true;
53 Color modulate = Color(1, 1, 1, 1);
54 AxisStretchMode axis_h = AXIS_STRETCH_MODE_STRETCH;
55 AxisStretchMode axis_v = AXIS_STRETCH_MODE_STRETCH;
56
57protected:
58 virtual float get_style_margin(Side p_side) const override;
59 static void _bind_methods();
60
61public:
62 void set_texture(Ref<Texture2D> p_texture);
63 Ref<Texture2D> get_texture() const;
64
65 void set_texture_margin(Side p_side, float p_size);
66 void set_texture_margin_all(float p_size);
67 void set_texture_margin_individual(float p_left, float p_top, float p_right, float p_bottom);
68 float get_texture_margin(Side p_side) const;
69
70 void set_expand_margin(Side p_expand_side, float p_size);
71 void set_expand_margin_all(float p_expand_margin_size);
72 void set_expand_margin_individual(float p_left, float p_top, float p_right, float p_bottom);
73 float get_expand_margin(Side p_expand_side) const;
74
75 void set_region_rect(const Rect2 &p_region_rect);
76 Rect2 get_region_rect() const;
77
78 void set_draw_center(bool p_enabled);
79 bool is_draw_center_enabled() const;
80
81 void set_h_axis_stretch_mode(AxisStretchMode p_mode);
82 AxisStretchMode get_h_axis_stretch_mode() const;
83
84 void set_v_axis_stretch_mode(AxisStretchMode p_mode);
85 AxisStretchMode get_v_axis_stretch_mode() const;
86
87 void set_modulate(const Color &p_modulate);
88 Color get_modulate() const;
89
90 virtual Rect2 get_draw_rect(const Rect2 &p_rect) const override;
91 virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const override;
92
93 StyleBoxTexture();
94 ~StyleBoxTexture();
95};
96
97VARIANT_ENUM_CAST(StyleBoxTexture::AxisStretchMode)
98
99#endif // STYLE_BOX_TEXTURE_H
100