| 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 "core/templates/lru.h" |
| 34 |
#include "scene/resources/texture.h" |
| 35 |
|
| 36 |
class BitMap; |
| 37 |
|
| 38 |
class DPITexture : public Texture2D { |
| 39 |
GDCLASS(DPITexture, Texture2D); |
| 40 |
RES_BASE_EXTENSION("dpitex"); |
| 41 |
|
| 42 |
String source; |
| 43 |
float base_scale = 1.0; |
| 44 |
float saturation = 1.0; |
| 45 |
Dictionary color_map; |
| 46 |
Size2 size_override; |
| 47 |
|
| 48 |
struct ScalingLevel { |
| 49 |
HashSet<DPITexture *> textures; |
| 50 |
int32_t refcount = 1; |
| 51 |
}; |
| 52 |
static Mutex mutex; |
| 53 |
static HashMap<double, ScalingLevel> scaling_levels; |
| 54 |
|
| 55 |
mutable RID base_texture; |
| 56 |
mutable HashMap<double, RID> texture_cache; |
| 57 |
mutable Ref<BitMap> alpha_cache; |
| 58 |
mutable HashMap<Color, Color> cmap; |
| 59 |
mutable Size2 base_size; |
| 60 |
mutable Size2 size; |
| 61 |
|
| 62 |
void _remove_scale(double p_scale); |
| 63 |
RID _ensure_scale(double p_scale) const; |
| 64 |
RID _load_at_scale(double p_scale, bool p_set_size) const; |
| 65 |
void _update_texture(); |
| 66 |
void _clear(); |
| 67 |
|
| 68 |
protected: |
| 69 |
static void _bind_methods(); |
| 70 |
|
| 71 |
public: |
| 72 |
static Ref<DPITexture> create_from_string(const String &p_source, float p_scale = 1.0, float p_saturation = 1.0, const Dictionary &p_color_map = Dictionary()); |
| 73 |
|
| 74 |
void set_source(const String &p_source); |
| 75 |
String get_source() const; |
| 76 |
|
| 77 |
void set_base_scale(float p_scale); |
| 78 |
float get_base_scale() const; |
| 79 |
|
| 80 |
void set_color_map(const Dictionary &p_color_map); |
| 81 |
Dictionary get_color_map() const; |
| 82 |
|
| 83 |
void set_saturation(float p_saturation); |
| 84 |
float get_saturation() const; |
| 85 |
|
| 86 |
Ref<Image> get_image() const override; |
| 87 |
|
| 88 |
int get_width() const override; |
| 89 |
int get_height() const override; |
| 90 |
|
| 91 |
virtual RID get_rid() const override; |
| 92 |
|
| 93 |
bool has_alpha() const override; |
| 94 |
virtual RID get_scaled_rid() const override; |
| 95 |
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override; |
| 96 |
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override; |
| 97 |
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = true) const override; |
| 98 |
|
| 99 |
void set_size_override(const Size2i &p_size); |
| 100 |
bool is_pixel_opaque(int p_x, int p_y) const override; |
| 101 |
|
| 102 |
static void reference_scaling_level(double p_scale); |
| 103 |
static void unreference_scaling_level(double p_scale); |
| 104 |
|
| 105 |
~DPITexture(); |
| 106 |
}; |