2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* canvas_item.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 01:10:30 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef CANVAS_ITEM_H
|
|
|
|
#define CANVAS_ITEM_H
|
|
|
|
|
|
|
|
#include "scene/main/node.h"
|
|
|
|
#include "scene/main/scene_main_loop.h"
|
2016-10-03 19:33:42 +00:00
|
|
|
#include "scene/resources/material.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/resources/shader.h"
|
|
|
|
#include "scene/resources/texture.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
class CanvasLayer;
|
|
|
|
class Viewport;
|
|
|
|
class Font;
|
|
|
|
|
|
|
|
class StyleBox;
|
|
|
|
|
2016-10-10 21:31:01 +00:00
|
|
|
class CanvasItemMaterial : public Material {
|
2015-03-02 03:54:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(CanvasItemMaterial, Material);
|
2015-03-02 03:54:10 +00:00
|
|
|
Ref<Shader> shader;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2015-04-03 04:43:37 +00:00
|
|
|
public:
|
2016-10-03 19:33:42 +00:00
|
|
|
/*enum ShadingMode {
|
2015-04-03 04:43:37 +00:00
|
|
|
SHADING_NORMAL,
|
|
|
|
SHADING_UNSHADED,
|
|
|
|
SHADING_ONLY_LIGHT,
|
2016-10-03 19:33:42 +00:00
|
|
|
};*/
|
2015-03-02 03:54:10 +00:00
|
|
|
|
|
|
|
protected:
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2015-03-02 03:54:10 +00:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
|
2015-03-02 03:54:10 +00:00
|
|
|
|
|
|
|
public:
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_shader(const Ref<Shader> &p_shader);
|
2015-03-02 03:54:10 +00:00
|
|
|
Ref<Shader> get_shader() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_shader_param(const StringName &p_param, const Variant &p_value);
|
|
|
|
Variant get_shader_param(const StringName &p_param) const;
|
2015-03-02 03:54:10 +00:00
|
|
|
|
|
|
|
CanvasItemMaterial();
|
|
|
|
~CanvasItemMaterial();
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class CanvasItem : public Node {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(CanvasItem, Node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
enum BlendMode {
|
|
|
|
|
|
|
|
BLEND_MODE_MIX, //default
|
|
|
|
BLEND_MODE_ADD,
|
|
|
|
BLEND_MODE_SUB,
|
2014-05-24 04:35:47 +00:00
|
|
|
BLEND_MODE_MUL,
|
|
|
|
BLEND_MODE_PREMULT_ALPHA
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable SelfList<Node> xform_change;
|
|
|
|
|
|
|
|
RID canvas_item;
|
|
|
|
String group;
|
|
|
|
|
|
|
|
CanvasLayer *canvas_layer;
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
Color modulate;
|
|
|
|
Color self_modulate;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
List<CanvasItem *> children_items;
|
|
|
|
List<CanvasItem *>::Element *C;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-02-18 22:39:44 +00:00
|
|
|
int light_mask;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool first_draw;
|
2017-01-13 13:45:50 +00:00
|
|
|
bool visible;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool pending_update;
|
|
|
|
bool toplevel;
|
|
|
|
bool drawing;
|
|
|
|
bool block_transform_notify;
|
2014-04-05 15:39:30 +00:00
|
|
|
bool behind;
|
2015-03-02 03:54:10 +00:00
|
|
|
bool use_parent_material;
|
2015-09-16 01:07:03 +00:00
|
|
|
bool notify_local_transform;
|
2017-01-12 23:35:46 +00:00
|
|
|
bool notify_transform;
|
2015-02-18 22:39:44 +00:00
|
|
|
|
2015-03-02 03:54:10 +00:00
|
|
|
Ref<CanvasItemMaterial> material;
|
2015-01-11 14:43:31 +00:00
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
mutable Transform2D global_transform;
|
2014-02-10 01:10:30 +00:00
|
|
|
mutable bool global_invalid;
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
void _toplevel_raise_self();
|
2014-02-10 01:10:30 +00: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 15:39:30 +00: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(); }
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
2017-03-05 15:44:50 +00: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 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +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();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
enum {
|
2017-03-05 15:44:50 +00: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 01:10:30 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* EDITOR */
|
|
|
|
|
|
|
|
virtual Variant edit_get_state() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void edit_set_state(const Variant &p_state);
|
|
|
|
virtual void edit_set_rect(const Rect2 &p_edit_rect);
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual void edit_rotate(float p_rot);
|
|
|
|
virtual Size2 edit_get_minimum_size() const;
|
|
|
|
|
|
|
|
/* 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();
|
|
|
|
|
|
|
|
void update();
|
|
|
|
|
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;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_modulate(const Color &p_modulate);
|
2016-10-03 19:33:42 +00:00
|
|
|
Color get_modulate() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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
|
|
|
|
|
|
|
/* DRAWING API */
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width = 1.0, bool p_antialiased = false);
|
|
|
|
void draw_rect(const Rect2 &p_rect, const Color &p_color);
|
|
|
|
void draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color);
|
|
|
|
void draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1));
|
|
|
|
void draw_texture_rect(const Ref<Texture> &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<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
|
|
|
|
void draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect);
|
|
|
|
void draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture = Ref<Texture>(), float p_width = 1);
|
|
|
|
void draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture> p_texture = Ref<Texture>());
|
|
|
|
void draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture> p_texture = Ref<Texture>());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00: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 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00: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 01:10:30 +00:00
|
|
|
|
|
|
|
/* RECT / TRANSFORM */
|
|
|
|
|
|
|
|
void set_as_toplevel(bool p_toplevel);
|
|
|
|
bool is_set_as_toplevel() const;
|
|
|
|
|
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-03-05 15:44:50 +00:00
|
|
|
virtual Rect2 get_item_rect() const = 0;
|
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-14 00:37:04 +00:00
|
|
|
Rect2 get_item_and_children_rect() const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
CanvasItem *get_toplevel() const;
|
|
|
|
_FORCE_INLINE_ RID get_canvas_item() const { return canvas_item; }
|
|
|
|
|
|
|
|
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;
|
|
|
|
Ref<World2D> get_world_2d() const;
|
2014-04-10 03:18:27 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_material(const Ref<CanvasItemMaterial> &p_material);
|
2015-03-02 03:54:10 +00:00
|
|
|
Ref<CanvasItemMaterial> get_material() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-03-02 03:54:10 +00:00
|
|
|
void set_use_parent_material(bool p_use_parent_material);
|
|
|
|
bool get_use_parent_material() const;
|
2015-01-12 23:44:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
InputEvent make_input_local(const InputEvent &pevent) const;
|
|
|
|
Vector2 make_canvas_pos_local(const Vector2 &screen_point) const;
|
2015-02-11 09:51:20 +00:00
|
|
|
|
2015-05-02 00:13:20 +00:00
|
|
|
Vector2 get_global_mouse_pos() const;
|
|
|
|
Vector2 get_local_mouse_pos() const;
|
|
|
|
|
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;
|
|
|
|
|
2016-01-24 13:57:42 +00:00
|
|
|
int get_canvas_layer() const;
|
2015-09-16 01:07:03 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
CanvasItem();
|
|
|
|
~CanvasItem();
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VARIANT_ENUM_CAST(CanvasItem::BlendMode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#endif // CANVAS_ITEM_H
|