Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5 iPad] input tracking

This thread is locked; no one can reply to it. rss feed Print
 1   2 
[A5 iPad] input tracking
Matthew Leverton
Supreme Loser
January 1999
avatar

For the iPhone, it doesn't matter as much. The programmer will do something to make sure touch works.

Having emulation on by default helps in Windows / Mac / Linux systems that have some sort of touch-only input that isn't registered as a mouse. I'm not even sure if that is a reality though.

Michał Cichoń
Member #11,736
March 2010

OK. This is an API proposal. Please comment and criticize it. It is very likely I forgot about something.

Mouse emulation is provided as alternative event source.

Edit: Granularity was removed as a result of conversation about API on #allegro.

touch_input.h#SelectExpand
1#ifndef __al_included_allegro5_touch_input_h 2#define __al_included_allegro5_touch_input_h 3 4#include "allegro5/base.h" 5 6#ifdef __cplusplus 7 extern "C" { 8#endif 9 10 11/* Maximum number of simultaneous touches. */ 12#define ALLEGRO_TOUCH_INPUT_MAX_TOUCH_COUNT 16 13 14 15typedef struct ALLEGRO_TOUCH_INPUT ALLEGRO_TOUCH_INPUT; 16 17 18/* Type: ALLEGRO_TOUCH_INPUT_STATE 19 */ 20typedef struct ALLEGRO_TOUCH_STATE ALLEGRO_TOUCH_STATE; 21typedef struct ALLEGRO_TOUCH ALLEGRO_TOUCH; 22 23struct ALLEGRO_TOUCH 24{ 25 /* (id) An identifier of touch. If touch is valid this number is positive. 26 * (x, y) Touch position on the screen in 1:1 resolution. 27 * (primary) True, if touch is a primary one (usually first one). 28 */ 29 int id; 30 float x, y; 31 bool primary; 32}; 33 34struct ALLEGRO_TOUCH_INPUT_STATE 35{ 36 ALLEGRO_TOUCH touches[ALLEGRO_TOUCH_INPUT_MAX_TOUCH_COUNT]; 37 struct ALLEGRO_DISPLAY *display; 38}; 39 40 41AL_FUNC(bool, al_is_touch_input_installed, (void)); 42AL_FUNC(bool, al_install_touch_input, (void)); 43AL_FUNC(void, al_uninstall_touch_input, (void)); 44AL_FUNC(void, al_get_touch_input_state, (ALLEGRO_TOUCH_INPUT_STATE *ret_state)); 45 46AL_FUNC(ALLEGRO_EVENT_SOURCE *, al_get_touch_input_event_source, (void)); 47AL_FUNC(ALLEGRO_EVENT_SOURCE *, al_get_touch_input_mouse_emulation_event_source, (void)); 48 49 50#ifdef __cplusplus 51 } 52#endif 53 54#endif

event.h#SelectExpand
1/* Type: ALLEGRO_TOUCH_EVENT 2 */ 3typedef struct ALLEGRO_TOUCH_EVENT 4{ 5 _AL_EVENT_HEADER(struct ALLEGRO_TOUCH_INPUT) 6 struct ALLEGRO_DISPLAY *display; 7 /* (id) Identifier of the event, always positive number. 8 * (x, y) Touch position on the screen in 1:1 resolution. 9 * (primary) True, if touch is a primary one (usually first one). 10 */ 11 int id; 12 float x, y; 13 bool primary; 14} ALLEGRO_TOUCH_EVENT;

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Peter Wang
Member #23
April 2000

Any reason not to use float sub-pixel positions, so the user doesn't need to look up the granularity?

What does 'primary' mean?

Michał Cichoń
Member #11,736
March 2010

Absolutely no reason right now. Elias convinced me to use float instead of granularity. I have to agree to that, this is much simpler now.

Primary determine, well primary touch. Usually mean 'the first one'. Purpose of this is to make easy for GUI libraries. If control do not need multi-touch feature all but primary touches have to be ignored. There is also guarantee that there is only one primary touch at once.

This could be realized using ID, but the are not relayable. Just because they can take any positive value.

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Trent Gamblin
Member #261
April 2000
avatar

Looks pretty simple an that I like. I haven't given it a great deal of thought though.

ImLeftFooted
Member #3,935
October 2003
avatar

Here's what iOS gives you.

UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer

You can subclass UIGestureRecognizer as well, you are encouraged to override these methods:

– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
– reset
– ignoreTouch:forEvent:
– canBePreventedByGestureRecognizer:
– canPreventGestureRecognizer:

This is all true for iOS 3.2 and above (the release that came at the same time as the iPad).

Michał Cichoń
Member #11,736
March 2010

Touch Input was implemented on 5.1 branch. You all are free to test it. :)

At the moment two drivers are implemented, one for iDevices, second for Windows 7.

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Matthew Leverton
Supreme Loser
January 1999
avatar

I must call this function al_get_touch_input_mouse_emulation_event_source().

Michał Cichoń
Member #11,736
March 2010

Actually to make it work, you will need also to call al_install_touch_input().
Rest of application to not change. Please keep in mind, you still need to call al_install_mouse() to get emulation work.

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Neil Walker
Member #210
April 2000
avatar

al_get_touch_input_mouse_emulation_event_source()

Well, the clueless java fan-boys make all their methods cover at least three-quarters of screen space, so if it's good enough for them ;)

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Michał Cichoń
Member #11,736
March 2010

That's good. Because rest of the screen is usually unused. :)

In real, this name looks that way because there are some rules to follow in Allegro.

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Neil Walker
Member #210
April 2000
avatar

there are some rules to follow in Allegro

Being consistent is boring, I like the olden days when palette was spelt wrong and draw sprite and blit had the parameters the wrong way round from each other.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Michał Cichoń
Member #11,736
March 2010

Everything was wrong then. You got DOS instead of OS and so on.

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Aaron Santiago
Member #12,074
June 2010
avatar

Being consistent is boring, I like the olden days when palette was spelt wrong and draw sprite and blit had the parameters the wrong way round from each other.

Oh, hell yeah. ;D

 1   2 


Go to: