graph_node.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /*************************************************************************/
  2. /* graph_node.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "graph_node.h"
  31. bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
  32. if (!p_name.operator String().begins_with("slot/")) {
  33. return false;
  34. }
  35. int idx = p_name.operator String().get_slice("/", 1).to_int();
  36. String what = p_name.operator String().get_slice("/", 2);
  37. Slot si;
  38. if (slot_info.has(idx)) {
  39. si = slot_info[idx];
  40. }
  41. if (what == "left_enabled") {
  42. si.enable_left = p_value;
  43. } else if (what == "left_type") {
  44. si.type_left = p_value;
  45. } else if (what == "left_color") {
  46. si.color_left = p_value;
  47. } else if (what == "right_enabled") {
  48. si.enable_right = p_value;
  49. } else if (what == "right_type") {
  50. si.type_right = p_value;
  51. } else if (what == "right_color") {
  52. si.color_right = p_value;
  53. } else {
  54. return false;
  55. }
  56. set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right);
  57. update();
  58. return true;
  59. }
  60. bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
  61. if (!p_name.operator String().begins_with("slot/")) {
  62. return false;
  63. }
  64. int idx = p_name.operator String().get_slice("/", 1).to_int();
  65. String what = p_name.operator String().get_slice("/", 2);
  66. Slot si;
  67. if (slot_info.has(idx)) {
  68. si = slot_info[idx];
  69. }
  70. if (what == "left_enabled") {
  71. r_ret = si.enable_left;
  72. } else if (what == "left_type") {
  73. r_ret = si.type_left;
  74. } else if (what == "left_color") {
  75. r_ret = si.color_left;
  76. } else if (what == "right_enabled") {
  77. r_ret = si.enable_right;
  78. } else if (what == "right_type") {
  79. r_ret = si.type_right;
  80. } else if (what == "right_color") {
  81. r_ret = si.color_right;
  82. } else {
  83. return false;
  84. }
  85. return true;
  86. }
  87. void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
  88. int idx = 0;
  89. for (int i = 0; i < get_child_count(); i++) {
  90. Control *c = Object::cast_to<Control>(get_child(i));
  91. if (!c || c->is_set_as_top_level()) {
  92. continue;
  93. }
  94. String base = "slot/" + itos(idx) + "/";
  95. p_list->push_back(PropertyInfo(Variant::BOOL, base + "left_enabled"));
  96. p_list->push_back(PropertyInfo(Variant::INT, base + "left_type"));
  97. p_list->push_back(PropertyInfo(Variant::COLOR, base + "left_color"));
  98. p_list->push_back(PropertyInfo(Variant::BOOL, base + "right_enabled"));
  99. p_list->push_back(PropertyInfo(Variant::INT, base + "right_type"));
  100. p_list->push_back(PropertyInfo(Variant::COLOR, base + "right_color"));
  101. idx++;
  102. }
  103. }
  104. void GraphNode::_resort() {
  105. int sep = get_theme_constant("separation");
  106. Ref<StyleBox> sb = get_theme_stylebox("frame");
  107. bool first = true;
  108. Size2 minsize;
  109. for (int i = 0; i < get_child_count(); i++) {
  110. Control *c = Object::cast_to<Control>(get_child(i));
  111. if (!c) {
  112. continue;
  113. }
  114. if (c->is_set_as_top_level()) {
  115. continue;
  116. }
  117. Size2i size = c->get_combined_minimum_size();
  118. minsize.y += size.y;
  119. minsize.x = MAX(minsize.x, size.x);
  120. if (first) {
  121. first = false;
  122. } else {
  123. minsize.y += sep;
  124. }
  125. }
  126. int vofs = 0;
  127. int w = get_size().x - sb->get_minimum_size().x;
  128. cache_y.clear();
  129. for (int i = 0; i < get_child_count(); i++) {
  130. Control *c = Object::cast_to<Control>(get_child(i));
  131. if (!c) {
  132. continue;
  133. }
  134. if (c->is_set_as_top_level()) {
  135. continue;
  136. }
  137. Size2i size = c->get_combined_minimum_size();
  138. Rect2 r(sb->get_margin(MARGIN_LEFT), sb->get_margin(MARGIN_TOP) + vofs, w, size.y);
  139. fit_child_in_rect(c, r);
  140. cache_y.push_back(vofs + size.y * 0.5);
  141. vofs += size.y + sep;
  142. }
  143. update();
  144. connpos_dirty = true;
  145. }
  146. bool GraphNode::has_point(const Point2 &p_point) const {
  147. if (comment) {
  148. Ref<StyleBox> comment = get_theme_stylebox("comment");
  149. Ref<Texture2D> resizer = get_theme_icon("resizer");
  150. if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) {
  151. return true;
  152. }
  153. if (Rect2(0, 0, get_size().width, comment->get_margin(MARGIN_TOP)).has_point(p_point)) {
  154. return true;
  155. }
  156. return false;
  157. } else {
  158. return Control::has_point(p_point);
  159. }
  160. }
  161. void GraphNode::_notification(int p_what) {
  162. switch (p_what) {
  163. case NOTIFICATION_DRAW: {
  164. Ref<StyleBox> sb;
  165. if (comment) {
  166. sb = get_theme_stylebox(selected ? "commentfocus" : "comment");
  167. } else {
  168. sb = get_theme_stylebox(selected ? "selectedframe" : "frame");
  169. }
  170. //sb=sb->duplicate();
  171. //sb->call("set_modulate",modulate);
  172. Ref<Texture2D> port = get_theme_icon("port");
  173. Ref<Texture2D> close = get_theme_icon("close");
  174. Ref<Texture2D> resizer = get_theme_icon("resizer");
  175. int close_offset = get_theme_constant("close_offset");
  176. int close_h_offset = get_theme_constant("close_h_offset");
  177. Color close_color = get_theme_color("close_color");
  178. Color resizer_color = get_theme_color("resizer_color");
  179. Ref<Font> title_font = get_theme_font("title_font");
  180. int title_offset = get_theme_constant("title_offset");
  181. int title_h_offset = get_theme_constant("title_h_offset");
  182. Color title_color = get_theme_color("title_color");
  183. Point2i icofs = -port->get_size() * 0.5;
  184. int edgeofs = get_theme_constant("port_offset");
  185. icofs.y += sb->get_margin(MARGIN_TOP);
  186. draw_style_box(sb, Rect2(Point2(), get_size()));
  187. switch (overlay) {
  188. case OVERLAY_DISABLED: {
  189. } break;
  190. case OVERLAY_BREAKPOINT: {
  191. draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size()));
  192. } break;
  193. case OVERLAY_POSITION: {
  194. draw_style_box(get_theme_stylebox("position"), Rect2(Point2(), get_size()));
  195. } break;
  196. }
  197. int w = get_size().width - sb->get_minimum_size().x;
  198. if (show_close) {
  199. w -= close->get_width();
  200. }
  201. draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
  202. if (show_close) {
  203. Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT) + close_h_offset, -close->get_height() + close_offset);
  204. draw_texture(close, cpos, close_color);
  205. close_rect.position = cpos;
  206. close_rect.size = close->get_size();
  207. } else {
  208. close_rect = Rect2();
  209. }
  210. for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
  211. if (E->key() < 0 || E->key() >= cache_y.size()) {
  212. continue;
  213. }
  214. if (!slot_info.has(E->key())) {
  215. continue;
  216. }
  217. const Slot &s = slot_info[E->key()];
  218. //left
  219. if (s.enable_left) {
  220. Ref<Texture2D> p = port;
  221. if (s.custom_slot_left.is_valid()) {
  222. p = s.custom_slot_left;
  223. }
  224. p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left);
  225. }
  226. if (s.enable_right) {
  227. Ref<Texture2D> p = port;
  228. if (s.custom_slot_right.is_valid()) {
  229. p = s.custom_slot_right;
  230. }
  231. p->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E->key()]), s.color_right);
  232. }
  233. }
  234. if (resizable) {
  235. draw_texture(resizer, get_size() - resizer->get_size(), resizer_color);
  236. }
  237. } break;
  238. case NOTIFICATION_SORT_CHILDREN: {
  239. _resort();
  240. } break;
  241. case NOTIFICATION_THEME_CHANGED: {
  242. minimum_size_changed();
  243. } break;
  244. }
  245. }
  246. void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture2D> &p_custom_left, const Ref<Texture2D> &p_custom_right) {
  247. ERR_FAIL_COND(p_idx < 0);
  248. if (!p_enable_left && p_type_left == 0 && p_color_left == Color(1, 1, 1, 1) && !p_enable_right && p_type_right == 0 && p_color_right == Color(1, 1, 1, 1)) {
  249. slot_info.erase(p_idx);
  250. return;
  251. }
  252. Slot s;
  253. s.enable_left = p_enable_left;
  254. s.type_left = p_type_left;
  255. s.color_left = p_color_left;
  256. s.enable_right = p_enable_right;
  257. s.type_right = p_type_right;
  258. s.color_right = p_color_right;
  259. s.custom_slot_left = p_custom_left;
  260. s.custom_slot_right = p_custom_right;
  261. slot_info[p_idx] = s;
  262. update();
  263. connpos_dirty = true;
  264. }
  265. void GraphNode::clear_slot(int p_idx) {
  266. slot_info.erase(p_idx);
  267. update();
  268. connpos_dirty = true;
  269. }
  270. void GraphNode::clear_all_slots() {
  271. slot_info.clear();
  272. update();
  273. connpos_dirty = true;
  274. }
  275. bool GraphNode::is_slot_enabled_left(int p_idx) const {
  276. if (!slot_info.has(p_idx)) {
  277. return false;
  278. }
  279. return slot_info[p_idx].enable_left;
  280. }
  281. int GraphNode::get_slot_type_left(int p_idx) const {
  282. if (!slot_info.has(p_idx)) {
  283. return 0;
  284. }
  285. return slot_info[p_idx].type_left;
  286. }
  287. Color GraphNode::get_slot_color_left(int p_idx) const {
  288. if (!slot_info.has(p_idx)) {
  289. return Color(1, 1, 1, 1);
  290. }
  291. return slot_info[p_idx].color_left;
  292. }
  293. bool GraphNode::is_slot_enabled_right(int p_idx) const {
  294. if (!slot_info.has(p_idx)) {
  295. return false;
  296. }
  297. return slot_info[p_idx].enable_right;
  298. }
  299. int GraphNode::get_slot_type_right(int p_idx) const {
  300. if (!slot_info.has(p_idx)) {
  301. return 0;
  302. }
  303. return slot_info[p_idx].type_right;
  304. }
  305. Color GraphNode::get_slot_color_right(int p_idx) const {
  306. if (!slot_info.has(p_idx)) {
  307. return Color(1, 1, 1, 1);
  308. }
  309. return slot_info[p_idx].color_right;
  310. }
  311. Size2 GraphNode::get_minimum_size() const {
  312. Ref<Font> title_font = get_theme_font("title_font");
  313. int sep = get_theme_constant("separation");
  314. Ref<StyleBox> sb = get_theme_stylebox("frame");
  315. bool first = true;
  316. Size2 minsize;
  317. minsize.x = title_font->get_string_size(title).x;
  318. if (show_close) {
  319. Ref<Texture2D> close = get_theme_icon("close");
  320. minsize.x += sep + close->get_width();
  321. }
  322. for (int i = 0; i < get_child_count(); i++) {
  323. Control *c = Object::cast_to<Control>(get_child(i));
  324. if (!c) {
  325. continue;
  326. }
  327. if (c->is_set_as_top_level()) {
  328. continue;
  329. }
  330. Size2i size = c->get_combined_minimum_size();
  331. minsize.y += size.y;
  332. minsize.x = MAX(minsize.x, size.x);
  333. if (first) {
  334. first = false;
  335. } else {
  336. minsize.y += sep;
  337. }
  338. }
  339. return minsize + sb->get_minimum_size();
  340. }
  341. void GraphNode::set_title(const String &p_title) {
  342. if (title == p_title) {
  343. return;
  344. }
  345. title = p_title;
  346. update();
  347. _change_notify("title");
  348. minimum_size_changed();
  349. }
  350. String GraphNode::get_title() const {
  351. return title;
  352. }
  353. void GraphNode::set_offset(const Vector2 &p_offset) {
  354. offset = p_offset;
  355. emit_signal("offset_changed");
  356. update();
  357. }
  358. Vector2 GraphNode::get_offset() const {
  359. return offset;
  360. }
  361. void GraphNode::set_selected(bool p_selected) {
  362. selected = p_selected;
  363. update();
  364. }
  365. bool GraphNode::is_selected() {
  366. return selected;
  367. }
  368. void GraphNode::set_drag(bool p_drag) {
  369. if (p_drag) {
  370. drag_from = get_offset();
  371. } else {
  372. emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo
  373. }
  374. }
  375. Vector2 GraphNode::get_drag_from() {
  376. return drag_from;
  377. }
  378. void GraphNode::set_show_close_button(bool p_enable) {
  379. show_close = p_enable;
  380. update();
  381. }
  382. bool GraphNode::is_close_button_visible() const {
  383. return show_close;
  384. }
  385. void GraphNode::_connpos_update() {
  386. int edgeofs = get_theme_constant("port_offset");
  387. int sep = get_theme_constant("separation");
  388. Ref<StyleBox> sb = get_theme_stylebox("frame");
  389. conn_input_cache.clear();
  390. conn_output_cache.clear();
  391. int vofs = 0;
  392. int idx = 0;
  393. for (int i = 0; i < get_child_count(); i++) {
  394. Control *c = Object::cast_to<Control>(get_child(i));
  395. if (!c) {
  396. continue;
  397. }
  398. if (c->is_set_as_top_level()) {
  399. continue;
  400. }
  401. Size2i size = c->get_combined_minimum_size();
  402. int y = sb->get_margin(MARGIN_TOP) + vofs;
  403. int h = size.y;
  404. if (slot_info.has(idx)) {
  405. if (slot_info[idx].enable_left) {
  406. ConnCache cc;
  407. cc.pos = Point2i(edgeofs, y + h / 2);
  408. cc.type = slot_info[idx].type_left;
  409. cc.color = slot_info[idx].color_left;
  410. conn_input_cache.push_back(cc);
  411. }
  412. if (slot_info[idx].enable_right) {
  413. ConnCache cc;
  414. cc.pos = Point2i(get_size().width - edgeofs, y + h / 2);
  415. cc.type = slot_info[idx].type_right;
  416. cc.color = slot_info[idx].color_right;
  417. conn_output_cache.push_back(cc);
  418. }
  419. }
  420. vofs += sep;
  421. vofs += size.y;
  422. idx++;
  423. }
  424. connpos_dirty = false;
  425. }
  426. int GraphNode::get_connection_input_count() {
  427. if (connpos_dirty) {
  428. _connpos_update();
  429. }
  430. return conn_input_cache.size();
  431. }
  432. int GraphNode::get_connection_output_count() {
  433. if (connpos_dirty) {
  434. _connpos_update();
  435. }
  436. return conn_output_cache.size();
  437. }
  438. Vector2 GraphNode::get_connection_input_position(int p_idx) {
  439. if (connpos_dirty) {
  440. _connpos_update();
  441. }
  442. ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2());
  443. Vector2 pos = conn_input_cache[p_idx].pos;
  444. pos.x *= get_scale().x;
  445. pos.y *= get_scale().y;
  446. return pos;
  447. }
  448. int GraphNode::get_connection_input_type(int p_idx) {
  449. if (connpos_dirty) {
  450. _connpos_update();
  451. }
  452. ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0);
  453. return conn_input_cache[p_idx].type;
  454. }
  455. Color GraphNode::get_connection_input_color(int p_idx) {
  456. if (connpos_dirty) {
  457. _connpos_update();
  458. }
  459. ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color());
  460. return conn_input_cache[p_idx].color;
  461. }
  462. Vector2 GraphNode::get_connection_output_position(int p_idx) {
  463. if (connpos_dirty) {
  464. _connpos_update();
  465. }
  466. ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2());
  467. Vector2 pos = conn_output_cache[p_idx].pos;
  468. pos.x *= get_scale().x;
  469. pos.y *= get_scale().y;
  470. return pos;
  471. }
  472. int GraphNode::get_connection_output_type(int p_idx) {
  473. if (connpos_dirty) {
  474. _connpos_update();
  475. }
  476. ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0);
  477. return conn_output_cache[p_idx].type;
  478. }
  479. Color GraphNode::get_connection_output_color(int p_idx) {
  480. if (connpos_dirty) {
  481. _connpos_update();
  482. }
  483. ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color());
  484. return conn_output_cache[p_idx].color;
  485. }
  486. void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
  487. Ref<InputEventMouseButton> mb = p_ev;
  488. if (mb.is_valid()) {
  489. ERR_FAIL_COND_MSG(get_parent_control() == nullptr, "GraphNode must be the child of a GraphEdit node.");
  490. if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  491. Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y);
  492. if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
  493. //send focus to parent
  494. get_parent_control()->grab_focus();
  495. emit_signal("close_request");
  496. accept_event();
  497. return;
  498. }
  499. Ref<Texture2D> resizer = get_theme_icon("resizer");
  500. if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) {
  501. resizing = true;
  502. resizing_from = mpos;
  503. resizing_from_size = get_size();
  504. accept_event();
  505. return;
  506. }
  507. emit_signal("raise_request");
  508. }
  509. if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  510. resizing = false;
  511. }
  512. }
  513. Ref<InputEventMouseMotion> mm = p_ev;
  514. if (resizing && mm.is_valid()) {
  515. Vector2 mpos = mm->get_position();
  516. Vector2 diff = mpos - resizing_from;
  517. emit_signal("resize_request", resizing_from_size + diff);
  518. }
  519. }
  520. void GraphNode::set_overlay(Overlay p_overlay) {
  521. overlay = p_overlay;
  522. update();
  523. }
  524. GraphNode::Overlay GraphNode::get_overlay() const {
  525. return overlay;
  526. }
  527. void GraphNode::set_comment(bool p_enable) {
  528. comment = p_enable;
  529. update();
  530. }
  531. bool GraphNode::is_comment() const {
  532. return comment;
  533. }
  534. void GraphNode::set_resizable(bool p_enable) {
  535. resizable = p_enable;
  536. update();
  537. }
  538. bool GraphNode::is_resizable() const {
  539. return resizable;
  540. }
  541. void GraphNode::_bind_methods() {
  542. ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
  543. ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
  544. ClassDB::bind_method(D_METHOD("_gui_input"), &GraphNode::_gui_input);
  545. ClassDB::bind_method(D_METHOD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right", "custom_left", "custom_right"), &GraphNode::set_slot, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()));
  546. ClassDB::bind_method(D_METHOD("clear_slot", "idx"), &GraphNode::clear_slot);
  547. ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots);
  548. ClassDB::bind_method(D_METHOD("is_slot_enabled_left", "idx"), &GraphNode::is_slot_enabled_left);
  549. ClassDB::bind_method(D_METHOD("get_slot_type_left", "idx"), &GraphNode::get_slot_type_left);
  550. ClassDB::bind_method(D_METHOD("get_slot_color_left", "idx"), &GraphNode::get_slot_color_left);
  551. ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "idx"), &GraphNode::is_slot_enabled_right);
  552. ClassDB::bind_method(D_METHOD("get_slot_type_right", "idx"), &GraphNode::get_slot_type_right);
  553. ClassDB::bind_method(D_METHOD("get_slot_color_right", "idx"), &GraphNode::get_slot_color_right);
  554. ClassDB::bind_method(D_METHOD("set_offset", "offset"), &GraphNode::set_offset);
  555. ClassDB::bind_method(D_METHOD("get_offset"), &GraphNode::get_offset);
  556. ClassDB::bind_method(D_METHOD("set_comment", "comment"), &GraphNode::set_comment);
  557. ClassDB::bind_method(D_METHOD("is_comment"), &GraphNode::is_comment);
  558. ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &GraphNode::set_resizable);
  559. ClassDB::bind_method(D_METHOD("is_resizable"), &GraphNode::is_resizable);
  560. ClassDB::bind_method(D_METHOD("set_selected", "selected"), &GraphNode::set_selected);
  561. ClassDB::bind_method(D_METHOD("is_selected"), &GraphNode::is_selected);
  562. ClassDB::bind_method(D_METHOD("get_connection_output_count"), &GraphNode::get_connection_output_count);
  563. ClassDB::bind_method(D_METHOD("get_connection_input_count"), &GraphNode::get_connection_input_count);
  564. ClassDB::bind_method(D_METHOD("get_connection_output_position", "idx"), &GraphNode::get_connection_output_position);
  565. ClassDB::bind_method(D_METHOD("get_connection_output_type", "idx"), &GraphNode::get_connection_output_type);
  566. ClassDB::bind_method(D_METHOD("get_connection_output_color", "idx"), &GraphNode::get_connection_output_color);
  567. ClassDB::bind_method(D_METHOD("get_connection_input_position", "idx"), &GraphNode::get_connection_input_position);
  568. ClassDB::bind_method(D_METHOD("get_connection_input_type", "idx"), &GraphNode::get_connection_input_type);
  569. ClassDB::bind_method(D_METHOD("get_connection_input_color", "idx"), &GraphNode::get_connection_input_color);
  570. ClassDB::bind_method(D_METHOD("set_show_close_button", "show"), &GraphNode::set_show_close_button);
  571. ClassDB::bind_method(D_METHOD("is_close_button_visible"), &GraphNode::is_close_button_visible);
  572. ClassDB::bind_method(D_METHOD("set_overlay", "overlay"), &GraphNode::set_overlay);
  573. ClassDB::bind_method(D_METHOD("get_overlay"), &GraphNode::get_overlay);
  574. ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
  575. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
  576. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), "set_show_close_button", "is_close_button_visible");
  577. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable"), "set_resizable", "is_resizable");
  578. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selected"), "set_selected", "is_selected");
  579. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "comment"), "set_comment", "is_comment");
  580. ADD_PROPERTY(PropertyInfo(Variant::INT, "overlay", PROPERTY_HINT_ENUM, "Disabled,Breakpoint,Position"), "set_overlay", "get_overlay");
  581. ADD_SIGNAL(MethodInfo("offset_changed"));
  582. ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));
  583. ADD_SIGNAL(MethodInfo("raise_request"));
  584. ADD_SIGNAL(MethodInfo("close_request"));
  585. ADD_SIGNAL(MethodInfo("resize_request", PropertyInfo(Variant::VECTOR2, "new_minsize")));
  586. BIND_ENUM_CONSTANT(OVERLAY_DISABLED);
  587. BIND_ENUM_CONSTANT(OVERLAY_BREAKPOINT);
  588. BIND_ENUM_CONSTANT(OVERLAY_POSITION);
  589. }
  590. GraphNode::GraphNode() {
  591. overlay = OVERLAY_DISABLED;
  592. show_close = false;
  593. connpos_dirty = true;
  594. set_mouse_filter(MOUSE_FILTER_STOP);
  595. comment = false;
  596. resizable = false;
  597. resizing = false;
  598. selected = false;
  599. }