2014-02-10 01:10:30 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* canvas_item.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef CANVAS_ITEM_H
|
|
|
|
#define CANVAS_ITEM_H
|
|
|
|
|
|
|
|
#include "scene/main/node.h"
|
2021-08-12 23:05:59 +00:00
|
|
|
#include "scene/resources/canvas_item_material.h"
|
2021-10-25 08:49:18 +00:00
|
|
|
#include "scene/resources/font.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
class CanvasLayer;
|
2021-08-12 23:05:59 +00:00
|
|
|
class MultiMesh;
|
2014-02-10 01:10:30 +00:00
|
|
|
class StyleBox;
|
2021-08-12 23:05:59 +00:00
|
|
|
class Window;
|
|
|
|
class World2D;
|
2017-06-23 17:31:21 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class CanvasItem : public Node {
|
2017-01-03 02:03:46 +00:00
|
|
|
GDCLASS(CanvasItem, Node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-04-18 18:49:21 +00:00
|
|
|
friend class CanvasLayer;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2019-06-25 01:24:07 +00:00
|
|
|
enum TextureFilter {
|
2019-07-21 14:31:30 +00:00
|
|
|
TEXTURE_FILTER_PARENT_NODE,
|
2019-06-25 01:24:07 +00:00
|
|
|
TEXTURE_FILTER_NEAREST,
|
|
|
|
TEXTURE_FILTER_LINEAR,
|
2020-02-19 23:31:43 +00:00
|
|
|
TEXTURE_FILTER_NEAREST_WITH_MIPMAPS,
|
2019-07-21 14:31:30 +00:00
|
|
|
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS,
|
2020-02-19 23:31:43 +00:00
|
|
|
TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC,
|
2019-07-21 14:31:30 +00:00
|
|
|
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC,
|
2019-06-25 01:24:07 +00:00
|
|
|
TEXTURE_FILTER_MAX
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-06-25 01:24:07 +00:00
|
|
|
enum TextureRepeat {
|
2019-07-21 14:31:30 +00:00
|
|
|
TEXTURE_REPEAT_PARENT_NODE,
|
2019-06-25 01:24:07 +00:00
|
|
|
TEXTURE_REPEAT_DISABLED,
|
|
|
|
TEXTURE_REPEAT_ENABLED,
|
|
|
|
TEXTURE_REPEAT_MIRROR,
|
|
|
|
TEXTURE_REPEAT_MAX,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2022-10-12 19:45:47 +00:00
|
|
|
enum ClipChildrenMode {
|
|
|
|
CLIP_CHILDREN_DISABLED,
|
|
|
|
CLIP_CHILDREN_ONLY,
|
|
|
|
CLIP_CHILDREN_AND_DRAW,
|
|
|
|
CLIP_CHILDREN_MAX,
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
private:
|
2022-10-12 19:45:47 +00:00
|
|
|
mutable SelfList<Node>
|
|
|
|
xform_change;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
RID canvas_item;
|
2022-07-20 10:44:44 +00:00
|
|
|
StringName canvas_group;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-12-11 14:54:03 +00:00
|
|
|
CanvasLayer *canvas_layer = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-12-11 14:54:03 +00:00
|
|
|
Color modulate = Color(1, 1, 1, 1);
|
|
|
|
Color self_modulate = Color(1, 1, 1, 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<CanvasItem *> children_items;
|
2020-12-11 14:54:03 +00:00
|
|
|
List<CanvasItem *>::Element *C = nullptr;
|
|
|
|
|
|
|
|
int light_mask = 1;
|
2021-09-02 18:07:04 +00:00
|
|
|
uint32_t visibility_layer = 1;
|
2020-12-11 14:54:03 +00:00
|
|
|
|
2022-11-29 16:11:06 +00:00
|
|
|
int z_index = 0;
|
|
|
|
bool z_relative = true;
|
|
|
|
bool y_sort_enabled = false;
|
|
|
|
|
2020-12-11 14:54:03 +00:00
|
|
|
Window *window = nullptr;
|
|
|
|
bool visible = true;
|
2022-02-19 12:24:35 +00:00
|
|
|
bool parent_visible_in_tree = false;
|
2020-12-11 14:54:03 +00:00
|
|
|
bool pending_update = false;
|
|
|
|
bool top_level = false;
|
|
|
|
bool drawing = false;
|
|
|
|
bool block_transform_notify = false;
|
|
|
|
bool behind = false;
|
|
|
|
bool use_parent_material = false;
|
|
|
|
bool notify_local_transform = false;
|
|
|
|
bool notify_transform = false;
|
2023-01-26 12:17:26 +00:00
|
|
|
bool hide_clip_children = false;
|
2020-12-11 14:54:03 +00:00
|
|
|
|
2022-10-12 19:45:47 +00:00
|
|
|
ClipChildrenMode clip_children_mode = CLIP_CHILDREN_DISABLED;
|
|
|
|
|
2023-06-22 14:23:15 +00:00
|
|
|
mutable RS::CanvasItemTextureFilter texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
|
|
|
|
mutable RS::CanvasItemTextureRepeat texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
|
2020-12-11 14:54:03 +00:00
|
|
|
TextureFilter texture_filter = TEXTURE_FILTER_PARENT_NODE;
|
|
|
|
TextureRepeat texture_repeat = TEXTURE_REPEAT_PARENT_NODE;
|
2019-06-25 01:24:07 +00:00
|
|
|
|
2017-06-23 17:31:21 +00:00
|
|
|
Ref<Material> material;
|
2015-01-11 14:43:31 +00:00
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
mutable Transform2D global_transform;
|
2023-05-16 23:44:41 +00:00
|
|
|
mutable MTFlag global_invalid;
|
|
|
|
|
|
|
|
_FORCE_INLINE_ bool _is_global_invalid() const { return is_group_processing() ? global_invalid.mt.is_set() : global_invalid.st; }
|
|
|
|
void _set_global_invalid(bool p_invalid) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-02 21:03:52 +00:00
|
|
|
void _top_level_raise_self();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-02-22 00:13:32 +00:00
|
|
|
void _propagate_visibility_changed(bool p_parent_visible_in_tree);
|
|
|
|
void _handle_visibility_change(bool p_visible);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-02-02 16:20:31 +00:00
|
|
|
virtual void _top_level_changed();
|
|
|
|
virtual void _top_level_changed_on_parent();
|
2022-10-16 17:41:42 +00:00
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
void _redraw_callback();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _enter_canvas();
|
|
|
|
void _exit_canvas();
|
|
|
|
|
2020-03-06 17:00:16 +00:00
|
|
|
void _window_visibility_changed();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _notify_transform(CanvasItem *p_node);
|
|
|
|
|
2024-02-16 23:57:32 +00:00
|
|
|
virtual void _physics_interpolated_changed() override;
|
|
|
|
|
2019-01-24 13:21:56 +00:00
|
|
|
static CanvasItem *current_item_drawn;
|
2019-06-25 01:24:07 +00:00
|
|
|
friend class Viewport;
|
2023-06-22 14:23:15 +00:00
|
|
|
void _refresh_texture_repeat_cache() const;
|
2019-06-25 01:24:07 +00:00
|
|
|
void _update_texture_repeat_changed(bool p_propagate);
|
2023-06-22 14:23:15 +00:00
|
|
|
void _refresh_texture_filter_cache() const;
|
2019-06-25 01:24:07 +00:00
|
|
|
void _update_texture_filter_changed(bool p_propagate);
|
2019-01-24 13:21:56 +00:00
|
|
|
|
2023-05-12 11:53:15 +00:00
|
|
|
void _notify_transform_deferred();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
2024-03-05 12:55:23 +00:00
|
|
|
virtual void _update_self_texture_repeat(RS::CanvasItemTextureRepeat p_texture_repeat);
|
|
|
|
virtual void _update_self_texture_filter(RS::CanvasItemTextureFilter p_texture_filter);
|
|
|
|
|
2015-09-16 01:07:03 +00:00
|
|
|
_FORCE_INLINE_ void _notify_transform() {
|
|
|
|
_notify_transform(this);
|
2023-07-31 23:55:31 +00:00
|
|
|
if (is_inside_tree() && !block_transform_notify && notify_local_transform) {
|
2015-09-16 01:07:03 +00:00
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-08-31 02:44:14 +00:00
|
|
|
void item_rect_changed(bool p_size_changed = true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2023-01-26 12:17:26 +00:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
|
|
|
|
|
|
|
_FORCE_INLINE_ void set_hide_clip_children(bool p_value) { hide_clip_children = p_value; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL0(_draw)
|
2022-10-16 20:53:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
enum {
|
2014-11-06 00:20:42 +00:00
|
|
|
NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique
|
2014-02-10 01:10:30 +00:00
|
|
|
NOTIFICATION_DRAW = 30,
|
|
|
|
NOTIFICATION_VISIBILITY_CHANGED = 31,
|
|
|
|
NOTIFICATION_ENTER_CANVAS = 32,
|
|
|
|
NOTIFICATION_EXIT_CANVAS = 33,
|
|
|
|
NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 35,
|
|
|
|
NOTIFICATION_WORLD_2D_CHANGED = 36,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* EDITOR */
|
2019-10-21 21:37:07 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2018-05-05 14:59:00 +00:00
|
|
|
// Select the node
|
|
|
|
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
|
|
|
|
|
2018-03-08 20:35:41 +00:00
|
|
|
// Save and restore a CanvasItem state
|
2020-05-12 15:01:17 +00:00
|
|
|
virtual void _edit_set_state(const Dictionary &p_state) {}
|
2022-10-16 20:53:25 +00:00
|
|
|
virtual Dictionary _edit_get_state() const { return Dictionary(); }
|
2017-11-15 22:03:25 +00:00
|
|
|
|
2018-03-08 20:35:41 +00:00
|
|
|
// Used to move the node
|
|
|
|
virtual void _edit_set_position(const Point2 &p_position) = 0;
|
|
|
|
virtual Point2 _edit_get_position() const = 0;
|
2017-11-15 22:03:25 +00:00
|
|
|
|
2018-03-08 20:35:41 +00:00
|
|
|
// Used to scale the node
|
|
|
|
virtual void _edit_set_scale(const Size2 &p_scale) = 0;
|
|
|
|
virtual Size2 _edit_get_scale() const = 0;
|
|
|
|
|
2018-05-05 14:59:00 +00:00
|
|
|
// Used to rotate the node
|
|
|
|
virtual bool _edit_use_rotation() const { return false; };
|
2021-01-30 04:10:32 +00:00
|
|
|
virtual void _edit_set_rotation(real_t p_rotation) {}
|
|
|
|
virtual real_t _edit_get_rotation() const { return 0.0; };
|
2018-05-05 14:59:00 +00:00
|
|
|
|
2018-03-08 20:35:41 +00:00
|
|
|
// Used to resize/move the node
|
2018-05-05 14:59:00 +00:00
|
|
|
virtual bool _edit_use_rect() const { return false; }; // MAYBE REPLACE BY A _edit_get_editmode()
|
2020-05-12 15:01:17 +00:00
|
|
|
virtual void _edit_set_rect(const Rect2 &p_rect) {}
|
2018-03-08 20:35:41 +00:00
|
|
|
virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); };
|
2018-05-05 14:59:00 +00:00
|
|
|
virtual Size2 _edit_get_minimum_size() const { return Size2(-1, -1); }; // LOOKS WEIRD
|
2017-11-15 22:03:25 +00:00
|
|
|
|
|
|
|
// Used to set a pivot
|
2018-05-05 14:59:00 +00:00
|
|
|
virtual bool _edit_use_pivot() const { return false; };
|
2020-05-12 15:01:17 +00:00
|
|
|
virtual void _edit_set_pivot(const Point2 &p_pivot) {}
|
2018-05-05 14:59:00 +00:00
|
|
|
virtual Point2 _edit_get_pivot() const { return Point2(); };
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-10-20 10:11:06 +00:00
|
|
|
virtual Transform2D _edit_get_transform() const;
|
2019-10-21 21:37:07 +00:00
|
|
|
#endif
|
2019-10-20 10:11:06 +00:00
|
|
|
|
2023-04-05 16:53:32 +00:00
|
|
|
void update_draw_order();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* VISIBILITY */
|
|
|
|
|
2017-01-13 13:45:50 +00:00
|
|
|
void set_visible(bool p_visible);
|
2014-02-10 01:10:30 +00:00
|
|
|
bool is_visible() const;
|
2017-01-13 13:45:50 +00:00
|
|
|
bool is_visible_in_tree() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
void show();
|
|
|
|
void hide();
|
|
|
|
|
2022-08-13 21:21:24 +00:00
|
|
|
void queue_redraw();
|
2022-04-10 18:52:55 +00:00
|
|
|
void move_to_front();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-10-12 19:45:47 +00:00
|
|
|
void set_clip_children_mode(ClipChildrenMode p_clip_mode);
|
|
|
|
ClipChildrenMode get_clip_children_mode() const;
|
2020-10-28 18:34:27 +00:00
|
|
|
|
2015-12-29 17:47:13 +00:00
|
|
|
virtual void set_light_mask(int p_light_mask);
|
2015-02-18 22:39:44 +00:00
|
|
|
int get_light_mask() const;
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
void set_modulate(const Color &p_modulate);
|
|
|
|
Color get_modulate() const;
|
2022-12-19 10:51:37 +00:00
|
|
|
Color get_modulate_in_tree() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2024-01-12 16:23:53 +00:00
|
|
|
virtual void set_self_modulate(const Color &p_self_modulate);
|
2016-10-03 19:33:42 +00:00
|
|
|
Color get_self_modulate() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-09-02 18:07:04 +00:00
|
|
|
void set_visibility_layer(uint32_t p_visibility_layer);
|
|
|
|
uint32_t get_visibility_layer() const;
|
|
|
|
|
|
|
|
void set_visibility_layer_bit(uint32_t p_visibility_layer, bool p_enable);
|
|
|
|
bool get_visibility_layer_bit(uint32_t p_visibility_layer) const;
|
|
|
|
|
2022-11-29 16:11:06 +00:00
|
|
|
/* ORDERING */
|
|
|
|
|
2024-01-12 16:23:53 +00:00
|
|
|
virtual void set_z_index(int p_z);
|
2022-11-29 16:11:06 +00:00
|
|
|
int get_z_index() const;
|
2022-11-10 21:55:57 +00:00
|
|
|
int get_effective_z_index() const;
|
2022-11-29 16:11:06 +00:00
|
|
|
|
|
|
|
void set_z_as_relative(bool p_enabled);
|
|
|
|
bool is_z_relative() const;
|
|
|
|
|
|
|
|
virtual void set_y_sort_enabled(bool p_enabled);
|
|
|
|
virtual bool is_y_sort_enabled() const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* DRAWING API */
|
|
|
|
|
2023-01-14 05:28:55 +00:00
|
|
|
void draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = -1.0, real_t p_dash = 2.0, bool p_aligned = true);
|
|
|
|
void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
2023-01-19 12:38:15 +00:00
|
|
|
void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
|
|
|
void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0, bool p_antialiased = false);
|
|
|
|
void draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width = -1.0, bool p_antialiased = false);
|
2023-01-14 05:28:55 +00:00
|
|
|
void draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0);
|
|
|
|
void draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0);
|
|
|
|
void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true, real_t p_width = -1.0);
|
2021-01-30 04:10:32 +00:00
|
|
|
void draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color);
|
2020-10-24 15:15:43 +00:00
|
|
|
void draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1));
|
|
|
|
void draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
|
|
|
|
void draw_texture_rect_region(const Ref<Texture2D> &p_texture, 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 = false);
|
2022-12-17 20:47:33 +00:00
|
|
|
void draw_msdf_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), double p_outline = 0.0, double p_pixel_range = 4.0, double p_scale = 1.0);
|
2022-08-12 11:03:28 +00:00
|
|
|
void draw_lcd_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1));
|
2014-02-10 01:10:30 +00:00
|
|
|
void draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect);
|
2023-01-14 05:28:55 +00:00
|
|
|
void draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture = Ref<Texture2D>());
|
2020-10-24 15:15:43 +00:00
|
|
|
void draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture2D> p_texture = Ref<Texture2D>());
|
|
|
|
void draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture2D> p_texture = Ref<Texture2D>());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
void draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_texture, const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1));
|
|
|
|
void draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture2D> &p_texture);
|
2018-02-21 12:38:21 +00:00
|
|
|
|
2022-07-11 09:40:31 +00:00
|
|
|
void draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
|
|
|
|
void draw_multiline_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_max_lines = -1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
|
2022-05-09 09:47:10 +00:00
|
|
|
|
2023-06-08 16:15:38 +00:00
|
|
|
void draw_string_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
|
2022-07-11 09:40:31 +00:00
|
|
|
void draw_multiline_string_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_max_lines = -1, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
|
2022-05-09 09:47:10 +00:00
|
|
|
|
|
|
|
void draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size = Font::DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0)) const;
|
|
|
|
void draw_char_outline(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, int p_font_size = Font::DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0)) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-01-30 04:10:32 +00:00
|
|
|
void draw_set_transform(const Point2 &p_offset, real_t p_rot = 0.0, const Size2 &p_scale = Size2(1.0, 1.0));
|
2017-01-11 03:52:51 +00:00
|
|
|
void draw_set_transform_matrix(const Transform2D &p_matrix);
|
2021-06-17 14:30:20 +00:00
|
|
|
void draw_animation_slice(double p_animation_length, double p_slice_begin, double p_slice_end, double p_offset = 0);
|
|
|
|
void draw_end_animation();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-24 13:21:56 +00:00
|
|
|
static CanvasItem *get_current_item_drawn();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* RECT / TRANSFORM */
|
|
|
|
|
2020-10-02 21:03:52 +00:00
|
|
|
void set_as_top_level(bool p_top_level);
|
2020-10-01 07:17:33 +00:00
|
|
|
bool is_set_as_top_level() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-04-05 15:39:30 +00:00
|
|
|
void set_draw_behind_parent(bool p_enable);
|
|
|
|
bool is_draw_behind_parent_enabled() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
CanvasItem *get_parent_item() const;
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
virtual Transform2D get_transform() const = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
virtual Transform2D get_global_transform() const;
|
|
|
|
virtual Transform2D get_global_transform_with_canvas() const;
|
2020-03-12 12:37:40 +00:00
|
|
|
virtual Transform2D get_screen_transform() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-01 07:17:33 +00:00
|
|
|
CanvasItem *get_top_level() const;
|
2018-03-08 20:35:41 +00:00
|
|
|
_FORCE_INLINE_ RID get_canvas_item() const {
|
|
|
|
return canvas_item;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void set_block_transform_notify(bool p_enable);
|
|
|
|
bool is_block_transform_notify_enabled() const;
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D get_canvas_transform() const;
|
|
|
|
Transform2D get_viewport_transform() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
Rect2 get_viewport_rect() const;
|
|
|
|
RID get_viewport_rid() const;
|
|
|
|
RID get_canvas() const;
|
2018-08-24 22:03:26 +00:00
|
|
|
ObjectID get_canvas_layer_instance_id() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<World2D> get_world_2d() const;
|
2014-04-10 03:18:27 +00:00
|
|
|
|
2017-08-15 21:33:19 +00:00
|
|
|
virtual void set_material(const Ref<Material> &p_material);
|
2017-06-23 17:31:21 +00:00
|
|
|
Ref<Material> get_material() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-15 21:33:19 +00:00
|
|
|
virtual void set_use_parent_material(bool p_use_parent_material);
|
2015-03-02 03:54:10 +00:00
|
|
|
bool get_use_parent_material() const;
|
2015-01-12 23:44:02 +00:00
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
Ref<InputEvent> make_input_local(const Ref<InputEvent> &p_event) const;
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 make_canvas_position_local(const Vector2 &screen_point) const;
|
2015-02-11 09:51:20 +00:00
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
Vector2 get_global_mouse_position() const;
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 get_local_mouse_position() const;
|
2015-05-02 00:13:20 +00:00
|
|
|
|
2015-09-16 01:07:03 +00:00
|
|
|
void set_notify_local_transform(bool p_enable);
|
|
|
|
bool is_local_transform_notification_enabled() const;
|
|
|
|
|
2017-01-12 23:35:46 +00:00
|
|
|
void set_notify_transform(bool p_enable);
|
|
|
|
bool is_transform_notification_enabled() const;
|
|
|
|
|
2018-09-06 23:38:16 +00:00
|
|
|
void force_update_transform();
|
|
|
|
|
2020-02-19 21:26:24 +00:00
|
|
|
virtual void set_texture_filter(TextureFilter p_texture_filter);
|
2019-06-25 01:24:07 +00:00
|
|
|
TextureFilter get_texture_filter() const;
|
|
|
|
|
2020-02-19 21:26:24 +00:00
|
|
|
virtual void set_texture_repeat(TextureRepeat p_texture_repeat);
|
2019-06-25 01:24:07 +00:00
|
|
|
TextureRepeat get_texture_repeat() const;
|
|
|
|
|
2023-06-22 14:23:15 +00:00
|
|
|
TextureFilter get_texture_filter_in_tree() const;
|
|
|
|
TextureRepeat get_texture_repeat_in_tree() const;
|
2022-09-28 14:50:58 +00:00
|
|
|
|
2018-09-13 01:38:39 +00:00
|
|
|
// Used by control nodes to retrieve the parent's anchorable area
|
2018-05-05 14:59:00 +00:00
|
|
|
virtual Rect2 get_anchorable_rect() const { return Rect2(0, 0, 0, 0); };
|
|
|
|
|
2016-01-24 13:57:42 +00:00
|
|
|
int get_canvas_layer() const;
|
2024-01-12 01:37:23 +00:00
|
|
|
CanvasLayer *get_canvas_layer_node() const;
|
2015-09-16 01:07:03 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
CanvasItem();
|
|
|
|
~CanvasItem();
|
|
|
|
};
|
|
|
|
|
2019-06-25 01:24:07 +00:00
|
|
|
VARIANT_ENUM_CAST(CanvasItem::TextureFilter)
|
|
|
|
VARIANT_ENUM_CAST(CanvasItem::TextureRepeat)
|
2022-10-12 19:45:47 +00:00
|
|
|
VARIANT_ENUM_CAST(CanvasItem::ClipChildrenMode)
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
class CanvasTexture : public Texture2D {
|
|
|
|
GDCLASS(CanvasTexture, Texture2D);
|
|
|
|
OBJ_SAVE_TYPE(Texture2D); // Saves derived classes with common type so they can be interchanged.
|
|
|
|
|
|
|
|
Ref<Texture2D> diffuse_texture;
|
|
|
|
Ref<Texture2D> normal_texture;
|
|
|
|
Ref<Texture2D> specular_texture;
|
|
|
|
Color specular = Color(1, 1, 1, 1);
|
2021-01-30 04:10:32 +00:00
|
|
|
real_t shininess = 1.0;
|
2020-10-24 15:15:43 +00:00
|
|
|
|
|
|
|
RID canvas_texture;
|
|
|
|
|
|
|
|
CanvasItem::TextureFilter texture_filter = CanvasItem::TEXTURE_FILTER_PARENT_NODE;
|
|
|
|
CanvasItem::TextureRepeat texture_repeat = CanvasItem::TEXTURE_REPEAT_PARENT_NODE;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_diffuse_texture(const Ref<Texture2D> &p_diffuse);
|
|
|
|
Ref<Texture2D> get_diffuse_texture() const;
|
|
|
|
|
|
|
|
void set_normal_texture(const Ref<Texture2D> &p_normal);
|
|
|
|
Ref<Texture2D> get_normal_texture() const;
|
|
|
|
|
|
|
|
void set_specular_texture(const Ref<Texture2D> &p_specular);
|
|
|
|
Ref<Texture2D> get_specular_texture() const;
|
|
|
|
|
|
|
|
void set_specular_color(const Color &p_color);
|
|
|
|
Color get_specular_color() const;
|
|
|
|
|
2021-01-30 04:10:32 +00:00
|
|
|
void set_specular_shininess(real_t p_shininess);
|
|
|
|
real_t get_specular_shininess() const;
|
2020-10-24 15:15:43 +00:00
|
|
|
|
|
|
|
void set_texture_filter(CanvasItem::TextureFilter p_filter);
|
|
|
|
CanvasItem::TextureFilter get_texture_filter() const;
|
|
|
|
|
|
|
|
void set_texture_repeat(CanvasItem::TextureRepeat p_repeat);
|
|
|
|
CanvasItem::TextureRepeat get_texture_repeat() const;
|
|
|
|
|
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
|
|
|
|
virtual bool is_pixel_opaque(int p_x, int p_y) const override;
|
|
|
|
virtual bool has_alpha() const override;
|
|
|
|
|
2021-03-28 11:32:17 +00:00
|
|
|
virtual Ref<Image> get_image() const override;
|
2020-10-24 15:15:43 +00:00
|
|
|
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
|
|
|
|
CanvasTexture();
|
|
|
|
~CanvasTexture();
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif // CANVAS_ITEM_H
|