input_event.cpp 40 KB

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