/* * view的事件处理函数 */ static rt_bool_t dc_buffer_event_handler(PVOID wdt, rtgui_event_t *event) { /* 仅对PAINT事件进行处理 */ if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; rtgui_rect_t rect; /* * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view * 先绘图 */ rtgui_view_event_handler(wdt, event); /* 获得控件所属的DC */ dc = rtgui_dc_begin_drawing(wdt); /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ if (dc == RT_NULL) return RT_FALSE; rtgui_widget_get_rect(wdt, &rect); rect.x1 += 10; rect.y1 += 40; rtgui_dc_blit(dc_buffer, NULL, dc, &rect); /* 绘图完成 */ rtgui_dc_end_drawing(dc); } else { /* 其他事件,调用默认的事件处理函数 */ return rtgui_view_event_handler(wdt, event); } return RT_FALSE; }
static rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) { if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; rtgui_rect_t rect; /* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */ rtgui_view_event_handler(widget, event); /* 获得控件所属的DC */ dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ return RT_FALSE; /* 获得demo view允许绘图的区域 */ demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect); /* 绘图 */ rect = text_rect; rtgui_rect_inflate(&rect, +1); rtgui_dc_blit(dc_buffer, NULL, dc, &rect); /* 绘图完成 */ rtgui_dc_end_drawing(dc); } else { /* 调用默认的事件处理函数 */ return rtgui_view_event_handler(widget, event); } return RT_FALSE; }
void _draw_default(PVOID wdt, rtgui_event_t* event) { struct rtgui_dc* dc; rtgui_widget_t* widget = (rtgui_widget_t*)wdt; rtgui_rect_t rect; /* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */ rtgui_view_event_handler(widget, event); /* 获得控件所属的DC */ dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ return ; /* 获得demo view允许绘图的区域 */ rtgui_widget_get_rect(widget, &rect); rtgui_rect_inflate(&rect, -5); rect.y1 += 35; /* 擦除所有 */ RTGUI_WIDGET_BACKGROUND(widget) = default_background; rtgui_dc_fill_rect(dc, &rect); /* 显示提示 */ rtgui_dc_draw_text(dc, "按鼠标键开始/停止测试...", &rect); /* 绘图完成 */ rtgui_dc_end_drawing(dc); }
/* 演示视图的事件处理函数 */ static rt_bool_t demo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) { rt_bool_t result; /* 先调用默认的事件处理函数(这里只关心PAINT事件,但演示视图还有本身的一些控件) */ result = rtgui_view_event_handler(widget, event); if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; rtgui_rect_t rect; /* 获得控件所属的DC */ dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ return RT_FALSE; /* 获得demo view允许绘图的区域 */ demo_view_get_rect(RTGUI_VIEW(widget), &rect); /* 获得图像显示区域 */ rect.x1 += 5; rect.x2 -= 5; rect.y1 += 30; if (image != RT_NULL) rtgui_image_blit(image, dc, &rect); /* 绘图完成 */ rtgui_dc_end_drawing(dc); } return result; }
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; struct rtgui_rect rect; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; rtgui_widget_get_rect(widget, &rect); rtgui_dc_fill_rect(dc, &rect); if (background != RT_NULL) rtgui_image_blit(background, dc, &rect); rtgui_dc_draw_text(dc, "Radio Today", &rect); rtgui_dc_end_drawing(dc); return RT_FALSE; } return rtgui_view_event_handler(widget, event); }
rt_bool_t benchmark_event_handler(PVOID wdt, rtgui_event_t *event) { rtgui_widget_t *widget = (rtgui_widget_t*)wdt; if (event->type == RTGUI_EVENT_PAINT) { _draw_default(widget, event); } else if (event->type == RTGUI_EVENT_MOUSE_BUTTON) { rtgui_event_mouse_t *emouse = (rtgui_event_mouse_t*)event; if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN) { if (running) { /* stop */ rtgui_thread_set_onidle(RT_NULL); _draw_default(widget, event); } else { /* run */ rtgui_thread_set_onidle(_onidle); } running = !running; } return RT_TRUE; } else { /* 调用默认的事件处理函数 */ return rtgui_view_event_handler(widget, event); } return RT_FALSE; }
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; struct rtgui_rect rect; rtgui_image_t *image; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; rtgui_widget_get_rect(widget, &rect); rtgui_dc_fill_rect(dc, &rect); rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2 - 1); /* draw RT-Thread logo */ image = rtgui_image_create_from_file("hdc", "/resource/RTT.hdc", RT_FALSE); if (image != RT_NULL) { rtgui_image_blit(image, dc, &rect); rtgui_image_destroy(image); image = RT_NULL; } if (network_image != RT_NULL) { rect.x1 = rect.x2 - (network_image->w + 2); rtgui_image_blit(network_image, dc, &rect); } rtgui_dc_end_drawing(dc); return RT_FALSE; } else if (event->type == RTGUI_EVENT_MOUSE_BUTTON) { struct rtgui_rect rect; struct rtgui_event_mouse* emouse; emouse = (struct rtgui_event_mouse*) event; rtgui_widget_get_rect(widget, &rect); rect.y2 = rect.y1 + 100; if (emouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP) && (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)) { /* enter function view */ player_notfiy_functionview(); } } return rtgui_view_event_handler(widget, event); }
static rt_bool_t update_radio_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { switch (event->type) { case RTGUI_EVENT_COMMAND: { struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event; switch(ecmd->type) { case RTGUI_EVENT_PAINT: drawing_update_state_info(widget); /* this event has handled, return TRUE */ return RT_TRUE; } return RT_FALSE; } case RTGUI_EVENT_PAINT: { drawing_update_state_info(widget); return RT_FALSE; } case RTGUI_EVENT_KBD: { struct rtgui_event_kbd* ekbd; ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN) { rtgui_workbench_t* workbench; workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(update_radio_list_view)->parent); rtgui_workbench_remove_view(workbench, update_radio_list_view); rtgui_view_destroy(update_radio_list_view); update_radio_list_view = RT_NULL; } } return RT_FALSE; } /* use parent event handler */ return rtgui_view_event_handler(widget, event); }
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { if (event->type == RTGUI_EVENT_KBD) { struct rtgui_event_kbd* ekbd; ekbd = (struct rtgui_event_kbd*) event; if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN) { rtgui_view_t* view; rtgui_workbench_t* workbench; /* remove view in workbench */ view = RTGUI_VIEW(widget); workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); rtgui_workbench_remove_view(workbench, view); rtgui_view_destroy(view); return RT_TRUE; } return RT_FALSE; } return rtgui_view_event_handler(widget, event); }
rt_bool_t rtgui_combo_event_handler(pvoid wdt, rtgui_event_t* event) { rtgui_widget_t *widget = RTGUI_WIDGET(wdt); rtgui_combo_t* cbo = RTGUI_COMBO(wdt); RT_ASSERT(widget != RT_NULL); switch(event->type) { case RTGUI_EVENT_PAINT: if(widget->on_draw != RT_NULL) widget->on_draw(widget, event); else rtgui_combo_ondraw(cbo); break; case RTGUI_EVENT_KBD: if(widget->on_key != RT_NULL) widget->on_key(widget, event); return RT_TRUE; case RTGUI_EVENT_MOUSE_BUTTON: { rtgui_rect_t rect; struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event; rt_bool_t inclip=RT_EOK; if(!RTGUI_WIDGET_IS_ENABLE(cbo)) break; if(cbo->tbox->isedit == RT_TRUE) { /* only detect textbox area */ inclip = rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect); } else { /* detect all area */ inclip = (rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) && rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo->tbox),emouse->x,emouse->y,&rect)); } if(inclip == RT_EOK) { rtgui_combo_get_downarrow_rect(cbo,&rect); if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN) { if(rtgui_rect_contains_point(&rect,emouse->x,emouse->y) == RT_EOK) { /* on pull-down button */ cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_DOWN; rtgui_combo_draw_downarrow(cbo); } if(cbo->lbox != RT_NULL) { if(RTGUI_WIDGET_IS_HIDE(cbo->lbox)) { /* display pupup listbox */ RTGUI_WIDGET_SHOW(cbo->lbox); rtgui_widget_focus(cbo->lbox); rtgui_widget_update_clip_pirate(RTGUI_WIDGET_PARENT(cbo->lbox),cbo->lbox); /* set listbox location is 0 */ cbo->lbox->first_item=0; cbo->lbox->now_item = 0; if(cbo->lbox->scroll != RT_NULL) { if(!RTGUI_WIDGET_IS_HIDE(cbo->lbox->scroll)) { rtgui_scrollbar_set_value(cbo->lbox->scroll,cbo->lbox->first_item); } } rtgui_widget_update(RTGUI_WIDGET_PARENT(cbo->lbox)); } else { /* hide it */ rtgui_widget_hide(cbo->lbox); } } } else if(emouse->button & RTGUI_MOUSE_BUTTON_UP) { if(rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) == RT_EOK) { /* on upriver button */ cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_UP; rtgui_combo_draw_downarrow(cbo); } } } else rtgui_view_event_handler(widget,event); return RT_TRUE; } default: return rtgui_view_event_handler(widget,event); } return RT_FALSE; }
/* * Device Information View * Device: Win32 or Cortex-M3 etc * Memory: * Thread: * IP Address: * Gateway: * DNS: */ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { switch (event->type) { case RTGUI_EVENT_PAINT: { struct rtgui_dc* dc; struct rtgui_rect rect; char* line; rt_uint32_t total, used, max_used; line = rtgui_malloc(256); if (line == RT_NULL) return RT_FALSE; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) { rtgui_free(line); return RT_FALSE; } rtgui_widget_get_rect(widget, &rect); /* fill background */ rtgui_dc_fill_rect(dc, &rect); rect.y2 = rect.y1 + 18; { rt_uint32_t dev_index, rev_index; dev_index = DBGMCU_GetDEVID(); dev_index = (dev_index - 0x410)/2; rev_index = DBGMCU_GetREVID(); switch (rev_index) { case 0x1000: case 0x0000: rev_index = 0; /* Revision A */ break; case 0x1001: case 0x2001: rev_index = 3; /* Revision Z */ break; case 0x2000: rev_index = 1; /* Revision B */ break; case 0x2002: rev_index = 2; /* Revision Y */ break; default: rev_index = 4; /* Unknown */ break; }; /* check device index */ if (dev_index > 4) dev_index = 3; /* draw each information */ sprintf(line, "设备: %s %s", stm32_devname[dev_index], stm32_revname[rev_index]); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; } rt_memory_info(&total, &used, &max_used); sprintf(line, "内存: 当前使用 %d 字节", used); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; { rt_uint16_t rect_width; rtgui_color_t saved; rtgui_rect_t mem_rect = rect; rtgui_rect_inflate(&mem_rect, -2); rtgui_dc_draw_rect(dc, &mem_rect); rtgui_rect_inflate(&mem_rect, -1); rect_width = rtgui_rect_width(mem_rect); saved = RTGUI_WIDGET_BACKGROUND(widget); RTGUI_WIDGET_BACKGROUND(widget) = light_grey; mem_rect.x2 = mem_rect.x1 + (max_used * rect_width / total); rtgui_dc_fill_rect(dc, &mem_rect); RTGUI_WIDGET_BACKGROUND(widget) = blue; mem_rect.x2 = mem_rect.x1 + (used * rect_width / total); rtgui_dc_fill_rect(dc, &mem_rect); /* restore color */ RTGUI_WIDGET_BACKGROUND(widget) = saved; } rect.y1 += 18; rect.y2 += 18; sprintf(line, "线程数: %d", get_thread_cnt()); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #ifdef RT_USING_LWIP { struct ip_addr ip_addr; struct _ip_addr { rt_uint8_t addr0, addr1, addr2, addr3; } *addr; addr = (struct _ip_addr*)&netif_default->ip_addr.addr; sprintf(line, "IP地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; addr = (struct _ip_addr*)&netif_default->gw.addr; sprintf(line, "网关地址: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; addr = (struct _ip_addr*)&netif_default->netmask.addr; sprintf(line, "网络掩码: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #if LWIP_DNS ip_addr = dns_getserver(0); addr = (struct _ip_addr*)&ip_addr; sprintf(line, "DNS地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #endif } #endif rtgui_dc_end_drawing(dc); rtgui_free(line); return RT_FALSE; } case RTGUI_EVENT_KBD: { struct rtgui_event_kbd* ekbd; ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN) { rtgui_workbench_t* workbench; workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(device_view)->parent); rtgui_workbench_remove_view(workbench, device_view); rtgui_view_destroy(device_view); device_view = RT_NULL; } } return RT_FALSE; } /* use parent event handler */ return rtgui_view_event_handler(widget, event); }
/* * view的事件处理函数 */ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) { /* 仅对PAINT事件进行处理 */ if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; rtgui_rect_t rect; /* const int vx[] = {20, 50, 60, 45, 60, 20}; const int vy[] = {150, 50, 90, 60, 45, 50}; */ /* * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view * 先绘图 */ rtgui_view_event_handler(widget, event); /************************************************************************/ /* 下面的是DC的操作 */ /************************************************************************/ /* 获得控件所属的DC */ dc = rtgui_dc_begin_drawing(widget); /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ if (dc == RT_NULL) return RT_FALSE; /* 获得demo view允许绘图的区域 */ demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect); RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL; /* 显示GUI的版本信息 */ #ifdef RTGUI_USING_SMALL_SIZE rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect); #else rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect); #endif { rtgui_rect_t rect = {0, 0, 0x1c, 0x16}; rtgui_rect_moveto(&rect, 80, 80); rtgui_image_blit((rtgui_image_t*)&play_image, dc, &rect); rect.x1 = 0; rect.y1 = 0; rect.x2 = 0x1c; rect.y2 = 0x16; rtgui_rect_moveto(&rect, 130, 80); rtgui_image_blit((rtgui_image_t*)&stop_image, dc, &rect); } /* 绘制一个圆形 */ RTGUI_DC_FC(dc) = red; rtgui_dc_draw_circle(dc, rect.x1 + 10, rect.y1 + 10, 10); /* 填充一个圆形 */ RTGUI_DC_FC(dc) = green; rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10); #if 0 /* 画一个圆角矩形 */ rect.x1 = 150; rect.y1 = 180; rect.x2 = 210; rect.y2 = 260; RTGUI_DC_FC(dc) = RTGUI_RGB(25, 70, 150); rtgui_dc_draw_round_rect(dc, &rect, 10); rect.x1 = 160; rect.y1 = 190; rect.x2 = 200; rect.y2 = 250; RTGUI_DC_FC(dc) = RTGUI_RGB(170, 7, 80); rtgui_dc_fill_round_rect(dc, &rect, 7); /* 画一个圆弧 */ RTGUI_DC_FC(dc) = RTGUI_RGB(250, 120, 120); rtgui_dc_draw_arc(dc, rect.x1 + 120, rect.y1 + 60, 30, 0, 120); /* 画一个扇形圆环 */ RTGUI_DC_FC(dc) = RTGUI_RGB(150, 23, 100); rtgui_dc_draw_annulus(dc, 180, 170, 30, 50, 210, 330); /* 多边形 */ RTGUI_DC_FC(dc) = blue; rtgui_dc_draw_polygon(dc, vx, vy, 6); #endif RTGUI_DC_FC(dc) = blue; /* 绘制不同的边框 */ { rtgui_rect_t rect = {0, 0, 16, 16}; rtgui_rect_moveto(&rect, 30, 120); rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE); rect.x1 += 20; rect.x2 += 20 + 50; rtgui_dc_draw_text(dc, "raise", &rect); rect.x1 -= 20; rect.x2 -= 20 + 50; rect.y1 += 20; rect.y2 += 20; rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SIMPLE); rect.x1 += 20; rect.x2 += 20 + 50; rtgui_dc_draw_text(dc, "simple", &rect); rect.x1 -= 20; rect.x2 -= 20 + 50; rect.y1 += 20; rect.y2 += 20; rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN); rect.x1 += 20; rect.x2 += 20 + 50; rtgui_dc_draw_text(dc, "sunken", &rect); rect.x1 -= 20; rect.x2 -= 20 + 50; rect.y1 += 20; rect.y2 += 20; rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX); rect.x1 += 20; rect.x2 += 20 + 50; rtgui_dc_draw_text(dc, "box", &rect); rect.x1 -= 20; rect.x2 -= 20 + 50; rect.y1 += 20; rect.y2 += 20; rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC); rect.x1 += 20; rect.x2 += 20 + 50; rtgui_dc_draw_text(dc, "static", &rect); rect.x1 -= 20; rect.x2 -= 20 + 50; rect.y1 += 20; rect.y2 += 20; rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_EXTRA); rect.x1 += 20; rect.x2 += 20 + 50; rtgui_dc_draw_text(dc, "extera", &rect); rect.x1 -= 20; rect.x2 -= 20 + 50; rect.y1 += 20; rect.y2 += 20; } /* 绘图完成 */ rtgui_dc_end_drawing(dc); } else { /* 其他事件,调用默认的事件处理函数 */ return rtgui_view_event_handler(widget, event); } return RT_FALSE; }
/* * view的事件处理函数 */ rt_bool_t instrument_panel_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) { char ac[4]; int i; int x0 = 120; int y0 = 170; int x, y; int default_color; /* 仅对PAINT事件进行处理 */ if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; rtgui_rect_t rect; const int arrowx[] = {120+75, 120+75, 120+85}; const int arrowy[] = {170-5, 170+5, 170}; /* * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view * 先绘图 */ rtgui_view_event_handler(widget, event); /************************************************************************/ /* 下面的是DC的操作 */ /************************************************************************/ /* 获得控件所属的DC */ dc = rtgui_dc_begin_drawing(widget); /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ if (dc == RT_NULL) return RT_FALSE; /* 获得demo view允许绘图的区域 */ demo_view_get_rect(RTGUI_VIEW(widget), &rect); RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL; /* 显示GUI的版本信息 */ #ifdef RTGUI_USING_SMALL_SIZE rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect); #else rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect); #endif RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL; RTGUI_DC_FC(dc) = blue; rect.y2 = 270; rtgui_dc_draw_text(dc, "rtgui-panel", &rect); for(i = 0; i < 6; i++) { rtgui_dc_draw_arc(dc, x0, y0, 117-i, 150, 30); } RTGUI_DC_FC(dc) = black; RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT; for(i = 0; i <= 23; i++) { if(i < 12) { x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180); y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180); rect.x1 = x; rect.y1 = y; rect.x2 = rect.x1 + 12 * 3; rect.y2 = rect.y1 + 12; rt_sprintf(ac, "%d", 10 * i); rtgui_dc_draw_text(dc, ac, &rect); } else { RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT; x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180); y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180); rect.x1 = x - 12 * 3; rect.y1 = y; rect.x2 = rect.x1 + 12 * 3; rect.y2 = rect.y1 + 12; rt_sprintf(ac, "%d", 10 * i); rtgui_dc_draw_text(dc, ac, &rect); } x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180); y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180); rtgui_dc_fill_circle(dc, x, y, 3); } RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166); rtgui_dc_fill_circle(dc, x0, y0, 3); RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30); rtgui_dc_draw_circle(dc, x0, y0, 5); default_color = RTGUI_DC_BC(dc); RTGUI_DC_BC(dc) = red; rect.x1 = x0 + 7; rect.y1 = y0 - 1; rect.x2 = x0 + 75; rect.y2 = y0 + 1; rtgui_dc_fill_rect(dc, &rect); RTGUI_DC_BC(dc) = default_color; rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3); /* 绘图完成 */ rtgui_dc_end_drawing(dc); } else { /* 其他事件,调用默认的事件处理函数 */ return rtgui_view_event_handler(widget, event); } return RT_FALSE; }
static rt_bool_t picture_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; struct rtgui_rect rect; struct rtgui_image* image; char fn[32]; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; rtgui_widget_get_rect(widget, &rect); /* open image */ rt_snprintf(fn, sizeof(fn), "%s/%s", PICTURE_DIR, current_fn); image = rtgui_image_create_from_file("hdc", fn, RT_FALSE); if (image != RT_NULL) { /* blit image */ rtgui_image_blit(image, dc, &rect); /* destroy image */ rtgui_image_destroy(image); } else { rtgui_dc_fill_rect(dc, &rect); rtgui_dc_draw_text(dc, "没有文件被打开", &rect); } rtgui_dc_end_drawing(dc); return RT_FALSE; } else if (event->type == RTGUI_EVENT_KBD) { struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN) { switch (ekbd->key) { case RTGUIK_RIGHT: if (view_mode == VIEW_DIR_MODE) picture_show_next(); else if (view_mode == VIEW_FN_LIST_MODE) { picture_fn_list_current ++; if (picture_fn_list_current == picture_fn_list_size) { picture_fn_list_current = 0; } strcpy(current_fn, picture_fn_list[picture_fn_list_current]); rtgui_widget_update(RTGUI_WIDGET(picture_view)); } break; case RTGUIK_LEFT: if (view_mode == VIEW_DIR_MODE) picture_show_prev(); else if (view_mode == VIEW_FN_LIST_MODE) { if (picture_fn_list_current == 0) { picture_fn_list_current = picture_fn_list_size - 1; } else picture_fn_list_current --; strcpy(current_fn, picture_fn_list[picture_fn_list_current]); rtgui_widget_update(RTGUI_WIDGET(picture_view)); } break; case RTGUIK_RETURN: { rtgui_view_t* view; view = RTGUI_VIEW(widget); /* close this view */ current_fn[0] = '\0'; /* end of modal */ rtgui_view_end_modal(view, RTGUI_MODAL_OK); picture_view = RT_NULL; } break; } } return RT_FALSE; } return rtgui_view_event_handler(widget, event); }
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; struct rtgui_rect rect; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; rtgui_widget_get_rect(widget, &rect); rtgui_dc_fill_rect(dc, &rect); rect.x2 -= 1; rect.y2 -= 1; rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1); rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2); rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2); rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2 + 1); /* shrink border */ rtgui_rect_inflate(&rect, -1); /* draw text */ rtgui_widget_get_rect(widget, &rect); rect.y1 += 25; rtgui_dc_draw_text(dc, " FM3 Easy Kit Demo", &rect); rect.y1 += 10; rtgui_dc_draw_text(dc, " rt-thread / RTGUI", &rect); rtgui_dc_end_drawing(dc); return RT_FALSE; } else if (event->type == RTGUI_EVENT_KBD) { struct rtgui_dc* dc; struct rtgui_rect rect; struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN) { char key_str[16]; switch (ekbd->key) { case RTGUIK_LEFT: rt_sprintf(key_str, "%s", "L"); break; case RTGUIK_RIGHT: rt_sprintf(key_str, "%s", "R"); break; case RTGUIK_DOWN: rt_sprintf(key_str, "%s", "D"); break; case RTGUIK_UP: rt_sprintf(key_str, "%s", "U"); break; default: rt_sprintf(key_str, "%s", "S"); break; } dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; rect.x1 = 118; rect.y1 = 1; rect.x2 = 127; rect.y2 = 10; rtgui_dc_fill_rect(dc, &rect); rtgui_dc_draw_text(dc, key_str, &rect); rtgui_dc_end_drawing(dc); } else if (ekbd->type == RTGUI_KEYUP) { dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; rect.x1 = 118; rect.y1 = 1; rect.x2 = 127; rect.y2 = 10; rtgui_dc_fill_rect(dc, &rect); //rtgui_dc_draw_text(dc, key_str, &rect); rtgui_dc_end_drawing(dc); } } else if (event->type == RTGUI_EVENT_COMMAND) { char str[16]; struct rtgui_dc* dc; struct rtgui_rect rect; struct rtgui_event_command* ecmd; rt_uint8_t major,minor; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; ecmd = (struct rtgui_event_command*)event; switch (ecmd->command_id) { case ADC_UPDATE: rect.x1 = 1; rect.y1 = 1; rect.x2 = 117; rect.y2 = 10; rtgui_dc_fill_rect(dc, &rect); rt_sprintf(str, "ADC = %d mv", adc_value); rtgui_dc_draw_text(dc, str, &rect); break; case CPU_UPDATE: cpu_usage_get(&major, &minor); rect.x1 = 1; rect.y1 = 12; rect.x2 = 127; rect.y2 = 22; rtgui_dc_fill_rect(dc, &rect); rt_sprintf(str, "CPU : %d.%d%", major, minor); rtgui_dc_draw_text(dc, str, &rect); rect.y1 = 23; rect.y2 = 63; index++; if (index == 127) { index = 1; rtgui_dc_fill_rect(dc, &rect); } if (major>40) rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2); else rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2); break; } rtgui_dc_end_drawing(dc); } return rtgui_view_event_handler(widget, event); }
rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { struct rtgui_list_view* view = RT_NULL; view = RTGUI_LIST_VIEW(widget); switch (event->type) { case RTGUI_EVENT_PAINT: rtgui_list_view_ondraw(view); return RT_FALSE; case RTGUI_EVENT_RESIZE: { struct rtgui_event_resize* resize; resize = (struct rtgui_event_resize*)event; /* recalculate page items */ view->page_items = resize->h / (2 + rtgui_theme_get_selected_height()); } break; case RTGUI_EVENT_MOUSE_BUTTON: { struct rtgui_event_mouse* emouse; emouse = (struct rtgui_event_mouse*)event; return rtgui_list_view_onmouse(view, emouse); } case RTGUI_EVENT_KBD: { struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN) { rt_uint16_t old_item; old_item = view->current_item; switch (ekbd->key) { case RTGUIK_LEFT: if (view->flag == RTGUI_LIST_VIEW_LIST) { if (view->current_item - view->page_items >= 0) view->current_item -= view->page_items; rtgui_list_view_update_list(view, old_item); } else if (view->flag == RTGUI_LIST_VIEW_ICON) { if (view->current_item > 0) view->current_item --; rtgui_list_view_update_icon(view, old_item); } return RT_FALSE; case RTGUIK_UP: if (view->flag == RTGUI_LIST_VIEW_LIST) { if (view->current_item > 0) view->current_item --; rtgui_list_view_update_list(view, old_item); } else if (view->flag == RTGUI_LIST_VIEW_ICON) { if (view->current_item >= view->col_items) view->current_item -= view->col_items; else view->current_item = 0; rtgui_list_view_update_icon(view, old_item); } return RT_FALSE; case RTGUIK_RIGHT: if (view->flag == RTGUI_LIST_VIEW_LIST) { if (view->current_item + view->page_items < view->items_count - 1) view->current_item += view->page_items; rtgui_list_view_update_list(view, old_item); } else if (view->flag == RTGUI_LIST_VIEW_ICON) { if (view->current_item < view->items_count - 1) view->current_item ++; rtgui_list_view_update_icon(view, old_item); } return RT_FALSE; case RTGUIK_DOWN: if (view->flag == RTGUI_LIST_VIEW_LIST) { if (view->current_item < view->items_count - 1) view->current_item ++; rtgui_list_view_update_list(view, old_item); } else if (view->flag == RTGUI_LIST_VIEW_ICON) { if (view->current_item + view->col_items <= (view->items_count - 1)) view->current_item += view->col_items; else view->current_item = view->items_count - 1; rtgui_list_view_update_icon(view, old_item); } return RT_FALSE; case RTGUIK_RETURN: if (view->items[view->current_item].action != RT_NULL) { view->items[view->current_item].action(view->items[view->current_item].parameter); } return RT_FALSE; default: break; } } } return RT_FALSE; } /* use view event handler */ return rtgui_view_event_handler(widget, event); }
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; struct rtgui_rect rect; rtgui_image_t *background; /* draw child */ rtgui_view_event_handler(widget, event); dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; rtgui_widget_get_rect(widget, &rect); /* draw background */ background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE); if (background != RT_NULL) { rtgui_image_blit(background, dc, &rect); rtgui_image_destroy(background); } else { rtgui_dc_fill_rect(dc, &rect); } /* draw playing information */ player_update_tag_info(); rtgui_dc_end_drawing(dc); return RT_FALSE; } else if (event->type == RTGUI_EVENT_KBD) { struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN) { if ((ekbd->key == RTGUIK_LEFT) || (ekbd->key == RTGUIK_RIGHT)) { if (player_mode == PLAYER_STOP) { rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE); } else { rt_device_t dev = rt_device_find("snd"); if (ekbd->key == RTGUIK_LEFT && radio_setup.default_volume > 0) { radio_setup.default_volume--; rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume); } else if (ekbd->key == RTGUIK_RIGHT && radio_setup.default_volume < CODEC_VOLUME_MAX) { radio_setup.default_volume++; rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume); } } } else { return RTGUI_WIDGET(music_listbox)->event_handler(RTGUI_WIDGET(music_listbox), event); } } return RT_FALSE; } else if (event->type == RTGUI_EVENT_MOUSE_BUTTON) { struct rtgui_event_mouse* emouse; emouse = (struct rtgui_event_mouse*)event; if (emouse->button & RTGUI_MOUSE_BUTTON_UP) { if (rtgui_rect_contains_point(&next_btn_rect, emouse->x, emouse->y) == RT_EOK) player_onbutton(NEXT_BUTTON); else if (rtgui_rect_contains_point(&prev_btn_rect, emouse->x, emouse->y) == RT_EOK) player_onbutton(PREV_BUTTON); else if (rtgui_rect_contains_point(&playing_btn_rect, emouse->x, emouse->y) == RT_EOK) player_onbutton(PLAYING_BUTTON); } } else if (event->type == RTGUI_EVENT_COMMAND) { struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event; switch (ecmd->command_id) { case PLAYER_REQUEST_PLAY_SINGLE_FILE: case PLAYER_REQUEST_PLAY_LIST: rtgui_timer_start(info_timer); return RT_TRUE; case PLAYER_REQUEST_STOP: { struct play_item *item = RT_NULL; /* if it's radio mode, set next mode to stop */ if (player_mode == PLAYER_PLAY_RADIO) next_step = PLAYER_STEP_STOP; /* set player mode */ player_mode = PLAYER_STOP; switch (next_step) { case PLAYER_STEP_NEXT: /* play next */ item = play_list_next(play_list_get_mode()); break; case PLAYER_STEP_PREV: /* play prev */ item = play_list_prev(play_list_get_mode()); break; case PLAYER_STEP_SEEK: /* play current item */ item = play_list_current(); } if (item != RT_NULL) player_play_item(item); else { player_mode = PLAYER_STOP; rtgui_timer_stop(info_timer); } /* update tag information */ player_update_tag_info(); } return RT_TRUE; case PLAYER_REQUEST_FREEZE: { /* stop play */ if (player_is_playing() == RT_TRUE) { player_stop(); } /* delay some tick */ rt_thread_delay(50); /* show a modal view */ { rtgui_view_t *view; rtgui_label_t *label; rtgui_rect_t rect = {0, 0, 150, 150}, container_rect; rtgui_graphic_driver_get_default_rect(&container_rect); /* set centre */ rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); view = rtgui_view_create("USB"); rtgui_workbench_add_view(workbench, view); /* set container to window rect */ container_rect = rect; rect.x1 = 0; rect.y1 = 0; rect.x2 = 120; rect.y2 = 20; label = rtgui_label_create("USB 联机中..."); rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_view_show(view, RT_TRUE); /* never reach hear */ } } case PLAYER_REQUEST_UPDATE_INFO: /* update status information */ player_update_tag_info(); return RT_TRUE; default: break; } return RT_FALSE; } return rtgui_view_event_handler(widget, event); }