1/**************************************************************************/
2/* texture_rect.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 TEXTURE_RECT_H
32#define TEXTURE_RECT_H
33
34#include "scene/gui/control.h"
35
36class TextureRect : public Control {
37 GDCLASS(TextureRect, Control);
38
39public:
40 enum ExpandMode {
41 EXPAND_KEEP_SIZE,
42 EXPAND_IGNORE_SIZE,
43 EXPAND_FIT_WIDTH,
44 EXPAND_FIT_WIDTH_PROPORTIONAL,
45 EXPAND_FIT_HEIGHT,
46 EXPAND_FIT_HEIGHT_PROPORTIONAL,
47 };
48
49 enum StretchMode {
50 STRETCH_SCALE,
51 STRETCH_TILE,
52 STRETCH_KEEP,
53 STRETCH_KEEP_CENTERED,
54 STRETCH_KEEP_ASPECT,
55 STRETCH_KEEP_ASPECT_CENTERED,
56 STRETCH_KEEP_ASPECT_COVERED,
57 };
58
59private:
60 bool hflip = false;
61 bool vflip = false;
62 Ref<Texture2D> texture;
63 ExpandMode expand_mode = EXPAND_KEEP_SIZE;
64 StretchMode stretch_mode = STRETCH_SCALE;
65
66 void _texture_changed();
67
68protected:
69 void _notification(int p_what);
70 virtual Size2 get_minimum_size() const override;
71 static void _bind_methods();
72#ifndef DISABLE_DEPRECATED
73 bool _set(const StringName &p_name, const Variant &p_value);
74#endif
75
76public:
77 void set_texture(const Ref<Texture2D> &p_tex);
78 Ref<Texture2D> get_texture() const;
79
80 void set_expand_mode(ExpandMode p_mode);
81 ExpandMode get_expand_mode() const;
82
83 void set_stretch_mode(StretchMode p_mode);
84 StretchMode get_stretch_mode() const;
85
86 void set_flip_h(bool p_flip);
87 bool is_flipped_h() const;
88
89 void set_flip_v(bool p_flip);
90 bool is_flipped_v() const;
91
92 TextureRect();
93 ~TextureRect();
94};
95
96VARIANT_ENUM_CAST(TextureRect::ExpandMode);
97VARIANT_ENUM_CAST(TextureRect::StretchMode);
98
99#endif // TEXTURE_RECT_H
100