PageRenderTime 34ms CodeModel.GetById 12ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/backend/sdl/ftk_source_sdl.c

http://ftk.googlecode.com/
C | 97 lines | 84 code | 12 blank | 1 comment | 7 complexity | abf35a1f68c64e951e41e064b3c9b902 MD5 | raw file
 1
 2#include "ftk.h"
 3#include "ftk_typedef.h"
 4#include "ftk_source_sdl.h"
 5#include <SDL.h>
 6
 7typedef struct _PrivInfo
 8{
 9	FtkEvent event;
10}PrivInfo;
11
12static int ftk_source_sdl_get_fd(FtkSource* thiz)
13{
14	return -1;
15}
16
17static int ftk_source_sdl_check(FtkSource* thiz)
18{
19	return 0;
20}
21
22static Ret ftk_source_sdl_dispatch(FtkSource* thiz)
23{
24	SDL_Event event;
25	DECL_PRIV(thiz, priv);
26
27	do
28	{
29		if(!SDL_PollEvent(&event))
30		{
31			usleep(20000);
32			break;
33		}
34
35		/* TODO: event.type */
36
37		switch(event.type)
38		{
39		case SDL_KEYDOWN:
40			break;
41		case SDL_KEYUP:
42			break;
43		case SDL_MOUSEBUTTONDOWN:
44			priv->event.type = FTK_EVT_MOUSE_DOWN;
45			priv->event.u.mouse.x = event.button.x;
46			priv->event.u.mouse.y = event.button.y;
47			ftk_wnd_manager_queue_event_auto_rotate(ftk_default_wnd_manager(), &priv->event);
48			break;
49		case SDL_MOUSEBUTTONUP:
50			priv->event.type = FTK_EVT_MOUSE_UP;
51			priv->event.u.mouse.x = event.button.x;
52			priv->event.u.mouse.y = event.button.y;
53			ftk_wnd_manager_queue_event_auto_rotate(ftk_default_wnd_manager(), &priv->event);
54			break;
55		case SDL_MOUSEMOTION:
56			if(event.motion.state != SDL_PRESSED)
57			{
58				break;
59			}
60			priv->event.type = FTK_EVT_MOUSE_MOVE;
61			priv->event.u.mouse.x = event.motion.x;
62			priv->event.u.mouse.y = event.motion.y;
63			ftk_wnd_manager_queue_event_auto_rotate(ftk_default_wnd_manager(), &priv->event);
64			break;
65		case SDL_QUIT:
66			FTK_QUIT();
67			break;
68		default:
69			break;
70		}
71	} while(1);
72
73	return RET_OK;
74}
75
76static void ftk_source_sdl_destroy(FtkSource* thiz)
77{
78	if(thiz != NULL)
79	{
80		FTK_ZFREE(thiz, sizeof(FtkSource) + sizeof(PrivInfo));
81	}
82}
83
84FtkSource* ftk_source_sdl_create(void)
85{
86	FtkSource* thiz = (FtkSource*)FTK_ZALLOC(sizeof(FtkSource) + sizeof(PrivInfo));
87	if(thiz != NULL)
88	{
89		thiz->get_fd = ftk_source_sdl_get_fd;
90		thiz->check = ftk_source_sdl_check;
91		thiz->dispatch = ftk_source_sdl_dispatch;
92		thiz->destroy = ftk_source_sdl_destroy;
93		thiz->ref = 1;
94	}
95
96	return thiz;
97}