1+ #include <board.h>
2+ #include <rthw.h>
3+ #include <rtthread.h>
4+ #include "drv_lcd.h"
5+ #include "drv_touch.h"
6+
7+ #define COLOR_MAX 14
8+
9+ //像素最大放大倍数
10+ #define PIXEL_SIZE_MAX 20
11+
12+ typedef struct button_struct
13+ {
14+ uint16_t x ;
15+ uint16_t y ;
16+ uint16_t w ;
17+ uint16_t h ;
18+ uint16_t color ;
19+ uint16_t value ;
20+ } _widget_object_struct ;
21+
22+ uint16_t color_buf [COLOR_MAX ] = {GRAYBLUE , BLACK , BLUE , BRED , GRED , GBLUE , RED , MAGENTA , GREEN , YELLOW , CYAN , BROWN , BRRED , GRAY };
23+ _widget_object_struct button_clear , button_color , button_pixel , button_eraser ;
24+
25+
26+ /**********************************************************
27+ * 函 数 名 称:widget_object_init
28+ * 函 数 功 能:控件对象初始化
29+ * 传 入 参 数:obj:要初始化的控件
30+ * xywh:控件的(x,y)起点坐标 w宽h高
31+ * color:控件颜色
32+ * value:控件值
33+ * 函 数 返 回:无
34+ * 作 者:LCKFB
35+ * 备 注:无
36+ **********************************************************/
37+ void widget_object_init (_widget_object_struct * obj , uint16_t x , uint16_t y , uint16_t w , uint16_t h , uint16_t color , uint16_t value )
38+ {
39+ obj -> x = x ;
40+ obj -> y = y ;
41+ obj -> h = h ;
42+ obj -> w = w ;
43+ obj -> color = color ;
44+ obj -> value = value ;
45+ }
46+
47+
48+ /**********************************************************
49+ * 函 数 名 称:ui_init
50+ * 函 数 功 能:UI界面初始化
51+ * 传 入 参 数:无
52+ * 函 数 返 回:无
53+ * 作 者:LCKFB
54+ * 备 注:无
55+ **********************************************************/
56+ void ui_init (void )
57+ {
58+ char temp_buf [20 ] = {0 };
59+
60+ //绘制[清除]按钮
61+ //绘制一个圆角按钮
62+ tli_show_button (button_clear .x , button_clear .y , button_clear .w , button_clear .h , 12 , button_clear .color );
63+ //绘制圆角按钮的文本
64+ tli_show_string (button_clear .x + 20 , button_clear .y + 20 , WHITE , button_clear .color , 2 , "clear" , 0 );
65+
66+ //绘制[颜色]按钮
67+ //绘制一个圆角按钮
68+ tli_show_button (button_color .x , button_color .y , button_color .w , button_color .h , 12 , button_color .color );
69+ //绘制圆角按钮的文本
70+ tli_show_string (button_color .x + 20 , button_color .y + 20 , WHITE , button_color .color , 2 , "color" , 0 );
71+
72+ //绘制[像素]按钮
73+ //绘制一个圆角按钮
74+ tli_show_button (button_pixel .x , button_pixel .y , button_pixel .w , button_pixel .h , 12 , button_pixel .color );
75+ if (button_pixel .value == 0 )
76+ {
77+ //绘制圆角按钮的文本
78+ tli_show_string (button_pixel .x + 20 , button_pixel .y + 20 , WHITE , button_pixel .color , 2 , "pixel" , 0 );
79+ button_pixel .value = 1 ;
80+ }
81+ else
82+ {
83+ //绘制居中显示的字符串
84+ sprintf (temp_buf , "%d" , button_pixel .value );
85+ tli_show_string (button_pixel .x + (button_pixel .w / 2 ) - (strlen (temp_buf ) / 2 * 16 ), button_pixel .y + 20 , WHITE , button_pixel .color , 2 , (uint8_t * )temp_buf , 0 );
86+ }
87+
88+ //绘制[擦除]按钮
89+ //绘制一个圆角按钮
90+ tli_show_button (button_eraser .x , button_eraser .y , button_eraser .w , button_eraser .h , 12 , button_eraser .color );
91+ //绘制圆角按钮的文本
92+ tli_show_string (button_eraser .x + (button_eraser .w / 2 ) - (strlen ("eraser" ) / 2 * 16 ), button_eraser .y + 20 , WHITE , button_eraser .color , 2 , "eraser" , 0 );
93+ }
94+
95+ int draw_panel_test (void )
96+ {
97+ int touch_state = 0 ;
98+ char color_num = 0 ;
99+ char pixel_size = 0 ;
100+
101+ // 屏幕初始化
102+ lcd_disp_config ();
103+ // 触摸初始化
104+ FT5206_Init ();
105+ //全屏清屏
106+ tli_draw_Rectangle (0 , 0 , 800 , 480 , WHITE , 1 );
107+
108+
109+ //初始化[清除]按钮的xywh
110+ widget_object_init (& button_clear , 800 - 130 , 480 - 80 , 120 , 70 , BLUE , 0 );
111+ //初始化[颜色]按钮的xywh
112+ widget_object_init (& button_color , 10 , 480 - 80 , 120 , 70 , BLUE , 0 );
113+ //初始化[像素]按钮的xywh
114+ widget_object_init (& button_pixel , 400 - 60 , 480 - 80 , 120 , 70 , BLUE , pixel_size );
115+ //初始化[橡皮擦]按钮的xywh
116+ widget_object_init (& button_eraser , 800 - 130 - 130 , 480 - 80 , 120 , 70 , BLUE , 0 );
117+
118+ //UI显示
119+ ui_init ();
120+
121+ while (1 )
122+ {
123+ //触摸扫描
124+ touch_state = FT5206_Scan (0 );
125+ //如果屏幕被触摸
126+ if (touch_state == 1 )
127+ {
128+ //[颜色]按钮被按下
129+ if (tp_dev .x [0 ] >= button_color .x && tp_dev .x [0 ] <= (button_color .x + button_color .w ))
130+ {
131+ if (tp_dev .y [0 ] >= button_color .y && tp_dev .y [0 ] <= (button_color .y + button_color .h ))
132+ {
133+ //判断是否松手
134+ letgo_scan (0 , button_color .x , button_color .y , (button_color .x + button_color .w ), (button_color .y + button_color .h ));
135+ //改变颜色
136+ color_num = (color_num + 1 ) % COLOR_MAX ;
137+ //重新设置[颜色]按钮的背景色
138+ widget_object_init (& button_color , button_color .x , button_color .y , button_color .w , button_color .h , color_buf [color_num ], 0 );
139+ //UI重新显示
140+ ui_init ();
141+ }
142+ }
143+ //[清除]按钮被按下
144+ if (tp_dev .x [0 ] >= button_clear .x && tp_dev .x [0 ] <= (button_clear .x + button_clear .w ))
145+ {
146+ if (tp_dev .y [0 ] >= button_clear .y && tp_dev .y [0 ] <= (button_clear .y + button_clear .h ))
147+ {
148+ //判断是否松手
149+ letgo_scan (0 , button_clear .x , button_clear .y , (button_clear .x + button_clear .w ), (button_clear .y + button_clear .h ));
150+ //清屏为背景色
151+ tli_draw_Rectangle (0 , 0 , 800 , 480 , WHITE , 1 );
152+ //UI重新显示
153+ ui_init ();
154+ }
155+ }
156+ //[像素]按钮被按下
157+ if (tp_dev .x [0 ] >= button_pixel .x && tp_dev .x [0 ] <= (button_pixel .x + button_pixel .w ))
158+ {
159+ if (tp_dev .y [0 ] >= button_pixel .y && tp_dev .y [0 ] <= (button_pixel .y + button_pixel .h ))
160+ {
161+ //判断是否松手
162+ letgo_scan (0 , button_pixel .x , button_pixel .y , (button_pixel .x + button_pixel .w ), (button_pixel .y + button_pixel .h ));
163+ //像素放大倍数自增
164+ pixel_size ++ ;
165+ //如果像素放大倍数大于最大倍数
166+ if (pixel_size > PIXEL_SIZE_MAX ) pixel_size = 1 ;
167+ //重新设置[颜色]按钮的背景色
168+ widget_object_init (& button_pixel , button_pixel .x , button_pixel .y , button_pixel .w , button_pixel .h , button_pixel .color , pixel_size );
169+ //UI重新显示
170+ ui_init ();
171+ }
172+ }
173+
174+ //[擦除]按钮被按下
175+ if (tp_dev .x [0 ] >= button_eraser .x && tp_dev .x [0 ] <= (button_eraser .x + button_eraser .w ))
176+ {
177+ if (tp_dev .y [0 ] >= button_eraser .y && tp_dev .y [0 ] <= (button_eraser .y + button_eraser .h ))
178+ {
179+ //判断是否松手
180+ letgo_scan (0 , button_eraser .x , button_eraser .y , (button_eraser .x + button_eraser .w ), (button_eraser .y + button_eraser .h ));
181+ //修改擦除按钮的状态
182+ button_eraser .value = !button_eraser .value ;
183+ //如果是擦除状态
184+ if (button_eraser .value )
185+ {
186+ //初始化[橡皮擦]按钮的xywh颜色修改为黑色
187+ widget_object_init (& button_eraser , 800 - 130 - 130 , 480 - 80 , 120 , 70 , BLACK , button_eraser .value );
188+ }
189+ else
190+ {
191+ //初始化[橡皮擦]按钮的xywh颜色修改为蓝色
192+ widget_object_init (& button_eraser , 800 - 130 - 130 , 480 - 80 , 120 , 70 , BLUE , button_eraser .value );
193+ }
194+ //UI重新显示
195+ ui_init ();
196+ }
197+ }
198+
199+ //如果不是擦除状态
200+ if (!button_eraser .value )
201+ {
202+ //绘制触摸点
203+ //根据[颜色]按钮的背景色设置触摸点的颜色
204+ point_enlargement (tp_dev .x [0 ], tp_dev .y [0 ], color_buf [color_num ], button_pixel .value );
205+ }
206+ else
207+ {
208+ //擦除
209+ point_enlargement (tp_dev .x [0 ], tp_dev .y [0 ], WHITE , button_pixel .value );
210+ }
211+ }
212+ }
213+ }
214+ // MSH_CMD_EXPORT(draw_panel_test, draw panel test)
215+ INIT_COMPONENT_EXPORT (draw_panel_test );
0 commit comments