2
0

input_event.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. /*************************************************************************/
  2. /* input_event.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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_physical_scancode(uint32_t p_scancode) {
  174. physical_scancode = p_scancode;
  175. }
  176. uint32_t InputEventKey::get_physical_scancode() const {
  177. return physical_scancode;
  178. }
  179. void InputEventKey::set_unicode(uint32_t p_unicode) {
  180. unicode = p_unicode;
  181. }
  182. uint32_t InputEventKey::get_unicode() const {
  183. return unicode;
  184. }
  185. void InputEventKey::set_echo(bool p_enable) {
  186. echo = p_enable;
  187. }
  188. bool InputEventKey::is_echo() const {
  189. return echo;
  190. }
  191. uint32_t InputEventKey::get_scancode_with_modifiers() const {
  192. uint32_t sc = scancode;
  193. if (get_control()) {
  194. sc |= KEY_MASK_CTRL;
  195. }
  196. if (get_alt()) {
  197. sc |= KEY_MASK_ALT;
  198. }
  199. if (get_shift()) {
  200. sc |= KEY_MASK_SHIFT;
  201. }
  202. if (get_metakey()) {
  203. sc |= KEY_MASK_META;
  204. }
  205. return sc;
  206. }
  207. uint32_t InputEventKey::get_physical_scancode_with_modifiers() const {
  208. uint32_t sc = physical_scancode;
  209. if (get_control())
  210. sc |= KEY_MASK_CTRL;
  211. if (get_alt())
  212. sc |= KEY_MASK_ALT;
  213. if (get_shift())
  214. sc |= KEY_MASK_SHIFT;
  215. if (get_metakey())
  216. sc |= KEY_MASK_META;
  217. return sc;
  218. }
  219. String InputEventKey::as_text() const {
  220. String kc = keycode_get_string(scancode);
  221. if (kc == String()) {
  222. return kc;
  223. }
  224. if (get_metakey()) {
  225. kc = find_keycode_name(KEY_META) + ("+" + kc);
  226. }
  227. if (get_alt()) {
  228. kc = find_keycode_name(KEY_ALT) + ("+" + kc);
  229. }
  230. if (get_shift()) {
  231. kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
  232. }
  233. if (get_control()) {
  234. kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
  235. }
  236. return kc;
  237. }
  238. bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  239. Ref<InputEventKey> key = p_event;
  240. if (key.is_null()) {
  241. return false;
  242. }
  243. bool match = false;
  244. if (get_scancode() == 0) {
  245. uint32_t code = get_physical_scancode_with_modifiers();
  246. uint32_t event_code = key->get_physical_scancode_with_modifiers();
  247. match = get_physical_scancode() == key->get_physical_scancode() && (!key->is_pressed() || (code & event_code) == code);
  248. } else {
  249. uint32_t code = get_scancode_with_modifiers();
  250. uint32_t event_code = key->get_scancode_with_modifiers();
  251. match = get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
  252. }
  253. if (match) {
  254. if (p_pressed != nullptr) {
  255. *p_pressed = key->is_pressed();
  256. }
  257. if (p_strength != nullptr) {
  258. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  259. }
  260. }
  261. return match;
  262. }
  263. bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
  264. Ref<InputEventKey> key = p_event;
  265. if (key.is_null()) {
  266. return false;
  267. }
  268. uint32_t code = get_scancode_with_modifiers();
  269. uint32_t event_code = key->get_scancode_with_modifiers();
  270. return code == event_code;
  271. }
  272. void InputEventKey::_bind_methods() {
  273. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
  274. ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode);
  275. ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode);
  276. ClassDB::bind_method(D_METHOD("set_physical_scancode", "scancode"), &InputEventKey::set_physical_scancode);
  277. ClassDB::bind_method(D_METHOD("get_physical_scancode"), &InputEventKey::get_physical_scancode);
  278. ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
  279. ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
  280. ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
  281. ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers);
  282. ClassDB::bind_method(D_METHOD("get_physical_scancode_with_modifiers"), &InputEventKey::get_physical_scancode_with_modifiers);
  283. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  284. ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode");
  285. ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_scancode"), "set_physical_scancode", "get_physical_scancode");
  286. ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
  287. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo");
  288. }
  289. InputEventKey::InputEventKey() {
  290. pressed = false;
  291. scancode = 0;
  292. physical_scancode = 0;
  293. unicode = 0; ///unicode
  294. echo = false;
  295. }
  296. ////////////////////////////////////////
  297. void InputEventMouse::set_button_mask(int p_mask) {
  298. button_mask = p_mask;
  299. }
  300. int InputEventMouse::get_button_mask() const {
  301. return button_mask;
  302. }
  303. void InputEventMouse::set_position(const Vector2 &p_pos) {
  304. pos = p_pos;
  305. }
  306. Vector2 InputEventMouse::get_position() const {
  307. return pos;
  308. }
  309. void InputEventMouse::set_global_position(const Vector2 &p_global_pos) {
  310. global_pos = p_global_pos;
  311. }
  312. Vector2 InputEventMouse::get_global_position() const {
  313. return global_pos;
  314. }
  315. void InputEventMouse::_bind_methods() {
  316. ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
  317. ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
  318. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventMouse::set_position);
  319. ClassDB::bind_method(D_METHOD("get_position"), &InputEventMouse::get_position);
  320. ClassDB::bind_method(D_METHOD("set_global_position", "global_position"), &InputEventMouse::set_global_position);
  321. ClassDB::bind_method(D_METHOD("get_global_position"), &InputEventMouse::get_global_position);
  322. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
  323. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  324. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position");
  325. }
  326. InputEventMouse::InputEventMouse() {
  327. button_mask = 0;
  328. }
  329. ///////////////////////////////////////
  330. void InputEventMouseButton::set_factor(float p_factor) {
  331. factor = p_factor;
  332. }
  333. float InputEventMouseButton::get_factor() const {
  334. return factor;
  335. }
  336. void InputEventMouseButton::set_button_index(int p_index) {
  337. button_index = p_index;
  338. }
  339. int InputEventMouseButton::get_button_index() const {
  340. return button_index;
  341. }
  342. void InputEventMouseButton::set_pressed(bool p_pressed) {
  343. pressed = p_pressed;
  344. }
  345. bool InputEventMouseButton::is_pressed() const {
  346. return pressed;
  347. }
  348. void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
  349. doubleclick = p_doubleclick;
  350. }
  351. bool InputEventMouseButton::is_doubleclick() const {
  352. return doubleclick;
  353. }
  354. Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  355. Vector2 g = get_global_position();
  356. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  357. Ref<InputEventMouseButton> mb;
  358. mb.instance();
  359. mb->set_device(get_device());
  360. mb->set_modifiers_from_event(this);
  361. mb->set_position(l);
  362. mb->set_global_position(g);
  363. mb->set_button_mask(get_button_mask());
  364. mb->set_pressed(pressed);
  365. mb->set_doubleclick(doubleclick);
  366. mb->set_factor(factor);
  367. mb->set_button_index(button_index);
  368. return mb;
  369. }
  370. bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  371. Ref<InputEventMouseButton> mb = p_event;
  372. if (mb.is_null()) {
  373. return false;
  374. }
  375. bool match = mb->button_index == button_index;
  376. if (match) {
  377. if (p_pressed != nullptr) {
  378. *p_pressed = mb->is_pressed();
  379. }
  380. if (p_strength != nullptr) {
  381. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  382. }
  383. }
  384. return match;
  385. }
  386. String InputEventMouseButton::as_text() const {
  387. String button_index_string = "";
  388. switch (get_button_index()) {
  389. case BUTTON_LEFT:
  390. button_index_string = "BUTTON_LEFT";
  391. break;
  392. case BUTTON_RIGHT:
  393. button_index_string = "BUTTON_RIGHT";
  394. break;
  395. case BUTTON_MIDDLE:
  396. button_index_string = "BUTTON_MIDDLE";
  397. break;
  398. case BUTTON_WHEEL_UP:
  399. button_index_string = "BUTTON_WHEEL_UP";
  400. break;
  401. case BUTTON_WHEEL_DOWN:
  402. button_index_string = "BUTTON_WHEEL_DOWN";
  403. break;
  404. case BUTTON_WHEEL_LEFT:
  405. button_index_string = "BUTTON_WHEEL_LEFT";
  406. break;
  407. case BUTTON_WHEEL_RIGHT:
  408. button_index_string = "BUTTON_WHEEL_RIGHT";
  409. break;
  410. case BUTTON_XBUTTON1:
  411. button_index_string = "BUTTON_XBUTTON1";
  412. break;
  413. case BUTTON_XBUTTON2:
  414. button_index_string = "BUTTON_XBUTTON2";
  415. break;
  416. default:
  417. button_index_string = itos(get_button_index());
  418. break;
  419. }
  420. 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");
  421. }
  422. void InputEventMouseButton::_bind_methods() {
  423. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
  424. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
  425. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
  426. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
  427. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
  428. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed);
  429. ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
  430. ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
  431. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  432. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  433. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  434. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
  435. }
  436. InputEventMouseButton::InputEventMouseButton() {
  437. factor = 1;
  438. button_index = 0;
  439. pressed = false;
  440. doubleclick = false;
  441. }
  442. ////////////////////////////////////////////
  443. void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) {
  444. tilt = p_tilt;
  445. }
  446. Vector2 InputEventMouseMotion::get_tilt() const {
  447. return tilt;
  448. }
  449. void InputEventMouseMotion::set_pressure(float p_pressure) {
  450. pressure = p_pressure;
  451. }
  452. float InputEventMouseMotion::get_pressure() const {
  453. return pressure;
  454. }
  455. void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
  456. relative = p_relative;
  457. }
  458. Vector2 InputEventMouseMotion::get_relative() const {
  459. return relative;
  460. }
  461. void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
  462. speed = p_speed;
  463. }
  464. Vector2 InputEventMouseMotion::get_speed() const {
  465. return speed;
  466. }
  467. Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  468. Vector2 g = get_global_position();
  469. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  470. Vector2 r = p_xform.basis_xform(get_relative());
  471. Vector2 s = p_xform.basis_xform(get_speed());
  472. Ref<InputEventMouseMotion> mm;
  473. mm.instance();
  474. mm->set_device(get_device());
  475. mm->set_modifiers_from_event(this);
  476. mm->set_position(l);
  477. mm->set_pressure(get_pressure());
  478. mm->set_tilt(get_tilt());
  479. mm->set_global_position(g);
  480. mm->set_button_mask(get_button_mask());
  481. mm->set_relative(r);
  482. mm->set_speed(s);
  483. return mm;
  484. }
  485. String InputEventMouseMotion::as_text() const {
  486. String button_mask_string = "";
  487. switch (get_button_mask()) {
  488. case BUTTON_MASK_LEFT:
  489. button_mask_string = "BUTTON_MASK_LEFT";
  490. break;
  491. case BUTTON_MASK_MIDDLE:
  492. button_mask_string = "BUTTON_MASK_MIDDLE";
  493. break;
  494. case BUTTON_MASK_RIGHT:
  495. button_mask_string = "BUTTON_MASK_RIGHT";
  496. break;
  497. case BUTTON_MASK_XBUTTON1:
  498. button_mask_string = "BUTTON_MASK_XBUTTON1";
  499. break;
  500. case BUTTON_MASK_XBUTTON2:
  501. button_mask_string = "BUTTON_MASK_XBUTTON2";
  502. break;
  503. default:
  504. button_mask_string = itos(get_button_mask());
  505. break;
  506. }
  507. return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + "), pressure=(" + rtos(get_pressure()) + "), tilt=(" + String(get_tilt()) + ")";
  508. }
  509. bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
  510. Ref<InputEventMouseMotion> motion = p_event;
  511. if (motion.is_null()) {
  512. return false;
  513. }
  514. if (is_pressed() != motion->is_pressed()) {
  515. return false;
  516. }
  517. if (get_button_mask() != motion->get_button_mask()) {
  518. return false;
  519. }
  520. if (get_shift() != motion->get_shift()) {
  521. return false;
  522. }
  523. if (get_control() != motion->get_control()) {
  524. return false;
  525. }
  526. if (get_alt() != motion->get_alt()) {
  527. return false;
  528. }
  529. if (get_metakey() != motion->get_metakey()) {
  530. return false;
  531. }
  532. set_position(motion->get_position());
  533. set_global_position(motion->get_global_position());
  534. set_speed(motion->get_speed());
  535. relative += motion->get_relative();
  536. return true;
  537. }
  538. void InputEventMouseMotion::_bind_methods() {
  539. ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt);
  540. ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt);
  541. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMouseMotion::set_pressure);
  542. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMouseMotion::get_pressure);
  543. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
  544. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
  545. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
  546. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
  547. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt");
  548. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  549. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  550. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  551. }
  552. InputEventMouseMotion::InputEventMouseMotion() {
  553. pressure = 0;
  554. }
  555. ////////////////////////////////////////
  556. void InputEventJoypadMotion::set_axis(int p_axis) {
  557. axis = p_axis;
  558. }
  559. int InputEventJoypadMotion::get_axis() const {
  560. return axis;
  561. }
  562. void InputEventJoypadMotion::set_axis_value(float p_value) {
  563. axis_value = p_value;
  564. }
  565. float InputEventJoypadMotion::get_axis_value() const {
  566. return axis_value;
  567. }
  568. bool InputEventJoypadMotion::is_pressed() const {
  569. return Math::abs(axis_value) >= 0.5f;
  570. }
  571. bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  572. Ref<InputEventJoypadMotion> jm = p_event;
  573. if (jm.is_null()) {
  574. return false;
  575. }
  576. bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
  577. if (match) {
  578. bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
  579. bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
  580. if (p_pressed != nullptr) {
  581. *p_pressed = pressed;
  582. }
  583. if (p_strength != nullptr) {
  584. if (pressed) {
  585. if (p_deadzone == 1.0f) {
  586. *p_strength = 1.0f;
  587. } else {
  588. *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
  589. }
  590. } else {
  591. *p_strength = 0.0f;
  592. }
  593. }
  594. }
  595. return match;
  596. }
  597. String InputEventJoypadMotion::as_text() const {
  598. return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
  599. }
  600. void InputEventJoypadMotion::_bind_methods() {
  601. ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
  602. ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
  603. ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
  604. ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
  605. ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
  606. ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
  607. }
  608. InputEventJoypadMotion::InputEventJoypadMotion() {
  609. axis = 0;
  610. axis_value = 0;
  611. }
  612. /////////////////////////////////
  613. void InputEventJoypadButton::set_button_index(int p_index) {
  614. button_index = p_index;
  615. }
  616. int InputEventJoypadButton::get_button_index() const {
  617. return button_index;
  618. }
  619. void InputEventJoypadButton::set_pressed(bool p_pressed) {
  620. pressed = p_pressed;
  621. }
  622. bool InputEventJoypadButton::is_pressed() const {
  623. return pressed;
  624. }
  625. void InputEventJoypadButton::set_pressure(float p_pressure) {
  626. pressure = p_pressure;
  627. }
  628. float InputEventJoypadButton::get_pressure() const {
  629. return pressure;
  630. }
  631. bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  632. Ref<InputEventJoypadButton> jb = p_event;
  633. if (jb.is_null()) {
  634. return false;
  635. }
  636. bool match = button_index == jb->button_index;
  637. if (match) {
  638. if (p_pressed != nullptr) {
  639. *p_pressed = jb->is_pressed();
  640. }
  641. if (p_strength != nullptr) {
  642. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  643. }
  644. }
  645. return match;
  646. }
  647. bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
  648. Ref<InputEventJoypadButton> button = p_event;
  649. if (button.is_null()) {
  650. return false;
  651. }
  652. return button_index == button->button_index;
  653. }
  654. String InputEventJoypadButton::as_text() const {
  655. return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
  656. }
  657. void InputEventJoypadButton::_bind_methods() {
  658. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
  659. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
  660. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
  661. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
  662. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
  663. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
  664. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  665. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  666. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  667. }
  668. InputEventJoypadButton::InputEventJoypadButton() {
  669. button_index = 0;
  670. pressure = 0;
  671. pressed = false;
  672. }
  673. //////////////////////////////////////////////
  674. void InputEventScreenTouch::set_index(int p_index) {
  675. index = p_index;
  676. }
  677. int InputEventScreenTouch::get_index() const {
  678. return index;
  679. }
  680. void InputEventScreenTouch::set_position(const Vector2 &p_pos) {
  681. pos = p_pos;
  682. }
  683. Vector2 InputEventScreenTouch::get_position() const {
  684. return pos;
  685. }
  686. void InputEventScreenTouch::set_pressed(bool p_pressed) {
  687. pressed = p_pressed;
  688. }
  689. bool InputEventScreenTouch::is_pressed() const {
  690. return pressed;
  691. }
  692. Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  693. Ref<InputEventScreenTouch> st;
  694. st.instance();
  695. st->set_device(get_device());
  696. st->set_index(index);
  697. st->set_position(p_xform.xform(pos + p_local_ofs));
  698. st->set_pressed(pressed);
  699. return st;
  700. }
  701. String InputEventScreenTouch::as_text() const {
  702. return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
  703. }
  704. void InputEventScreenTouch::_bind_methods() {
  705. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
  706. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
  707. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenTouch::set_position);
  708. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
  709. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
  710. //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
  711. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  712. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  713. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  714. }
  715. InputEventScreenTouch::InputEventScreenTouch() {
  716. index = 0;
  717. pressed = false;
  718. }
  719. /////////////////////////////
  720. void InputEventScreenDrag::set_index(int p_index) {
  721. index = p_index;
  722. }
  723. int InputEventScreenDrag::get_index() const {
  724. return index;
  725. }
  726. void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
  727. pos = p_pos;
  728. }
  729. Vector2 InputEventScreenDrag::get_position() const {
  730. return pos;
  731. }
  732. void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
  733. relative = p_relative;
  734. }
  735. Vector2 InputEventScreenDrag::get_relative() const {
  736. return relative;
  737. }
  738. void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
  739. speed = p_speed;
  740. }
  741. Vector2 InputEventScreenDrag::get_speed() const {
  742. return speed;
  743. }
  744. Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  745. Ref<InputEventScreenDrag> sd;
  746. sd.instance();
  747. sd->set_device(get_device());
  748. sd->set_index(index);
  749. sd->set_position(p_xform.xform(pos + p_local_ofs));
  750. sd->set_relative(p_xform.basis_xform(relative));
  751. sd->set_speed(p_xform.basis_xform(speed));
  752. return sd;
  753. }
  754. String InputEventScreenDrag::as_text() const {
  755. return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  756. }
  757. void InputEventScreenDrag::_bind_methods() {
  758. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
  759. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
  760. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
  761. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
  762. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
  763. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
  764. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
  765. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
  766. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  767. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  768. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  769. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  770. }
  771. InputEventScreenDrag::InputEventScreenDrag() {
  772. index = 0;
  773. }
  774. /////////////////////////////
  775. void InputEventAction::set_action(const StringName &p_action) {
  776. action = p_action;
  777. }
  778. StringName InputEventAction::get_action() const {
  779. return action;
  780. }
  781. void InputEventAction::set_pressed(bool p_pressed) {
  782. pressed = p_pressed;
  783. }
  784. bool InputEventAction::is_pressed() const {
  785. return pressed;
  786. }
  787. void InputEventAction::set_strength(float p_strength) {
  788. strength = CLAMP(p_strength, 0.0f, 1.0f);
  789. }
  790. float InputEventAction::get_strength() const {
  791. return strength;
  792. }
  793. bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
  794. if (p_event.is_null()) {
  795. return false;
  796. }
  797. return p_event->is_action(action);
  798. }
  799. bool InputEventAction::is_action(const StringName &p_action) const {
  800. return action == p_action;
  801. }
  802. bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  803. Ref<InputEventAction> act = p_event;
  804. if (act.is_null()) {
  805. return false;
  806. }
  807. bool match = action == act->action;
  808. if (match) {
  809. if (p_pressed != nullptr) {
  810. *p_pressed = act->pressed;
  811. }
  812. if (p_strength != nullptr) {
  813. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  814. }
  815. }
  816. return match;
  817. }
  818. String InputEventAction::as_text() const {
  819. return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
  820. }
  821. void InputEventAction::_bind_methods() {
  822. ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
  823. ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
  824. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
  825. //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
  826. ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
  827. ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
  828. // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
  829. ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
  830. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  831. ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
  832. }
  833. InputEventAction::InputEventAction() {
  834. pressed = false;
  835. strength = 1.0f;
  836. }
  837. /////////////////////////////
  838. void InputEventGesture::set_position(const Vector2 &p_pos) {
  839. pos = p_pos;
  840. }
  841. void InputEventGesture::_bind_methods() {
  842. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
  843. ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
  844. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  845. }
  846. Vector2 InputEventGesture::get_position() const {
  847. return pos;
  848. }
  849. /////////////////////////////
  850. void InputEventMagnifyGesture::set_factor(real_t p_factor) {
  851. factor = p_factor;
  852. }
  853. real_t InputEventMagnifyGesture::get_factor() const {
  854. return factor;
  855. }
  856. Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  857. Ref<InputEventMagnifyGesture> ev;
  858. ev.instance();
  859. ev->set_device(get_device());
  860. ev->set_modifiers_from_event(this);
  861. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  862. ev->set_factor(get_factor());
  863. return ev;
  864. }
  865. String InputEventMagnifyGesture::as_text() const {
  866. return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
  867. }
  868. void InputEventMagnifyGesture::_bind_methods() {
  869. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
  870. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
  871. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  872. }
  873. InputEventMagnifyGesture::InputEventMagnifyGesture() {
  874. factor = 1.0;
  875. }
  876. /////////////////////////////
  877. void InputEventPanGesture::set_delta(const Vector2 &p_delta) {
  878. delta = p_delta;
  879. }
  880. Vector2 InputEventPanGesture::get_delta() const {
  881. return delta;
  882. }
  883. Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  884. Ref<InputEventPanGesture> ev;
  885. ev.instance();
  886. ev->set_device(get_device());
  887. ev->set_modifiers_from_event(this);
  888. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  889. ev->set_delta(get_delta());
  890. return ev;
  891. }
  892. String InputEventPanGesture::as_text() const {
  893. return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
  894. }
  895. void InputEventPanGesture::_bind_methods() {
  896. ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
  897. ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
  898. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
  899. }
  900. InputEventPanGesture::InputEventPanGesture() {
  901. delta = Vector2(0, 0);
  902. }
  903. /////////////////////////////
  904. void InputEventMIDI::set_channel(const int p_channel) {
  905. channel = p_channel;
  906. }
  907. int InputEventMIDI::get_channel() const {
  908. return channel;
  909. }
  910. void InputEventMIDI::set_message(const int p_message) {
  911. message = p_message;
  912. }
  913. int InputEventMIDI::get_message() const {
  914. return message;
  915. }
  916. void InputEventMIDI::set_pitch(const int p_pitch) {
  917. pitch = p_pitch;
  918. }
  919. int InputEventMIDI::get_pitch() const {
  920. return pitch;
  921. }
  922. void InputEventMIDI::set_velocity(const int p_velocity) {
  923. velocity = p_velocity;
  924. }
  925. int InputEventMIDI::get_velocity() const {
  926. return velocity;
  927. }
  928. void InputEventMIDI::set_instrument(const int p_instrument) {
  929. instrument = p_instrument;
  930. }
  931. int InputEventMIDI::get_instrument() const {
  932. return instrument;
  933. }
  934. void InputEventMIDI::set_pressure(const int p_pressure) {
  935. pressure = p_pressure;
  936. }
  937. int InputEventMIDI::get_pressure() const {
  938. return pressure;
  939. }
  940. void InputEventMIDI::set_controller_number(const int p_controller_number) {
  941. controller_number = p_controller_number;
  942. }
  943. int InputEventMIDI::get_controller_number() const {
  944. return controller_number;
  945. }
  946. void InputEventMIDI::set_controller_value(const int p_controller_value) {
  947. controller_value = p_controller_value;
  948. }
  949. int InputEventMIDI::get_controller_value() const {
  950. return controller_value;
  951. }
  952. String InputEventMIDI::as_text() const {
  953. return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
  954. }
  955. void InputEventMIDI::_bind_methods() {
  956. ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel);
  957. ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel);
  958. ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message);
  959. ClassDB::bind_method(D_METHOD("get_message"), &InputEventMIDI::get_message);
  960. ClassDB::bind_method(D_METHOD("set_pitch", "pitch"), &InputEventMIDI::set_pitch);
  961. ClassDB::bind_method(D_METHOD("get_pitch"), &InputEventMIDI::get_pitch);
  962. ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventMIDI::set_velocity);
  963. ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventMIDI::get_velocity);
  964. ClassDB::bind_method(D_METHOD("set_instrument", "instrument"), &InputEventMIDI::set_instrument);
  965. ClassDB::bind_method(D_METHOD("get_instrument"), &InputEventMIDI::get_instrument);
  966. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMIDI::set_pressure);
  967. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMIDI::get_pressure);
  968. ClassDB::bind_method(D_METHOD("set_controller_number", "controller_number"), &InputEventMIDI::set_controller_number);
  969. ClassDB::bind_method(D_METHOD("get_controller_number"), &InputEventMIDI::get_controller_number);
  970. ClassDB::bind_method(D_METHOD("set_controller_value", "controller_value"), &InputEventMIDI::set_controller_value);
  971. ClassDB::bind_method(D_METHOD("get_controller_value"), &InputEventMIDI::get_controller_value);
  972. ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel");
  973. ADD_PROPERTY(PropertyInfo(Variant::INT, "message"), "set_message", "get_message");
  974. ADD_PROPERTY(PropertyInfo(Variant::INT, "pitch"), "set_pitch", "get_pitch");
  975. ADD_PROPERTY(PropertyInfo(Variant::INT, "velocity"), "set_velocity", "get_velocity");
  976. ADD_PROPERTY(PropertyInfo(Variant::INT, "instrument"), "set_instrument", "get_instrument");
  977. ADD_PROPERTY(PropertyInfo(Variant::INT, "pressure"), "set_pressure", "get_pressure");
  978. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_number"), "set_controller_number", "get_controller_number");
  979. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_value"), "set_controller_value", "get_controller_value");
  980. }
  981. InputEventMIDI::InputEventMIDI() {
  982. channel = 0;
  983. message = 0;
  984. pitch = 0;
  985. velocity = 0;
  986. instrument = 0;
  987. pressure = 0;
  988. controller_number = 0;
  989. controller_value = 0;
  990. }