| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/resources/gradient.h" |
| 34 |
#include "scene/resources/texture.h" |
| 35 |
|
| 36 |
class GradientTexture1D : public Texture2D { |
| 37 |
GDCLASS(GradientTexture1D, Texture2D); |
| 38 |
|
| 39 |
private: |
| 40 |
Ref<Gradient> gradient; |
| 41 |
mutable bool update_pending = false; |
| 42 |
mutable RID texture; |
| 43 |
int width = 256; |
| 44 |
bool use_hdr = false; |
| 45 |
|
| 46 |
void _queue_update(); |
| 47 |
void _update() const; |
| 48 |
|
| 49 |
protected: |
| 50 |
static void _bind_methods(); |
| 51 |
|
| 52 |
public: |
| 53 |
void set_gradient(Ref<Gradient> p_gradient); |
| 54 |
Ref<Gradient> get_gradient() const; |
| 55 |
|
| 56 |
void set_width(int p_width); |
| 57 |
int get_width() const override; |
| 58 |
|
| 59 |
void set_use_hdr(bool p_enabled); |
| 60 |
bool is_using_hdr() const; |
| 61 |
|
| 62 |
virtual RID get_rid() const override; |
| 63 |
virtual int get_height() const override { return 1; } |
| 64 |
virtual bool has_alpha() const override { return true; } |
| 65 |
|
| 66 |
virtual Ref<Image> get_image() const override; |
| 67 |
void update_now() const; |
| 68 |
|
| 69 |
GradientTexture1D(); |
| 70 |
virtual ~GradientTexture1D(); |
| 71 |
}; |
| 72 |
|
| 73 |
class GradientTexture2D : public Texture2D { |
| 74 |
GDCLASS(GradientTexture2D, Texture2D); |
| 75 |
|
| 76 |
public: |
| 77 |
enum Fill { |
| 78 |
FILL_LINEAR, |
| 79 |
FILL_RADIAL, |
| 80 |
FILL_SQUARE, |
| 81 |
}; |
| 82 |
enum Repeat { |
| 83 |
REPEAT_NONE, |
| 84 |
REPEAT, |
| 85 |
REPEAT_MIRROR, |
| 86 |
}; |
| 87 |
|
| 88 |
private: |
| 89 |
Ref<Gradient> gradient; |
| 90 |
mutable RID texture; |
| 91 |
|
| 92 |
int width = 64; |
| 93 |
int height = 64; |
| 94 |
|
| 95 |
bool use_hdr = false; |
| 96 |
|
| 97 |
Vector2 fill_from; |
| 98 |
Vector2 fill_to = Vector2(1, 0); |
| 99 |
|
| 100 |
Fill fill = FILL_LINEAR; |
| 101 |
Repeat repeat = REPEAT_NONE; |
| 102 |
|
| 103 |
float _get_gradient_offset_at(int x, int y) const; |
| 104 |
|
| 105 |
mutable bool update_pending = false; |
| 106 |
void _queue_update(); |
| 107 |
void _update() const; |
| 108 |
|
| 109 |
protected: |
| 110 |
static void _bind_methods(); |
| 111 |
|
| 112 |
public: |
| 113 |
void set_gradient(Ref<Gradient> p_gradient); |
| 114 |
Ref<Gradient> get_gradient() const; |
| 115 |
|
| 116 |
void set_width(int p_width); |
| 117 |
virtual int get_width() const override; |
| 118 |
void set_height(int p_height); |
| 119 |
virtual int get_height() const override; |
| 120 |
|
| 121 |
void set_use_hdr(bool p_enabled); |
| 122 |
bool is_using_hdr() const; |
| 123 |
|
| 124 |
void set_fill(Fill p_fill); |
| 125 |
Fill get_fill() const; |
| 126 |
void set_fill_from(Vector2 p_fill_from); |
| 127 |
Vector2 get_fill_from() const; |
| 128 |
void set_fill_to(Vector2 p_fill_to); |
| 129 |
Vector2 get_fill_to() const; |
| 130 |
|
| 131 |
void set_repeat(Repeat p_repeat); |
| 132 |
Repeat get_repeat() const; |
| 133 |
|
| 134 |
virtual RID get_rid() const override; |
| 135 |
virtual bool has_alpha() const override { return true; } |
| 136 |
virtual Ref<Image> get_image() const override; |
| 137 |
void update_now() const; |
| 138 |
|
| 139 |
GradientTexture2D(); |
| 140 |
virtual ~GradientTexture2D(); |
| 141 |
}; |
| 142 |
|
| 143 |
VARIANT_ENUM_CAST(GradientTexture2D::Fill); |
| 144 |
VARIANT_ENUM_CAST(GradientTexture2D::Repeat); |