示例#1
0
static void rtgui_list_view_onicondraw(struct rtgui_list_view *view, struct rtgui_dc *dc)
{
    struct rtgui_rect rect, item_rect, drawing_rect;
    rt_ubase_t c, r, item_index; /* col and row index */
    rt_ubase_t item_width, item_height;
    rtgui_image_t *image;

    if (view->items_count == 0) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    item_index = (view->current_item / view->page_items) * view->page_items;

    item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / view->col_items;
    item_height = (rtgui_rect_height(rect) - 4) / view->row_items;
    image = view->items[0].image;

    for (r = 0; r < view->row_items; r ++)
    {
        for (c = 0; c < view->col_items; c ++)
        {
            if (item_index < view->items_count)
            {
                item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
                item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
                item_rect.x2 = item_rect.x1 + item_width;
                item_rect.y2 = item_rect.y1 + item_height;

                if (item_index == view->current_item)
                {
                    rtgui_theme_draw_selected(dc, &item_rect);
                }

                drawing_rect.x1 = drawing_rect.y1 = 0;
                drawing_rect.x2 = image->w;
                drawing_rect.y2 = image->h;
                rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
                drawing_rect.y1 += 5;
                drawing_rect.y2 += 5;
                rtgui_image_blit(view->items[item_index].image, dc, &drawing_rect);

                item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
                item_rect.x1 += 3;
                item_rect.x2 -= 3;
                rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[item_index].name,
                                       &drawing_rect);
                rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
                rtgui_dc_draw_text(dc, view->items[item_index].name, &drawing_rect);

                item_index ++;
            }
            else break;
        }
    }
}
示例#2
0
static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
{
    struct rtgui_win *menu;
    rtgui_rect_t screen, rect = {0, 0, 140, 85};

    rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen);
    rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);

    menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)),
                            "Folder Menu", &rect, RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
    if (menu != RT_NULL)
    {
        rtgui_listbox_t *listbox;
        /* Pass the pointer to filelist_view via user_data. */
        menu->user_data = (rt_uint32_t)parent;

        rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate);

        listbox = rtgui_listbox_create(_folder_actions,
                                       sizeof(_folder_actions) / sizeof(_folder_actions[0]),
                                       &rect);
        /* Set the item index *before* setup the callback. `set_current_item`
         * will invoke the "onitem". So just keep it clean when setting the
         * current item. */
        rtgui_listbox_set_current_item(listbox, 0);
        rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);

        rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));

        rtgui_win_show(menu, RT_TRUE);
    }
}
示例#3
0
static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
{
	rtgui_win_t *menu;
	rtgui_listbox_t *listbox;
	rtgui_rect_t screen, rect = {0, 0, 140, 85};

	rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen);
	rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);

	menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)),
							"Folder Menu", &rect, RTGUI_WIN_STYLE_DEFAULT);
	if (menu != RT_NULL)
	{
		/* set user data on menu window */
		menu->user_data = (rt_uint32_t)parent;

		rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate);

		listbox = rtgui_listbox_create(items, sizeof(items)/sizeof(items[0]), &rect);
		rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);
		rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));
		rtgui_win_show(menu, RT_FALSE);
		rtgui_widget_focus(RTGUI_WIDGET(listbox));
		rtgui_listbox_set_current_item(listbox, 0);
	}
}
示例#4
0
/* 触发无标题窗口显示 */
static void demo_ntitlewin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
{
	rtgui_win_t *win;
	rtgui_label_t *label;
	rtgui_button_t *button;
	rtgui_toplevel_t *parent;
	rtgui_rect_t widget_rect, rect = {0, 0, 150, 80};

	parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
	rtgui_rect_moveto(&rect, delta_x, delta_y);
	delta_x += 20;
	delta_y += 20;

	/* 创建一个窗口,风格为无标题及无边框 */
	win = rtgui_win_create(parent,
		"no title", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win)) = white;

	/* 创建一个文本标签 */
	label = rtgui_label_create("无边框窗口");
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)), "无边框窗口", &widget_rect);
	rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	widget_rect.y1 += 20;
	widget_rect.y2 += 20;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &widget_rect);
	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white;

	/* 创建一个关闭按钮 */
	widget_rect.x1 = 0;
	widget_rect.y1 = 0;
	widget_rect.x2 = 40;
	widget_rect.y2 = 20;
	rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	widget_rect.y1 += 40;
	widget_rect.y2 += 40;
	button = rtgui_button_create("关闭");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button));
	rtgui_button_set_onbutton(button, window_demo_close);

	/* 非模态显示窗口 */
	rtgui_win_show(win, RT_FALSE);
}
示例#5
0
文件: apps_list.c 项目: amsl/RTGUI
static void _app_info_draw(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index)
{
	struct rtgui_image *image;
	rtgui_rect_t item_rect, image_rect;
	struct rtgui_application_item *item, *items;

	item_rect = *rect;
	item_rect.x1 += 5;

	/* draw item */
	items = (struct rtgui_application_item*)list->items;
	item = &items[index];

	/* draw image */
	if (item->app->icon != RT_NULL) image = item->app->icon;
	else image = app_default_icon;

	if (image != RT_NULL)
	{
		image_rect.x1 = image_rect.y1 = 0;
		image_rect.x2 = app_default_icon->w;
		image_rect.y2 = app_default_icon->h;

		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_image_blit(image, dc, &image_rect);
	}
	item_rect.x1 += app_default_icon->w + RTGUI_WIDGET_DEFAULT_MARGIN;

	/* draw text */
	rtgui_dc_draw_text(dc, (const char*)item->app->name, &item_rect); item_rect.x1 += 60;

	if (list->current_item == index)
	{
		/* draw close button */
		image_rect.x1 = image_rect.y1 = 0;
		image_rect.x2 = app_close->w;
		image_rect.y2 = app_close->h;

		item_rect.x1 = item_rect.x2 - 50;
		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_image_blit(app_close, dc, &image_rect);
	}
}
示例#6
0
static void rtgui_list_view_onlistdraw(struct rtgui_list_view *view, struct rtgui_dc *dc)
{
    rt_ubase_t index, page_index;
    rtgui_rect_t rect, item_rect, image_rect;
    const struct rtgui_list_item *item;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    /* get item base rect */
    item_rect = rect;
    item_rect.y1 += 2;
    item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

    /* get current page */
    page_index = (view->current_item / view->page_items) * view->page_items;
    for (index = 0; index < view->page_items; index ++)
    {
        if (page_index + index >= view->items_count) break;

        item = &(view->items[page_index + index]);

        if (page_index + index == view->current_item)
        {
            rtgui_theme_draw_selected(dc, &item_rect);
        }
        item_rect.x1 += LIST_MARGIN;

        if (item->image != RT_NULL)
        {
            /* blit on center */
            image_rect.x1 = 0;
            image_rect.y1 = 0;
            image_rect.x2 = item->image->w;
            image_rect.y2 = item->image->h;

            rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
            rtgui_image_blit(item->image, dc, &image_rect);
            item_rect.x1 += item->image->w + 2;
        }
        /* draw text */
        rtgui_dc_draw_text(dc, item->name, &item_rect);

        if (item->image != RT_NULL)
            item_rect.x1 -= (item->image->w + 2);
        item_rect.x1 -= LIST_MARGIN;

        /* move to next item position */
        item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
        item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
    }
}
static void _rtgui_menu_item_ondraw(struct rtgui_listctrl *list,
									struct rtgui_dc* dc,
									rtgui_rect_t* rect,
									rt_uint16_t index)
{
	rtgui_rect_t item_rect;
	struct rtgui_menu_item* item;

	item_rect = *rect;
	item_rect.x1 += 5;

	/* re-fill item */
	if (list->current_item == index)
	{
		rtgui_color_t bc;

		bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(list));
		RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(list)) = blue;
		rtgui_dc_fill_rect(dc, rect);
		RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(list)) = bc;
	}

	/* get menu item */
	item = (rtgui_menu_item_t*)list->items;
	item = &item[index];

	if (item->type == RTGUI_ITEM_SUBMENU)
	{
		rtgui_rect_t r = {0, 0, 8, 8};
		rtgui_dc_draw_text(dc, item->label, &item_rect);
		item_rect.x1 = item_rect.x2 - 16; item_rect.x2 -= 8;
		rtgui_rect_moveto_align(&item_rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, r.x1, r.y1, 8, right_arrow);
	}
	else if (item->type == RTGUI_ITEM_SEPARATOR)
	{
		rtgui_dc_draw_horizontal_line(dc, item_rect.x1, item_rect.x2, (item_rect.y2 + item_rect.y1)/2);
	}
	else if (item->type == RTGUI_ITEM_CHECK)
	{
		/* not support right now */
	}
	else
	{
		/* normal menu item */	
		rtgui_dc_draw_text(dc, item->label, &item_rect);
		if (item->image != RT_NULL)
			rtgui_image_blit(item->image, dc, &item_rect);
	}
}
示例#8
0
static int draw_form_head(struct rtgui_form *form, const struct rtgui_font *font,
						  struct rtgui_dc* dc, struct rtgui_rect *rect, struct rtgui_rect *row_rect, char *buf)
{
	struct rtgui_rect form_rect;
	char *pch1;
	const char *pch2;
	int i, j, len;
#if 0
	form_debug(("func:%s, (%d,%d), (%d,%d),bytes:%d, h:%d, r:%d\n", __FUNCTION__,
				rect->x1, rect->y1, rect->x2, rect->y2, form->bytes_of_row, font->height, form->row_cnt_of_fbody));
#endif
	form_rect.x1 = 0;
	form_rect.y1 = 0;
	form_rect.x2 = (form->bytes_of_row + GAG_BETWEEN_COL*form->head_item_cnt) * 8;
	form_rect.y2 = (font->height + GAG_BETWEEN_ROW) * (form->row_cnt_of_fbody + 1);
	rtgui_rect_moveto_align(rect, &form_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	form_rect.y1 += GAG_BEFORE_FORM_HEAD;
	form_rect.y2 += GAG_BEFORE_FORM_HEAD;

	if (0xffff == form->form_rect.x1) {
		form->form_rect = form_rect;
	}

	j = form->head_item_cnt;
	pch1 = buf;
	for (i=0; i<j; ++i) {
		pch2 = form->head_name[i];
		while ('\0' != *pch2)
			*pch1++ = *pch2++;

		/* 用空格填充列间隔 */
		len = GAG_BETWEEN_COL;
		while (len--)
			*pch1++ = ' ';
	}
	*--pch1 = '\0';

	row_rect->x1 = form_rect.x1;
	row_rect->y1 = form_rect.y1;
	row_rect->x2 = form_rect.x2;
	row_rect->y2 = form_rect.y1 + font->height;
#if 0
	form_debug(("func:%s, (%d,%d), (%d,%d),hic:%d, len:%d, buf:%s\n", __FUNCTION__,
				row_rect->x1, row_rect->y1, row_rect->x2,row_rect->y2,j,pch1 -buf, buf));
#endif
	rtgui_dc_draw_text(dc, buf, row_rect);
	rtgui_dc_draw_horizontal_line(dc, row_rect->x1, row_rect->x2, row_rect->y2+1);

	return SUCC;
}
static void rtgui_combobox_ondraw(struct rtgui_combobox* box)
{
    /* draw button */
    rtgui_color_t bc;
    struct rtgui_dc* dc;
    struct rtgui_rect rect, r;

    /* begin drawing */
    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
    if (dc == RT_NULL) return;

    bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box));

    /* get widget rect */
    rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
    RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = white;

    /* fill widget rect with background color */
    rtgui_dc_fill_rect(dc, &rect);
    rtgui_dc_draw_rect(dc, &rect);

    /* draw current item */
    if (box->current_item < box->items_count)
    {
        rect.x1 += 5;
        rtgui_dc_draw_text(dc, box->items[box->current_item].name, &rect);
    }

    /* restore background color */
    RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = bc;

    /* draw pull down button */
    rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
    rtgui_rect_inflate(&rect, -1);
    rtgui_dc_fill_rect(dc, &rect);
    if (box->pd_pressed == RT_TRUE) rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
    else rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);

    r.x1 = 0;
    r.y1 = 0;
    r.x2 = 8;
    r.y2 = 4;
    rtgui_rect_moveto_align(&rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
    rtgui_dc_draw_byte(dc, r.x1, r.y1, 4, down_arrow);

    /* end drawing */
    rtgui_dc_end_drawing(dc);
    return;
}
void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list,
                               struct rtgui_dc *dc,
                               rtgui_rect_t *rect,
                               rt_uint16_t index)
{
    char age_str[8];
    rtgui_rect_t item_rect;
    struct list_item *items, *item;

    item_rect = *rect;
    item_rect.x1 += 5;
    items = (struct list_item *)list->items;
    item = &items[index];

    /* draw text */
    rtgui_dc_draw_text(dc, item->name, &item_rect);
    item_rect.x1 += 60;
    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);

    item_rect.x1 += 5;
    rtgui_dc_draw_text(dc, item->gender, &item_rect);
    item_rect.x1 += 60;
    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);

    item_rect.x1 += 5;
    rt_snprintf(age_str, sizeof(age_str), "%d", item->age);
    rtgui_dc_draw_text(dc, age_str, &item_rect);
    item_rect.x1 += 40;
    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);

    item_rect.x1 += 5;

    /* draw image */
    if (item->image != RT_NULL)
    {
        rtgui_rect_t image_rect;

        image_rect.x1 = 0;
        image_rect.y1 = 0;
        image_rect.x2 = item->image->w;
        image_rect.y2 = item->image->h;
        rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
        rtgui_image_blit(item->image, dc, &image_rect);
    }
}
示例#11
0
static struct app_list_view *app_list_create(rtgui_rect_t *rect,
                                             struct app_item *items,
                                             rt_uint16_t item_count,
                                             rt_uint8_t row_items,
                                             rt_uint8_t col_items,
                                             rtgui_image_t *bg_image)
{
    struct app_list_view *view = RT_NULL;
    view = (struct app_list_view *)rtgui_malloc(sizeof(struct app_list_view));
    view->rect = *rect;
    view->view_rect.x1 = rect->x1;
    view->view_rect.x2 = rect->x2;
    view->view_rect.y1 = rect->y1 + 4 * LIST_MARGIN;
    view->view_rect.y2 = rect->y2 - 6 * LIST_MARGIN;
    view->col_items = col_items;
    view->row_items = row_items;
    view->current_page = 0;
    view->old_page = 0;
    view->page_items = col_items * row_items;
    view->page_count = (item_count + view->page_items - 1) / view->page_items;
    view->current_item = -1;
    view->items = items;
    view->items_count = item_count;
    if (bg_image != RT_NULL)
    {
        rtgui_rect_t bg_rect;

        RTGUI_RECT(bg_rect, 0, 0, bg_image->w, bg_image->h);
        /* create background dc buffer */
        view->bg_buffer = rtgui_dc_buffer_create(bg_image->w, bg_image->h);
        /* draw background image to buffer */
        rtgui_image_blit(bg_image, view->bg_buffer, &bg_rect);
    }
    /* create the main menu dc buffer */
    view->view_buffer =
        rtgui_dc_buffer_create_pixformat(RTGRAPHIC_PIXEL_FORMAT_ARGB888,
                                         rtgui_rect_width(view->view_rect) *
                                         view->page_count,
                                         rtgui_rect_height(view->view_rect));
    RTGUI_DC_BC(view->view_buffer) = RTGUI_ARGB(0, 0, 0, 0);

    view->pm_rect.x1 = 0;
    view->pm_rect.y1 = rect->y2 - 6 * LIST_MARGIN;
    view->pm_rect.x2 = PAGE_MARK_ITEM_WIDTH * view->page_count + PAGE_MARK_MARGIN *
                       (view->page_count - 1);
    view->pm_rect.y2 = view->pm_rect.y1 + PAGE_MARK_ITEM_HEIGHT;

    view->pm_buffer =
        rtgui_dc_buffer_create_pixformat(RTGRAPHIC_PIXEL_FORMAT_ARGB888,
                                         rtgui_rect_width(view->pm_rect) ,
                                         rtgui_rect_height(view->pm_rect));
    rtgui_rect_moveto_align(rect, &view->pm_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);

    RTGUI_DC_BC(view->pm_buffer) = RTGUI_ARGB(0, 0, 0, 0);

    view->bgdisp_point.x = 0;
    view->bgdisp_point.y = 0;
    view->listdisp_point.x = 0;
    view->listdisp_point.y = 0;
    view->on_select = RT_NULL;
    return view;
}
示例#12
0
文件: fileview.c 项目: amsl/RTGUI
/* update fileview */
void rtgui_fileview_update_current(rtgui_fileview_t* fview)
{
	rtgui_fileview_item_t *item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t *dc;

	RT_ASSERT(fview != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(fview);
	if(dc == RT_NULL)return;

	/* if directory is null, no dispost */
	if(fview->items==RT_NULL)return;

	rtgui_widget_get_rect(fview, &rect);
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	if((fview->old_item >= fview->first_item) &&
	        (fview->old_item < fview->first_item+fview->item_per_page) &&
	        (fview->old_item != fview->now_item))
	{
		/* these condition dispell blinked when drawed */
		/* get old item rect */
		item_rect = rect;
		item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += ((fview->old_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
		item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

		/* get image rect */
		image_rect.x1 = RTGUI_MARGIN;
		image_rect.y1 = 0;
		image_rect.x2 = RTGUI_MARGIN + file_image->w;
		image_rect.y2 = file_image->h;
		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

		/* draw old item */
		item = &(fview->items[fview->old_item]);
		if(item->type == RTGUI_FITEM_FILE) /* draw item image */
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect,Black);

		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		RTGUI_DC_BC(dc) = theme.blankspace;
		RTGUI_DC_FC(dc) = theme.foreground;
		rtgui_dc_fill_rect(dc,&item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}
	/* draw current item */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += ((fview->now_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_MARGIN + file_image->w;
	image_rect.y2 = file_image->h;
	rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

	item = &(fview->items[fview->now_item]);
	if(item->type == RTGUI_FITEM_FILE) /* draw item image */
		rtgui_image_paste(file_image, dc, &image_rect, Black);
	else
		rtgui_image_paste(folder_image, dc, &image_rect, Black);

	if(fview->dlg != RT_NULL)
	{
		if(fview->dlg->filename != RT_NULL)
		{
			rt_free(fview->dlg->filename);
			fview->dlg->filename = RT_NULL;
		}
		fview->dlg->filename = rt_strdup(item->name);
	}

	item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
	item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);

	{
		if(RTGUI_WIDGET_IS_FOCUSED(fview))
		{
			RTGUI_DC_BC(dc) = DarkBlue;
			RTGUI_DC_FC(dc) = theme.blankspace;
		}
		else
		{
			RTGUI_DC_BC(dc) = Gray;
			RTGUI_DC_FC(dc) = theme.foreground;
		}
		rtgui_dc_fill_rect(dc, &item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}

	if(fview->dlg != RT_NULL)
	{
		if(item->type == RTGUI_FITEM_FILE)
		{
			if(fview->dlg->tbox_filename != RT_NULL)
			{
				rtgui_textbox_set_value(fview->dlg->tbox_filename,fview->dlg->filename);
				RTGUI_DC_FC(dc) = theme.foreground;
				rtgui_textbox_ondraw(fview->dlg->tbox_filename);
			}
		}
	}

	rtgui_dc_end_drawing(dc);
}
示例#13
0
void rtgui_filelist_view_ondraw(struct rtgui_filelist_view *view)
{
    struct rtgui_dc *dc;
    rt_uint16_t page_index, index;
    struct rtgui_file_item *item;
    struct rtgui_rect rect, item_rect, image_rect;

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_dc_fill_rect(dc, &rect);

    /* get item base rect */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    /* get image base rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    /* get current page */
    page_index = (view->current_item / view->page_items) * view->page_items;
    for (index = 0; index < view->page_items; index ++)
    {
        if (page_index + index >= view->items_count) break;

        item = &(view->items[page_index + index]);

        if (page_index + index == view->current_item)
        {
            rtgui_theme_draw_selected(dc, &item_rect);
        }
        else
        {
            /* draw background */
            rtgui_dc_fill_rect(dc, &item_rect);
        }

        /* draw item */
        if (item->type == RTGUI_FITEM_FILE)
            rtgui_image_blit(file_image, dc, &image_rect);
        else
            rtgui_image_blit(folder_image, dc, &image_rect);

        /* draw text */
        item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
        rtgui_dc_draw_text(dc, item->name, &item_rect);
        item_rect.x1 -= RTGUI_FILELIST_MARGIN + file_image->w + 2;

        /* move to next item position */
        item_rect.y1 += (rtgui_theme_get_selected_height() + 1);
        item_rect.y2 += (rtgui_theme_get_selected_height() + 1);

        image_rect.y1 += (rtgui_theme_get_selected_height() + 1);
        image_rect.y2 += (rtgui_theme_get_selected_height() + 1);
    }

    rtgui_dc_end_drawing(dc);
}
void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar)
{
	/* draw scroll bar */
	struct rtgui_dc* dc;
	rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
	rtgui_color_t bc, fc;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(&(bar->parent));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);

	/* draw background */
	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar));
	if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(128, 128, 128);

	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar));
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = white;
	rtgui_dc_fill_rect(dc, &rect);

	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = bc;

	if (bar->orient == RTGUI_VERTICAL)
	{
		btn_rect = rect;
		btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);

		/* draw up button */
		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		/* draw arrow */
		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _up_arrow);

		/* draw thumb */
		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		{
			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
			rtgui_dc_fill_rect(dc, &thum_rect);
			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		}

		/* draw down button */
		btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
		btn_rect.y2 = rect.y2;

		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _down_arrow);
	}
	else
	{
		btn_rect.x1 = rect.x1;
		btn_rect.y1 = rect.y1;
		btn_rect.x2 = rect.y2;
		btn_rect.y2 = rect.y2;

		/* draw left button */
		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _left_arrow);

		/* draw thumb */
		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		{
			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
			rtgui_dc_fill_rect(dc, &thum_rect);
			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		}

		btn_rect.x1 = rect.x2 - rect.y2;
		btn_rect.x2 = rect.x2;

		/* draw right button */
		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _right_arrow);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = fc;

	return;
}
示例#15
0
文件: fileview.c 项目: amsl/RTGUI
void rtgui_fileview_ondraw(rtgui_fileview_t* fview)
{
	rt_uint16_t first, i,rx2;
	rtgui_fileview_item_t* item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t* dc;

	RT_ASSERT(fview != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(fview);
	if(dc == RT_NULL)return;

	rtgui_widget_get_rect(fview, &rect);
	rtgui_dc_draw_border(dc, &rect,RTGUI_WIDGET_BORDER_STYLE(fview));
	rtgui_rect_inflate(&rect,-RTGUI_WIDGET_BORDER_SIZE(fview));
	RTGUI_DC_BC(dc) = theme.blankspace;
	rtgui_dc_fill_rect(dc,&rect);
	rtgui_rect_inflate(&rect,RTGUI_WIDGET_BORDER_SIZE(fview));
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	rect.x2 -=1;
	rect.y2 -= 1;

	/* get item base rect */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	rx2 = item_rect.x2;
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_MARGIN + file_image->w;
	image_rect.y2 = file_image->h;
	rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

	/* get current page */
	first = fview->first_item;
	for(i = 0; i < fview->item_per_page; i ++)
	{
		char str_size[32];

		if(first + i >= fview->item_count) break;

		item = &(fview->items[first + i]);

		/* draw item image */
		if(item->type == RTGUI_FITEM_FILE)
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect, Black);

		/* draw text */
		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		if(first + i == fview->now_item)
		{
			if(RTGUI_WIDGET_IS_FOCUSED(fview))
			{
				RTGUI_DC_BC(dc) = DarkBlue;
				RTGUI_DC_FC(dc) = theme.blankspace;
			}
			else
			{
				RTGUI_DC_BC(dc) = Gray;
				RTGUI_DC_FC(dc) = theme.foreground;
			}
			rtgui_dc_fill_rect(dc, &item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}
		else
		{
			/* draw background */
			RTGUI_DC_BC(dc) = theme.blankspace;
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_fill_rect(dc,&item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}

#if (1) /* please turn off it when need. */
		if(item->type == RTGUI_FITEM_FILE)
		{
			rtgui_rect_t rect=item_rect;
			/* print file information */
			rt_snprintf(str_size, 16, "(%dB)",item->size);
			rect.x1 = rect.x2 + RTGUI_MARGIN;
			rect.x2 = rect.x1 + rt_strlen(str_size) * FONT_W(RTGUI_WIDGET_FONT(fview));
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_draw_text(dc, str_size, &rect);
		}
#endif
		item_rect.x1 -= RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = rx2;
		/* move to next item position */
		item_rect.y1 += (RTGUI_SEL_H + 1);
		item_rect.y2 += (RTGUI_SEL_H + 1);

		image_rect.y1 += (RTGUI_SEL_H + 1);
		image_rect.y2 += (RTGUI_SEL_H + 1);
	}

	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
	{
		rtgui_scrollbar_ondraw(fview->sbar);
	}

	rtgui_dc_end_drawing(dc);
}
void rtgui_theme_draw_checkbox(struct rtgui_checkbox* checkbox)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, box_rect;
	rtgui_color_t bc, fc;

	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox));
	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox));

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(checkbox));
	if (dc == RT_NULL) return;

	/* get rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(checkbox), &rect);

    /* fill rect */
	rtgui_dc_fill_rect(dc, &rect);

	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(checkbox)))
	{
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = black;

		/* draw focused border */
		rtgui_rect_inflate(&rect, -1);
		rtgui_dc_draw_focus_rect(dc, &rect);

		rtgui_rect_inflate(&rect, 1);
	}

	/* draw check box */
	box_rect.x1 = 0;
	box_rect.y1 = 0;
	box_rect.x2 = CHECK_BOX_W;
	box_rect.y2 = CHECK_BOX_H;
	rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL);
	box_rect.x1 += 2; box_rect.x2 += 2;

	rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_BOX);
	rtgui_rect_inflate(&box_rect, -1);
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox)) = RTGUI_RGB(247, 247, 246);
	rtgui_dc_fill_rect(dc, &box_rect);
	if (checkbox->status_down == RTGUI_CHECKBOX_STATUS_CHECKED)
	{
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = RTGUI_RGB(33, 161, 33);
		rtgui_dc_draw_byte(dc, box_rect.x1 + 2, box_rect.y1 + 2, 7, checked_byte);
	}

	/* restore saved color */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox)) = bc;
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = fc;

	/* draw text */
	rect.x1 += rtgui_rect_height(rect) - 4 + 5;
	rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(checkbox)), &rect);

	/* end drawing */
	rtgui_dc_end_drawing(dc);

	return;
}
/* window drawing */
void rtgui_theme_draw_win(struct rtgui_topwin* win)
{
	struct rtgui_dc* dc;
	rtgui_rect_t rect;

	if (win->title == RT_NULL) return; /* no title and no board */

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win->title));
	if (dc == RT_NULL) return;

	/* get rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(win->title), &rect);

	/* draw border */
	if (win->flag & WINTITLE_BORDER)
	{
		rect.x2 -= 1; rect.y2 -= 1;
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(212, 208, 200);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
		rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = white;
		rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2 - 1, rect.y1 + 1);
		rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1 + 1, rect.y2 - 1);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(128, 128, 128);
		rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2 - 1, rect.y2 - 1);
		rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2 - 1);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(64, 64, 64);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
		rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2);

		/* shrink border */
		rtgui_rect_inflate(&rect, -WINTITLE_BORDER_SIZE);
	}

	/* draw title */
	if (!(win->flag & WINTITLE_NO))
	{
		rt_uint32_t index;
		float r, g, b, delta;

		if (win->flag & WINTITLE_ACTIVATE)
		{
			r = 10; g = 36; b = 106;
			delta = 150 / (float)(rect.x2 - rect.x1);
		}
		else
		{
			r = 128; g = 128; b = 128;
			delta = 64 / (float)(rect.x2 - rect.x1);
		}

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(r, g, b);
		for (index = rect.x1; index < rect.x2 + 1; index ++)
		{
			rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
			r += delta; g += delta; b += delta;
		}

		if (win->flag & WINTITLE_ACTIVATE)
		{
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = white;
		}
		else
		{
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(212, 208, 200);
		}

		rect.x1 += 4;
		rect.y1 += 2; rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT;
		rtgui_dc_draw_text(dc, rtgui_wintitle_get_title(win->title), &rect);

		if (win->flag & WINTITLE_CLOSEBOX)
		{
			/* get close button rect */
			rtgui_rect_t box_rect = {0, 0, WINTITLE_CB_WIDTH, WINTITLE_CB_HEIGHT};
			rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_RIGHT);
			box_rect.x1 -= 3; box_rect.x2 -= 3;
			rtgui_dc_fill_rect(dc, &box_rect);

			/* draw close box */
			if (win->flag & WINTITLE_CB_PRESSED)
			{
				rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_SUNKEN);
				RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = red;
				rtgui_dc_draw_word(dc, box_rect.x1, box_rect.y1 + 6, 7, close_byte);
			}
			else
			{
				rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_RAISE);
				RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = black;
				rtgui_dc_draw_word(dc, box_rect.x1 - 1, box_rect.y1 + 5, 7, close_byte);
			}
		}
	}

	rtgui_dc_end_drawing(dc);
}
示例#18
0
rt_bool_t rtgui_digtube_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
	struct rtgui_digtube *digtube;
    struct rtgui_dc *dc;
    rtgui_rect_t rect;
    rtgui_rect_t text_rect;
	rtgui_color_t color = 0;
	char * disbuf;
	char tempbuf[8];
	int i;

	RTGUI_WIDGET_EVENT_HANDLER_PREPARE

	digtube = RTGUI_DIGTUBE(object);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:

	    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
		if (dc == RT_NULL)
			break;
		rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
		rtgui_dc_fill_rect(dc, &rect);

		if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
		{
			color = RTGUI_DC_BC(dc);
			RTGUI_DC_BC(dc) = digtube->digit_bc;
		}
		
		if (digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISCODES)
			disbuf = (char *) (digtube->value);
		else
		{
			const char * format =  
				digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISHEXNUM ? 
				"%7x" : "%7d";

			disbuf = &tempbuf[0];
			rt_snprintf(disbuf, 8, format, digtube->value);
			
			/* */
			for (i=0; i<7; i++)
			{
				if (disbuf[i] == ' ')
					disbuf[i] = 0;
				else
				{
					disbuf[i] = (disbuf[i] >= '0' && disbuf[i] <= '9') ? disbuf[i] - '0':
						disbuf[i] - 'a' + 10;

					disbuf[i] = digtube_code_table[disbuf[i]];
				}
			}

			disbuf = tempbuf + 7 - digtube->tube_count;
		}

		text_rect.x1 = 0;
		text_rect.y1 = 0;
		text_rect.x2 = (digtube->digit_width + digtube->digit_space) * digtube->tube_count
		                -digtube->digit_space;
		text_rect.y2 = digtube->digit_hight;

		rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
		for (i=0; i<digtube->tube_count; i++)
		{
			rtgui_dc_draw_digitfont_code(dc, &digtube->digitfont, &text_rect, disbuf[i]);
			text_rect.x1 += digtube->digit_width + digtube->digit_space;
		}

		if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
			RTGUI_DC_BC(dc) = color;
		rtgui_dc_end_drawing(dc);
		break;
	default:
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
/* widget drawing */
void rtgui_theme_draw_button(rtgui_button_t* btn)
{
	/* draw button */
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
	rtgui_color_t bc, fc;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(btn));
	if (dc == RT_NULL) return;

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);

	/* get foreground color */
	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn));
	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn));

	if (btn->flag & RTGUI_BUTTON_TYPE_PUSH && btn->flag & RTGUI_BUTTON_FLAG_PRESS)
	{
		/* fill button rect with background color */
		rtgui_dc_fill_rect(dc, &rect);

		/* draw border */
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(64, 64, 64);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
		rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(128, 128, 128);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2 - 1, rect.y1 + 1);
		rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1 + 1, rect.y2 - 2);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(255, 255, 255);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2 - 1);
		rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1, rect.y2);

		if (btn->pressed_image != RT_NULL)
		{
			rtgui_rect_t image_rect;
			image_rect.x1 = 0; image_rect.y1 = 0;
			image_rect.x2 = btn->unpressed_image->w;
			image_rect.y2 = btn->unpressed_image->h;
			rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);

			rtgui_image_blit(btn->pressed_image, dc, &image_rect);
		}
	}
	else if (btn->flag & RTGUI_BUTTON_FLAG_PRESS)
	{
		if (btn->pressed_image != RT_NULL)
		{
			rtgui_rect_t image_rect;
			image_rect.x1 = 0; image_rect.y1 = 0;
			image_rect.x2 = btn->unpressed_image->w;
			image_rect.y2 = btn->unpressed_image->h;
			rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);

			rtgui_image_blit(btn->pressed_image, dc, &image_rect);
		}
		else
		{
			/* fill button rect with background color */
			RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(0xff, 0xff, 0xff);
			rtgui_dc_fill_rect(dc, &rect);

			/* draw border */
			RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0);
			rtgui_dc_draw_rect(dc, &rect);

			RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128);
			rect.x1 += 1; rect.y1 += 1; rect.x2 -= 1; rect.y2 -= 1;
			rtgui_dc_draw_rect(dc, &rect);
		}
	}
	else
	{
		if (btn->unpressed_image != RT_NULL)
		{
			rtgui_rect_t image_rect;
			image_rect.x1 = 0; image_rect.y1 = 0;
			image_rect.x2 = btn->unpressed_image->w;
			image_rect.y2 = btn->unpressed_image->h;
			rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);

			rtgui_image_blit(btn->unpressed_image, dc, &image_rect);
		}
		else
		{
			/* fill button rect with background color */
			rtgui_dc_fill_rect(dc, &rect);

			/* draw border */
			RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(255, 255, 255);
			rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
			rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);

			RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0);
			rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2);
			rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2);

			RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128);
			rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2, rect.y2 - 1);
			rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2 - 1);
		}
	}

	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(btn)))
	{
		/* re-set foreground and get default rect */
		rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);
		rtgui_rect_inflate(&rect, -2);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = black;
		rtgui_dc_draw_focus_rect(dc, &rect);
	}

	/* set forecolor */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn)) = bc;
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = fc;

	if (btn->pressed_image == RT_NULL)
	{
		/* re-set foreground and get default rect */
		rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);

		/* remove border */
		rtgui_rect_inflate(&rect, -2);

		/* draw text */
		rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(btn)), &rect);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
}
示例#20
0
void rtgui_scrollbar_ondraw(rtgui_scrollbar_t* bar)
{
	/* draw scroll bar */
	rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
	struct rtgui_dc* dc;
	rtgui_color_t bc;

	RT_ASSERT(bar != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(bar));
	if(dc == RT_NULL)return;

	bc = RTGUI_DC_BC(dc);
	/* begin drawing */
	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
	RTGUI_DC_BC(dc) = white;
	rtgui_dc_fill_rect(dc,&rect);
	RTGUI_DC_BC(dc) = bc;

	if(bar->orient == RTGUI_VERTICAL)
	{
		btn_rect = rect;
		btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
		rtgui_dc_fill_rect(dc,&btn_rect);
		/* draw up button */
		if(bar->status & SBS_UPARROW)
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
		/* draw up arrow */
		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _up_arrow);

		/* draw thumb */
		rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
		rtgui_dc_fill_rect(dc,&thum_rect);
		rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		
		/* draw down button */
		btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
		btn_rect.y2 = rect.y2;
		rtgui_dc_fill_rect(dc,&btn_rect);
		if(bar->status & SBS_DOWNARROW)
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
		/* draw down arrow */
		arrow_rect.x1 = 0;
		arrow_rect.y1 = 0;
		arrow_rect.x2 = 7;
		arrow_rect.y2 = 4;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _down_arrow);
	}
	else
	{
		btn_rect = rect;
		btn_rect.x2 = btn_rect.x1 + (rect.y2 - rect.y1);
		rtgui_dc_fill_rect(dc,&btn_rect);
		/* draw left button */
		if(bar->status & SBS_LEFTARROW)
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
		arrow_rect.x1 = 0;
		arrow_rect.y1 = 0;
		arrow_rect.x2 = 4;
		arrow_rect.y2 = 7;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _left_arrow);

		/* draw thumb */
		if(RTGUI_WIDGET_IS_ENABLE(bar))
		{
			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
			rtgui_dc_fill_rect(dc,&thum_rect);
			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		}

		btn_rect.x1 = rect.x2 - (rect.y2-rect.y1);
		btn_rect.x2 = rect.x2;
		rtgui_dc_fill_rect(dc,&btn_rect);
		/* draw right button */
		if(bar->status & SBS_RIGHTARROW)
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else
			rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
		arrow_rect.x1 = 0;
		arrow_rect.y1 = 0;
		arrow_rect.x2 = 4;
		arrow_rect.y2 = 7;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _right_arrow);

	}

	rtgui_dc_end_drawing(dc);
}
示例#21
0
static void app_list_draw(struct app_list_view *view)
{
    struct rtgui_rect item_rect, drawing_rect;
    rt_ubase_t p, c, r, item_index; /* col and row index */
    rt_ubase_t item_width, item_height;
    rtgui_image_t *image;
    rt_uint16_t width, height;

    if (view->items_count == 0)
        return;

    width = rtgui_rect_width(view->view_rect);
    height = rtgui_rect_height(view->view_rect);
    item_index = (view->current_item / view->page_items) * view->page_items;
    item_width = (width - 2 * LIST_MARGIN) / view->col_items;
    item_height = (height - 4) / view->row_items;
    image = view->items[0].icon;
    for (p = 0; p < view->page_count; p++)
    {
        for (r = 0; r < view->row_items; r++)
        {
            for (c = 0; c < view->col_items; c++)
            {
                if (item_index < view->items_count)
                {
                    item_rect.y1 =  r * item_height;
                    item_rect.x1 =  p * width + LIST_MARGIN + c * item_width;
                    item_rect.x2 = item_rect.x1 + item_width;
                    item_rect.y2 = item_rect.y1 + item_height;
                    if (item_index == view->current_item)
                    {
                        //TO DO
                    }
                    if (view->items[item_index].icon)
                    {
                        drawing_rect.x1 = drawing_rect.y1 = 0;
                        drawing_rect.x2 = image->w;
                        drawing_rect.y2 = image->h;
                        rtgui_rect_moveto_align(&item_rect, &drawing_rect,
                                                RTGUI_ALIGN_CENTER_HORIZONTAL);
                        drawing_rect.y1 += 5;
                        drawing_rect.y2 += 5;
                        rtgui_image_blit(view->items[item_index].icon,
                                         view->view_buffer,
                                         &drawing_rect);
                    }
                    if (view->items[item_index].text)
                    {
                        item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
                        item_rect.x1 += 3;
                        item_rect.x2 -= 3;
                        rtgui_font_get_metrics(RTGUI_WIDGET_FONT(win),
                                               view->items[item_index].text,
                                               &drawing_rect);
                        rtgui_rect_moveto_align(&item_rect, &drawing_rect,
                                                RTGUI_ALIGN_CENTER_HORIZONTAL);
                        rtgui_dc_draw_text(view->view_buffer,
                                           view->items[item_index].text,
                                           &drawing_rect);
                    }
                    item_index++;
                }
                else
                    break;
            }
        }
    }
}
示例#22
0
static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_uint16_t old_item)
{
	struct rtgui_rect rect, item_rect, drawing_rect;
	rt_ubase_t c, r; /* col and row index */
	rt_ubase_t item_width, item_height;
	rtgui_image_t* image;
	struct rtgui_dc* dc;

	if ((view->items_count == 0) ||
		(old_item == view->current_item))
		return;

	if (old_item/view->page_items != view->current_item/view->page_items)
	{
		/* it's not a same page, update all */
		rtgui_widget_update(RTGUI_WIDGET(view));
		return;
	}

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

	item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN)/view->col_items;
	item_height = (rtgui_rect_height(rect) - 4)/view->row_items;
	image = view->items[0].image;

	/* update old item */
	r = (old_item % view->page_items)/ view->col_items;
	c = (old_item % view->page_items)% view->col_items;
	item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
	item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
	item_rect.x2 = item_rect.x1 + item_width;
	item_rect.y2 = item_rect.y1 + item_height;
	rtgui_dc_fill_rect(dc, &item_rect);

	/* draw image */
	drawing_rect.x1 = drawing_rect.y1 = 0;
	drawing_rect.x2 = image->w;
	drawing_rect.y2 = image->h;
	rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	drawing_rect.y1 += 3; drawing_rect.y2 += 3;
	rtgui_image_blit(view->items[old_item].image, dc, &drawing_rect);

	/* draw text */
	item_rect.y1 = drawing_rect.y2 + LIST_MARGIN; 
	item_rect.x1 += 3; item_rect.x2 -=3;
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), view->items[old_item].name, 
		&drawing_rect);
	rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	rtgui_dc_draw_text(dc, view->items[old_item].name, &drawing_rect);

	/* update new item as selected */
	r = (view->current_item % view->page_items) / view->col_items;
	c = (view->current_item % view->page_items) % view->col_items;
	item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
	item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
	item_rect.x2 = item_rect.x1 + item_width;
	item_rect.y2 = item_rect.y1 + item_height;
	rtgui_theme_draw_selected(dc, &item_rect);

	/* draw image */
	drawing_rect.x1 = 0;
	drawing_rect.y1 = 3;
	drawing_rect.x2 = image->w;
	drawing_rect.y2 = 3 + image->h;

	rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	rtgui_image_blit(view->items[view->current_item].image, dc, &drawing_rect);

	/* draw text */
	item_rect.y1 = drawing_rect.y2 + LIST_MARGIN; 
	item_rect.x1 += 3; item_rect.x2 -=3;
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), 
		view->items[view->current_item].name, 
		&drawing_rect);
	rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	rtgui_dc_draw_text(dc, view->items[view->current_item].name, &drawing_rect);

	rtgui_dc_end_drawing(dc);
}
示例#23
0
/* Draw tab bars of @param notebook. @param dc should be initialized and
 * finished outside this function. Don't pass @param notebook or @param dc as
 * RT_NULL, it should be checked outside.
 */
static void _rtgui_notebook_draw_bar(struct rtgui_notebook *notebook,
		struct rtgui_dc *dc)
{
	int index;
	struct rtgui_rect rect;
	struct rtgui_rect text_rect;
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
	struct rtgui_image* image = RT_NULL;
	struct rtgui_rect image_rect;
#endif

	RT_ASSERT((notebook != RT_NULL) && (dc != RT_NULL));

	if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
		return;

	_rtgui_notebook_get_bar_rect(notebook, &rect);
	rtgui_dc_fill_rect(dc, &rect);

	if (notebook->flag == RTGUI_NOTEBOOK_TOP ||
		notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
	{
		rect.x2 = rect.x1 + notebook->tab_w;
		/* draw tab bar */
		for (index = 0; index < notebook->count; index++)
		{
			if (notebook->current == index)
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].pressed_image != RT_NULL)
					image = notebook->childs[index].pressed_image;
				else
#endif
				rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
			}
			else
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].unpressed_image != RT_NULL)
					image = notebook->childs[index].unpressed_image;
				else
#endif
					rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
			}

			rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook), 
				notebook->childs[index].title, &text_rect);
			rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);

#ifdef RTGUI_USING_NOTEBOOK_IMAGE
			if (image != RT_NULL)
			{
				image_rect.x1 = 0;
				image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
				image_rect.x2 = image_rect.x1 + image->w;
				image_rect.y2 = image_rect.y1 + image->h;
				rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
				
				rtgui_image_blit(image, dc, &image_rect);
			}
			if (image != RT_NULL)
			{
				int text_height = text_rect.y2 - text_rect.y1;
				
				text_rect.y1 = image_rect.y2 +  RTGUI_WIDGET_DEFAULT_MARGIN;
				text_rect.y2 = text_rect.y1 + text_height;
			}
			image = RT_NULL;
#endif

			rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);

			/* move to next tab */
			rect.x1 = rect.x2;
			rect.x2 = rect.x1 + notebook->tab_w;
		}
	}
	else
	{
		rect.y2 = rect.y1 + notebook->tab_h;
		/* draw tab bar */
		for (index = 0; index < notebook->count; index++)
		{
			if (notebook->current == index)
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].pressed_image != RT_NULL)
					image = notebook->childs[index].pressed_image;
				else
#endif
					rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
			}
			else
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].unpressed_image != RT_NULL)
					image = notebook->childs[index].unpressed_image;
				else
#endif
					rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
			}

			rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook), 
				notebook->childs[index].title, &text_rect);
			rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
			if (image != RT_NULL)
			{
				image_rect.x1 = 0;
				image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
				image_rect.x2 = image->w;
				image_rect.y2 = image_rect.y1 + image->h;
				rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
				
				rtgui_image_blit(image, dc, &image_rect);
			}

			if (image != RT_NULL)
			{
				int text_height = text_rect.y2 - text_rect.y1;
				
				text_rect.y1 = image_rect.y2 +  RTGUI_WIDGET_DEFAULT_MARGIN;
				text_rect.y2 = text_rect.y1 + text_height;
			}
			image = RT_NULL;
#endif
			rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);

			/* move to next tab */
			rect.y1 = rect.y2;
			rect.y2 = rect.y1 + notebook->tab_h;
		}

	}
}
示例#24
0
void rtgui_filelist_view_update_current(struct rtgui_filelist_view *view, rt_uint16_t old_item)
{
    struct rtgui_dc *dc;
    struct rtgui_file_item *item;
    rtgui_rect_t rect, item_rect, image_rect;

    if (old_item / view->page_items != view->current_item / view->page_items)
    {
        /* it's not a same page, update all */
        rtgui_widget_update(RTGUI_WIDGET(view));
        return;
    }

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    /* get old item rect */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    /* get image rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    /* draw old item */
    rtgui_dc_fill_rect(dc, &item_rect);

    item = &(view->items[old_item]);
    if (item->type == RTGUI_FITEM_FILE) /* draw item image */
        rtgui_image_blit(file_image, dc, &image_rect);
    else
        rtgui_image_blit(folder_image, dc, &image_rect);

    item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
    rtgui_dc_draw_text(dc, item->name, &item_rect);

    /* draw current item */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    rtgui_theme_draw_selected(dc, &item_rect);

    /* get image base rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    item = &(view->items[view->current_item]);
    if (item->type == RTGUI_FITEM_FILE) /* draw item image */
        rtgui_image_blit(file_image, dc, &image_rect);
    else
        rtgui_image_blit(folder_image, dc, &image_rect);

    item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
    rtgui_dc_draw_text(dc, item->name, &item_rect);
    if(view->on_changed!=RT_NULL)
   {
    view->on_changed(RTGUI_OBJECT(view),RT_NULL);
   }
    rtgui_dc_end_drawing(dc);
}
示例#25
0
void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_uint16_t old_item)
{
	struct rtgui_dc* dc;
	const struct rtgui_list_item* item;
	rtgui_rect_t rect, item_rect;

	if (old_item/view->page_items != view->current_item/view->page_items)
	{
		/* it's not a same page, update all */
		rtgui_widget_update(RTGUI_WIDGET(view));
		return;
	}

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

	/* get old item's rect and draw old item */
	item_rect.x1 = rect.x1; item_rect.x2 = rect.x2;
	item_rect.y1 = rect.y1 + 2;
	item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
	rtgui_dc_fill_rect(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(view->items[old_item]);
	if (item->image != RT_NULL)
	{
		struct rtgui_rect image_rect;

		/* blit on center */
		image_rect.x1 = 0; image_rect.y1 = 0;
		image_rect.x2 = item->image->w;
		image_rect.y2 = item->image->h;

		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_image_blit(item->image, dc, &image_rect);
		item_rect.x1 += item->image->w + 2;
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	/* draw current item */
	item_rect = rect;
	/* get current item's rect */
	item_rect.y1 += 2;
	item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw current item */
	rtgui_theme_draw_selected(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(view->items[view->current_item]);
	if (item->image != RT_NULL)
	{
		struct rtgui_rect image_rect;

		/* blit on center */
		image_rect.x1 = 0; image_rect.y1 = 0;
		image_rect.x2 = item->image->w;
		image_rect.y2 = item->image->h;

		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_image_blit(item->image, dc, &image_rect);
		item_rect.x1 += (item->image->w + 2);
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	rtgui_dc_end_drawing(dc);
}
示例#26
0
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);
}