其实ui全靠贴图上面的段式液晶,就是背景图再加上rtgui_dc_fill_polygon函数画的
先定义好背景图片的数据数组和各个笔段的多边形数据
- static const rt_uint8_t back_raw_565[] = {
- #include "lcd_back_raw_565_data.c"
- };
- const int seg_a [] = { /* size */ 4,
- 34, 12, 55, 12, 51, 18, 41, 18, };
- const int seg_b [] = { /* size */ 6,
- 56, 13, 58, 14, 58, 34, 56, 36, 52, 33, 52, 20, };
当需要重画的时候,先画背景图片,然后再画对应的笔段
- for(y=0;y<LCD_HEIGHT;++y){
- dc->engine->blit_line(dc, 0, LCD_WIDTH, y, (rt_uint8_t*)line_data);
- line_data += LCD_LINE_DATA_SIZE;
- }
- RTGUI_DC_FC(dc) = black;
- if(me->flag & SEG_MEM){
- draw_seg(dc, seg_memory, 0);
- }
- if(me->flag & SEG_ERROR){
- draw_seg(dc, seg_error, 0);
- }
- if(me->flag & SEG_MINUS){
- draw_seg(dc, seg_minus, 0);
- }
- for(y=0;y<sizeof(me->seg_status);++y){
- int i=0;
- rt_uint8_t f = 1;
- while(i<8){
- if(me->seg_status[y] & f){
- draw_seg(dc, segs[i], y);
- }
- ++i;f<<=1;
- }
- }
完整的笔段液晶ui代码在这里下载
下面的按钮就是贴两张图片完成的,一张按下时显示,一张抬起时显示
- static void add_button_1(rtgui_container_t* container){
- struct rtgui_rect rect;
- rtgui_button_t *button;
- button = rtgui_button_create("MC");
- rect.x1 = 10;
- rect.x2 = 10+48;
- rect.y1 = 100;
- rect.y2 = 100+32;
- rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
- rtgui_container_add_child(container, RTGUI_WIDGET(button));
- RTGUI_WIDGET(button)->user_data = M_CLR; // set button id
- RTGUI_WIDGET_SET_UNFOCUSABLE(button);
- rtgui_button_set_onbutton(button, calc_on_button);
- rtgui_button_set_pressed_image(button, (rtgui_image_t *)&image_press_1);
- rtgui_button_set_unpressed_image(button, (rtgui_image_t *)&image_unpress_1);
- }
这里按钮很多,为了让按钮图片节约内存,我在rtgui框架下新增了一种imge_mem的图片类型,这种图片不能修改,不占用RAM空间
image_mem的代码在这里下载
|