1 #include <pthread.h>
2
3 typedef enum {
4 TOUCH_START = 0,
5 TOUCH_DRAG = 1,
6 TOUCH_RELEASE = 2,
7 TOUCH_HOLD = 3,
8 TOUCH_REPEAT = 4
9 } TOUCH_STATE;
10
11 #undef MAX
12 #define MAX(a,b) ((a) > (b) ? (a) : (b))
13 #undef MIN
14 #define MIN(a,b) ((a) < (b) ? (a) : (b))
15 #undef ABS
16 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
17
18 static pthread_mutex_t gUpdateMutex = PTHREAD_MUTEX_INITIALIZER;
19
draw_dot(int x,int y)20 int draw_dot(int x, int y)
21 {
22 if(x < 0 || y < 0){
23 // LOGE("%s invalid dot! (%d,%d), \n", x, y);
24 return -1;
25 }
26
27 // LOGE("draw (%d,%d)\n", x, y);
28 pthread_mutex_lock(&gUpdateMutex);
29 // drawline(0,0,255,255,x,y,2,2);
30 gr_color(0, 0, 255, 255);
31 gr_fill(x, y, 2, 2);
32 //gr_flip();
33 pthread_mutex_unlock(&gUpdateMutex);
34
35 //FillColor(0, 0, 255, 255,x, y, 1, 1);
36
37
38 return 0;
39 }
40
draw_line(int x1,int y1,int x2,int y2)41 int draw_line(int x1, int y1, int x2, int y2)
42 {
43 int x, y;
44
45 // printf("line: (%d,%d)-(%d,%d)\n", x1, y1, x2, y2);
46
47 if(x1 == x2){
48 x = x1;
49 for(y = MIN(y1, y2); y <= MAX(y1, y2); y++)
50 draw_dot(x, y);
51 }else if(y1 == y2){
52 y = y1;
53 for(x = MIN(x1, x2); x <= MAX(x1, x2); x++)
54 draw_dot(x, y);
55 }else if(ABS(x1-x2) > ABS(y1-y2)){
56 for(x = MIN(x1, x2); x <= MAX(x1, x2); x++){
57 y = ((y2 - y1) * (x - x1)) / (x2 - x1) + y1;
58 draw_dot(x, y);
59 }
60 }else{
61 for(y = MIN(y1, y2); y <= MAX(y1, y2); y++){
62 x = ((x2 - x1) * (y - y1)) / (y2 - y1) + x1;
63 draw_dot(x, y);
64 }
65 }
66
67 return 0;
68 }
69
70 int last_x = 0, last_y = 0;
71 #ifdef SOFIA3GR_PCBA
72 extern int sync_screen_for_prompt(void);
73 #endif
74
NotifyTouch(int action,int x,int y)75 int NotifyTouch(int action, int x, int y)
76 {
77 switch(action){
78 case TOUCH_START:
79 draw_dot(x, y);
80 last_x = x;
81 last_y = y;
82
83 break;
84 case TOUCH_DRAG:
85 draw_line(last_x, last_y, x, y);
86 last_x = x;
87 last_y = y;
88 pthread_mutex_lock(&gUpdateMutex);
89 gr_flip();
90 pthread_mutex_unlock(&gUpdateMutex);
91
92 break;
93 case TOUCH_RELEASE:
94 pthread_mutex_lock(&gUpdateMutex);
95 gr_flip();
96 pthread_mutex_unlock(&gUpdateMutex);
97 #ifdef SOFIA3GR_PCBA
98 sync_screen_for_prompt();
99 #endif
100 break;
101 case TOUCH_HOLD:
102 break;
103 case TOUCH_REPEAT:
104 break;
105 default:
106 break;
107 }
108
109 return 0;
110 }
111