editor_spin_slider.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**************************************************************************/
  2. /* editor_spin_slider.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "editor_spin_slider.h"
  31. #include "core/math/expression.h"
  32. #include "core/os/input.h"
  33. #include "core/os/keyboard.h"
  34. #include "editor_node.h"
  35. #include "editor_scale.h"
  36. String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const {
  37. if (grabber->is_visible()) {
  38. #ifdef OSX_ENABLED
  39. const int key = KEY_META;
  40. #else
  41. const int key = KEY_CONTROL;
  42. #endif
  43. return rtos(get_value()) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key));
  44. }
  45. return rtos(get_value());
  46. }
  47. String EditorSpinSlider::get_text_value() const {
  48. return String::num(get_value(), Math::range_step_decimals(get_step()));
  49. }
  50. void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) {
  51. if (read_only) {
  52. return;
  53. }
  54. Ref<InputEventMouseButton> mb = p_event;
  55. if (mb.is_valid()) {
  56. if (mb->get_button_index() == BUTTON_LEFT) {
  57. if (mb->is_pressed()) {
  58. if (updown_offset != -1 && mb->get_position().x > updown_offset) {
  59. //there is an updown, so use it.
  60. if (mb->get_position().y < get_size().height / 2) {
  61. set_value(get_value() + get_step());
  62. } else {
  63. set_value(get_value() - get_step());
  64. }
  65. return;
  66. } else {
  67. grabbing_spinner_attempt = true;
  68. grabbing_spinner_dist_cache = 0;
  69. pre_grab_value = get_value();
  70. grabbing_spinner = false;
  71. grabbing_spinner_mouse_pos = Input::get_singleton()->get_mouse_position();
  72. }
  73. } else {
  74. if (grabbing_spinner_attempt) {
  75. if (grabbing_spinner) {
  76. Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
  77. Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos);
  78. update();
  79. } else {
  80. _focus_entered();
  81. }
  82. grabbing_spinner = false;
  83. grabbing_spinner_attempt = false;
  84. }
  85. }
  86. } else if (mb->get_button_index() == BUTTON_WHEEL_UP || mb->get_button_index() == BUTTON_WHEEL_DOWN) {
  87. if (grabber->is_visible()) {
  88. call_deferred("update");
  89. }
  90. }
  91. }
  92. Ref<InputEventMouseMotion> mm = p_event;
  93. if (mm.is_valid()) {
  94. if (grabbing_spinner_attempt) {
  95. double diff_x = mm->get_relative().x;
  96. if (mm->get_shift() && grabbing_spinner) {
  97. diff_x *= 0.1;
  98. }
  99. grabbing_spinner_dist_cache += diff_x;
  100. if (!grabbing_spinner && ABS(grabbing_spinner_dist_cache) > 4 * EDSCALE) {
  101. Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
  102. grabbing_spinner = true;
  103. }
  104. if (grabbing_spinner) {
  105. // Don't make the user scroll all the way back to 'in range' if they went off the end.
  106. if (pre_grab_value < get_min() && !is_lesser_allowed()) {
  107. pre_grab_value = get_min();
  108. }
  109. if (pre_grab_value > get_max() && !is_greater_allowed()) {
  110. pre_grab_value = get_max();
  111. }
  112. if (mm->get_command()) {
  113. // If control was just pressed, don't make the value do a huge jump in magnitude.
  114. if (grabbing_spinner_dist_cache != 0) {
  115. pre_grab_value += grabbing_spinner_dist_cache * get_step();
  116. grabbing_spinner_dist_cache = 0;
  117. }
  118. set_value(Math::round(pre_grab_value + get_step() * grabbing_spinner_dist_cache * 10));
  119. } else {
  120. set_value(pre_grab_value + get_step() * grabbing_spinner_dist_cache);
  121. }
  122. }
  123. } else if (updown_offset != -1) {
  124. bool new_hover = (mm->get_position().x > updown_offset);
  125. if (new_hover != hover_updown) {
  126. hover_updown = new_hover;
  127. update();
  128. }
  129. }
  130. }
  131. Ref<InputEventKey> k = p_event;
  132. if (k.is_valid() && k->is_pressed() && k->is_action("ui_accept")) {
  133. _focus_entered();
  134. }
  135. }
  136. void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) {
  137. Ref<InputEventMouseButton> mb = p_event;
  138. if (grabbing_grabber) {
  139. if (mb.is_valid()) {
  140. if (mb->get_button_index() == BUTTON_WHEEL_UP) {
  141. set_value(get_value() + get_step());
  142. mousewheel_over_grabber = true;
  143. } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN) {
  144. set_value(get_value() - get_step());
  145. mousewheel_over_grabber = true;
  146. }
  147. }
  148. }
  149. if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) {
  150. if (mb->is_pressed()) {
  151. grabbing_grabber = true;
  152. if (!mousewheel_over_grabber) {
  153. grabbing_ratio = get_as_ratio();
  154. grabbing_from = grabber->get_transform().xform(mb->get_position()).x;
  155. }
  156. } else {
  157. grabbing_grabber = false;
  158. mousewheel_over_grabber = false;
  159. }
  160. }
  161. Ref<InputEventMouseMotion> mm = p_event;
  162. if (mm.is_valid() && grabbing_grabber) {
  163. if (mousewheel_over_grabber) {
  164. return;
  165. }
  166. float scale_x = get_global_transform_with_canvas().get_scale().x;
  167. ERR_FAIL_COND(Math::is_zero_approx(scale_x));
  168. float grabbing_ofs = (grabber->get_transform().xform(mm->get_position()).x - grabbing_from) / float(grabber_range) / scale_x;
  169. set_as_ratio(grabbing_ratio + grabbing_ofs);
  170. update();
  171. }
  172. }
  173. void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) {
  174. Ref<InputEventKey> k = p_event;
  175. if (k.is_valid() && k->is_pressed()) {
  176. double step = get_step();
  177. double real_step = step;
  178. if (step < 1) {
  179. double divisor = 1.0 / get_step();
  180. if (trunc(divisor) == divisor) {
  181. step = 1.0;
  182. }
  183. }
  184. #ifdef APPLE_STYLE_KEYS
  185. if (k->get_command()) {
  186. #else
  187. if (k->get_control()) {
  188. #endif
  189. step *= 100.0;
  190. } else if (k->get_shift()) {
  191. step *= 10.0;
  192. #ifdef APPLE_STYLE_KEYS
  193. } else if (k->get_metakey()) {
  194. #else
  195. } else if (k->get_alt()) {
  196. #endif
  197. step *= 0.1;
  198. }
  199. uint32_t code = k->get_scancode();
  200. switch (code) {
  201. case KEY_UP: {
  202. _evaluate_input_text();
  203. double last_value = get_value();
  204. set_value(last_value + step);
  205. double new_value = get_value();
  206. if (new_value < CLAMP(last_value + step, get_min(), get_max())) {
  207. set_value(last_value + real_step);
  208. }
  209. value_input_dirty = true;
  210. set_process_internal(true);
  211. } break;
  212. case KEY_DOWN: {
  213. _evaluate_input_text();
  214. double last_value = get_value();
  215. set_value(last_value - step);
  216. double new_value = get_value();
  217. if (new_value > CLAMP(last_value - step, get_min(), get_max())) {
  218. set_value(last_value - real_step);
  219. }
  220. value_input_dirty = true;
  221. set_process_internal(true);
  222. } break;
  223. }
  224. }
  225. }
  226. void EditorSpinSlider::_draw_spin_slider() {
  227. updown_offset = -1;
  228. Ref<StyleBox> sb = get_stylebox("normal", "LineEdit");
  229. if (!flat) {
  230. draw_style_box(sb, Rect2(Vector2(), get_size()));
  231. }
  232. Ref<Font> font = get_font("font", "LineEdit");
  233. int sep_base = 4 * EDSCALE;
  234. int sep = sep_base + sb->get_offset().x; //make it have the same margin on both sides, looks better
  235. int string_width = font->get_string_size(label).width;
  236. int number_width = get_size().width - sb->get_minimum_size().width - string_width - sep;
  237. Ref<Texture> updown = get_icon("updown", "SpinBox");
  238. if (get_step() == 1) {
  239. number_width -= updown->get_width();
  240. }
  241. String numstr = get_text_value();
  242. int vofs = (get_size().height - font->get_height()) / 2 + font->get_ascent();
  243. Color fc = get_color("font_color", "LineEdit");
  244. Color lc;
  245. if (use_custom_label_color) {
  246. lc = custom_label_color;
  247. } else {
  248. lc = fc;
  249. }
  250. if (flat && label != String()) {
  251. Color label_bg_color = get_color("dark_color_3", "Editor");
  252. draw_rect(Rect2(Vector2(), Vector2(sb->get_offset().x * 2 + string_width, get_size().height)), label_bg_color);
  253. }
  254. if (has_focus()) {
  255. Ref<StyleBox> focus = get_stylebox("focus", "LineEdit");
  256. draw_style_box(focus, Rect2(Vector2(), get_size()));
  257. }
  258. draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, lc * Color(1, 1, 1, 0.5));
  259. draw_string(font, Vector2(Math::round(sb->get_offset().x + string_width + sep), vofs), numstr, fc, number_width);
  260. if (get_step() == 1) {
  261. Ref<Texture> updown2 = get_icon("updown", "SpinBox");
  262. int updown_vofs = (get_size().height - updown2->get_height()) / 2;
  263. updown_offset = get_size().width - sb->get_margin(MARGIN_RIGHT) - updown2->get_width();
  264. Color c(1, 1, 1);
  265. if (hover_updown) {
  266. c *= Color(1.2, 1.2, 1.2);
  267. }
  268. draw_texture(updown2, Vector2(updown_offset, updown_vofs), c);
  269. if (grabber->is_visible()) {
  270. grabber->hide();
  271. }
  272. } else if (!hide_slider) {
  273. const int grabber_w = 4 * EDSCALE;
  274. const int width = get_size().width - sb->get_minimum_size().width - grabber_w;
  275. const int ofs = sb->get_offset().x;
  276. const int svofs = (get_size().height + vofs) / 2 - 1;
  277. Color c = fc;
  278. // Draw the horizontal slider's background.
  279. c.a = 0.2;
  280. draw_rect(Rect2(ofs, svofs + 1, width, 2 * EDSCALE), c);
  281. // Draw the horizontal slider's filled part on the left.
  282. const int gofs = get_as_ratio() * width;
  283. c.a = 0.45;
  284. draw_rect(Rect2(ofs, svofs + 1, gofs, 2 * EDSCALE), c);
  285. // Draw the horizontal slider's grabber.
  286. c.a = 0.9;
  287. const Rect2 grabber_rect = Rect2(ofs + gofs, svofs, grabber_w, 4 * EDSCALE);
  288. draw_rect(grabber_rect, c);
  289. bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !value_input->is_visible();
  290. if (grabber->is_visible() != display_grabber) {
  291. if (display_grabber) {
  292. grabber->show();
  293. } else {
  294. grabber->hide();
  295. }
  296. }
  297. if (display_grabber) {
  298. Ref<Texture> grabber_tex;
  299. if (mouse_over_grabber) {
  300. grabber_tex = get_icon("grabber_highlight", "HSlider");
  301. } else {
  302. grabber_tex = get_icon("grabber", "HSlider");
  303. }
  304. if (grabber->get_texture() != grabber_tex) {
  305. grabber->set_texture(grabber_tex);
  306. }
  307. Vector2 scale = get_global_transform_with_canvas().get_scale();
  308. grabber->set_scale(scale);
  309. grabber->set_size(Size2(0, 0));
  310. grabber->set_position(get_global_position() + (grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5) * scale);
  311. if (mousewheel_over_grabber) {
  312. Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size);
  313. }
  314. grabber_range = width;
  315. }
  316. }
  317. }
  318. void EditorSpinSlider::_notification(int p_what) {
  319. switch (p_what) {
  320. case NOTIFICATION_ENTER_TREE:
  321. case NOTIFICATION_THEME_CHANGED: {
  322. // Add a left margin to the stylebox to make the number align with the Label
  323. // when it's edited. The LineEdit "focus" stylebox uses the "normal" stylebox's
  324. // default margins.
  325. Ref<StyleBox> stylebox = get_stylebox("normal", "LineEdit")->duplicate();
  326. // EditorSpinSliders with a label have more space on the left, so add an
  327. // higher margin to match the location where the text begins.
  328. // The margin values below were determined by empirical testing.
  329. stylebox->set_default_margin(MARGIN_LEFT, (get_label() != String() ? 23 : 16) * EDSCALE);
  330. value_input->add_style_override("normal", stylebox);
  331. } break;
  332. case NOTIFICATION_INTERNAL_PROCESS:
  333. if (value_input_dirty) {
  334. value_input_dirty = false;
  335. value_input->set_text(get_text_value());
  336. }
  337. set_process_internal(false);
  338. break;
  339. case NOTIFICATION_DRAW:
  340. _draw_spin_slider();
  341. break;
  342. case MainLoop::NOTIFICATION_WM_FOCUS_IN:
  343. case MainLoop::NOTIFICATION_WM_FOCUS_OUT:
  344. case NOTIFICATION_EXIT_TREE:
  345. if (grabbing_spinner) {
  346. grabber->hide();
  347. Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
  348. Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos);
  349. grabbing_spinner = false;
  350. grabbing_spinner_attempt = false;
  351. }
  352. break;
  353. case NOTIFICATION_MOUSE_ENTER:
  354. mouse_over_spin = true;
  355. update();
  356. break;
  357. case NOTIFICATION_MOUSE_EXIT:
  358. mouse_over_spin = false;
  359. update();
  360. break;
  361. case NOTIFICATION_FOCUS_ENTER:
  362. /* Sorry, I don't like this, it makes navigating the different fields with arrows more difficult.
  363. * Just press enter to edit.
  364. * if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && !value_input_just_closed) {
  365. _focus_entered();
  366. }*/
  367. if ((Input::get_singleton()->is_action_pressed("ui_focus_next") || Input::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) {
  368. _focus_entered();
  369. }
  370. value_input_just_closed = false;
  371. break;
  372. }
  373. }
  374. Size2 EditorSpinSlider::get_minimum_size() const {
  375. Ref<StyleBox> sb = get_stylebox("normal", "LineEdit");
  376. Ref<Font> font = get_font("font", "LineEdit");
  377. Size2 ms = sb->get_minimum_size();
  378. ms.height += font->get_height();
  379. return ms;
  380. }
  381. void EditorSpinSlider::set_hide_slider(bool p_hide) {
  382. hide_slider = p_hide;
  383. update();
  384. }
  385. bool EditorSpinSlider::is_hiding_slider() const {
  386. return hide_slider;
  387. }
  388. void EditorSpinSlider::set_label(const String &p_label) {
  389. label = p_label;
  390. update();
  391. }
  392. String EditorSpinSlider::get_label() const {
  393. return label;
  394. }
  395. void EditorSpinSlider::_evaluate_input_text() {
  396. // Replace comma with dot to support it as decimal separator (GH-6028).
  397. // This prevents using functions like `pow()`, but using functions
  398. // in EditorSpinSlider is a barely known (and barely used) feature.
  399. // Instead, we'd rather support German/French keyboard layouts out of the box.
  400. const String text = value_input->get_text().replace(",", ".");
  401. Ref<Expression> expr;
  402. expr.instance();
  403. Error err = expr->parse(text);
  404. if (err != OK) {
  405. return;
  406. }
  407. Variant v = expr->execute(Array(), nullptr, false);
  408. if (v.get_type() == Variant::NIL) {
  409. return;
  410. }
  411. set_value(v);
  412. }
  413. //text_entered signal
  414. void EditorSpinSlider::_value_input_entered(const String &p_text) {
  415. value_input_just_closed = true;
  416. value_input->hide();
  417. }
  418. //modal_closed signal
  419. void EditorSpinSlider::_value_input_closed() {
  420. _evaluate_input_text();
  421. value_input_just_closed = true;
  422. }
  423. //focus_exited signal
  424. void EditorSpinSlider::_value_focus_exited() {
  425. // discontinue because the focus_exit was caused by right-click context menu
  426. if (value_input->get_menu()->is_visible()) {
  427. return;
  428. }
  429. _evaluate_input_text();
  430. // focus is not on the same element after the vlalue_input was exited
  431. // -> focus is on next element
  432. // -> TAB was pressed
  433. // -> modal_close was not called
  434. // -> need to close/hide manually
  435. if (!value_input_just_closed) { //value_input_just_closed should do the same
  436. value_input->hide();
  437. //tab was pressed
  438. } else {
  439. //enter, click, esc
  440. }
  441. }
  442. void EditorSpinSlider::_grabber_mouse_entered() {
  443. mouse_over_grabber = true;
  444. update();
  445. }
  446. void EditorSpinSlider::_grabber_mouse_exited() {
  447. mouse_over_grabber = false;
  448. update();
  449. }
  450. void EditorSpinSlider::set_read_only(bool p_enable) {
  451. read_only = p_enable;
  452. update();
  453. }
  454. bool EditorSpinSlider::is_read_only() const {
  455. return read_only;
  456. }
  457. void EditorSpinSlider::set_flat(bool p_enable) {
  458. flat = p_enable;
  459. update();
  460. }
  461. bool EditorSpinSlider::is_flat() const {
  462. return flat;
  463. }
  464. void EditorSpinSlider::set_custom_label_color(bool p_use_custom_label_color, Color p_custom_label_color) {
  465. use_custom_label_color = p_use_custom_label_color;
  466. custom_label_color = p_custom_label_color;
  467. }
  468. void EditorSpinSlider::_focus_entered() {
  469. Rect2 gr = get_global_rect();
  470. value_input->set_text(get_text_value());
  471. value_input->set_position(gr.position);
  472. value_input->set_size(gr.size);
  473. value_input->show_modal();
  474. value_input->select_all();
  475. value_input->call_deferred("grab_focus"); // deferred to avoid losing focus
  476. value_input->set_focus_next(find_next_valid_focus()->get_path());
  477. value_input->set_focus_previous(find_prev_valid_focus()->get_path());
  478. }
  479. void EditorSpinSlider::_bind_methods() {
  480. ClassDB::bind_method(D_METHOD("set_label", "label"), &EditorSpinSlider::set_label);
  481. ClassDB::bind_method(D_METHOD("get_label"), &EditorSpinSlider::get_label);
  482. ClassDB::bind_method(D_METHOD("set_read_only", "read_only"), &EditorSpinSlider::set_read_only);
  483. ClassDB::bind_method(D_METHOD("is_read_only"), &EditorSpinSlider::is_read_only);
  484. ClassDB::bind_method(D_METHOD("set_flat", "flat"), &EditorSpinSlider::set_flat);
  485. ClassDB::bind_method(D_METHOD("is_flat"), &EditorSpinSlider::is_flat);
  486. ClassDB::bind_method(D_METHOD("set_hide_slider", "hide_slider"), &EditorSpinSlider::set_hide_slider);
  487. ClassDB::bind_method(D_METHOD("is_hiding_slider"), &EditorSpinSlider::is_hiding_slider);
  488. ClassDB::bind_method(D_METHOD("_gui_input"), &EditorSpinSlider::_gui_input);
  489. ClassDB::bind_method(D_METHOD("_value_input_gui_input", "event"), &EditorSpinSlider::_value_input_gui_input);
  490. ClassDB::bind_method(D_METHOD("_grabber_mouse_entered"), &EditorSpinSlider::_grabber_mouse_entered);
  491. ClassDB::bind_method(D_METHOD("_grabber_mouse_exited"), &EditorSpinSlider::_grabber_mouse_exited);
  492. ClassDB::bind_method(D_METHOD("_grabber_gui_input"), &EditorSpinSlider::_grabber_gui_input);
  493. ClassDB::bind_method(D_METHOD("_value_input_closed"), &EditorSpinSlider::_value_input_closed);
  494. ClassDB::bind_method(D_METHOD("_value_input_entered"), &EditorSpinSlider::_value_input_entered);
  495. ClassDB::bind_method(D_METHOD("_value_focus_exited"), &EditorSpinSlider::_value_focus_exited);
  496. ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label");
  497. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only");
  498. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
  499. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_slider"), "set_hide_slider", "is_hiding_slider");
  500. }
  501. EditorSpinSlider::EditorSpinSlider() {
  502. flat = false;
  503. grabbing_spinner_attempt = false;
  504. grabbing_spinner = false;
  505. grabbing_spinner_dist_cache = 0;
  506. pre_grab_value = 0;
  507. set_focus_mode(FOCUS_ALL);
  508. updown_offset = -1;
  509. hover_updown = false;
  510. grabber = memnew(TextureRect);
  511. add_child(grabber);
  512. grabber->hide();
  513. grabber->set_as_toplevel(true);
  514. grabber->set_mouse_filter(MOUSE_FILTER_STOP);
  515. grabber->connect("mouse_entered", this, "_grabber_mouse_entered");
  516. grabber->connect("mouse_exited", this, "_grabber_mouse_exited");
  517. grabber->connect("gui_input", this, "_grabber_gui_input");
  518. mouse_over_spin = false;
  519. mouse_over_grabber = false;
  520. mousewheel_over_grabber = false;
  521. grabbing_grabber = false;
  522. grabber_range = 1;
  523. value_input = memnew(LineEdit);
  524. add_child(value_input);
  525. value_input->set_as_toplevel(true);
  526. value_input->hide();
  527. value_input->connect("modal_closed", this, "_value_input_closed");
  528. value_input->connect("text_entered", this, "_value_input_entered");
  529. value_input->connect("focus_exited", this, "_value_focus_exited");
  530. value_input->connect("gui_input", this, "_value_input_gui_input");
  531. value_input_just_closed = false;
  532. value_input_dirty = false;
  533. hide_slider = false;
  534. read_only = false;
  535. use_custom_label_color = false;
  536. }