2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* graph_edit.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2016-06-18 14:46:12 +02: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. */
|
|
|
|
/*************************************************************************/
|
2015-01-03 20:52:37 +01:00
|
|
|
#ifndef GRAPH_EDIT_H
|
|
|
|
#define GRAPH_EDIT_H
|
|
|
|
|
|
|
|
#include "scene/gui/graph_node.h"
|
|
|
|
#include "scene/gui/scroll_bar.h"
|
2016-01-19 02:10:44 +01:00
|
|
|
#include "scene/gui/slider.h"
|
2016-02-08 20:28:12 +01:00
|
|
|
#include "scene/gui/tool_button.h"
|
2016-01-19 02:10:44 +01:00
|
|
|
#include "texture_frame.h"
|
2016-02-08 20:28:12 +01:00
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
class GraphEdit;
|
|
|
|
|
|
|
|
class GraphEditFilter : public Control {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
OBJ_TYPE(GraphEditFilter,Control);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
friend class GraphEdit;
|
|
|
|
GraphEdit *ge;
|
|
|
|
virtual bool has_point(const Point2& p_point) const;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEditFilter(GraphEdit *p_edit);
|
2015-01-03 20:52:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class GraphEdit : public Control {
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
OBJ_TYPE(GraphEdit,Control);
|
2015-01-03 20:52:37 +01:00
|
|
|
public:
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
struct Connection {
|
|
|
|
StringName from;
|
|
|
|
StringName to;
|
|
|
|
int from_port;
|
|
|
|
int to_port;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
};
|
2015-01-03 20:52:37 +01:00
|
|
|
private:
|
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
|
|
|
|
ToolButton *zoom_minus;
|
|
|
|
ToolButton *zoom_reset;
|
|
|
|
ToolButton *zoom_plus;
|
|
|
|
|
|
|
|
void _zoom_minus();
|
|
|
|
void _zoom_reset();
|
|
|
|
void _zoom_plus();
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
HScrollBar* h_scroll;
|
|
|
|
VScrollBar* v_scroll;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
bool connecting;
|
|
|
|
String connecting_from;
|
|
|
|
bool connecting_out;
|
|
|
|
int connecting_index;
|
|
|
|
int connecting_type;
|
|
|
|
Color connecting_color;
|
|
|
|
bool connecting_target;
|
|
|
|
Vector2 connecting_to;
|
|
|
|
String connecting_target_to;
|
|
|
|
int connecting_target_index;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
bool dragging;
|
|
|
|
bool just_selected;
|
|
|
|
Vector2 drag_accum;
|
2016-07-26 23:19:41 +02:00
|
|
|
Point2 drag_origin; // Workaround for GH-5907
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
float zoom;
|
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
bool box_selecting;
|
|
|
|
bool box_selection_mode_aditive;
|
|
|
|
Point2 box_selecting_from;
|
|
|
|
Point2 box_selecting_to;
|
|
|
|
Rect2 box_selecting_rect;
|
|
|
|
List<GraphNode*> previus_selected;
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
bool right_disconnects;
|
|
|
|
bool updating;
|
|
|
|
List<Connection> connections;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
void _graph_node_raised(Node* p_gn);
|
|
|
|
void _graph_node_moved(Node *p_gn);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
void _update_scroll();
|
|
|
|
void _scroll_moved(double);
|
|
|
|
void _input_event(const InputEvent& p_ev);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEditFilter *top_layer;
|
|
|
|
void _top_layer_input(const InputEvent& p_ev);
|
|
|
|
void _top_layer_draw();
|
|
|
|
void _update_scroll_offset();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Array _get_connection_list() const;
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
friend class GraphEditFilter;
|
|
|
|
bool _filter_input(const Point2& p_point);
|
2015-01-03 20:52:37 +01:00
|
|
|
protected:
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
static void _bind_methods();
|
|
|
|
virtual void add_child_notify(Node *p_child);
|
|
|
|
virtual void remove_child_notify(Node *p_child);
|
|
|
|
void _notification(int p_what);
|
2016-01-23 22:49:26 +01:00
|
|
|
virtual bool clips_input() const;
|
2015-01-03 20:52:37 +01:00
|
|
|
public:
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
|
|
|
|
bool is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
|
|
|
|
void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
|
|
|
|
void clear_connections();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
void set_zoom(float p_zoom);
|
|
|
|
float get_zoom() const;
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEditFilter *get_top_layer() const { return top_layer; }
|
|
|
|
void get_connection_list(List<Connection> *r_connections) const;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
void set_right_disconnects(bool p_enable);
|
|
|
|
bool is_right_disconnects_enabled() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-01-17 22:26:32 +01:00
|
|
|
Vector2 get_scroll_ofs() const;
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEdit();
|
2015-01-03 20:52:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GRAPHEdit_H
|