1 /* ______ ___ ___ 2 * /\ _ \ /\_ \ /\_ \ 3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ 4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ 5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ 6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ 7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ 8 * /\____/ 9 * \_/__/ 10 * 11 * Touch input API. 12 * 13 * By Michał Cichoń. 14 * 15 * See readme.txt for copyright information. 16 */ 17 18 19 #define ALLEGRO_NO_COMPATIBILITY 20 21 #include "allegro5/allegro.h" 22 #include "allegro5/internal/aintern.h" 23 #include "allegro5/internal/aintern_bitmap.h" 24 #include "allegro5/internal/aintern_exitfunc.h" 25 #include "allegro5/internal/aintern_system.h" 26 #include "allegro5/internal/aintern_touch_input.h" 27 28 29 /* the active driver */ 30 static ALLEGRO_TOUCH_INPUT_DRIVER *touch_input_driver = NULL; 31 32 33 /* Function: al_is_touch_input_installed 34 */ al_is_touch_input_installed(void)35bool al_is_touch_input_installed(void) 36 { 37 return (touch_input_driver ? true : false); 38 } 39 40 41 /* Function: al_install_touch_input 42 */ al_install_touch_input(void)43bool al_install_touch_input(void) 44 { 45 if (touch_input_driver) 46 return true; 47 48 if (al_get_system_driver()->vt->get_touch_input_driver) { 49 50 touch_input_driver = al_get_system_driver()->vt->get_touch_input_driver(); 51 if (touch_input_driver) { 52 if (!touch_input_driver->init_touch_input()) { 53 touch_input_driver = NULL; 54 return false; 55 } 56 57 _al_add_exit_func(al_uninstall_touch_input, "al_uninstall_touch_input"); 58 return true; 59 } 60 } 61 62 return false; 63 } 64 65 66 /* Function: al_uninstall_touch_input 67 */ al_uninstall_touch_input(void)68void al_uninstall_touch_input(void) 69 { 70 if (!touch_input_driver) 71 return; 72 73 touch_input_driver->exit_touch_input(); 74 touch_input_driver = NULL; 75 } 76 77 get_touch_input(void)78static ALLEGRO_TOUCH_INPUT *get_touch_input(void) 79 { 80 ALLEGRO_TOUCH_INPUT *touch_input; 81 82 ASSERT(touch_input_driver); 83 84 touch_input = touch_input_driver->get_touch_input(); 85 ASSERT(touch_input); 86 87 return touch_input; 88 } 89 90 91 /* Function: al_get_touch_input_state 92 */ al_get_touch_input_state(ALLEGRO_TOUCH_INPUT_STATE * ret_state)93void al_get_touch_input_state(ALLEGRO_TOUCH_INPUT_STATE *ret_state) 94 { 95 ASSERT(touch_input_driver); 96 ASSERT(ret_state); 97 98 touch_input_driver->get_touch_input_state(ret_state); 99 } 100 101 102 /* Function: al_set_mouse_emulation_mode 103 */ al_set_mouse_emulation_mode(int mode)104void al_set_mouse_emulation_mode(int mode) 105 { 106 ASSERT(touch_input_driver); 107 108 if (touch_input_driver->set_mouse_emulation_mode) 109 touch_input_driver->set_mouse_emulation_mode(mode); 110 else 111 get_touch_input()->mouse_emulation_mode = mode; 112 } 113 114 115 /* Function: al_get_mouse_emulation_mode 116 */ al_get_mouse_emulation_mode(void)117int al_get_mouse_emulation_mode(void) 118 { 119 ASSERT(touch_input_driver); 120 121 if (touch_input_driver->get_mouse_emulation_mode) 122 return touch_input_driver->get_mouse_emulation_mode(); 123 else 124 return get_touch_input()->mouse_emulation_mode; 125 } 126 127 128 /* Function: al_get_touch_input_event_source 129 */ al_get_touch_input_event_source(void)130ALLEGRO_EVENT_SOURCE *al_get_touch_input_event_source(void) 131 { 132 ALLEGRO_TOUCH_INPUT *touch_input = get_touch_input(); 133 134 return (touch_input) ? &touch_input->es : NULL; 135 } 136 137 138 /* Function: al_get_touch_input_mouse_emulation_event_source 139 */ al_get_touch_input_mouse_emulation_event_source(void)140ALLEGRO_EVENT_SOURCE *al_get_touch_input_mouse_emulation_event_source(void) 141 { 142 ALLEGRO_TOUCH_INPUT *touch_input = get_touch_input(); 143 144 return (touch_input) ? &touch_input->mouse_emulation_es : NULL; 145 } 146