input_event.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. /*************************************************************************/
  2. /* input_event.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "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, bool p_allow_echo) 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 && (p_allow_echo || !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", "allow_echo"), &InputEvent::is_action_pressed, DEFVAL(false));
  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 != NULL && *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::BOOL, "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() const {
  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 = 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 != NULL && *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_tilt(const Vector2 &p_tilt) {
  402. tilt = p_tilt;
  403. }
  404. Vector2 InputEventMouseMotion::get_tilt() const {
  405. return tilt;
  406. }
  407. void InputEventMouseMotion::set_pressure(float p_pressure) {
  408. pressure = p_pressure;
  409. }
  410. float InputEventMouseMotion::get_pressure() const {
  411. return pressure;
  412. }
  413. void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
  414. relative = p_relative;
  415. }
  416. Vector2 InputEventMouseMotion::get_relative() const {
  417. return relative;
  418. }
  419. void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
  420. speed = p_speed;
  421. }
  422. Vector2 InputEventMouseMotion::get_speed() const {
  423. return speed;
  424. }
  425. Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  426. Vector2 g = get_global_position();
  427. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  428. Vector2 r = p_xform.basis_xform(get_relative());
  429. Vector2 s = p_xform.basis_xform(get_speed());
  430. Ref<InputEventMouseMotion> mm;
  431. mm.instance();
  432. mm->set_device(get_device());
  433. mm->set_modifiers_from_event(this);
  434. mm->set_position(l);
  435. mm->set_pressure(get_pressure());
  436. mm->set_tilt(get_tilt());
  437. mm->set_global_position(g);
  438. mm->set_button_mask(get_button_mask());
  439. mm->set_relative(r);
  440. mm->set_speed(s);
  441. return mm;
  442. }
  443. String InputEventMouseMotion::as_text() const {
  444. String button_mask_string = "";
  445. switch (get_button_mask()) {
  446. case BUTTON_MASK_LEFT:
  447. button_mask_string = "BUTTON_MASK_LEFT";
  448. break;
  449. case BUTTON_MASK_MIDDLE:
  450. button_mask_string = "BUTTON_MASK_MIDDLE";
  451. break;
  452. case BUTTON_MASK_RIGHT:
  453. button_mask_string = "BUTTON_MASK_RIGHT";
  454. break;
  455. case BUTTON_MASK_XBUTTON1:
  456. button_mask_string = "BUTTON_MASK_XBUTTON1";
  457. break;
  458. case BUTTON_MASK_XBUTTON2:
  459. button_mask_string = "BUTTON_MASK_XBUTTON2";
  460. break;
  461. default:
  462. button_mask_string = itos(get_button_mask());
  463. break;
  464. }
  465. return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  466. }
  467. bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
  468. Ref<InputEventMouseMotion> motion = p_event;
  469. if (motion.is_null())
  470. return false;
  471. if (is_pressed() != motion->is_pressed()) {
  472. return false;
  473. }
  474. if (get_button_mask() != motion->get_button_mask()) {
  475. return false;
  476. }
  477. if (get_shift() != motion->get_shift()) {
  478. return false;
  479. }
  480. if (get_control() != motion->get_control()) {
  481. return false;
  482. }
  483. if (get_alt() != motion->get_alt()) {
  484. return false;
  485. }
  486. if (get_metakey() != motion->get_metakey()) {
  487. return false;
  488. }
  489. set_position(motion->get_position());
  490. set_global_position(motion->get_global_position());
  491. set_speed(motion->get_speed());
  492. relative += motion->get_relative();
  493. return true;
  494. }
  495. void InputEventMouseMotion::_bind_methods() {
  496. ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt);
  497. ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt);
  498. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMouseMotion::set_pressure);
  499. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMouseMotion::get_pressure);
  500. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
  501. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
  502. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
  503. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
  504. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt");
  505. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  506. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  507. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  508. }
  509. InputEventMouseMotion::InputEventMouseMotion() {
  510. pressure = 0;
  511. }
  512. ////////////////////////////////////////
  513. void InputEventJoypadMotion::set_axis(int p_axis) {
  514. axis = p_axis;
  515. }
  516. int InputEventJoypadMotion::get_axis() const {
  517. return axis;
  518. }
  519. void InputEventJoypadMotion::set_axis_value(float p_value) {
  520. axis_value = p_value;
  521. }
  522. float InputEventJoypadMotion::get_axis_value() const {
  523. return axis_value;
  524. }
  525. bool InputEventJoypadMotion::is_pressed() const {
  526. return Math::abs(axis_value) >= 0.5f;
  527. }
  528. bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  529. Ref<InputEventJoypadMotion> jm = p_event;
  530. if (jm.is_null())
  531. return false;
  532. bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
  533. if (match) {
  534. bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
  535. bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
  536. if (p_pressed != NULL)
  537. *p_pressed = pressed;
  538. if (p_strength != NULL) {
  539. if (pressed) {
  540. if (p_deadzone == 1.0f) {
  541. *p_strength = 1.0f;
  542. } else {
  543. *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
  544. }
  545. } else {
  546. *p_strength = 0.0f;
  547. }
  548. }
  549. }
  550. return match;
  551. }
  552. String InputEventJoypadMotion::as_text() const {
  553. return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
  554. }
  555. void InputEventJoypadMotion::_bind_methods() {
  556. ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
  557. ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
  558. ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
  559. ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
  560. ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
  561. ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
  562. }
  563. InputEventJoypadMotion::InputEventJoypadMotion() {
  564. axis = 0;
  565. axis_value = 0;
  566. }
  567. /////////////////////////////////
  568. void InputEventJoypadButton::set_button_index(int p_index) {
  569. button_index = p_index;
  570. }
  571. int InputEventJoypadButton::get_button_index() const {
  572. return button_index;
  573. }
  574. void InputEventJoypadButton::set_pressed(bool p_pressed) {
  575. pressed = p_pressed;
  576. }
  577. bool InputEventJoypadButton::is_pressed() const {
  578. return pressed;
  579. }
  580. void InputEventJoypadButton::set_pressure(float p_pressure) {
  581. pressure = p_pressure;
  582. }
  583. float InputEventJoypadButton::get_pressure() const {
  584. return pressure;
  585. }
  586. bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  587. Ref<InputEventJoypadButton> jb = p_event;
  588. if (jb.is_null())
  589. return false;
  590. bool match = button_index == jb->button_index;
  591. if (match) {
  592. if (p_pressed != NULL)
  593. *p_pressed = jb->is_pressed();
  594. if (p_strength != NULL)
  595. *p_strength = (p_pressed != NULL && *p_pressed) ? 1.0f : 0.0f;
  596. }
  597. return match;
  598. }
  599. bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
  600. Ref<InputEventJoypadButton> button = p_event;
  601. if (button.is_null())
  602. return false;
  603. return button_index == button->button_index;
  604. }
  605. String InputEventJoypadButton::as_text() const {
  606. return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
  607. }
  608. void InputEventJoypadButton::_bind_methods() {
  609. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
  610. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
  611. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
  612. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
  613. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
  614. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
  615. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  616. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  617. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  618. }
  619. InputEventJoypadButton::InputEventJoypadButton() {
  620. button_index = 0;
  621. pressure = 0;
  622. pressed = false;
  623. }
  624. //////////////////////////////////////////////
  625. void InputEventScreenTouch::set_index(int p_index) {
  626. index = p_index;
  627. }
  628. int InputEventScreenTouch::get_index() const {
  629. return index;
  630. }
  631. void InputEventScreenTouch::set_position(const Vector2 &p_pos) {
  632. pos = p_pos;
  633. }
  634. Vector2 InputEventScreenTouch::get_position() const {
  635. return pos;
  636. }
  637. void InputEventScreenTouch::set_pressed(bool p_pressed) {
  638. pressed = p_pressed;
  639. }
  640. bool InputEventScreenTouch::is_pressed() const {
  641. return pressed;
  642. }
  643. Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  644. Ref<InputEventScreenTouch> st;
  645. st.instance();
  646. st->set_device(get_device());
  647. st->set_index(index);
  648. st->set_position(p_xform.xform(pos + p_local_ofs));
  649. st->set_pressed(pressed);
  650. return st;
  651. }
  652. String InputEventScreenTouch::as_text() const {
  653. return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
  654. }
  655. void InputEventScreenTouch::_bind_methods() {
  656. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
  657. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
  658. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenTouch::set_position);
  659. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
  660. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
  661. //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
  662. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  663. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  664. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  665. }
  666. InputEventScreenTouch::InputEventScreenTouch() {
  667. index = 0;
  668. pressed = false;
  669. }
  670. /////////////////////////////
  671. void InputEventScreenDrag::set_index(int p_index) {
  672. index = p_index;
  673. }
  674. int InputEventScreenDrag::get_index() const {
  675. return index;
  676. }
  677. void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
  678. pos = p_pos;
  679. }
  680. Vector2 InputEventScreenDrag::get_position() const {
  681. return pos;
  682. }
  683. void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
  684. relative = p_relative;
  685. }
  686. Vector2 InputEventScreenDrag::get_relative() const {
  687. return relative;
  688. }
  689. void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
  690. speed = p_speed;
  691. }
  692. Vector2 InputEventScreenDrag::get_speed() const {
  693. return speed;
  694. }
  695. Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  696. Ref<InputEventScreenDrag> sd;
  697. sd.instance();
  698. sd->set_device(get_device());
  699. sd->set_index(index);
  700. sd->set_position(p_xform.xform(pos + p_local_ofs));
  701. sd->set_relative(p_xform.basis_xform(relative));
  702. sd->set_speed(p_xform.basis_xform(speed));
  703. return sd;
  704. }
  705. String InputEventScreenDrag::as_text() const {
  706. return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  707. }
  708. void InputEventScreenDrag::_bind_methods() {
  709. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
  710. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
  711. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
  712. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
  713. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
  714. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
  715. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
  716. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
  717. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  718. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  719. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  720. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  721. }
  722. InputEventScreenDrag::InputEventScreenDrag() {
  723. index = 0;
  724. }
  725. /////////////////////////////
  726. void InputEventAction::set_action(const StringName &p_action) {
  727. action = p_action;
  728. }
  729. StringName InputEventAction::get_action() const {
  730. return action;
  731. }
  732. void InputEventAction::set_pressed(bool p_pressed) {
  733. pressed = p_pressed;
  734. }
  735. bool InputEventAction::is_pressed() const {
  736. return pressed;
  737. }
  738. void InputEventAction::set_strength(float p_strength) {
  739. strength = CLAMP(p_strength, 0.0f, 1.0f);
  740. }
  741. float InputEventAction::get_strength() const {
  742. return strength;
  743. }
  744. bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
  745. if (p_event.is_null())
  746. return false;
  747. return p_event->is_action(action);
  748. }
  749. bool InputEventAction::is_action(const StringName &p_action) const {
  750. return action == p_action;
  751. }
  752. bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  753. Ref<InputEventAction> act = p_event;
  754. if (act.is_null())
  755. return false;
  756. bool match = action == act->action;
  757. if (match) {
  758. if (p_pressed != NULL)
  759. *p_pressed = act->pressed;
  760. if (p_strength != NULL)
  761. *p_strength = (p_pressed != NULL && *p_pressed) ? 1.0f : 0.0f;
  762. }
  763. return match;
  764. }
  765. String InputEventAction::as_text() const {
  766. return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
  767. }
  768. void InputEventAction::_bind_methods() {
  769. ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
  770. ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
  771. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
  772. //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
  773. ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
  774. ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
  775. // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
  776. ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
  777. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  778. ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
  779. }
  780. InputEventAction::InputEventAction() {
  781. pressed = false;
  782. strength = 1.0f;
  783. }
  784. /////////////////////////////
  785. void InputEventGesture::set_position(const Vector2 &p_pos) {
  786. pos = p_pos;
  787. }
  788. void InputEventGesture::_bind_methods() {
  789. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
  790. ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
  791. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  792. }
  793. Vector2 InputEventGesture::get_position() const {
  794. return pos;
  795. }
  796. /////////////////////////////
  797. void InputEventMagnifyGesture::set_factor(real_t p_factor) {
  798. factor = p_factor;
  799. }
  800. real_t InputEventMagnifyGesture::get_factor() const {
  801. return factor;
  802. }
  803. Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  804. Ref<InputEventMagnifyGesture> ev;
  805. ev.instance();
  806. ev->set_device(get_device());
  807. ev->set_modifiers_from_event(this);
  808. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  809. ev->set_factor(get_factor());
  810. return ev;
  811. }
  812. String InputEventMagnifyGesture::as_text() const {
  813. return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
  814. }
  815. void InputEventMagnifyGesture::_bind_methods() {
  816. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
  817. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
  818. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  819. }
  820. InputEventMagnifyGesture::InputEventMagnifyGesture() {
  821. factor = 1.0;
  822. }
  823. /////////////////////////////
  824. void InputEventPanGesture::set_delta(const Vector2 &p_delta) {
  825. delta = p_delta;
  826. }
  827. Vector2 InputEventPanGesture::get_delta() const {
  828. return delta;
  829. }
  830. Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  831. Ref<InputEventPanGesture> ev;
  832. ev.instance();
  833. ev->set_device(get_device());
  834. ev->set_modifiers_from_event(this);
  835. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  836. ev->set_delta(get_delta());
  837. return ev;
  838. }
  839. String InputEventPanGesture::as_text() const {
  840. return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
  841. }
  842. void InputEventPanGesture::_bind_methods() {
  843. ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
  844. ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
  845. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
  846. }
  847. InputEventPanGesture::InputEventPanGesture() {
  848. delta = Vector2(0, 0);
  849. }
  850. /////////////////////////////
  851. void InputEventMIDI::set_channel(const int p_channel) {
  852. channel = p_channel;
  853. }
  854. int InputEventMIDI::get_channel() const {
  855. return channel;
  856. }
  857. void InputEventMIDI::set_message(const int p_message) {
  858. message = p_message;
  859. }
  860. int InputEventMIDI::get_message() const {
  861. return message;
  862. }
  863. void InputEventMIDI::set_pitch(const int p_pitch) {
  864. pitch = p_pitch;
  865. }
  866. int InputEventMIDI::get_pitch() const {
  867. return pitch;
  868. }
  869. void InputEventMIDI::set_velocity(const int p_velocity) {
  870. velocity = p_velocity;
  871. }
  872. int InputEventMIDI::get_velocity() const {
  873. return velocity;
  874. }
  875. void InputEventMIDI::set_instrument(const int p_instrument) {
  876. instrument = p_instrument;
  877. }
  878. int InputEventMIDI::get_instrument() const {
  879. return instrument;
  880. }
  881. void InputEventMIDI::set_pressure(const int p_pressure) {
  882. pressure = p_pressure;
  883. }
  884. int InputEventMIDI::get_pressure() const {
  885. return pressure;
  886. }
  887. void InputEventMIDI::set_controller_number(const int p_controller_number) {
  888. controller_number = p_controller_number;
  889. }
  890. int InputEventMIDI::get_controller_number() const {
  891. return controller_number;
  892. }
  893. void InputEventMIDI::set_controller_value(const int p_controller_value) {
  894. controller_value = p_controller_value;
  895. }
  896. int InputEventMIDI::get_controller_value() const {
  897. return controller_value;
  898. }
  899. String InputEventMIDI::as_text() const {
  900. return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
  901. }
  902. void InputEventMIDI::_bind_methods() {
  903. ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel);
  904. ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel);
  905. ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message);
  906. ClassDB::bind_method(D_METHOD("get_message"), &InputEventMIDI::get_message);
  907. ClassDB::bind_method(D_METHOD("set_pitch", "pitch"), &InputEventMIDI::set_pitch);
  908. ClassDB::bind_method(D_METHOD("get_pitch"), &InputEventMIDI::get_pitch);
  909. ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventMIDI::set_velocity);
  910. ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventMIDI::get_velocity);
  911. ClassDB::bind_method(D_METHOD("set_instrument", "instrument"), &InputEventMIDI::set_instrument);
  912. ClassDB::bind_method(D_METHOD("get_instrument"), &InputEventMIDI::get_instrument);
  913. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMIDI::set_pressure);
  914. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMIDI::get_pressure);
  915. ClassDB::bind_method(D_METHOD("set_controller_number", "controller_number"), &InputEventMIDI::set_controller_number);
  916. ClassDB::bind_method(D_METHOD("get_controller_number"), &InputEventMIDI::get_controller_number);
  917. ClassDB::bind_method(D_METHOD("set_controller_value", "controller_value"), &InputEventMIDI::set_controller_value);
  918. ClassDB::bind_method(D_METHOD("get_controller_value"), &InputEventMIDI::get_controller_value);
  919. ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel");
  920. ADD_PROPERTY(PropertyInfo(Variant::INT, "message"), "set_message", "get_message");
  921. ADD_PROPERTY(PropertyInfo(Variant::INT, "pitch"), "set_pitch", "get_pitch");
  922. ADD_PROPERTY(PropertyInfo(Variant::INT, "velocity"), "set_velocity", "get_velocity");
  923. ADD_PROPERTY(PropertyInfo(Variant::INT, "instrument"), "set_instrument", "get_instrument");
  924. ADD_PROPERTY(PropertyInfo(Variant::INT, "pressure"), "set_pressure", "get_pressure");
  925. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_number"), "set_controller_number", "get_controller_number");
  926. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_value"), "set_controller_value", "get_controller_value");
  927. }
  928. InputEventMIDI::InputEventMIDI() {
  929. channel = 0;
  930. message = 0;
  931. pitch = 0;
  932. velocity = 0;
  933. instrument = 0;
  934. pressure = 0;
  935. controller_number = 0;
  936. controller_value = 0;
  937. }