graph_node.cpp 21 KB

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