input_event.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. /*************************************************************************/
  2. /* input_event.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "core/input_map.h"
  32. #include "core/os/keyboard.h"
  33. const int InputEvent::DEVICE_ID_TOUCH_MOUSE = -1;
  34. const int InputEvent::DEVICE_ID_INTERNAL = -2;
  35. void InputEvent::set_device(int p_device) {
  36. device = p_device;
  37. }
  38. int InputEvent::get_device() const {
  39. return device;
  40. }
  41. bool InputEvent::is_action(const StringName &p_action) const {
  42. return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action);
  43. }
  44. bool InputEvent::is_action_pressed(const StringName &p_action) const {
  45. bool pressed;
  46. bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
  47. return valid && pressed && !is_echo();
  48. }
  49. bool InputEvent::is_action_released(const StringName &p_action) const {
  50. bool pressed;
  51. bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
  52. return valid && !pressed;
  53. }
  54. float InputEvent::get_action_strength(const StringName &p_action) const {
  55. bool pressed;
  56. float strength;
  57. bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed, &strength);
  58. return valid ? strength : 0.0f;
  59. }
  60. bool InputEvent::is_pressed() const {
  61. return false;
  62. }
  63. bool InputEvent::is_echo() const {
  64. return false;
  65. }
  66. Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  67. return Ref<InputEvent>((InputEvent *)this);
  68. }
  69. String InputEvent::as_text() const {
  70. return String();
  71. }
  72. bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  73. return false;
  74. }
  75. bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const {
  76. return false;
  77. }
  78. bool InputEvent::is_action_type() const {
  79. return false;
  80. }
  81. void InputEvent::_bind_methods() {
  82. ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
  83. ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
  84. ClassDB::bind_method(D_METHOD("is_action", "action"), &InputEvent::is_action);
  85. ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &InputEvent::is_action_pressed);
  86. ClassDB::bind_method(D_METHOD("is_action_released", "action"), &InputEvent::is_action_released);
  87. ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &InputEvent::get_action_strength);
  88. ClassDB::bind_method(D_METHOD("is_pressed"), &InputEvent::is_pressed);
  89. ClassDB::bind_method(D_METHOD("is_echo"), &InputEvent::is_echo);
  90. ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
  91. ClassDB::bind_method(D_METHOD("shortcut_match", "event"), &InputEvent::shortcut_match);
  92. ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
  93. ClassDB::bind_method(D_METHOD("accumulate", "with_event"), &InputEvent::accumulate);
  94. ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
  95. ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device");
  96. }
  97. InputEvent::InputEvent() {
  98. device = 0;
  99. }
  100. //////////////////
  101. void InputEventWithModifiers::set_shift(bool p_enabled) {
  102. shift = p_enabled;
  103. }
  104. bool InputEventWithModifiers::get_shift() const {
  105. return shift;
  106. }
  107. void InputEventWithModifiers::set_alt(bool p_enabled) {
  108. alt = p_enabled;
  109. }
  110. bool InputEventWithModifiers::get_alt() const {
  111. return alt;
  112. }
  113. void InputEventWithModifiers::set_control(bool p_enabled) {
  114. control = p_enabled;
  115. }
  116. bool InputEventWithModifiers::get_control() const {
  117. return control;
  118. }
  119. void InputEventWithModifiers::set_metakey(bool p_enabled) {
  120. meta = p_enabled;
  121. }
  122. bool InputEventWithModifiers::get_metakey() const {
  123. return meta;
  124. }
  125. void InputEventWithModifiers::set_command(bool p_enabled) {
  126. command = p_enabled;
  127. }
  128. bool InputEventWithModifiers::get_command() const {
  129. return command;
  130. }
  131. void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) {
  132. set_alt(event->get_alt());
  133. set_shift(event->get_shift());
  134. set_control(event->get_control());
  135. set_metakey(event->get_metakey());
  136. }
  137. void InputEventWithModifiers::_bind_methods() {
  138. ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
  139. ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
  140. ClassDB::bind_method(D_METHOD("set_shift", "enable"), &InputEventWithModifiers::set_shift);
  141. ClassDB::bind_method(D_METHOD("get_shift"), &InputEventWithModifiers::get_shift);
  142. ClassDB::bind_method(D_METHOD("set_control", "enable"), &InputEventWithModifiers::set_control);
  143. ClassDB::bind_method(D_METHOD("get_control"), &InputEventWithModifiers::get_control);
  144. ClassDB::bind_method(D_METHOD("set_metakey", "enable"), &InputEventWithModifiers::set_metakey);
  145. ClassDB::bind_method(D_METHOD("get_metakey"), &InputEventWithModifiers::get_metakey);
  146. ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
  147. ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
  148. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
  149. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
  150. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
  151. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta"), "set_metakey", "get_metakey");
  152. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
  153. }
  154. InputEventWithModifiers::InputEventWithModifiers() {
  155. alt = false;
  156. shift = false;
  157. control = false;
  158. meta = false;
  159. }
  160. //////////////////////////////////
  161. void InputEventKey::set_pressed(bool p_pressed) {
  162. pressed = p_pressed;
  163. }
  164. bool InputEventKey::is_pressed() const {
  165. return pressed;
  166. }
  167. void InputEventKey::set_scancode(uint32_t p_scancode) {
  168. scancode = p_scancode;
  169. }
  170. uint32_t InputEventKey::get_scancode() const {
  171. return scancode;
  172. }
  173. void InputEventKey::set_unicode(uint32_t p_unicode) {
  174. unicode = p_unicode;
  175. }
  176. uint32_t InputEventKey::get_unicode() const {
  177. return unicode;
  178. }
  179. void InputEventKey::set_echo(bool p_enable) {
  180. echo = p_enable;
  181. }
  182. bool InputEventKey::is_echo() const {
  183. return echo;
  184. }
  185. uint32_t InputEventKey::get_scancode_with_modifiers() const {
  186. uint32_t sc = scancode;
  187. if (get_control())
  188. sc |= KEY_MASK_CTRL;
  189. if (get_alt())
  190. sc |= KEY_MASK_ALT;
  191. if (get_shift())
  192. sc |= KEY_MASK_SHIFT;
  193. if (get_metakey())
  194. sc |= KEY_MASK_META;
  195. return sc;
  196. }
  197. String InputEventKey::as_text() const {
  198. String kc = keycode_get_string(scancode);
  199. if (kc == String())
  200. return kc;
  201. if (get_metakey()) {
  202. kc = find_keycode_name(KEY_META) + ("+" + kc);
  203. }
  204. if (get_alt()) {
  205. kc = find_keycode_name(KEY_ALT) + ("+" + kc);
  206. }
  207. if (get_shift()) {
  208. kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
  209. }
  210. if (get_control()) {
  211. kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
  212. }
  213. return kc;
  214. }
  215. bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  216. Ref<InputEventKey> key = p_event;
  217. if (key.is_null())
  218. return false;
  219. uint32_t code = get_scancode_with_modifiers();
  220. uint32_t event_code = key->get_scancode_with_modifiers();
  221. bool match = get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
  222. if (match) {
  223. if (p_pressed != NULL)
  224. *p_pressed = key->is_pressed();
  225. if (p_strength != NULL)
  226. *p_strength = (*p_pressed) ? 1.0f : 0.0f;
  227. }
  228. return match;
  229. }
  230. bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
  231. Ref<InputEventKey> key = p_event;
  232. if (key.is_null())
  233. return false;
  234. uint32_t code = get_scancode_with_modifiers();
  235. uint32_t event_code = key->get_scancode_with_modifiers();
  236. return code == event_code;
  237. }
  238. void InputEventKey::_bind_methods() {
  239. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
  240. ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode);
  241. ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode);
  242. ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
  243. ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
  244. ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
  245. ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers);
  246. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  247. ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode");
  248. ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
  249. ADD_PROPERTY(PropertyInfo(Variant::INT, "echo"), "set_echo", "is_echo");
  250. }
  251. InputEventKey::InputEventKey() {
  252. pressed = false;
  253. scancode = 0;
  254. unicode = 0; ///unicode
  255. echo = false;
  256. }
  257. ////////////////////////////////////////
  258. void InputEventMouse::set_button_mask(int p_mask) {
  259. button_mask = p_mask;
  260. }
  261. int InputEventMouse::get_button_mask() const {
  262. return button_mask;
  263. }
  264. void InputEventMouse::set_position(const Vector2 &p_pos) {
  265. pos = p_pos;
  266. }
  267. Vector2 InputEventMouse::get_position() const {
  268. return pos;
  269. }
  270. void InputEventMouse::set_global_position(const Vector2 &p_global_pos) {
  271. global_pos = p_global_pos;
  272. }
  273. Vector2 InputEventMouse::get_global_position() const {
  274. return global_pos;
  275. }
  276. void InputEventMouse::_bind_methods() {
  277. ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
  278. ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
  279. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventMouse::set_position);
  280. ClassDB::bind_method(D_METHOD("get_position"), &InputEventMouse::get_position);
  281. ClassDB::bind_method(D_METHOD("set_global_position", "global_position"), &InputEventMouse::set_global_position);
  282. ClassDB::bind_method(D_METHOD("get_global_position"), &InputEventMouse::get_global_position);
  283. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
  284. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  285. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position");
  286. }
  287. InputEventMouse::InputEventMouse() {
  288. button_mask = 0;
  289. }
  290. ///////////////////////////////////////
  291. void InputEventMouseButton::set_factor(float p_factor) {
  292. factor = p_factor;
  293. }
  294. float InputEventMouseButton::get_factor() {
  295. return factor;
  296. }
  297. void InputEventMouseButton::set_button_index(int p_index) {
  298. button_index = p_index;
  299. }
  300. int InputEventMouseButton::get_button_index() const {
  301. return button_index;
  302. }
  303. void InputEventMouseButton::set_pressed(bool p_pressed) {
  304. pressed = p_pressed;
  305. }
  306. bool InputEventMouseButton::is_pressed() const {
  307. return pressed;
  308. }
  309. void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
  310. doubleclick = p_doubleclick;
  311. }
  312. bool InputEventMouseButton::is_doubleclick() const {
  313. return doubleclick;
  314. }
  315. Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  316. Vector2 g = p_xform.xform(get_global_position());
  317. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  318. Ref<InputEventMouseButton> mb;
  319. mb.instance();
  320. mb->set_device(get_device());
  321. mb->set_modifiers_from_event(this);
  322. mb->set_position(l);
  323. mb->set_global_position(g);
  324. mb->set_button_mask(get_button_mask());
  325. mb->set_pressed(pressed);
  326. mb->set_doubleclick(doubleclick);
  327. mb->set_factor(factor);
  328. mb->set_button_index(button_index);
  329. return mb;
  330. }
  331. bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  332. Ref<InputEventMouseButton> mb = p_event;
  333. if (mb.is_null())
  334. return false;
  335. bool match = mb->button_index == button_index;
  336. if (match) {
  337. if (p_pressed != NULL)
  338. *p_pressed = mb->is_pressed();
  339. if (p_strength != NULL)
  340. *p_strength = (*p_pressed) ? 1.0f : 0.0f;
  341. }
  342. return match;
  343. }
  344. String InputEventMouseButton::as_text() const {
  345. String button_index_string = "";
  346. switch (get_button_index()) {
  347. case BUTTON_LEFT:
  348. button_index_string = "BUTTON_LEFT";
  349. break;
  350. case BUTTON_RIGHT:
  351. button_index_string = "BUTTON_RIGHT";
  352. break;
  353. case BUTTON_MIDDLE:
  354. button_index_string = "BUTTON_MIDDLE";
  355. break;
  356. case BUTTON_WHEEL_UP:
  357. button_index_string = "BUTTON_WHEEL_UP";
  358. break;
  359. case BUTTON_WHEEL_DOWN:
  360. button_index_string = "BUTTON_WHEEL_DOWN";
  361. break;
  362. case BUTTON_WHEEL_LEFT:
  363. button_index_string = "BUTTON_WHEEL_LEFT";
  364. break;
  365. case BUTTON_WHEEL_RIGHT:
  366. button_index_string = "BUTTON_WHEEL_RIGHT";
  367. break;
  368. case BUTTON_XBUTTON1:
  369. button_index_string = "BUTTON_XBUTTON1";
  370. break;
  371. case BUTTON_XBUTTON2:
  372. button_index_string = "BUTTON_XBUTTON2";
  373. break;
  374. default:
  375. button_index_string = itos(get_button_index());
  376. break;
  377. }
  378. return "InputEventMouseButton : button_index=" + button_index_string + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + "), button_mask=" + itos(get_button_mask()) + ", doubleclick=" + (doubleclick ? "true" : "false");
  379. }
  380. void InputEventMouseButton::_bind_methods() {
  381. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
  382. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
  383. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
  384. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
  385. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
  386. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed);
  387. ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
  388. ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
  389. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  390. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  391. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  392. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
  393. }
  394. InputEventMouseButton::InputEventMouseButton() {
  395. factor = 1;
  396. button_index = 0;
  397. pressed = false;
  398. doubleclick = false;
  399. }
  400. ////////////////////////////////////////////
  401. void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
  402. relative = p_relative;
  403. }
  404. Vector2 InputEventMouseMotion::get_relative() const {
  405. return relative;
  406. }
  407. void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
  408. speed = p_speed;
  409. }
  410. Vector2 InputEventMouseMotion::get_speed() const {
  411. return speed;
  412. }
  413. Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  414. Vector2 g = p_xform.xform(get_global_position());
  415. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  416. Vector2 r = p_xform.basis_xform(get_relative());
  417. Vector2 s = p_xform.basis_xform(get_speed());
  418. Ref<InputEventMouseMotion> mm;
  419. mm.instance();
  420. mm->set_device(get_device());
  421. mm->set_modifiers_from_event(this);
  422. mm->set_position(l);
  423. mm->set_global_position(g);
  424. mm->set_button_mask(get_button_mask());
  425. mm->set_relative(r);
  426. mm->set_speed(s);
  427. return mm;
  428. }
  429. String InputEventMouseMotion::as_text() const {
  430. String button_mask_string = "";
  431. switch (get_button_mask()) {
  432. case BUTTON_MASK_LEFT:
  433. button_mask_string = "BUTTON_MASK_LEFT";
  434. break;
  435. case BUTTON_MASK_MIDDLE:
  436. button_mask_string = "BUTTON_MASK_MIDDLE";
  437. break;
  438. case BUTTON_MASK_RIGHT:
  439. button_mask_string = "BUTTON_MASK_RIGHT";
  440. break;
  441. case BUTTON_MASK_XBUTTON1:
  442. button_mask_string = "BUTTON_MASK_XBUTTON1";
  443. break;
  444. case BUTTON_MASK_XBUTTON2:
  445. button_mask_string = "BUTTON_MASK_XBUTTON2";
  446. break;
  447. default:
  448. button_mask_string = itos(get_button_mask());
  449. break;
  450. }
  451. return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  452. }
  453. bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
  454. Ref<InputEventMouseMotion> motion = p_event;
  455. if (motion.is_null())
  456. return false;
  457. if (is_pressed() != motion->is_pressed()) {
  458. return false;
  459. }
  460. if (get_button_mask() != motion->get_button_mask()) {
  461. return false;
  462. }
  463. if (get_shift() != motion->get_shift()) {
  464. return false;
  465. }
  466. if (get_control() != motion->get_control()) {
  467. return false;
  468. }
  469. if (get_alt() != motion->get_alt()) {
  470. return false;
  471. }
  472. if (get_metakey() != motion->get_metakey()) {
  473. return false;
  474. }
  475. set_position(motion->get_position());
  476. set_global_position(motion->get_global_position());
  477. set_speed(motion->get_speed());
  478. relative += motion->get_relative();
  479. return true;
  480. }
  481. void InputEventMouseMotion::_bind_methods() {
  482. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
  483. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
  484. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
  485. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
  486. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  487. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  488. }
  489. InputEventMouseMotion::InputEventMouseMotion() {
  490. }
  491. ////////////////////////////////////////
  492. void InputEventJoypadMotion::set_axis(int p_axis) {
  493. axis = p_axis;
  494. }
  495. int InputEventJoypadMotion::get_axis() const {
  496. return axis;
  497. }
  498. void InputEventJoypadMotion::set_axis_value(float p_value) {
  499. axis_value = p_value;
  500. }
  501. float InputEventJoypadMotion::get_axis_value() const {
  502. return axis_value;
  503. }
  504. bool InputEventJoypadMotion::is_pressed() const {
  505. return Math::abs(axis_value) >= 0.5f;
  506. }
  507. bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  508. Ref<InputEventJoypadMotion> jm = p_event;
  509. if (jm.is_null())
  510. return false;
  511. bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
  512. if (match) {
  513. bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
  514. bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
  515. if (p_pressed != NULL)
  516. *p_pressed = pressed;
  517. if (p_strength != NULL) {
  518. if (pressed) {
  519. if (p_deadzone == 1.0f) {
  520. *p_strength = 1.0f;
  521. } else {
  522. *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
  523. }
  524. } else {
  525. *p_strength = 0.0f;
  526. }
  527. }
  528. }
  529. return match;
  530. }
  531. String InputEventJoypadMotion::as_text() const {
  532. return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
  533. }
  534. void InputEventJoypadMotion::_bind_methods() {
  535. ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
  536. ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
  537. ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
  538. ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
  539. ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
  540. ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
  541. }
  542. InputEventJoypadMotion::InputEventJoypadMotion() {
  543. axis = 0;
  544. axis_value = 0;
  545. }
  546. /////////////////////////////////
  547. void InputEventJoypadButton::set_button_index(int p_index) {
  548. button_index = p_index;
  549. }
  550. int InputEventJoypadButton::get_button_index() const {
  551. return button_index;
  552. }
  553. void InputEventJoypadButton::set_pressed(bool p_pressed) {
  554. pressed = p_pressed;
  555. }
  556. bool InputEventJoypadButton::is_pressed() const {
  557. return pressed;
  558. }
  559. void InputEventJoypadButton::set_pressure(float p_pressure) {
  560. pressure = p_pressure;
  561. }
  562. float InputEventJoypadButton::get_pressure() const {
  563. return pressure;
  564. }
  565. bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  566. Ref<InputEventJoypadButton> jb = p_event;
  567. if (jb.is_null())
  568. return false;
  569. bool match = button_index == jb->button_index;
  570. if (match) {
  571. if (p_pressed != NULL)
  572. *p_pressed = jb->is_pressed();
  573. if (p_strength != NULL)
  574. *p_strength = (*p_pressed) ? 1.0f : 0.0f;
  575. }
  576. return match;
  577. }
  578. bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
  579. Ref<InputEventJoypadButton> button = p_event;
  580. if (button.is_null())
  581. return false;
  582. return button_index == button->button_index;
  583. }
  584. String InputEventJoypadButton::as_text() const {
  585. return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
  586. }
  587. void InputEventJoypadButton::_bind_methods() {
  588. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
  589. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
  590. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
  591. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
  592. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
  593. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
  594. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  595. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  596. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  597. }
  598. InputEventJoypadButton::InputEventJoypadButton() {
  599. button_index = 0;
  600. pressure = 0;
  601. pressed = false;
  602. }
  603. //////////////////////////////////////////////
  604. void InputEventScreenTouch::set_index(int p_index) {
  605. index = p_index;
  606. }
  607. int InputEventScreenTouch::get_index() const {
  608. return index;
  609. }
  610. void InputEventScreenTouch::set_position(const Vector2 &p_pos) {
  611. pos = p_pos;
  612. }
  613. Vector2 InputEventScreenTouch::get_position() const {
  614. return pos;
  615. }
  616. void InputEventScreenTouch::set_pressed(bool p_pressed) {
  617. pressed = p_pressed;
  618. }
  619. bool InputEventScreenTouch::is_pressed() const {
  620. return pressed;
  621. }
  622. Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  623. Ref<InputEventScreenTouch> st;
  624. st.instance();
  625. st->set_device(get_device());
  626. st->set_index(index);
  627. st->set_position(p_xform.xform(pos + p_local_ofs));
  628. st->set_pressed(pressed);
  629. return st;
  630. }
  631. String InputEventScreenTouch::as_text() const {
  632. return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
  633. }
  634. void InputEventScreenTouch::_bind_methods() {
  635. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
  636. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
  637. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenTouch::set_position);
  638. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
  639. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
  640. //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
  641. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  642. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  643. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  644. }
  645. InputEventScreenTouch::InputEventScreenTouch() {
  646. index = 0;
  647. pressed = false;
  648. }
  649. /////////////////////////////
  650. void InputEventScreenDrag::set_index(int p_index) {
  651. index = p_index;
  652. }
  653. int InputEventScreenDrag::get_index() const {
  654. return index;
  655. }
  656. void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
  657. pos = p_pos;
  658. }
  659. Vector2 InputEventScreenDrag::get_position() const {
  660. return pos;
  661. }
  662. void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
  663. relative = p_relative;
  664. }
  665. Vector2 InputEventScreenDrag::get_relative() const {
  666. return relative;
  667. }
  668. void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
  669. speed = p_speed;
  670. }
  671. Vector2 InputEventScreenDrag::get_speed() const {
  672. return speed;
  673. }
  674. Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  675. Ref<InputEventScreenDrag> sd;
  676. sd.instance();
  677. sd->set_device(get_device());
  678. sd->set_index(index);
  679. sd->set_position(p_xform.xform(pos + p_local_ofs));
  680. sd->set_relative(p_xform.basis_xform(relative));
  681. sd->set_speed(p_xform.basis_xform(speed));
  682. return sd;
  683. }
  684. String InputEventScreenDrag::as_text() const {
  685. return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  686. }
  687. void InputEventScreenDrag::_bind_methods() {
  688. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
  689. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
  690. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
  691. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
  692. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
  693. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
  694. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
  695. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
  696. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  697. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  698. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  699. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  700. }
  701. InputEventScreenDrag::InputEventScreenDrag() {
  702. index = 0;
  703. }
  704. /////////////////////////////
  705. void InputEventAction::set_action(const StringName &p_action) {
  706. action = p_action;
  707. }
  708. StringName InputEventAction::get_action() const {
  709. return action;
  710. }
  711. void InputEventAction::set_pressed(bool p_pressed) {
  712. pressed = p_pressed;
  713. }
  714. bool InputEventAction::is_pressed() const {
  715. return pressed;
  716. }
  717. bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
  718. if (p_event.is_null())
  719. return false;
  720. return p_event->is_action(action);
  721. }
  722. bool InputEventAction::is_action(const StringName &p_action) const {
  723. return action == p_action;
  724. }
  725. bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  726. Ref<InputEventAction> act = p_event;
  727. if (act.is_null())
  728. return false;
  729. bool match = action == act->action;
  730. if (match) {
  731. if (p_pressed != NULL)
  732. *p_pressed = act->pressed;
  733. if (p_strength != NULL)
  734. *p_strength = (*p_pressed) ? 1.0f : 0.0f;
  735. }
  736. return match;
  737. }
  738. String InputEventAction::as_text() const {
  739. return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
  740. }
  741. void InputEventAction::_bind_methods() {
  742. ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
  743. ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
  744. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
  745. //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
  746. // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
  747. ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
  748. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  749. }
  750. InputEventAction::InputEventAction() {
  751. pressed = false;
  752. }
  753. /////////////////////////////
  754. void InputEventGesture::set_position(const Vector2 &p_pos) {
  755. pos = p_pos;
  756. }
  757. void InputEventGesture::_bind_methods() {
  758. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
  759. ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
  760. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  761. }
  762. Vector2 InputEventGesture::get_position() const {
  763. return pos;
  764. }
  765. /////////////////////////////
  766. void InputEventMagnifyGesture::set_factor(real_t p_factor) {
  767. factor = p_factor;
  768. }
  769. real_t InputEventMagnifyGesture::get_factor() const {
  770. return factor;
  771. }
  772. Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  773. Ref<InputEventMagnifyGesture> ev;
  774. ev.instance();
  775. ev->set_device(get_device());
  776. ev->set_modifiers_from_event(this);
  777. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  778. ev->set_factor(get_factor());
  779. return ev;
  780. }
  781. String InputEventMagnifyGesture::as_text() const {
  782. return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
  783. }
  784. void InputEventMagnifyGesture::_bind_methods() {
  785. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
  786. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
  787. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  788. }
  789. InputEventMagnifyGesture::InputEventMagnifyGesture() {
  790. factor = 1.0;
  791. }
  792. /////////////////////////////
  793. void InputEventPanGesture::set_delta(const Vector2 &p_delta) {
  794. delta = p_delta;
  795. }
  796. Vector2 InputEventPanGesture::get_delta() const {
  797. return delta;
  798. }
  799. Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  800. Ref<InputEventPanGesture> ev;
  801. ev.instance();
  802. ev->set_device(get_device());
  803. ev->set_modifiers_from_event(this);
  804. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  805. ev->set_delta(get_delta());
  806. return ev;
  807. }
  808. String InputEventPanGesture::as_text() const {
  809. return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
  810. }
  811. void InputEventPanGesture::_bind_methods() {
  812. ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
  813. ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
  814. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
  815. }
  816. InputEventPanGesture::InputEventPanGesture() {
  817. delta = Vector2(0, 0);
  818. }
  819. /////////////////////////////
  820. void InputEventMIDI::set_channel(const int p_channel) {
  821. channel = p_channel;
  822. }
  823. int InputEventMIDI::get_channel() const {
  824. return channel;
  825. }
  826. void InputEventMIDI::set_message(const int p_message) {
  827. message = p_message;
  828. }
  829. int InputEventMIDI::get_message() const {
  830. return message;
  831. }
  832. void InputEventMIDI::set_pitch(const int p_pitch) {
  833. pitch = p_pitch;
  834. }
  835. int InputEventMIDI::get_pitch() const {
  836. return pitch;
  837. }
  838. void InputEventMIDI::set_velocity(const int p_velocity) {
  839. velocity = p_velocity;
  840. }
  841. int InputEventMIDI::get_velocity() const {
  842. return velocity;
  843. }
  844. void InputEventMIDI::set_instrument(const int p_instrument) {
  845. instrument = p_instrument;
  846. }
  847. int InputEventMIDI::get_instrument() const {
  848. return instrument;
  849. }
  850. void InputEventMIDI::set_pressure(const int p_pressure) {
  851. pressure = p_pressure;
  852. }
  853. int InputEventMIDI::get_pressure() const {
  854. return pressure;
  855. }
  856. void InputEventMIDI::set_controller_number(const int p_controller_number) {
  857. controller_number = p_controller_number;
  858. }
  859. int InputEventMIDI::get_controller_number() const {
  860. return controller_number;
  861. }
  862. void InputEventMIDI::set_controller_value(const int p_controller_value) {
  863. controller_value = p_controller_value;
  864. }
  865. int InputEventMIDI::get_controller_value() const {
  866. return controller_value;
  867. }
  868. String InputEventMIDI::as_text() const {
  869. return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
  870. }
  871. void InputEventMIDI::_bind_methods() {
  872. ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel);
  873. ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel);
  874. ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message);
  875. ClassDB::bind_method(D_METHOD("get_message"), &InputEventMIDI::get_message);
  876. ClassDB::bind_method(D_METHOD("set_pitch", "pitch"), &InputEventMIDI::set_pitch);
  877. ClassDB::bind_method(D_METHOD("get_pitch"), &InputEventMIDI::get_pitch);
  878. ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventMIDI::set_velocity);
  879. ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventMIDI::get_velocity);
  880. ClassDB::bind_method(D_METHOD("set_instrument", "instrument"), &InputEventMIDI::set_instrument);
  881. ClassDB::bind_method(D_METHOD("get_instrument"), &InputEventMIDI::get_instrument);
  882. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMIDI::set_pressure);
  883. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMIDI::get_pressure);
  884. ClassDB::bind_method(D_METHOD("set_controller_number", "controller_number"), &InputEventMIDI::set_controller_number);
  885. ClassDB::bind_method(D_METHOD("get_controller_number"), &InputEventMIDI::get_controller_number);
  886. ClassDB::bind_method(D_METHOD("set_controller_value", "controller_value"), &InputEventMIDI::set_controller_value);
  887. ClassDB::bind_method(D_METHOD("get_controller_value"), &InputEventMIDI::get_controller_value);
  888. ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel");
  889. ADD_PROPERTY(PropertyInfo(Variant::INT, "message"), "set_message", "get_message");
  890. ADD_PROPERTY(PropertyInfo(Variant::INT, "pitch"), "set_pitch", "get_pitch");
  891. ADD_PROPERTY(PropertyInfo(Variant::INT, "velocity"), "set_velocity", "get_velocity");
  892. ADD_PROPERTY(PropertyInfo(Variant::INT, "instrument"), "set_instrument", "get_instrument");
  893. ADD_PROPERTY(PropertyInfo(Variant::INT, "pressure"), "set_pressure", "get_pressure");
  894. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_number"), "set_controller_number", "get_controller_number");
  895. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_value"), "set_controller_value", "get_controller_value");
  896. }
  897. InputEventMIDI::InputEventMIDI() {
  898. channel = 0;
  899. message = 0;
  900. pitch = 0;
  901. velocity = 0;
  902. instrument = 0;
  903. pressure = 0;
  904. controller_number = 0;
  905. controller_value = 0;
  906. }