Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/gradient_texture.h
9898 views
1
/**************************************************************************/
2
/* gradient_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
#pragma once
32
33
#include "scene/resources/texture.h"
34
35
class GradientTexture1D : public Texture2D {
36
GDCLASS(GradientTexture1D, Texture2D);
37
38
private:
39
Ref<Gradient> gradient;
40
mutable bool update_pending = false;
41
mutable RID texture;
42
int width = 256;
43
bool use_hdr = false;
44
45
void _queue_update();
46
void _update() const;
47
48
protected:
49
static void _bind_methods();
50
51
public:
52
void set_gradient(Ref<Gradient> p_gradient);
53
Ref<Gradient> get_gradient() const;
54
55
void set_width(int p_width);
56
int get_width() const override;
57
58
void set_use_hdr(bool p_enabled);
59
bool is_using_hdr() const;
60
61
virtual RID get_rid() const override;
62
virtual int get_height() const override { return 1; }
63
virtual bool has_alpha() const override { return true; }
64
65
virtual Ref<Image> get_image() const override;
66
void update_now() const;
67
68
GradientTexture1D();
69
virtual ~GradientTexture1D();
70
};
71
72
class GradientTexture2D : public Texture2D {
73
GDCLASS(GradientTexture2D, Texture2D);
74
75
public:
76
enum Fill {
77
FILL_LINEAR,
78
FILL_RADIAL,
79
FILL_SQUARE,
80
};
81
enum Repeat {
82
REPEAT_NONE,
83
REPEAT,
84
REPEAT_MIRROR,
85
};
86
87
private:
88
Ref<Gradient> gradient;
89
mutable RID texture;
90
91
int width = 64;
92
int height = 64;
93
94
bool use_hdr = false;
95
96
Vector2 fill_from;
97
Vector2 fill_to = Vector2(1, 0);
98
99
Fill fill = FILL_LINEAR;
100
Repeat repeat = REPEAT_NONE;
101
102
float _get_gradient_offset_at(int x, int y) const;
103
104
mutable bool update_pending = false;
105
void _queue_update();
106
void _update() const;
107
108
protected:
109
static void _bind_methods();
110
111
public:
112
void set_gradient(Ref<Gradient> p_gradient);
113
Ref<Gradient> get_gradient() const;
114
115
void set_width(int p_width);
116
virtual int get_width() const override;
117
void set_height(int p_height);
118
virtual int get_height() const override;
119
120
void set_use_hdr(bool p_enabled);
121
bool is_using_hdr() const;
122
123
void set_fill(Fill p_fill);
124
Fill get_fill() const;
125
void set_fill_from(Vector2 p_fill_from);
126
Vector2 get_fill_from() const;
127
void set_fill_to(Vector2 p_fill_to);
128
Vector2 get_fill_to() const;
129
130
void set_repeat(Repeat p_repeat);
131
Repeat get_repeat() const;
132
133
virtual RID get_rid() const override;
134
virtual bool has_alpha() const override { return true; }
135
virtual Ref<Image> get_image() const override;
136
void update_now() const;
137
138
GradientTexture2D();
139
virtual ~GradientTexture2D();
140
};
141
142
VARIANT_ENUM_CAST(GradientTexture2D::Fill);
143
VARIANT_ENUM_CAST(GradientTexture2D::Repeat);
144
145