PageRenderTime 53ms CodeModel.GetById 37ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/src/ftk_wnd_manager.c

http://ftk.googlecode.com/
C | 72 lines | 63 code | 9 blank | 0 comment | 12 complexity | bc193b437348617011b3ac73d79f9d81 MD5 | raw file
 1#include "ftk.h"
 2#include "ftk_wnd_manager.h"
 3#include "ftk_display_rotate.h"
 4
 5static inline int is_mouse_event(FtkEvent* event)
 6{
 7	if(event->type == FTK_EVT_MOUSE_DOWN || event->type == FTK_EVT_MOUSE_UP 
 8		|| event->type == FTK_EVT_MOUSE_MOVE || event->type == FTK_EVT_MOUSE_LONG_PRESS)
 9	{
10		return 1;
11	}
12	else
13	{
14		return 0;
15	}
16}
17
18Ret  ftk_wnd_manager_set_rotate(FtkWndManager* thiz, FtkRotate rotate)
19{
20	FtkRotate old = FTK_ROTATE_0;
21	return_val_if_fail(thiz != NULL, RET_FAIL);
22
23	old = ftk_display_get_rotate(ftk_default_display());
24	
25	if(old != rotate)
26	{
27		FtkEvent event;
28		ftk_event_init(&event, FTK_EVT_SCREEN_ROTATED);
29		ftk_wnd_manager_queue_event(thiz, &event);
30	}
31
32	return ftk_display_set_rotate(ftk_default_display(), rotate);
33}
34
35Ret  ftk_wnd_manager_queue_event_auto_rotate(FtkWndManager* thiz, FtkEvent* event)
36{
37	FtkRotate rotate = ftk_display_get_rotate(ftk_default_display());
38	FtkDisplay* display = ftk_display_get_real_display(ftk_default_display());
39
40	if(is_mouse_event(event))
41	{
42		int width = ftk_display_width(display);
43		int height = ftk_display_height(display);
44		
45		switch(rotate)
46		{
47			case FTK_ROTATE_90:
48			{
49				int y = event->u.mouse.y;
50				event->u.mouse.y = width - event->u.mouse.x;
51				event->u.mouse.x = y;
52				break;
53			}
54			case FTK_ROTATE_180:
55			{
56				event->u.mouse.x = width - event->u.mouse.x;
57				event->u.mouse.y = height - event->u.mouse.y;
58				break;
59			}
60			case FTK_ROTATE_270:
61			{
62				int x = event->u.mouse.x;
63				event->u.mouse.x = height - event->u.mouse.y;
64				event->u.mouse.y = x;
65				break;
66			}
67			default:break;
68		}
69	}
70
71	return ftk_wnd_manager_queue_event(thiz, event);
72}