2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* canvas_item.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2020-01-01 18:16:22 +08:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* 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-05 07:50:27 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
#ifndef CANVAS_ITEM_H
|
|
|
|
#define CANVAS_ITEM_H
|
|
|
|
|
|
|
|
#include "scene/main/node.h"
|
2017-06-27 09:58:03 +08:00
|
|
|
#include "scene/main/scene_tree.h"
|
2016-10-04 03:33:42 +08:00
|
|
|
#include "scene/resources/material.h"
|
2018-02-21 20:38:21 +08:00
|
|
|
#include "scene/resources/multimesh.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "scene/resources/shader.h"
|
|
|
|
#include "scene/resources/texture.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
class CanvasLayer;
|
|
|
|
class Viewport;
|
|
|
|
class Font;
|
|
|
|
|
|
|
|
class StyleBox;
|
|
|
|
|
2017-06-24 01:31:21 +08:00
|
|
|
class CanvasItemMaterial : public Material {
|
|
|
|
|
2019-03-20 02:35:57 +08:00
|
|
|
GDCLASS(CanvasItemMaterial, Material);
|
2017-06-24 01:31:21 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum BlendMode {
|
|
|
|
BLEND_MODE_MIX,
|
|
|
|
BLEND_MODE_ADD,
|
|
|
|
BLEND_MODE_SUB,
|
|
|
|
BLEND_MODE_MUL,
|
2018-05-07 19:24:29 +08:00
|
|
|
BLEND_MODE_PREMULT_ALPHA,
|
|
|
|
BLEND_MODE_DISABLED
|
2017-06-24 01:31:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum LightMode {
|
|
|
|
LIGHT_MODE_NORMAL,
|
|
|
|
LIGHT_MODE_UNSHADED,
|
|
|
|
LIGHT_MODE_LIGHT_ONLY
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
union MaterialKey {
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32_t blend_mode : 4;
|
|
|
|
uint32_t light_mode : 4;
|
2018-09-27 19:05:57 +08:00
|
|
|
uint32_t particles_animation : 1;
|
2017-06-24 01:31:21 +08:00
|
|
|
uint32_t invalid_key : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t key;
|
|
|
|
|
|
|
|
bool operator<(const MaterialKey &p_key) const {
|
|
|
|
return key < p_key.key;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-27 19:05:57 +08:00
|
|
|
struct ShaderNames {
|
|
|
|
StringName particles_anim_h_frames;
|
|
|
|
StringName particles_anim_v_frames;
|
|
|
|
StringName particles_anim_loop;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ShaderNames *shader_names;
|
|
|
|
|
2017-06-24 01:31:21 +08:00
|
|
|
struct ShaderData {
|
|
|
|
RID shader;
|
|
|
|
int users;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Map<MaterialKey, ShaderData> shader_map;
|
|
|
|
|
|
|
|
MaterialKey current_key;
|
|
|
|
|
|
|
|
_FORCE_INLINE_ MaterialKey _compute_key() const {
|
|
|
|
|
|
|
|
MaterialKey mk;
|
|
|
|
mk.key = 0;
|
|
|
|
mk.blend_mode = blend_mode;
|
|
|
|
mk.light_mode = light_mode;
|
2018-09-27 19:05:57 +08:00
|
|
|
mk.particles_animation = particles_animation;
|
2017-06-24 01:31:21 +08:00
|
|
|
return mk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Mutex *material_mutex;
|
2018-11-21 23:48:05 +08:00
|
|
|
static SelfList<CanvasItemMaterial>::List *dirty_materials;
|
2017-06-24 01:31:21 +08:00
|
|
|
SelfList<CanvasItemMaterial> element;
|
|
|
|
|
|
|
|
void _update_shader();
|
|
|
|
_FORCE_INLINE_ void _queue_shader_change();
|
|
|
|
_FORCE_INLINE_ bool _is_shader_dirty() const;
|
|
|
|
|
|
|
|
BlendMode blend_mode;
|
|
|
|
LightMode light_mode;
|
2018-09-27 19:05:57 +08:00
|
|
|
bool particles_animation;
|
|
|
|
|
|
|
|
int particles_anim_h_frames;
|
|
|
|
int particles_anim_v_frames;
|
|
|
|
bool particles_anim_loop;
|
2017-06-24 01:31:21 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _validate_property(PropertyInfo &property) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_blend_mode(BlendMode p_blend_mode);
|
|
|
|
BlendMode get_blend_mode() const;
|
|
|
|
|
|
|
|
void set_light_mode(LightMode p_light_mode);
|
|
|
|
LightMode get_light_mode() const;
|
|
|
|
|
2018-09-27 19:05:57 +08:00
|
|
|
void set_particles_animation(bool p_particles_anim);
|
|
|
|
bool get_particles_animation() const;
|
|
|
|
|
|
|
|
void set_particles_anim_h_frames(int p_frames);
|
|
|
|
int get_particles_anim_h_frames() const;
|
|
|
|
void set_particles_anim_v_frames(int p_frames);
|
|
|
|
int get_particles_anim_v_frames() const;
|
|
|
|
|
2019-06-26 21:08:25 +08:00
|
|
|
void set_particles_anim_loop(bool p_loop);
|
2018-09-27 19:05:57 +08:00
|
|
|
bool get_particles_anim_loop() const;
|
|
|
|
|
2017-06-24 01:31:21 +08:00
|
|
|
static void init_shaders();
|
|
|
|
static void finish_shaders();
|
|
|
|
static void flush_changes();
|
|
|
|
|
2017-11-15 02:44:51 +08:00
|
|
|
RID get_shader_rid() const;
|
|
|
|
|
2017-12-07 06:43:22 +08:00
|
|
|
virtual Shader::Mode get_shader_mode() const;
|
|
|
|
|
2017-06-24 01:31:21 +08:00
|
|
|
CanvasItemMaterial();
|
|
|
|
virtual ~CanvasItemMaterial();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(CanvasItemMaterial::BlendMode)
|
|
|
|
VARIANT_ENUM_CAST(CanvasItemMaterial::LightMode)
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
class CanvasItem : public Node {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(CanvasItem, Node);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
2019-06-25 09:24:07 +08:00
|
|
|
enum TextureFilter {
|
2019-07-21 22:31:30 +08:00
|
|
|
TEXTURE_FILTER_PARENT_NODE,
|
2019-06-25 09:24:07 +08:00
|
|
|
TEXTURE_FILTER_NEAREST,
|
|
|
|
TEXTURE_FILTER_LINEAR,
|
|
|
|
TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS,
|
2019-07-21 22:31:30 +08:00
|
|
|
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS,
|
|
|
|
TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS_ANISOTROPIC,
|
|
|
|
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC,
|
2019-06-25 09:24:07 +08:00
|
|
|
TEXTURE_FILTER_MAX
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-06-25 09:24:07 +08:00
|
|
|
enum TextureRepeat {
|
2019-07-21 22:31:30 +08:00
|
|
|
TEXTURE_REPEAT_PARENT_NODE,
|
2019-06-25 09:24:07 +08:00
|
|
|
TEXTURE_REPEAT_DISABLED,
|
|
|
|
TEXTURE_REPEAT_ENABLED,
|
|
|
|
TEXTURE_REPEAT_MIRROR,
|
|
|
|
TEXTURE_REPEAT_MAX,
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable SelfList<Node> xform_change;
|
|
|
|
|
|
|
|
RID canvas_item;
|
|
|
|
String group;
|
|
|
|
|
|
|
|
CanvasLayer *canvas_layer;
|
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
Color modulate;
|
|
|
|
Color self_modulate;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
List<CanvasItem *> children_items;
|
|
|
|
List<CanvasItem *>::Element *C;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-02-19 06:39:44 +08:00
|
|
|
int light_mask;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
bool first_draw;
|
2017-01-13 21:45:50 +08:00
|
|
|
bool visible;
|
2014-02-10 09:10:30 +08:00
|
|
|
bool pending_update;
|
|
|
|
bool toplevel;
|
|
|
|
bool drawing;
|
|
|
|
bool block_transform_notify;
|
2014-04-05 23:39:30 +08:00
|
|
|
bool behind;
|
2015-03-02 11:54:10 +08:00
|
|
|
bool use_parent_material;
|
2015-09-16 09:07:03 +08:00
|
|
|
bool notify_local_transform;
|
2017-01-13 07:35:46 +08:00
|
|
|
bool notify_transform;
|
2015-02-19 06:39:44 +08:00
|
|
|
|
2019-06-25 09:24:07 +08:00
|
|
|
VS::CanvasItemTextureFilter texture_filter_cache;
|
|
|
|
VS::CanvasItemTextureRepeat texture_repeat_cache;
|
|
|
|
|
|
|
|
TextureFilter texture_filter;
|
|
|
|
TextureRepeat texture_repeat;
|
|
|
|
|
2017-06-24 01:31:21 +08:00
|
|
|
Ref<Material> material;
|
2015-01-11 22:43:31 +08:00
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
mutable Transform2D global_transform;
|
2014-02-10 09:10:30 +08:00
|
|
|
mutable bool global_invalid;
|
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
void _toplevel_raise_self();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void _propagate_visibility_changed(bool p_visible);
|
|
|
|
|
|
|
|
void _update_callback();
|
|
|
|
|
|
|
|
void _enter_canvas();
|
|
|
|
void _exit_canvas();
|
|
|
|
|
|
|
|
void _notify_transform(CanvasItem *p_node);
|
|
|
|
|
2014-04-05 23:39:30 +08:00
|
|
|
void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); }
|
|
|
|
bool _is_on_top() const { return !is_draw_behind_parent_enabled(); }
|
|
|
|
|
2019-01-24 21:21:56 +08:00
|
|
|
static CanvasItem *current_item_drawn;
|
2019-06-25 09:24:07 +08:00
|
|
|
friend class Viewport;
|
|
|
|
void _update_texture_repeat_changed(bool p_propagate);
|
|
|
|
void _update_texture_filter_changed(bool p_propagate);
|
2019-01-24 21:21:56 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
protected:
|
2017-03-05 23:44:50 +08:00
|
|
|
_FORCE_INLINE_ void _notify_transform() {
|
|
|
|
if (!is_inside_tree()) return;
|
|
|
|
_notify_transform(this);
|
|
|
|
if (!block_transform_notify && notify_local_transform) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void item_rect_changed(bool p_size_changed = true);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
2014-02-10 09:10:30 +08:00
|
|
|
enum {
|
2017-03-05 23:44:50 +08:00
|
|
|
NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique
|
|
|
|
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,
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* EDITOR */
|
2019-10-22 05:37:07 +08:00
|
|
|
#ifdef TOOLS_ENABLED
|
2018-05-05 22:59:00 +08:00
|
|
|
// Select the node
|
|
|
|
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
|
|
|
|
|
2018-03-09 04:35:41 +08:00
|
|
|
// Save and restore a CanvasItem state
|
2017-11-16 06:03:25 +08:00
|
|
|
virtual void _edit_set_state(const Dictionary &p_state){};
|
|
|
|
virtual Dictionary _edit_get_state() const { return Dictionary(); };
|
|
|
|
|
2018-03-09 04:35:41 +08: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-16 06:03:25 +08:00
|
|
|
|
2018-03-09 04:35:41 +08: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 22:59:00 +08:00
|
|
|
// Used to rotate the node
|
|
|
|
virtual bool _edit_use_rotation() const { return false; };
|
|
|
|
virtual void _edit_set_rotation(float p_rotation){};
|
|
|
|
virtual float _edit_get_rotation() const { return 0.0; };
|
|
|
|
|
2018-03-09 04:35:41 +08:00
|
|
|
// Used to resize/move the node
|
2018-05-05 22:59:00 +08:00
|
|
|
virtual bool _edit_use_rect() const { return false; }; // MAYBE REPLACE BY A _edit_get_editmode()
|
2017-11-16 06:03:25 +08:00
|
|
|
virtual void _edit_set_rect(const Rect2 &p_rect){};
|
2018-03-09 04:35:41 +08:00
|
|
|
virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); };
|
2018-05-05 22:59:00 +08:00
|
|
|
virtual Size2 _edit_get_minimum_size() const { return Size2(-1, -1); }; // LOOKS WEIRD
|
2017-11-16 06:03:25 +08:00
|
|
|
|
|
|
|
// Used to set a pivot
|
2018-05-05 22:59:00 +08:00
|
|
|
virtual bool _edit_use_pivot() const { return false; };
|
2017-11-16 06:03:25 +08:00
|
|
|
virtual void _edit_set_pivot(const Point2 &p_pivot){};
|
2018-05-05 22:59:00 +08:00
|
|
|
virtual Point2 _edit_get_pivot() const { return Point2(); };
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-10-20 18:11:06 +08:00
|
|
|
virtual Transform2D _edit_get_transform() const;
|
2019-10-22 05:37:07 +08:00
|
|
|
#endif
|
2019-10-20 18:11:06 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
/* VISIBILITY */
|
|
|
|
|
2017-01-13 21:45:50 +08:00
|
|
|
void set_visible(bool p_visible);
|
2014-02-10 09:10:30 +08:00
|
|
|
bool is_visible() const;
|
2017-01-13 21:45:50 +08:00
|
|
|
bool is_visible_in_tree() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
void show();
|
|
|
|
void hide();
|
|
|
|
|
|
|
|
void update();
|
|
|
|
|
2015-12-30 01:47:13 +08:00
|
|
|
virtual void set_light_mask(int p_light_mask);
|
2015-02-19 06:39:44 +08:00
|
|
|
int get_light_mask() const;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void set_modulate(const Color &p_modulate);
|
2016-10-04 03:33:42 +08:00
|
|
|
Color get_modulate() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void set_self_modulate(const Color &p_self_modulate);
|
2016-10-04 03:33:42 +08:00
|
|
|
Color get_self_modulate() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
/* DRAWING API */
|
|
|
|
|
2019-06-25 09:24:07 +08:00
|
|
|
void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width = 1.0);
|
|
|
|
void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width = 1.0);
|
|
|
|
void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = 1.0);
|
|
|
|
void draw_arc(const Vector2 &p_center, float p_radius, float p_start_angle, float p_end_angle, int p_point_count, const Color &p_color, float p_width = 1.0);
|
|
|
|
void draw_multiline(const Vector<Point2> &p_points, const Color &p_color, float p_width = 1.0);
|
|
|
|
void draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = 1.0);
|
|
|
|
void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true, float p_width = 1.0);
|
2017-03-05 23:44:50 +08:00
|
|
|
void draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color);
|
2019-07-21 22:31:30 +08:00
|
|
|
void draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1), const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
|
|
|
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, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
|
|
|
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, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), bool p_clip_uv = false, TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
2017-03-05 23:44:50 +08:00
|
|
|
void draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect);
|
2019-07-21 22:31:30 +08: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>(), float p_width = 1, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
|
|
|
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>(), const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
|
|
|
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>(), const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-07-21 22:31:30 +08:00
|
|
|
void draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
|
|
|
void draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE);
|
2018-02-21 20:38:21 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate = Color(1, 1, 1), int p_clip_w = -1);
|
|
|
|
float draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next = "", const Color &p_modulate = Color(1, 1, 1));
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale);
|
|
|
|
void draw_set_transform_matrix(const Transform2D &p_matrix);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-01-24 21:21:56 +08:00
|
|
|
static CanvasItem *get_current_item_drawn();
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
/* RECT / TRANSFORM */
|
|
|
|
|
|
|
|
void set_as_toplevel(bool p_toplevel);
|
|
|
|
bool is_set_as_toplevel() const;
|
|
|
|
|
2014-04-05 23:39:30 +08:00
|
|
|
void set_draw_behind_parent(bool p_enable);
|
|
|
|
bool is_draw_behind_parent_enabled() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
CanvasItem *get_parent_item() const;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
virtual Transform2D get_transform() const = 0;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
virtual Transform2D get_global_transform() const;
|
|
|
|
virtual Transform2D get_global_transform_with_canvas() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
CanvasItem *get_toplevel() const;
|
2018-03-09 04:35:41 +08:00
|
|
|
_FORCE_INLINE_ RID get_canvas_item() const {
|
|
|
|
return canvas_item;
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void set_block_transform_notify(bool p_enable);
|
|
|
|
bool is_block_transform_notify_enabled() const;
|
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D get_canvas_transform() const;
|
|
|
|
Transform2D get_viewport_transform() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
Rect2 get_viewport_rect() const;
|
|
|
|
RID get_viewport_rid() const;
|
|
|
|
RID get_canvas() const;
|
2018-08-25 06:03:26 +08:00
|
|
|
ObjectID get_canvas_layer_instance_id() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
Ref<World2D> get_world_2d() const;
|
2014-04-10 11:18:27 +08:00
|
|
|
|
2017-08-16 05:33:19 +08:00
|
|
|
virtual void set_material(const Ref<Material> &p_material);
|
2017-06-24 01:31:21 +08:00
|
|
|
Ref<Material> get_material() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-08-16 05:33:19 +08:00
|
|
|
virtual void set_use_parent_material(bool p_use_parent_material);
|
2015-03-02 11:54:10 +08:00
|
|
|
bool get_use_parent_material() const;
|
2015-01-13 07:44:02 +08:00
|
|
|
|
2017-08-12 03:10:05 +08:00
|
|
|
Ref<InputEvent> make_input_local(const Ref<InputEvent> &p_event) const;
|
2017-09-10 21:37:49 +08:00
|
|
|
Vector2 make_canvas_position_local(const Vector2 &screen_point) const;
|
2015-02-11 17:51:20 +08:00
|
|
|
|
2017-03-29 23:29:38 +08:00
|
|
|
Vector2 get_global_mouse_position() const;
|
2017-09-10 21:37:49 +08:00
|
|
|
Vector2 get_local_mouse_position() const;
|
2015-05-02 08:13:20 +08:00
|
|
|
|
2015-09-16 09:07:03 +08:00
|
|
|
void set_notify_local_transform(bool p_enable);
|
|
|
|
bool is_local_transform_notification_enabled() const;
|
|
|
|
|
2017-01-13 07:35:46 +08:00
|
|
|
void set_notify_transform(bool p_enable);
|
|
|
|
bool is_transform_notification_enabled() const;
|
|
|
|
|
2018-09-07 07:38:16 +08:00
|
|
|
void force_update_transform();
|
|
|
|
|
2019-06-25 09:24:07 +08:00
|
|
|
void set_texture_filter(TextureFilter p_texture_filter);
|
|
|
|
TextureFilter get_texture_filter() const;
|
|
|
|
|
|
|
|
void set_texture_repeat(TextureRepeat p_texture_repeat);
|
|
|
|
TextureRepeat get_texture_repeat() const;
|
|
|
|
|
2018-09-13 09:38:39 +08:00
|
|
|
// Used by control nodes to retrieve the parent's anchorable area
|
2018-05-05 22:59:00 +08:00
|
|
|
virtual Rect2 get_anchorable_rect() const { return Rect2(0, 0, 0, 0); };
|
|
|
|
|
2016-01-24 21:57:42 +08:00
|
|
|
int get_canvas_layer() const;
|
2015-09-16 09:07:03 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
CanvasItem();
|
|
|
|
~CanvasItem();
|
|
|
|
};
|
|
|
|
|
2019-06-25 09:24:07 +08:00
|
|
|
VARIANT_ENUM_CAST(CanvasItem::TextureFilter)
|
|
|
|
VARIANT_ENUM_CAST(CanvasItem::TextureRepeat)
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
#endif // CANVAS_ITEM_H
|