scroll_bar.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. /*************************************************************************/
  2. /* scroll_bar.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "scroll_bar.h"
  30. #include "os/keyboard.h"
  31. #include "print_string.h"
  32. #include "os/os.h"
  33. bool ScrollBar::focus_by_default=false;
  34. void ScrollBar::set_can_focus_by_default(bool p_can_focus) {
  35. focus_by_default=p_can_focus;
  36. }
  37. void ScrollBar::_input_event(InputEvent p_event) {
  38. switch(p_event.type) {
  39. case InputEvent::MOUSE_BUTTON: {
  40. const InputEventMouseButton &b=p_event.mouse_button;
  41. accept_event();
  42. if (b.button_index==5 && b.pressed) {
  43. if (orientation==VERTICAL)
  44. set_val( get_val() + get_page() / 4.0 );
  45. else
  46. set_val( get_val() + get_page() / 4.0 );
  47. accept_event();
  48. }
  49. if (b.button_index==4 && b.pressed) {
  50. if (orientation==HORIZONTAL)
  51. set_val( get_val() - get_page() / 4.0 );
  52. else
  53. set_val( get_val() - get_page() / 4.0 );
  54. accept_event();
  55. }
  56. if (b.button_index!=1)
  57. return;
  58. if (b.pressed) {
  59. double ofs = orientation==VERTICAL ? b.y : b.x ;
  60. Ref<Texture> decr = get_icon("decrement");
  61. Ref<Texture> incr = get_icon("increment");
  62. double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width();
  63. double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width();
  64. double grabber_ofs = get_grabber_offset();
  65. double grabber_size = get_grabber_size();
  66. double total = orientation==VERTICAL ? get_size().height : get_size().width;
  67. if (ofs < decr_size ) {
  68. set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
  69. break;
  70. }
  71. if (ofs > total-incr_size ) {
  72. set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
  73. break;
  74. }
  75. ofs-=decr_size;
  76. if ( ofs < grabber_ofs ) {
  77. set_val( get_val() - get_page() );
  78. break;
  79. }
  80. ofs-=grabber_ofs;
  81. if (ofs < grabber_size ) {
  82. drag.active=true;
  83. drag.pos_at_click=grabber_ofs+ofs;
  84. drag.value_at_click=get_unit_value();
  85. update();
  86. } else {
  87. set_val( get_val() + get_page() );
  88. }
  89. } else {
  90. drag.active=false;
  91. update();
  92. }
  93. } break;
  94. case InputEvent::MOUSE_MOTION: {
  95. const InputEventMouseMotion &m=p_event.mouse_motion;
  96. accept_event();
  97. if (drag.active) {
  98. double ofs = orientation==VERTICAL ? m.y : m.x ;
  99. Ref<Texture> decr = get_icon("decrement");
  100. double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width();
  101. ofs-=decr_size;
  102. double diff = (ofs-drag.pos_at_click) / get_area_size();
  103. set_unit_value( drag.value_at_click + diff );
  104. } else {
  105. double ofs = orientation==VERTICAL ? m.y : m.x ;
  106. Ref<Texture> decr = get_icon("decrement");
  107. Ref<Texture> incr = get_icon("increment");
  108. double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width();
  109. double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width();
  110. double total = orientation==VERTICAL ? get_size().height : get_size().width;
  111. HiliteStatus new_hilite;
  112. if (ofs < decr_size ) {
  113. new_hilite=HILITE_DECR;
  114. } else if (ofs > total-incr_size ) {
  115. new_hilite=HILITE_INCR;
  116. } else {
  117. new_hilite=HILITE_RANGE;
  118. }
  119. if (new_hilite!=hilite) {
  120. hilite=new_hilite;
  121. update();
  122. }
  123. }
  124. } break;
  125. case InputEvent::KEY: {
  126. const InputEventKey &k=p_event.key;
  127. if (!k.pressed)
  128. return;
  129. switch (k.scancode) {
  130. case KEY_LEFT: {
  131. if (orientation!=HORIZONTAL)
  132. return;
  133. set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
  134. } break;
  135. case KEY_RIGHT: {
  136. if (orientation!=HORIZONTAL)
  137. return;
  138. set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
  139. } break;
  140. case KEY_UP: {
  141. if (orientation!=VERTICAL)
  142. return;
  143. set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
  144. } break;
  145. case KEY_DOWN: {
  146. if (orientation!=VERTICAL)
  147. return;
  148. set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
  149. } break;
  150. case KEY_HOME: {
  151. set_val( get_min() );
  152. } break;
  153. case KEY_END: {
  154. set_val( get_max() );
  155. } break;
  156. } break;
  157. }
  158. }
  159. }
  160. void ScrollBar::_notification(int p_what) {
  161. if (p_what==NOTIFICATION_DRAW) {
  162. RID ci = get_canvas_item();
  163. Ref<Texture> decr = hilite==HILITE_DECR ? get_icon("decrement_hilite") : get_icon("decrement");
  164. Ref<Texture> incr = hilite==HILITE_INCR ? get_icon("increment_hilite") : get_icon("increment");
  165. Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll");
  166. Ref<StyleBox> grabber = (drag.active || hilite==HILITE_RANGE) ? get_stylebox("grabber_hilite") : get_stylebox("grabber");
  167. Point2 ofs;
  168. VisualServer *vs = VisualServer::get_singleton();
  169. vs->canvas_item_add_texture_rect( ci, Rect2( Point2(), decr->get_size()),decr->get_rid() );
  170. if (orientation==HORIZONTAL)
  171. ofs.x+=decr->get_width();
  172. else
  173. ofs.y+=decr->get_height();
  174. Size2 area=get_size();
  175. if (orientation==HORIZONTAL)
  176. area.width-=incr->get_width()+decr->get_width();
  177. else
  178. area.height-=incr->get_height()+decr->get_height();
  179. bg->draw(ci,Rect2(ofs,area));
  180. if (orientation==HORIZONTAL)
  181. ofs.width+=area.width;
  182. else
  183. ofs.height+=area.height;
  184. vs->canvas_item_add_texture_rect( ci, Rect2( ofs, decr->get_size()),incr->get_rid() );
  185. Rect2 grabber_rect;
  186. if (orientation==HORIZONTAL) {
  187. grabber_rect.size.width=get_grabber_size();
  188. grabber_rect.size.height=get_size().height;
  189. grabber_rect.pos.y=0;
  190. grabber_rect.pos.x=get_grabber_offset()+decr->get_width()+bg->get_margin( MARGIN_LEFT );
  191. } else {
  192. grabber_rect.size.width=get_size().width;
  193. grabber_rect.size.height=get_grabber_size();
  194. grabber_rect.pos.y=get_grabber_offset()+decr->get_height()+bg->get_margin( MARGIN_TOP );
  195. grabber_rect.pos.x=0;
  196. }
  197. grabber->draw(ci,grabber_rect);
  198. }
  199. if (p_what==NOTIFICATION_ENTER_SCENE) {
  200. if (has_node(drag_slave_path)) {
  201. Node *n = get_node(drag_slave_path);
  202. drag_slave=n->cast_to<Control>();
  203. }
  204. if (drag_slave) {
  205. drag_slave->connect("input_event",this,"_drag_slave_input");
  206. drag_slave->connect("exit_scene",this,"_drag_slave_exit",varray(),CONNECT_ONESHOT);
  207. }
  208. }
  209. if (p_what==NOTIFICATION_EXIT_SCENE) {
  210. if (drag_slave) {
  211. drag_slave->disconnect("input_event",this,"_drag_slave_input");
  212. drag_slave->disconnect("exit_scene",this,"_drag_slave_exit");
  213. }
  214. drag_slave=NULL;
  215. }
  216. if (p_what==NOTIFICATION_FIXED_PROCESS) {
  217. if (drag_slave_touching) {
  218. if (drag_slave_touching_deaccel) {
  219. Vector2 pos = Vector2(orientation==HORIZONTAL?get_val():0,orientation==VERTICAL?get_val():0);
  220. pos+=drag_slave_speed*get_fixed_process_delta_time();
  221. bool turnoff=false;
  222. if (orientation==HORIZONTAL) {
  223. if (pos.x<0) {
  224. pos.x=0;
  225. turnoff=true;
  226. }
  227. if (pos.x > (get_max()-get_page())) {
  228. pos.x=get_max()-get_page();
  229. turnoff=true;
  230. }
  231. set_val(pos.x);
  232. float sgn_x = drag_slave_speed.x<0? -1 : 1;
  233. float val_x = Math::abs(drag_slave_speed.x);
  234. val_x-=1000*get_fixed_process_delta_time();
  235. if (val_x<0) {
  236. turnoff=true;
  237. }
  238. drag_slave_speed.x=sgn_x*val_x;
  239. } else {
  240. if (pos.y<0) {
  241. pos.y=0;
  242. turnoff=true;
  243. }
  244. if (pos.y > (get_max()-get_page())) {
  245. pos.y=get_max()-get_page();
  246. turnoff=true;
  247. }
  248. set_val(pos.y);
  249. float sgn_y = drag_slave_speed.y<0? -1 : 1;
  250. float val_y = Math::abs(drag_slave_speed.y);
  251. val_y-=1000*get_fixed_process_delta_time();
  252. if (val_y<0) {
  253. turnoff=true;
  254. }
  255. drag_slave_speed.y=sgn_y*val_y;
  256. }
  257. if (turnoff) {
  258. set_fixed_process(false);
  259. drag_slave_touching=false;
  260. drag_slave_touching_deaccel=false;
  261. }
  262. } else {
  263. if (time_since_motion==0 || time_since_motion>0.1) {
  264. Vector2 diff = drag_slave_accum - last_drag_slave_accum;
  265. last_drag_slave_accum=drag_slave_accum;
  266. drag_slave_speed=diff/get_fixed_process_delta_time();
  267. }
  268. time_since_motion+=get_fixed_process_delta_time();
  269. }
  270. }
  271. }
  272. if (p_what==NOTIFICATION_MOUSE_EXIT) {
  273. hilite=HILITE_NONE;
  274. update();
  275. }
  276. }
  277. double ScrollBar::get_grabber_min_size() const {
  278. Ref<StyleBox> grabber=get_stylebox("grabber");
  279. Size2 gminsize=grabber->get_minimum_size()+grabber->get_center_size();
  280. return (orientation==VERTICAL)?gminsize.height:gminsize.width;
  281. }
  282. double ScrollBar::get_grabber_size() const {
  283. float range = get_max()-get_min();
  284. if (range<=0)
  285. return 0;
  286. float page = (get_page()>0)? get_page() : 0;
  287. // if (grabber_range < get_step())
  288. // grabber_range=get_step();
  289. double area_size=get_area_size();
  290. double grabber_size = page / range * area_size;
  291. return grabber_size+get_grabber_min_size();
  292. }
  293. double ScrollBar::get_area_size() const {
  294. if (orientation==VERTICAL) {
  295. double area=get_size().height;
  296. area-=get_stylebox("scroll")->get_minimum_size().height;
  297. area-=get_icon("increment")->get_height();
  298. area-=get_icon("decrement")->get_height();
  299. area-=get_grabber_min_size();
  300. return area;
  301. } else if (orientation==HORIZONTAL) {
  302. double area=get_size().width;
  303. area-=get_stylebox("scroll")->get_minimum_size().width;
  304. area-=get_icon("increment")->get_width();
  305. area-=get_icon("decrement")->get_width();
  306. area-=get_grabber_min_size();
  307. return area;
  308. } else {
  309. return 0;
  310. }
  311. }
  312. double ScrollBar::get_area_offset() const {
  313. double ofs=0;
  314. if (orientation==VERTICAL) {
  315. ofs+=get_stylebox("hscroll")->get_margin( MARGIN_TOP );
  316. ofs+=get_icon("decrement")->get_height();
  317. }
  318. if (orientation==HORIZONTAL) {
  319. ofs+=get_stylebox("hscroll")->get_margin( MARGIN_LEFT );
  320. ofs+=get_icon("decrement")->get_width();
  321. }
  322. return ofs;
  323. }
  324. double ScrollBar::get_click_pos(const Point2& p_pos) const {
  325. float pos=(orientation==VERTICAL)?p_pos.y:p_pos.x;
  326. pos-=get_area_offset();
  327. float area=get_area_size();
  328. if (area==0)
  329. return 0;
  330. else
  331. return pos/area;
  332. }
  333. double ScrollBar::get_grabber_offset() const {
  334. return (get_area_size()) * get_unit_value();
  335. }
  336. Size2 ScrollBar::get_minimum_size() const {
  337. Ref<Texture> incr = get_icon("increment");
  338. Ref<Texture> decr = get_icon("decrement");
  339. Ref<StyleBox> bg = get_stylebox("scroll");
  340. Size2 minsize;
  341. if (orientation==VERTICAL) {
  342. minsize.width=MAX(incr->get_size().width,(bg->get_minimum_size()+bg->get_center_size()).width);
  343. minsize.height+=incr->get_size().height;
  344. minsize.height+=decr->get_size().height;
  345. minsize.height+=bg->get_minimum_size().height;
  346. minsize.height+=get_grabber_min_size();
  347. }
  348. if (orientation==HORIZONTAL) {
  349. minsize.height=MAX(incr->get_size().height,(bg->get_center_size()+bg->get_minimum_size()).height);
  350. minsize.width+=incr->get_size().width;
  351. minsize.width+=decr->get_size().width;
  352. minsize.width+=bg->get_minimum_size().width;
  353. minsize.width+=get_grabber_min_size();
  354. }
  355. return minsize;
  356. }
  357. void ScrollBar::set_custom_step(float p_custom_step) {
  358. custom_step=p_custom_step;
  359. }
  360. float ScrollBar::get_custom_step() const {
  361. return custom_step;
  362. }
  363. void ScrollBar::_drag_slave_exit() {
  364. if (drag_slave) {
  365. drag_slave->disconnect("input_event",this,"_drag_slave_input");
  366. }
  367. drag_slave=NULL;
  368. }
  369. void ScrollBar::_drag_slave_input(const InputEvent& p_input) {
  370. switch(p_input.type) {
  371. case InputEvent::MOUSE_BUTTON: {
  372. const InputEventMouseButton &mb=p_input.mouse_button;
  373. if (mb.button_index!=1)
  374. break;
  375. if (mb.pressed) {
  376. if (drag_slave_touching) {
  377. set_fixed_process(false);
  378. drag_slave_touching_deaccel=false;
  379. drag_slave_touching=false;
  380. drag_slave_speed=Vector2();
  381. drag_slave_accum=Vector2();
  382. last_drag_slave_accum=Vector2();
  383. drag_slave_from=Vector2();
  384. }
  385. if (true) {
  386. drag_slave_speed=Vector2();
  387. drag_slave_accum=Vector2();
  388. last_drag_slave_accum=Vector2();
  389. //drag_slave_from=Vector2(h_scroll->get_val(),v_scroll->get_val());
  390. drag_slave_from= Vector2(orientation==HORIZONTAL?get_val():0,orientation==VERTICAL?get_val():0);
  391. drag_slave_touching=OS::get_singleton()->has_touchscreen_ui_hint();
  392. drag_slave_touching_deaccel=false;
  393. time_since_motion=0;
  394. if (drag_slave_touching) {
  395. set_fixed_process(true);
  396. time_since_motion=0;
  397. }
  398. }
  399. } else {
  400. if (drag_slave_touching) {
  401. if (drag_slave_speed==Vector2()) {
  402. drag_slave_touching_deaccel=false;
  403. drag_slave_touching=false;
  404. set_fixed_process(false);
  405. } else {
  406. drag_slave_touching_deaccel=true;
  407. }
  408. }
  409. }
  410. } break;
  411. case InputEvent::MOUSE_MOTION: {
  412. const InputEventMouseMotion &mm=p_input.mouse_motion;
  413. if (drag_slave_touching && ! drag_slave_touching_deaccel) {
  414. Vector2 motion = Vector2(mm.relative_x,mm.relative_y);
  415. drag_slave_accum-=motion;
  416. Vector2 diff = drag_slave_from+drag_slave_accum;
  417. if (orientation==HORIZONTAL)
  418. set_val(diff.x);
  419. //else
  420. // drag_slave_accum.x=0;
  421. if (orientation==VERTICAL)
  422. set_val(diff.y);
  423. //else
  424. // drag_slave_accum.y=0;
  425. time_since_motion=0;
  426. }
  427. } break;
  428. }
  429. }
  430. void ScrollBar::set_drag_slave(const NodePath& p_path) {
  431. if (is_inside_scene()) {
  432. if (drag_slave) {
  433. drag_slave->disconnect("input_event",this,"_drag_slave_input");
  434. drag_slave->disconnect("exit_scene",this,"_drag_slave_exit");
  435. }
  436. }
  437. drag_slave=NULL;
  438. drag_slave_path=p_path;
  439. if (is_inside_scene()) {
  440. if (has_node(p_path)) {
  441. Node *n = get_node(p_path);
  442. drag_slave=n->cast_to<Control>();
  443. }
  444. if (drag_slave) {
  445. drag_slave->connect("input_event",this,"_drag_slave_input");
  446. drag_slave->connect("exit_scene",this,"_drag_slave_exit",varray(),CONNECT_ONESHOT);
  447. }
  448. }
  449. }
  450. NodePath ScrollBar::get_drag_slave() const{
  451. return drag_slave_path;
  452. }
  453. #if 0
  454. void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pressed,int p_modifier_mask) {
  455. // wheel!
  456. if (b.button_index==BUTTON_WHEEL_UP && b.pressed) {
  457. if (orientation==VERTICAL)
  458. set_val( get_val() - get_page() / 4.0 );
  459. else
  460. set_val( get_val() + get_page() / 4.0 );
  461. }
  462. if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) {
  463. if (orientation==HORIZONTAL)
  464. set_val( get_val() - get_page() / 4.0 );
  465. else
  466. set_val( get_val() + get_page() / 4.0 );
  467. }
  468. if (b.button_index!=BUTTON_LEFT)
  469. return;
  470. if (b.pressed) {
  471. int ofs = orientation==VERTICAL ? p_pos.y : p_pos.x ;
  472. int grabber_ofs = get_grabber_offset();
  473. int grabber_size = get_grabber_size();
  474. if ( ofs < grabber_ofs ) {
  475. set_val( get_val() - get_page() );
  476. } else if (ofs > grabber_ofs + grabber_size ) {
  477. set_val( get_val() + get_page() );
  478. } else {
  479. drag.active=true;
  480. drag.pos_at_click=get_click_pos(p_pos);
  481. drag.value_at_click=get_unit_value();
  482. }
  483. } else {
  484. drag.active=false;
  485. }
  486. }
  487. void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b.button_index_mask) {
  488. if (!drag.active)
  489. return;
  490. double value_ofs=drag.value_at_click+(get_click_pos(p_pos)-drag.pos_at_click);
  491. value_ofs=value_ofs*( get_max() - get_min() );
  492. if (value_ofs<get_min())
  493. value_ofs=get_min();
  494. if (value_ofs>(get_max()-get_page()))
  495. value_ofs=get_max()-get_page();
  496. if (get_val()==value_ofs)
  497. return; //dont bother if the value is the same
  498. set_val( value_ofs );
  499. }
  500. bool ScrollBar::key(unsigned long p_unicode, unsigned long p_scan_code,bool b.pressed,bool p_repeat,int p_modifier_mask) {
  501. if (!b.pressed)
  502. return false;
  503. switch (p_scan_code) {
  504. case KEY_LEFT: {
  505. if (orientation!=HORIZONTAL)
  506. return false;
  507. set_val( get_val() - get_step() );
  508. } break;
  509. case KEY_RIGHT: {
  510. if (orientation!=HORIZONTAL)
  511. return false;
  512. set_val( get_val() + get_step() );
  513. } break;
  514. case KEY_UP: {
  515. if (orientation!=VERTICAL)
  516. return false;
  517. set_val( get_val() - get_step() );
  518. } break;
  519. case KEY_DOWN: {
  520. if (orientation!=VERTICAL)
  521. return false;
  522. set_val( get_val() + get_step() );
  523. } break;
  524. case KEY_HOME: {
  525. set_val( get_min() );
  526. } break;
  527. case KEY_END: {
  528. set_val( get_max() );
  529. } break;
  530. default:
  531. return false;
  532. }
  533. return true;
  534. }
  535. #endif
  536. void ScrollBar::_bind_methods() {
  537. ObjectTypeDB::bind_method(_MD("_input_event"),&ScrollBar::_input_event);
  538. ObjectTypeDB::bind_method(_MD("set_custom_step","step"),&ScrollBar::set_custom_step);
  539. ObjectTypeDB::bind_method(_MD("get_custom_step"),&ScrollBar::get_custom_step);
  540. ObjectTypeDB::bind_method(_MD("_drag_slave_input"),&ScrollBar::_drag_slave_input);
  541. ObjectTypeDB::bind_method(_MD("_drag_slave_exit"),&ScrollBar::_drag_slave_exit);
  542. ADD_PROPERTY( PropertyInfo(Variant::REAL,"custom_step",PROPERTY_HINT_RANGE,"-1,4096"), _SCS("set_custom_step"),_SCS("get_custom_step"));
  543. }
  544. ScrollBar::ScrollBar(Orientation p_orientation)
  545. {
  546. orientation=p_orientation;
  547. hilite=HILITE_NONE;
  548. custom_step=-1;
  549. drag_slave=NULL;
  550. drag.active=false;
  551. drag_slave_speed=Vector2();
  552. drag_slave_touching=false;
  553. drag_slave_touching_deaccel=false;
  554. if (focus_by_default)
  555. set_focus_mode( FOCUS_ALL );
  556. }
  557. ScrollBar::~ScrollBar()
  558. {
  559. }