static rt_bool_t picture_view_event_handler(rtgui_object_t *object, rtgui_event_t *event) { if (event->type == RTGUI_EVENT_PAINT) { struct rtgui_dc* dc; struct rtgui_rect rect; struct rtgui_image* image = RT_NULL; char fn[32]; dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object)); if (dc == RT_NULL) return RT_FALSE; rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect); /* open image */ rt_snprintf(fn, sizeof(fn), "%s/%s", PICTURE_DIR, current_fn); rt_kprintf("pic fn: %s\n", fn); if (strstr(fn, ".hdc") != RT_NULL || strstr(fn, ".HDC") != RT_NULL) { image = rtgui_image_create_from_file("hdc", fn, RT_FALSE); } else if (strstr(fn, ".bmp") != RT_NULL || strstr(fn, ".BMP") != RT_NULL) { image = rtgui_image_create_from_file("bmp", 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; } return rtgui_container_event_handler(object, event); }
void demo_bitmap_open(struct rtgui_object* object, struct rtgui_event* event) { char *str; rtgui_button_t *button = RTGUI_BUTTON(object); /* 从textbox控件中取得文件名 */ str = (char*)rtgui_textbox_get_value(bmpdt.box); if(str == RT_NULL) return; if(*str == '/' && (rt_strstr(str, ".bmp")!=RT_NULL || rt_strstr(str, ".BMP")!=RT_NULL)) { /* 如果是bmp文件, 且文件名有效, 则读入图像数据 */ if(bmpdt.filename != RT_NULL) rt_free(bmpdt.filename); bmpdt.filename = rt_strdup(str); if(bmpdt.image != RT_NULL) rtgui_image_destroy(bmpdt.image); bmpdt.image = rtgui_image_create_from_file("bmp", bmpdt.filename, RT_TRUE); if(bmpdt.image != RT_NULL) { bmpdt.showimg = bmpdt.image; bmpdt.scale = 1.0; bmpdt.angle = 0.0; rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox)); } } else rt_kprintf("Bad filename!"); }
static void today_entry(void* parameter) { rt_mq_t mq; struct rtgui_view* view; struct rtgui_workbench* workbench; mq = rt_mq_create("qToday", 256, 4, RT_IPC_FLAG_FIFO); rtgui_thread_register(rt_thread_self(), mq); /* create background image */ background = rtgui_image_create_from_file("png", "/bg.png", RT_FALSE); workbench = rtgui_workbench_create("main", "workbench"); if (workbench == RT_NULL) return; view = rtgui_view_create("Today"); rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler); rtgui_workbench_add_view(workbench, view); rtgui_view_show(view); rtgui_workbench_event_loop(workbench); rtgui_thread_deregister(rt_thread_self()); rt_mq_delete(mq); }
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 void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event) { rtgui_filelist_view_t *view; rtgui_workbench_t *workbench; rtgui_rect_t rect; /* 获得顶层的workbench */ workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget)); rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); /* WIN32平台上和真实设备上的初始路径处理 */ #ifdef _WIN32 view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect); #else view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect); #endif /* 模态显示一个文件列表视图,以提供给用户选择图像文件 */ if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK) { char path[32], image_type[8]; /* 设置文件路径的标签 */ rtgui_filelist_view_get_fullpath(view, path, sizeof(path)); if (image != RT_NULL) { rtgui_image_destroy(image); image = RT_NULL; } rt_memset(image_type, 0, sizeof(image_type)); /* 获得图像的类型 */ if (rt_strstr(path, ".bmp") != RT_NULL || rt_strstr(path, ".BMP") != RT_NULL) strcat(image_type, "bmp"); if (rt_strstr(path, ".png") != RT_NULL || rt_strstr(path, ".PNG") != RT_NULL) strcat(image_type, "png"); if (rt_strstr(path, ".jpg") != RT_NULL || rt_strstr(path, ".JPG") != RT_NULL) strcat(image_type, "jpeg"); if (rt_strstr(path, ".hdc") != RT_NULL || rt_strstr(path, ".HDC") != RT_NULL) strcat(image_type, "hdc"); /* 如果图像文件有效,创建相应的rtgui_image对象 */ if (image_type[0] != '\0') image = rtgui_image_create_from_file(image_type, path, RT_TRUE); } /* 删除 文件列表 视图 */ rtgui_view_destroy(RTGUI_VIEW(view)); rtgui_view_show(_view, 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 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); }