Debian Codegraph @

scene/resources/dpi_texture.h

raw symbols SCIP
1 /**************************************************************************/
2 /* dpi_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 "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 };