PageRenderTime 97ms CodeModel.GetById 86ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ftk_gesture_listener.h

http://ftk.googlecode.com/
C++ Header | 140 lines | 85 code | 26 blank | 29 comment | 19 complexity | 41089e12529c9b2a9e7e59ee74af7ee2 MD5 | raw file
  1/*
  2 * File: ftk_gesture_listener.h
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   gesture listener
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2009-11-19 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#ifndef FTK_GESTURE_LISTENER_H
 33#define FTK_GESTURE_LISTENER_H
 34
 35#include "ftk_event.h"
 36#include "ftk_log.h"
 37
 38struct _FtkGestureListener;
 39typedef struct _FtkGestureListener FtkGestureListener;
 40
 41typedef Ret (*FtkGestureListenerOnClicked)(FtkGestureListener* thiz, FtkEvent* event);
 42typedef Ret (*FtkGestureListenerOnDblClicked)(FtkGestureListener* thiz, FtkEvent* event);
 43typedef Ret (*FtkGestureListenerOnLongPressed)(FtkGestureListener* thiz, FtkEvent* event);
 44typedef Ret (*FtkGestureListenerOnFling)(FtkGestureListener* thiz, 
 45		FtkEvent* e1, FtkEvent* e2, int velocity_x, int velocity_y);
 46typedef Ret (*FtkGestureListenerOnScroll)(FtkGestureListener* thiz, 
 47		FtkEvent* e1, FtkEvent* e2, int distance_x, int distance_y);
 48typedef void (*FtkGestureListenerDestroy)(FtkGestureListener* thiz);
 49
 50struct _FtkGestureListener
 51{
 52	FtkGestureListenerOnFling       on_fling;
 53	FtkGestureListenerOnScroll      on_scroll;
 54	FtkGestureListenerOnClicked     on_clicked;
 55	FtkGestureListenerOnDblClicked  on_dbl_clicked;
 56	FtkGestureListenerOnLongPressed on_long_pressed;
 57	FtkGestureListenerDestroy       destroy;
 58
 59	char priv[ZERO_LEN_ARRAY];
 60};
 61
 62static inline Ret ftk_gesture_listener_on_clicked(FtkGestureListener* thiz, FtkEvent* event)
 63{
 64	Ret ret = RET_FAIL;
 65	return_val_if_fail(thiz != NULL, ret);
 66	
 67	if(thiz->on_clicked != NULL)
 68	{
 69		ret = thiz->on_clicked(thiz, event);
 70	}
 71
 72	return ret;
 73}
 74
 75static inline Ret ftk_gesture_listener_on_dbl_clicked(FtkGestureListener* thiz, FtkEvent* event)
 76{
 77	Ret ret = RET_FAIL;
 78	return_val_if_fail(thiz != NULL, ret);
 79	
 80	if(thiz->on_dbl_clicked != NULL)
 81	{
 82		ret = thiz->on_dbl_clicked(thiz, event);
 83	}
 84
 85	return ret;
 86}
 87
 88static inline Ret ftk_gesture_listener_on_long_pressed(FtkGestureListener* thiz, FtkEvent* event)
 89{
 90	Ret ret = RET_FAIL;
 91	return_val_if_fail(thiz != NULL, ret);
 92	
 93	if(thiz->on_long_pressed != NULL)
 94	{
 95		ret = thiz->on_long_pressed(thiz, event);
 96	}
 97
 98	return ret;
 99}
100
101static inline Ret ftk_gesture_listener_on_fling(FtkGestureListener* thiz, 
102		FtkEvent* e1, FtkEvent* e2, int velocity_x, int velocity_y)
103{
104	Ret ret = RET_FAIL;
105	return_val_if_fail(thiz != NULL, ret);
106	
107	if(thiz->on_fling != NULL)
108	{
109		ret = thiz->on_fling(thiz, e1, e2, velocity_x, velocity_y);
110	}
111
112	return ret;
113}
114
115static inline Ret ftk_gesture_listener_on_scroll(FtkGestureListener* thiz, 
116		FtkEvent* e1, FtkEvent* e2, int distance_x, int distance_y)
117{
118	Ret ret = RET_FAIL;
119	return_val_if_fail(thiz != NULL, ret);
120	
121	if(thiz->on_scroll != NULL)
122	{
123		ret = thiz->on_scroll(thiz, e1, e2, distance_x, distance_y);
124	}
125
126	return ret;
127}
128
129static inline void ftk_gesture_listener_destroy(FtkGestureListener* thiz)
130{
131	if(thiz != NULL && thiz->destroy != NULL)
132	{
133		thiz->destroy(thiz);
134	}
135
136	return;
137}
138
139#endif/*FTK_GESTURE_LISTENER_H*/
140