input_event.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /*************************************************************************/
  2. /* input_event.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "input_event.h"
  31. #include "input_map.h"
  32. #include "os/keyboard.h"
  33. /**
  34. *
  35. */
  36. void InputEvent::set_id(uint32_t p_id) {
  37. id = p_id;
  38. }
  39. uint32_t InputEvent::get_id() const {
  40. return id;
  41. }
  42. void InputEvent::set_device(int p_device) {
  43. device = p_device;
  44. }
  45. int InputEvent::get_device() const {
  46. return device;
  47. }
  48. bool InputEvent::is_pressed() const {
  49. return false;
  50. }
  51. bool InputEvent::is_action(const StringName &p_action) const {
  52. return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action);
  53. }
  54. bool InputEvent::is_action_pressed(const StringName &p_action) const {
  55. return (is_pressed() && !is_echo() && is_action(p_action));
  56. }
  57. bool InputEvent::is_action_released(const StringName &p_action) const {
  58. return (!is_pressed() && is_action(p_action));
  59. }
  60. bool InputEvent::is_echo() const {
  61. return false;
  62. }
  63. Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  64. return Ref<InputEvent>((InputEvent *)this);
  65. }
  66. String InputEvent::as_text() const {
  67. return String();
  68. }
  69. bool InputEvent::action_match(const Ref<InputEvent> &p_event) const {
  70. return false;
  71. }
  72. bool InputEvent::is_action_type() const {
  73. return false;
  74. }
  75. #if 0
  76. if (String(p_method) == "is_action" && p_argidx == 0) {
  77. List<PropertyInfo> pinfo;
  78. GlobalConfig::get_singleton()->get_property_list(&pinfo);
  79. for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
  80. const PropertyInfo &pi = E->get();
  81. if (!pi.name.begins_with("input/"))
  82. continue;
  83. String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
  84. result.insert("\"" + name + "\"");
  85. }
  86. } else
  87. #endif
  88. void InputEvent::_bind_methods() {
  89. ClassDB::bind_method(D_METHOD("set_id", "id"), &InputEvent::set_id);
  90. ClassDB::bind_method(D_METHOD("get_id"), &InputEvent::get_id);
  91. ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
  92. ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
  93. ClassDB::bind_method(D_METHOD("is_pressed"), &InputEvent::is_pressed);
  94. ClassDB::bind_method(D_METHOD("is_action", "action"), &InputEvent::is_action);
  95. ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &InputEvent::is_action_pressed);
  96. ClassDB::bind_method(D_METHOD("is_action_released", "action"), &InputEvent::is_action_released);
  97. ClassDB::bind_method(D_METHOD("is_echo"), &InputEvent::is_echo);
  98. ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
  99. ClassDB::bind_method(D_METHOD("action_match", "event:InputEvent"), &InputEvent::action_match);
  100. ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
  101. ClassDB::bind_method(D_METHOD("xformed_by:InputEvent", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
  102. }
  103. InputEvent::InputEvent() {
  104. id = 0;
  105. device = 0;
  106. }
  107. //////////////////
  108. void InputEventWithModifiers::set_shift(bool p_enabled) {
  109. shift = p_enabled;
  110. }
  111. bool InputEventWithModifiers::get_shift() const {
  112. return shift;
  113. }
  114. void InputEventWithModifiers::set_alt(bool p_enabled) {
  115. alt = p_enabled;
  116. }
  117. bool InputEventWithModifiers::get_alt() const {
  118. return alt;
  119. }
  120. void InputEventWithModifiers::set_control(bool p_enabled) {
  121. control = p_enabled;
  122. }
  123. bool InputEventWithModifiers::get_control() const {
  124. return control;
  125. }
  126. void InputEventWithModifiers::set_metakey(bool p_enabled) {
  127. meta = p_enabled;
  128. }
  129. bool InputEventWithModifiers::get_metakey() const {
  130. return meta;
  131. }
  132. void InputEventWithModifiers::set_command(bool p_enabled) {
  133. command = p_enabled;
  134. }
  135. bool InputEventWithModifiers::get_command() const {
  136. return command;
  137. }
  138. void InputEventWithModifiers::_bind_methods() {
  139. ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
  140. ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
  141. ClassDB::bind_method(D_METHOD("set_shift", "enable"), &InputEventWithModifiers::set_shift);
  142. ClassDB::bind_method(D_METHOD("get_shift"), &InputEventWithModifiers::get_shift);
  143. ClassDB::bind_method(D_METHOD("set_control", "enable"), &InputEventWithModifiers::set_control);
  144. ClassDB::bind_method(D_METHOD("get_control"), &InputEventWithModifiers::get_control);
  145. ClassDB::bind_method(D_METHOD("set_metakey", "enable"), &InputEventWithModifiers::set_metakey);
  146. ClassDB::bind_method(D_METHOD("get_metakey"), &InputEventWithModifiers::get_metakey);
  147. ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
  148. ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
  149. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
  150. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
  151. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
  152. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta"), "set_metakey", "get_metakey");
  153. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
  154. }
  155. InputEventWithModifiers::InputEventWithModifiers() {
  156. alt = false;
  157. shift = false;
  158. control = false;
  159. meta = false;
  160. }
  161. //////////////////////////////////
  162. void InputEventKey::set_pressed(bool p_pressed) {
  163. pressed = p_pressed;
  164. }
  165. bool InputEventKey::is_pressed() const {
  166. return pressed;
  167. }
  168. void InputEventKey::set_scancode(uint32_t p_scancode) {
  169. scancode = p_scancode;
  170. }
  171. uint32_t InputEventKey::get_scancode() const {
  172. return scancode;
  173. }
  174. void InputEventKey::set_unicode(uint32_t p_unicode) {
  175. unicode = p_unicode;
  176. }
  177. uint32_t InputEventKey::get_unicode() const {
  178. return unicode;
  179. }
  180. void InputEventKey::set_echo(bool p_enable) {
  181. echo = p_enable;
  182. }
  183. bool InputEventKey::is_echo() const {
  184. return echo;
  185. }
  186. uint32_t InputEventKey::get_scancode_with_modifiers() const {
  187. uint32_t sc = scancode;
  188. if (get_control())
  189. sc |= KEY_MASK_CTRL;
  190. if (get_alt())
  191. sc |= KEY_MASK_ALT;
  192. if (get_shift())
  193. sc |= KEY_MASK_SHIFT;
  194. if (get_metakey())
  195. sc |= KEY_MASK_META;
  196. return sc;
  197. }
  198. bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const {
  199. Ref<InputEventKey> key = p_event;
  200. if (key.is_null())
  201. return false;
  202. return get_scancode_with_modifiers() == key->get_scancode_with_modifiers();
  203. }
  204. void InputEventKey::_bind_methods() {
  205. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
  206. ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode);
  207. ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode);
  208. ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
  209. ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
  210. ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
  211. ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers);
  212. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  213. ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode");
  214. ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
  215. ADD_PROPERTY(PropertyInfo(Variant::INT, "echo"), "set_echo", "is_echo");
  216. }
  217. InputEventKey::InputEventKey() {
  218. pressed = false;
  219. scancode = 0;
  220. unicode = 0; ///unicode
  221. echo = false;
  222. }
  223. ////////////////////////////////////////
  224. void InputEventMouse::set_button_mask(int p_mask) {
  225. button_mask = p_mask;
  226. }
  227. int InputEventMouse::get_button_mask() const {
  228. return button_mask;
  229. }
  230. void InputEventMouse::set_pos(const Vector2 &p_pos) {
  231. pos = p_pos;
  232. }
  233. Vector2 InputEventMouse::get_pos() const {
  234. return pos;
  235. }
  236. void InputEventMouse::set_global_pos(const Vector2 &p_global_pos) {
  237. global_pos = p_global_pos;
  238. }
  239. Vector2 InputEventMouse::get_global_pos() const {
  240. return global_pos;
  241. }
  242. void InputEventMouse::_bind_methods() {
  243. ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
  244. ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
  245. ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventMouse::set_pos);
  246. ClassDB::bind_method(D_METHOD("get_pos"), &InputEventMouse::get_pos);
  247. ClassDB::bind_method(D_METHOD("set_global_pos", "global_pos"), &InputEventMouse::set_global_pos);
  248. ClassDB::bind_method(D_METHOD("get_global_pos"), &InputEventMouse::get_global_pos);
  249. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
  250. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos");
  251. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_pos"), "set_global_pos", "get_global_pos");
  252. }
  253. InputEventMouse::InputEventMouse() {
  254. button_mask = 0;
  255. }
  256. ///////////////////////////////////////
  257. void InputEventMouseButton::set_factor(float p_factor) {
  258. factor = p_factor;
  259. }
  260. float InputEventMouseButton::get_factor() {
  261. return factor;
  262. }
  263. void InputEventMouseButton::set_button_index(int p_index) {
  264. button_index = p_index;
  265. }
  266. int InputEventMouseButton::get_button_index() const {
  267. return button_index;
  268. }
  269. void InputEventMouseButton::set_pressed(bool p_pressed) {
  270. pressed = p_pressed;
  271. }
  272. bool InputEventMouseButton::is_pressed() const {
  273. return pressed;
  274. }
  275. void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
  276. doubleclick = p_doubleclick;
  277. }
  278. bool InputEventMouseButton::is_doubleclick() const {
  279. return doubleclick;
  280. }
  281. Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  282. Vector2 g = p_xform.xform(get_global_pos());
  283. Vector2 l = p_xform.xform(get_pos() + p_local_ofs);
  284. Ref<InputEventMouseButton> mb;
  285. mb.instance();
  286. mb->set_id(get_id());
  287. mb->set_device(get_device());
  288. mb->set_alt(get_alt());
  289. mb->set_shift(get_shift());
  290. mb->set_control(get_control());
  291. mb->set_metakey(get_metakey());
  292. mb->set_pos(l);
  293. mb->set_global_pos(g);
  294. mb->set_button_mask(get_button_mask());
  295. mb->set_pressed(pressed);
  296. mb->set_doubleclick(doubleclick);
  297. mb->set_factor(factor);
  298. mb->set_button_index(button_index);
  299. return mb;
  300. }
  301. bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event) const {
  302. Ref<InputEventMouseButton> mb = p_event;
  303. if (mb.is_null())
  304. return false;
  305. return mb->button_index == button_index;
  306. }
  307. void InputEventMouseButton::_bind_methods() {
  308. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
  309. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
  310. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
  311. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
  312. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
  313. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed);
  314. ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
  315. ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
  316. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  317. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  318. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  319. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
  320. }
  321. InputEventMouseButton::InputEventMouseButton() {
  322. factor = 1;
  323. button_index = 0;
  324. pressed = false;
  325. doubleclick = false;
  326. }
  327. ////////////////////////////////////////////
  328. void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
  329. relative = p_relative;
  330. }
  331. Vector2 InputEventMouseMotion::get_relative() const {
  332. return relative;
  333. }
  334. void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
  335. speed = p_speed;
  336. }
  337. Vector2 InputEventMouseMotion::get_speed() const {
  338. return speed;
  339. }
  340. Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  341. Vector2 g = p_xform.xform(get_global_pos());
  342. Vector2 l = p_xform.xform(get_pos() + p_local_ofs);
  343. Vector2 r = p_xform.basis_xform(get_relative());
  344. Vector2 s = p_xform.basis_xform(get_speed());
  345. Ref<InputEventMouseMotion> mm;
  346. mm.instance();
  347. mm->set_id(get_id());
  348. mm->set_device(get_device());
  349. mm->set_alt(get_alt());
  350. mm->set_shift(get_shift());
  351. mm->set_control(get_control());
  352. mm->set_metakey(get_metakey());
  353. mm->set_pos(l);
  354. mm->set_global_pos(g);
  355. mm->set_button_mask(get_button_mask());
  356. mm->set_relative(r);
  357. mm->set_speed(s);
  358. return mm;
  359. }
  360. void InputEventMouseMotion::_bind_methods() {
  361. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
  362. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
  363. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
  364. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
  365. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  366. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  367. }
  368. InputEventMouseMotion::InputEventMouseMotion() {
  369. }
  370. ////////////////////////////////////////
  371. void InputEventJoypadMotion::set_axis(int p_axis) {
  372. axis = p_axis;
  373. }
  374. int InputEventJoypadMotion::get_axis() const {
  375. return axis;
  376. }
  377. void InputEventJoypadMotion::set_axis_value(float p_value) {
  378. axis_value = p_value;
  379. }
  380. float InputEventJoypadMotion::get_axis_value() const {
  381. return axis_value;
  382. }
  383. bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event) const {
  384. Ref<InputEventJoypadMotion> jm = p_event;
  385. if (jm.is_null())
  386. return false;
  387. return (axis == jm->axis && (axis_value < 0) == (jm->axis_value < 0));
  388. }
  389. void InputEventJoypadMotion::_bind_methods() {
  390. ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
  391. ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
  392. ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
  393. ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
  394. ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
  395. ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
  396. }
  397. InputEventJoypadMotion::InputEventJoypadMotion() {
  398. axis = 0;
  399. axis_value = 0;
  400. }
  401. /////////////////////////////////
  402. void InputEventJoypadButton::set_button_index(int p_index) {
  403. button_index = p_index;
  404. }
  405. int InputEventJoypadButton::get_button_index() const {
  406. return button_index;
  407. }
  408. void InputEventJoypadButton::set_pressed(bool p_pressed) {
  409. pressed = p_pressed;
  410. }
  411. bool InputEventJoypadButton::is_pressed() const {
  412. return pressed;
  413. }
  414. void InputEventJoypadButton::set_pressure(float p_pressure) {
  415. pressure = p_pressure;
  416. }
  417. float InputEventJoypadButton::get_pressure() const {
  418. return pressure;
  419. }
  420. bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event) const {
  421. Ref<InputEventJoypadButton> jb = p_event;
  422. if (jb.is_null())
  423. return false;
  424. return button_index == jb->button_index;
  425. }
  426. void InputEventJoypadButton::_bind_methods() {
  427. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
  428. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
  429. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
  430. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
  431. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
  432. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
  433. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  434. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  435. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  436. }
  437. InputEventJoypadButton::InputEventJoypadButton() {
  438. button_index = 0;
  439. pressure = 0;
  440. pressed = false;
  441. }
  442. //////////////////////////////////////////////
  443. void InputEventScreenTouch::set_index(int p_index) {
  444. index = p_index;
  445. }
  446. int InputEventScreenTouch::get_index() const {
  447. return index;
  448. }
  449. void InputEventScreenTouch::set_pos(const Vector2 &p_pos) {
  450. pos = p_pos;
  451. }
  452. Vector2 InputEventScreenTouch::get_pos() const {
  453. return pos;
  454. }
  455. void InputEventScreenTouch::set_pressed(bool p_pressed) {
  456. pressed = p_pressed;
  457. }
  458. bool InputEventScreenTouch::is_pressed() const {
  459. return pressed;
  460. }
  461. Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  462. Ref<InputEventScreenTouch> st;
  463. st.instance();
  464. st->set_id(get_id());
  465. st->set_device(get_device());
  466. st->set_index(index);
  467. st->set_pos(p_xform.xform(pos + p_local_ofs));
  468. st->set_pressed(pressed);
  469. return st;
  470. }
  471. void InputEventScreenTouch::_bind_methods() {
  472. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
  473. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
  474. ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventScreenTouch::set_pos);
  475. ClassDB::bind_method(D_METHOD("get_pos"), &InputEventScreenTouch::get_pos);
  476. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
  477. //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
  478. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  479. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos");
  480. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  481. }
  482. InputEventScreenTouch::InputEventScreenTouch() {
  483. index = 0;
  484. pressed = false;
  485. }
  486. /////////////////////////////
  487. void InputEventScreenDrag::set_index(int p_index) {
  488. index = p_index;
  489. }
  490. int InputEventScreenDrag::get_index() const {
  491. return index;
  492. }
  493. void InputEventScreenDrag::set_pos(const Vector2 &p_pos) {
  494. pos = p_pos;
  495. }
  496. Vector2 InputEventScreenDrag::get_pos() const {
  497. return pos;
  498. }
  499. void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
  500. relative = p_relative;
  501. }
  502. Vector2 InputEventScreenDrag::get_relative() const {
  503. return relative;
  504. }
  505. void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
  506. speed = p_speed;
  507. }
  508. Vector2 InputEventScreenDrag::get_speed() const {
  509. return speed;
  510. }
  511. Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  512. Ref<InputEventScreenDrag> sd;
  513. sd.instance();
  514. sd->set_id(get_id());
  515. sd->set_device(get_device());
  516. sd->set_index(index);
  517. sd->set_pos(p_xform.xform(pos + p_local_ofs));
  518. sd->set_relative(p_xform.basis_xform(relative));
  519. sd->set_speed(p_xform.basis_xform(speed));
  520. return sd;
  521. }
  522. void InputEventScreenDrag::_bind_methods() {
  523. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
  524. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
  525. ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventScreenDrag::set_pos);
  526. ClassDB::bind_method(D_METHOD("get_pos"), &InputEventScreenDrag::get_pos);
  527. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
  528. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
  529. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
  530. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
  531. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  532. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos");
  533. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  534. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  535. }
  536. InputEventScreenDrag::InputEventScreenDrag() {
  537. index = 0;
  538. }
  539. /////////////////////////////
  540. void InputEventAction::set_action(const StringName &p_action) {
  541. action = p_action;
  542. }
  543. StringName InputEventAction::get_action() const {
  544. return action;
  545. }
  546. void InputEventAction::set_pressed(bool p_pressed) {
  547. pressed = p_pressed;
  548. }
  549. bool InputEventAction::is_pressed() const {
  550. return pressed;
  551. }
  552. bool InputEventAction::is_action(const StringName &p_action) const {
  553. return action == p_action;
  554. }
  555. void InputEventAction::_bind_methods() {
  556. ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
  557. ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
  558. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
  559. //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
  560. // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
  561. ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
  562. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  563. }
  564. InputEventAction::InputEventAction() {
  565. pressed = false;
  566. }