-Cleaned up GraphEdit, also fixes #3568

This commit is contained in:
Juan Linietsky 2016-02-08 16:28:12 -03:00
parent a84dfbc46b
commit 34c022a0a2
8 changed files with 112 additions and 30 deletions

View File

@ -4,6 +4,12 @@
#include "scene/gui/box_container.h"
#define ZOOM_SCALE 1.2
#define MIN_ZOOM (((1/ZOOM_SCALE)/ZOOM_SCALE)/ZOOM_SCALE)
#define MAX_ZOOM (1*ZOOM_SCALE*ZOOM_SCALE*ZOOM_SCALE)
bool GraphEditFilter::has_point(const Point2& p_point) const {
return ge->_filter_input(p_point);
@ -85,9 +91,10 @@ void GraphEdit::_update_scroll_offset() {
if (!gn)
continue;
Point2 pos=gn->get_offset();
Point2 pos=gn->get_offset()*zoom;
pos-=Point2(h_scroll->get_val(),v_scroll->get_val());
gn->set_pos(pos);
gn->set_scale(Vector2(zoom,zoom));
}
}
@ -106,8 +113,8 @@ void GraphEdit::_update_scroll() {
continue;
Rect2 r;
r.pos=gn->get_offset();
r.size=gn->get_size();
r.pos=gn->get_offset()*zoom;
r.size=gn->get_size()*zoom;
screen = screen.merge(r);
}
@ -193,10 +200,11 @@ void GraphEdit::_notification(int p_what) {
h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height);
h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
zoom_icon->set_texture( get_icon("Zoom", "EditorIcons"));
// zoom_icon->set_texture( get_icon("Zoom", "EditorIcons"));
}
if (p_what==NOTIFICATION_DRAW) {
draw_style_box( get_stylebox("bg"),Rect2(Point2(),get_size()) );
VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
}
@ -516,7 +524,7 @@ void GraphEdit::_input_event(const InputEvent& p_ev) {
for(int i=get_child_count()-1;i>=0;i--) {
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
if (gn && gn->is_selected())
gn->set_offset(gn->get_drag_from()+drag_accum);
gn->set_offset((gn->get_drag_from()*zoom+drag_accum)/zoom);
}
}
@ -650,6 +658,8 @@ void GraphEdit::_input_event(const InputEvent& p_ev) {
} else {
if (_filter_input(Vector2(b.x,b.y)))
return;
if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
return;
box_selecting = true;
box_selecting_from = get_local_mouse_pos();
@ -697,11 +707,13 @@ void GraphEdit::_input_event(const InputEvent& p_ev) {
}
if (b.button_index==BUTTON_WHEEL_UP && b.pressed) {
sl_zoom->set_val(zoom/0.9);
//too difficult to get right
//set_zoom(zoom*ZOOM_SCALE);
}
if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) {
sl_zoom->set_val(zoom*0.9);
//too difficult to get right
//set_zoom(zoom/ZOOM_SCALE);
}
}
@ -725,21 +737,29 @@ void GraphEdit::clear_connections() {
void GraphEdit::set_zoom(float p_zoom) {
if (p_zoom<0.01) p_zoom=0.01;
if (p_zoom>4) p_zoom=4;
p_zoom=CLAMP(p_zoom,MIN_ZOOM,MAX_ZOOM);
if (zoom == p_zoom)
return;
zoom_minus->set_disabled(zoom==MIN_ZOOM);
zoom_plus->set_disabled(zoom==MAX_ZOOM);
Vector2 sbofs = (Vector2( h_scroll->get_val(), v_scroll->get_val() ) + get_size()/2)/zoom;
float prev_zoom = zoom;
zoom = p_zoom;
for (int i = 0; i < get_child_count(); i++) {
GraphNode *child = get_child(i)->cast_to<GraphNode>();
if (!child)
continue;
Point2 ofs = child->get_offset() / prev_zoom * zoom;
child->set_scale(Vector2(zoom,zoom));
child->set_offset(ofs);
top_layer->update();
_update_scroll();
if (is_visible()) {
Vector2 ofs = sbofs*zoom - get_size()/2;
h_scroll->set_val( ofs.x );
v_scroll->set_val( ofs.y );
}
update();
}
@ -772,6 +792,26 @@ Array GraphEdit::_get_connection_list() const {
}
return arr;
}
void GraphEdit::_zoom_minus() {
set_zoom(zoom/ZOOM_SCALE);
}
void GraphEdit::_zoom_reset() {
set_zoom(1);
}
void GraphEdit::_zoom_plus() {
set_zoom(zoom*ZOOM_SCALE);
}
void GraphEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node);
@ -792,6 +832,9 @@ void GraphEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_top_layer_input"),&GraphEdit::_top_layer_input);
ObjectTypeDB::bind_method(_MD("_top_layer_draw"),&GraphEdit::_top_layer_draw);
ObjectTypeDB::bind_method(_MD("_scroll_moved"),&GraphEdit::_scroll_moved);
ObjectTypeDB::bind_method(_MD("_zoom_minus"),&GraphEdit::_zoom_minus);
ObjectTypeDB::bind_method(_MD("_zoom_reset"),&GraphEdit::_zoom_reset);
ObjectTypeDB::bind_method(_MD("_zoom_plus"),&GraphEdit::_zoom_plus);
ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event);
@ -837,18 +880,25 @@ GraphEdit::GraphEdit() {
zoom = 1;
HBoxContainer* tools = memnew( HBoxContainer );
add_child(tools);
HBoxContainer *zoom_hb = memnew( HBoxContainer );
top_layer->add_child(zoom_hb);
zoom_hb->set_pos(Vector2(10,10));
zoom_minus = memnew( ToolButton );
zoom_hb->add_child(zoom_minus);
zoom_minus->connect("pressed",this,"_zoom_minus");
zoom_minus->set_icon(get_icon("minus"));
zoom_reset = memnew( ToolButton );
zoom_hb->add_child(zoom_reset);
zoom_reset->connect("pressed",this,"_zoom_reset");
zoom_reset->set_icon(get_icon("reset"));
zoom_plus = memnew( ToolButton );
zoom_hb->add_child(zoom_plus);
zoom_plus->connect("pressed",this,"_zoom_plus");
zoom_plus->set_icon(get_icon("more"));
zoom_icon = memnew( TextureFrame );
tools->add_child(zoom_icon);
sl_zoom = memnew( HSlider );
sl_zoom->set_min(0.01);
sl_zoom->set_max(4);
sl_zoom->set_val(1);
sl_zoom->set_step(0.01);
sl_zoom->connect("value_changed", this, "set_zoom");
tools->add_child(sl_zoom);
sl_zoom->set_custom_minimum_size(Size2(200,0));
}

View File

@ -4,7 +4,9 @@
#include "scene/gui/graph_node.h"
#include "scene/gui/scroll_bar.h"
#include "scene/gui/slider.h"
#include "scene/gui/tool_button.h"
#include "texture_frame.h"
class GraphEdit;
class GraphEditFilter : public Control {
@ -35,8 +37,15 @@ public:
};
private:
TextureFrame* zoom_icon;
HSlider* sl_zoom;
ToolButton *zoom_minus;
ToolButton *zoom_reset;
ToolButton *zoom_plus;
void _zoom_minus();
void _zoom_reset();
void _zoom_plus();
HScrollBar* h_scroll;
VScrollBar* v_scroll;

View File

@ -591,4 +591,5 @@ void GraphNode::_bind_methods() {
GraphNode::GraphNode() {
show_close=false;
connpos_dirty=true;
set_stop_mouse(false);
}

View File

@ -884,6 +884,13 @@ void make_default_theme() {
t->set_stylebox("panelf","Panel", tc_sb );
t->set_stylebox("panel","PanelContainer", tc_sb );
t->set_icon("minus","GraphEdit", make_icon(icon_zoom_less_png) );
t->set_icon("reset","GraphEdit", make_icon(icon_zoom_reset_png) );
t->set_icon("more","GraphEdit", make_icon(icon_zoom_more_png) );
t->set_stylebox("bg","GraphEdit", make_stylebox( tree_bg_png,4,4,4,5) );
t->set_icon( "logo","Icons", make_icon(logo_png) );

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

View File

@ -214,6 +214,21 @@ static const unsigned char icon_stop_png[]={
};
static const unsigned char icon_zoom_less_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x12,0x0,0x0,0xb,0x12,0x1,0xd2,0xdd,0x7e,0xfc,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x2,0x8,0x11,0x19,0x15,0x8e,0xdd,0x4e,0x19,0x0,0x0,0x1,0x25,0x49,0x44,0x41,0x54,0x38,0xcb,0x9d,0x92,0xc1,0x8a,0xc2,0x30,0x10,0x86,0xbf,0x99,0x36,0x94,0xd2,0xaa,0x4,0x5b,0x28,0x78,0xe9,0xfb,0x3f,0x95,0x22,0x78,0x11,0x9,0x4a,0xf,0xb5,0xd8,0x64,0x2f,0xdb,0xec,0xb2,0xad,0xbb,0xae,0xdf,0x29,0xcc,0x64,0xfe,0xfc,0x33,0x19,0xe1,0x13,0xe7,0x1c,0xd6,0x5a,0x2e,0x97,0xb,0xde,0x7b,0x0,0x54,0x95,0xed,0x76,0x1b,0x73,0x4b,0xc8,0x54,0xc,0xd0,0x75,0x1d,0xe3,0x38,0x92,0xa6,0x29,0x0,0x8f,0xc7,0x83,0x24,0x49,0x28,0x8a,0x2,0x11,0x59,0x14,0x91,0xe9,0xb0,0xdf,0xef,0x11,0x11,0xd2,0x34,0x65,0xb7,0xdb,0xc5,0xb,0xa7,0xd3,0x89,0x61,0x18,0x68,0xdb,0x76,0xd1,0x89,0x38,0xe7,0xb8,0xdf,0xef,0xf4,0x7d,0xf,0xc0,0x66,0xb3,0x1,0xc0,0x5a,0x1b,0xb,0x8e,0xc7,0x23,0xc6,0x18,0x9a,0xa6,0x99,0x39,0x50,0x6b,0x2d,0x7d,0xdf,0x53,0x96,0x25,0xab,0xd5,0x2a,0x16,0x7f,0x17,0xc9,0xf3,0x3c,0x3e,0x30,0x13,0x88,0x56,0x44,0x50,0xd5,0xe5,0x3e,0x45,0x78,0x86,0x0,0x1c,0xe,0x7,0x42,0x8,0x81,0x7f,0xd0,0xb6,0xad,0x0,0xa8,0x73,0x8e,0x2c,0xcb,0x78,0x17,0x5,0x16,0x87,0xf3,0xb2,0xc0,0x34,0xa8,0x77,0x91,0xa5,0x4d,0x1c,0xc7,0x11,0x80,0x24,0x49,0xe2,0x26,0x5e,0xaf,0x57,0xb2,0x2c,0xc3,0x18,0x43,0x55,0x55,0xf3,0x5f,0x98,0xa6,0xaf,0xaa,0x18,0x63,0x30,0xc6,0xa0,0x1a,0xd3,0xe4,0x79,0xce,0x30,0xc,0x74,0x5d,0xc7,0xf9,0x7c,0x9e,0x3b,0xf8,0xd,0xe7,0x1c,0x21,0x4,0x6e,0xb7,0x5b,0x8c,0x15,0x45,0x41,0x5d,0xd7,0xaf,0x9,0x3c,0x13,0x29,0xcb,0xf2,0xab,0x85,0xbf,0xb0,0xd6,0x22,0x22,0xac,0xd7,0xeb,0x18,0xf3,0xde,0xbf,0xee,0xe0,0xa7,0x13,0xef,0x3d,0x55,0x55,0xf1,0x1,0x48,0x6e,0x80,0x3e,0x13,0xf0,0x5,0xd,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};
static const unsigned char icon_zoom_more_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x12,0x0,0x0,0xb,0x12,0x1,0xd2,0xdd,0x7e,0xfc,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x2,0x8,0x11,0x19,0x1f,0x6e,0x8,0xa7,0x7,0x0,0x0,0x1,0x23,0x49,0x44,0x41,0x54,0x38,0xcb,0x9d,0x92,0x4d,0xaf,0x82,0x30,0x10,0x45,0xcf,0x8c,0x36,0xe0,0x77,0x1a,0x59,0xb0,0x70,0xe1,0xff,0xff,0x57,0xae,0xd5,0x34,0x10,0x30,0x60,0x68,0xeb,0xe6,0xc1,0xf3,0x9,0x26,0xfa,0xee,0xae,0x69,0xe7,0xcc,0xcc,0xbd,0x15,0x7e,0xe4,0x9c,0xc3,0x5a,0xcb,0xf5,0x7a,0x25,0x84,0x0,0x80,0xaa,0xb2,0xdf,0xef,0x87,0xbb,0x29,0x49,0x5f,0x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x21,0x2f,0x17,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};
static const unsigned char icon_zoom_reset_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x12,0x0,0x0,0xb,0x12,0x1,0xd2,0xdd,0x7e,0xfc,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x2,0x8,0x11,0x1b,0xa,0x31,0xe3,0x21,0x6e,0x0,0x0,0x0,0xd6,0x49,0x44,0x41,0x54,0x38,0xcb,0xa5,0x92,0xc1,0xaa,0x84,0x30,0xc,0x45,0x4f,0xaa,0x20,0xea,0x42,0x8a,0x2e,0x5c,0xf6,0xff,0xbf,0xaa,0x1f,0xa0,0x4,0xc4,0x85,0x82,0xb6,0x6f,0xf3,0x94,0x19,0x47,0x1d,0x66,0xe6,0xac,0x4a,0x93,0x9b,0x26,0xe9,0x15,0xfe,0x51,0x55,0xac,0xb5,0xf4,0x7d,0x4f,0x8,0x1,0x0,0x63,0xc,0x75,0x5d,0xef,0xb1,0x33,0x64,0x13,0x3,0x8c,0xe3,0xc8,0xba,0xae,0xa4,0x69,0xa,0xc0,0xb2,0x2c,0x24,0x49,0x42,0x59,0x96,0x88,0xc8,0x69,0x11,0xd9,0xe,0xde,0x7b,0x80,0x78,0xbc,0xdf,0x70,0xce,0x3d,0xe5,0x38,0xe7,0x4,0x20,0x55,0x55,0xe6,0x79,0x66,0x9a,0xa6,0xc8,0xd,0x87,0x7,0x76,0x8c,0xb5,0xf6,0x4e,0x1c,0x1f,0x44,0xa7,0x39,0x86,0x1f,0x31,0x0,0x22,0x22,0x67,0x73,0x9f,0xec,0xeb,0x25,0xc7,0xa8,0x2a,0x59,0x96,0x7d,0x24,0x7a,0xe9,0xa0,0x6d,0xdb,0xef,0x47,0xb0,0xd6,0xee,0x3e,0x78,0xb3,0xc4,0xeb,0xe,0xac,0xb5,0x54,0x55,0xf5,0xfd,0x12,0xb7,0x22,0x77,0xe4,0x79,0x7e,0x6d,0x65,0xef,0x7d,0xbc,0x8a,0x1d,0xc6,0x39,0xba,0x53,0x7e,0xf2,0x41,0xd7,0x75,0x6f,0xff,0xfe,0x9,0x55,0x25,0xc6,0xc8,0x30,0xc,0x0,0x14,0x45,0xf1,0x59,0x81,0xc7,0x22,0x21,0x4,0x9a,0xa6,0xe1,0xf,0x29,0x54,0x56,0xd3,0x43,0xf4,0x61,0x53,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};
static const unsigned char line_edit_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x8,0x6,0x0,0x0,0x0,0x8d,0x32,0xcf,0xbd,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0xa,0x14,0x3,0x1d,0x2f,0xec,0x8c,0x33,0x2f,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x9d,0x49,0x44,0x41,0x54,0x18,0xd3,0xb5,0x90,0x31,0xe,0xc2,0x40,0x10,0x3,0xed,0xbb,0xd5,0x25,0xa1,0xa1,0x3,0x9,0x41,0xc1,0x33,0x78,0x15,0x5f,0xc8,0x93,0x41,0x14,0x49,0x2e,0xbb,0xb7,0x29,0x2,0x52,0x20,0x14,0x34,0x58,0x72,0x63,0x4f,0x61,0x99,0xfb,0xdd,0xe1,0x9a,0x52,0xd5,0xc6,0x10,0x6b,0x92,0x58,0xca,0xdd,0x61,0xc5,0xfa,0x9c,0x87,0x96,0xa7,0xe3,0xf9,0x56,0xa5,0x7a,0x2b,0x22,0x0,0xde,0x41,0xc0,0xa1,0xaa,0x18,0x72,0x7f,0x97,0x18,0x62,0x23,0x22,0x88,0x22,0xe0,0x7,0xe8,0x70,0x0,0x80,0x6a,0x6c,0x2,0xc9,0x2,0x70,0x5,0x1,0x78,0x66,0x4,0xc9,0x12,0xf0,0xa3,0xfe,0x0,0xba,0x7b,0x98,0x67,0xfb,0xaa,0x9c,0x33,0x87,0xbb,0x7,0xb1,0x62,0x9d,0xaa,0xa6,0xd7,0xfc,0x6f,0xf7,0x58,0xb1,0x3e,0x36,0xf5,0xa6,0x3,0x70,0x29,0x66,0x30,0x53,0x5d,0x5a,0x75,0xd4,0x51,0xc7,0x47,0xce,0x43,0x3b,0x1,0xc,0x2e,0x55,0x5d,0x5f,0x72,0xb6,0x33,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};