rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench)
{
	rtgui_view_t *view;

	view = demo_view(workbench, "DC 缓冲区动画");
	if (view != RT_NULL)
		rtgui_widget_set_event_handler(RTGUI_WIDGET(view), animation_event_handler);

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "缓冲动画", &text_rect);
	if (dc_buffer == RT_NULL)
	{
		rtgui_rect_t rect;

		rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2;
		rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2;

		/* 创建 DC Buffer,长 50,宽 50 */
		dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
		RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view));
		rtgui_dc_fill_rect(dc_buffer, &rect);
		RTGUI_DC_FC(dc_buffer) = black;
		rect.x1 = 1; rect.y1 = 1;
		rtgui_dc_draw_text(dc_buffer, "缓冲动画", &rect);
	}

	/* 启动定时器以触发动画 */
	timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view);
	rtgui_timer_start(timer);

	return view;
}
Пример #2
0
static void rtgui_image_hdcmm_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *dst_rect)
{
    rt_uint8_t *ptr;
    rt_uint16_t y, w, h;
    struct rtgui_image_hdcmm *hdc;

    RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);

    /* this dc is not visible */
    if (rtgui_dc_get_visible(dc) != RT_TRUE) return;

    hdc = (struct rtgui_image_hdcmm *) image;
    RT_ASSERT(hdc != RT_NULL);

    /* the minimum rect */
    if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
    else w = rtgui_rect_width(*dst_rect);
    if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
    else h = rtgui_rect_height(*dst_rect);


    /* get pixel pointer */
    ptr = hdc->pixels;

    for (y = 0; y < h; y ++)
    {
        dc->engine->blit_line(dc, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y, ptr);
        ptr += hdc->pitch;
    }
}
Пример #3
0
static void rtgui_list_view_calc(struct rtgui_list_view* view)
{
    rtgui_rect_t rect;
    rt_uint32_t image_width, image_height;
    rt_ubase_t text_width, text_height;
    rt_ubase_t item_width, item_height;

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

    /* get image width and height */
    if (view->items[0].image != RT_NULL) {
        image_width  = view->items[0].image->w;
        image_height = view->items[0].image->h;
    } else {
        image_width  = 0;
        image_height = 0;
    }

    rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "HHHHHH", &rect);

    text_height = rtgui_rect_height(rect);
    text_width = rtgui_rect_width(rect);

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    item_width = (image_width + LIST_MARGIN);
    if (item_width < (text_width + LIST_MARGIN)) item_width = text_width + LIST_MARGIN;
    item_height = image_height + 8 + text_height + LIST_MARGIN;
    if (item_width > item_height) item_height = item_width;
    else item_width = item_height;

    view->row_items = (rtgui_rect_height(rect) - 2 * LIST_MARGIN) / item_height;
    view->col_items = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / item_width;
    view->page_items = view->row_items * view->col_items;
}
Пример #4
0
static void rtgui_list_view_calc(struct rtgui_list_view* view)
{
	/* get image of first item*/
	rtgui_image_t *image;
	rtgui_rect_t rect;
	rt_ubase_t text_width, text_height;
	rt_ubase_t item_width, item_height;

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

	image = view->items[0].image;
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "HHHHHH", &rect);

	text_height = rtgui_rect_height(rect);
	text_width = rtgui_rect_width(rect);

	rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

	item_width = (image->w + LIST_MARGIN);
	if (item_width < (text_width + LIST_MARGIN)) item_width = text_width + LIST_MARGIN;
	item_height = image->h + 3 + text_height + LIST_MARGIN; 

	view->row_items = (rtgui_rect_height(rect) - 2 * LIST_MARGIN) / item_height;
	view->col_items = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / item_width;
	view->page_items = view->row_items * view->col_items;
}
Пример #5
0
Файл: edit.c Проект: amsl/RTGUI
void rtgui_edit_adjust_scroll(rtgui_scrollbar_t *bar)
{
	struct rtgui_edit *edit;
	
	RT_ASSERT(bar != RT_NULL);
	
	if(bar->WIDGET_GROUP != RT_NULL)
	{
		rtgui_rect_t rect;
		rt_uint32_t _left=0,_top=0,_width=RTGUI_DEFAULT_SB_WIDTH,_len=0;

		edit = bar->WIDGET_GROUP;
		rtgui_widget_get_rect(edit, &rect);
		rtgui_widget_rect_to_device(edit,&rect);
		if(bar->orient==RTGUI_HORIZONTAL)
		{
			if(RTGUI_WIDGET_IS_HIDE(edit->hscroll))
			{
				if(edit->max_rows > edit->row_per_page)
				{
					RTGUI_WIDGET_SHOW(edit->hscroll);
					rtgui_scrollbar_set_line_step(edit->hscroll, 1);
					rtgui_scrollbar_set_page_step(edit->hscroll, edit->row_per_page);
					rtgui_scrollbar_set_range(edit->hscroll, edit->max_rows);
				}
				else
					RTGUI_WIDGET_HIDE(edit->vscroll);
				rtgui_widget_update_clip(RTGUI_WIDGET(edit));
			}
			else
			{
				_left = RTGUI_WIDGET_BORDER_SIZE(edit);
				_top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
				_len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
				
				if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll)) 
					_len -= _width;
				rect.x1 += _left;
				rect.y1 += _top;
				rect.x2 = rect.x1+_len;
				rect.y2 = rect.y1+_width;
			}
		}
		else if(bar->orient==RTGUI_VERTICAL)
		{
			_left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_top = RTGUI_WIDGET_BORDER_SIZE(edit);
			_len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			
			if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll))  
				_len -= _width;
			rect.x1 += _left;
			rect.y1 += _top;
			rect.x2 = rect.x1+_width;
			rect.y2 = rect.y1+_len;
		}
		rtgui_widget_set_rect(bar,&rect);
	}
}
Пример #6
0
/* get active area length */
rt_uint32_t get_sbar_active_len(rtgui_scrollbar_t *bar)
{
	rtgui_rect_t rect;

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);

	if(bar->orient & RTGUI_VERTICAL)
		return rtgui_rect_height(rect) - 2*rtgui_rect_width(rect);
	else
		return rtgui_rect_width(rect) - 2*rtgui_rect_height(rect);
}
Пример #7
0
static void rtgui_image_hdc_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *dst_rect)
{
    rt_uint16_t y, w, h;
    struct rtgui_image_hdc *hdc;

    RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);

    /* this dc is not visible */
    if (rtgui_dc_get_visible(dc) != RT_TRUE) return;

    hdc = (struct rtgui_image_hdc *) image->data;
    RT_ASSERT(hdc != RT_NULL);

    /* the minimum rect */
    if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
    else w = rtgui_rect_width(*dst_rect);
    if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
    else h = rtgui_rect_height(*dst_rect);

    if (hdc->pixels != RT_NULL)
    {
        rt_uint8_t *ptr;

        /* get pixel pointer */
        ptr = hdc->pixels;

        for (y = 0; y < h; y ++)
        {
            dc->engine->blit_line(dc, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y, ptr);
            ptr += hdc->pitch;
        }
    }
    else
    {
        rt_uint8_t *ptr;
        ptr = rtgui_malloc(hdc->pitch);
        if (ptr == RT_NULL) return; /* no memory */

        /* seek to the begin of pixel data */
        rtgui_filerw_seek(hdc->filerw, hdc->pixel_offset, RTGUI_FILE_SEEK_SET);

        for (y = 0; y < h; y ++)
        {
            /* read pixel data */
            if (rtgui_filerw_read(hdc->filerw, ptr, 1, hdc->pitch) != hdc->pitch)
                break; /* read data failed */

            dc->engine->blit_line(dc, dst_rect->x1,  dst_rect->x1 + w, dst_rect->y1 + y, ptr);
        }

        rtgui_free(ptr);
    }
}
Пример #8
0
rt_uint32_t _rtgui_scrollbar_get_length(rtgui_scrollbar_t *bar)
{
	rtgui_rect_t rect;
	rt_uint32_t result;

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);

	if(bar->orient & RTGUI_VERTICAL)
		result = rtgui_rect_height(rect) - 2*rtgui_rect_width(rect) - bar->thumb_len;
	else
		result = rtgui_rect_width(rect) - 2*rtgui_rect_height(rect) - bar->thumb_len;

	return result;
}
static void _calc_width(rtgui_textview_t *textview)
{
	rtgui_rect_t rect;
	rt_uint16_t width, height;

	width = rtgui_rect_width(RTGUI_WIDGET(textview)->extent) - 6;
	height = rtgui_rect_height(RTGUI_WIDGET(textview)->extent);

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(textview)), "W", &rect);
	textview->line_width = width / rtgui_rect_width(rect) + 1;
	textview->line_page_count = height / (rtgui_rect_height(rect) + 3);

	/* set minimal value */
	if (textview->line_page_count == 0) textview->line_page_count = 1;
}
static void _draw_textview(rtgui_textview_t *textview)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, font_rect;
	char* line;
	rt_ubase_t line_index, item_height;

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(textview)), "W", &font_rect);
	item_height = rtgui_rect_height(font_rect) + 3;

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

	/* fill rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(textview), &rect);
	rtgui_dc_fill_rect(dc, &rect);

	rect.x1 += 3;
	rect.x2 -= 3;

	for (line_index = textview->line_current; 
		(line_index < textview->line_current + textview->line_page_count) &&
		(line_index < textview->line_count); 
		line_index ++)
	{
		line = (char* )_get_line_text(textview, line_index);
		rtgui_dc_draw_text(dc, line, &rect);

		rect.y1 += item_height;
	}

	rtgui_dc_end_drawing(dc);
}
Пример #11
0
static void _rtgui_listctrl_scrollbar_onmouse(struct rtgui_listctrl* ctrl, struct rtgui_event_mouse* mouse)
{
	rtgui_rect_t rect;
	rt_uint32_t height, y1;
	rt_uint16_t old_item;

	/* get scrollbar rect */
	_rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
	height = rtgui_rect_height(rect);
	height = height / ((ctrl->items_count + (ctrl->page_items - 1))/ctrl->page_items);
	y1 = (ctrl->current_item / ctrl->page_items) * height;

	rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height;
	rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);

	old_item = ctrl->current_item;
	if (mouse->y < rect.y1)
	{
		if (ctrl->current_item - ctrl->page_items >= 0)
			ctrl->current_item -= ctrl->page_items;
		rtgui_listctrl_update_current(ctrl, old_item);
	}
	else if (mouse->y > rect.y2)
	{
		if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
			ctrl->current_item += ctrl->page_items;
		else
			ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
		rtgui_listctrl_update_current(ctrl, old_item);
	}
}
Пример #12
0
static void rtgui_textbox_init_caret(rtgui_textbox_t *box, rt_uint16_t position)
{
	int x, y;
	rtgui_color_t color;
	rtgui_rect_t rect;
	int ofs = 0;

	RT_ASSERT(box != RT_NULL);

	if (!RTGUI_WIDGET_IS_FOCUSED(box))
		return;

	rtgui_textbox_get_caret_rect(box, &box->caret_rect, position);
	rect = box->caret_rect;
	rtgui_widget_rect_to_device(RTGUI_WIDGET(box), &rect);

	if (box->caret == RT_NULL)
		box->caret = rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect) * sizeof(rtgui_color_t));

	for (x = rect.x1; x < rect.x2; x++)
	{
		for (y = rect.y1; y < rect.y2; y++)
		{
			rtgui_graphic_driver_get_default()->ops->get_pixel(&color, x, y);
			*(box->caret + ofs) = color;
			ofs++;
		}
	}
}
Пример #13
0
static rt_bool_t app_list_view_onmouse(struct app_list_view *view,
                                       struct rtgui_event_mouse *emouse)
{
    if (rtgui_rect_contains_point(&view->view_rect,
                                  emouse->x, emouse->y) == RT_EOK)
    {
        rt_uint16_t index;
        rt_uint16_t old_item;

        /* get old item */
        old_item = view->current_item;

        {
            rt_uint16_t x, y;
            rt_uint16_t item_height, item_width;


            item_width = (rtgui_rect_width(view->view_rect) - 2 * LIST_MARGIN) /
                         view->col_items;
            item_height = (rtgui_rect_height(view->view_rect) - 4) / view->row_items;
            x = emouse->x - view->view_rect.x1;
            y = emouse->y - view->view_rect.y1;

            index = (y / item_height * view->col_items) + x / item_width;

            if ((index + (view->current_page * view->page_items) <
                    view->items_count))
            {

                if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
                {
                    view->current_item = index + (view->current_page *
                                                  view->page_items);
                    /* down event */
                    // rtgui_list_view_update_icon(view, old_item);
                }
                else
                {
                    if (view->current_item == index + (view->current_page *
                                                       view->page_items))
                    {
                        rt_kprintf("mouse up,current item:%d\n", view->current_item);
                        /* up event */
                        if (view->on_select != RT_NULL)
                        {
                            view->on_select(&view->items[view->current_item]);
                        }
                    }
                }

            }
        }


        return RT_TRUE;
    }

    return RT_FALSE;
}
Пример #14
0
static void _rtgui_listctrl_get_rect(struct rtgui_listctrl* ctrl, rtgui_rect_t* rect)
{
	rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
	if (ctrl->items_count > rtgui_rect_height(*rect)/rtgui_theme_get_selected_height())
	{
		rect->x2 = rect->x2 - 8;
	}
}
Пример #15
0
void rtgui_listctrl_set_itemheight(struct rtgui_listctrl *ctrl, int height)
{
    RT_ASSERT(ctrl != RT_NULL);
    if (height <= 0) return;

    ctrl->item_height = height;
    ctrl->page_items = rtgui_rect_height(RTGUI_WIDGET(ctrl)->extent) / (2 + ctrl->item_height);
}
Пример #16
0
static void gui_win_entry(void* parameter)
{
	const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default();
	struct rt_messagequeue *mq;
	rtgui_win_t *win;
	rtgui_button_t *button;
	rtgui_point_t p;
	rtgui_rect_t rect = {0,0,200,180};
	rtgui_label_t *label;
	rtgui_font_t *font;
	
	/* 创建GUI应用需要的消息队列 */
	mq = rt_mq_create("demo_win", 256, 32, RT_IPC_FLAG_FIFO);
	/* 注册当前线程 */
	rtgui_thread_register(rt_thread_self(), mq);

	/* 窗口居中 */
	rtgui_rect_moveto(&rect, (gd->width - rtgui_rect_width(rect))/2, (gd->height - rtgui_rect_height(rect))/2);
	/* 创建窗口 */
	win = rtgui_win_create(RT_NULL,"demo_win",&rect,RTGUI_WIN_DEFAULT);
	if(win == RT_NULL) return;
 
	/* 取得客户区坐标零点 */
	p = rtgui_win_get_client_zero(win);
	label = rtgui_label_create(win, "hello world!", p.x+5, p.y+5, 100,25);
	font = rtgui_font_refer("asc", 12);	
	RTGUI_WIDGET_FONT(label) = font;

	button = rtgui_button_create(win, "Exit", (rtgui_rect_width(rect)-50)/2,
								rtgui_rect_height(rect)-40,50,25);
	rtgui_button_set_onbutton(button,rtgui_win_close);

	rtgui_widget_set_event_handler(win, demo_gui_win_event_handler);
	
	rtgui_win_show(win,RT_FALSE);
	
	/* 执行工作台事件循环 */
	rtgui_win_event_loop(win);

	demo_win_inited = RT_FALSE;
	
	/* 去注册GUI线程 */
	rtgui_thread_deregister(rt_thread_self());
	rt_mq_delete(mq);
}
Пример #17
0
static void rtgui_textbox_get_caret_rect(rtgui_textbox_t *box, rtgui_rect_t *rect, rt_uint16_t position)
{
	int font_h, box_h;
	rtgui_rect_t item_rect;

	RT_ASSERT(box != RT_NULL);

	rtgui_widget_get_rect(RTGUI_WIDGET(box), rect);

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &item_rect);
	font_h = rtgui_rect_height(item_rect);
	box_h = rtgui_rect_height(*rect);

	rect->x1 += position * box->font_width + 2;
	rect->x2 = rect->x1 + 2;
	rect->y1 += (box_h - font_h) / 2;
	rect->y2 = rect->y1 + font_h;
}
Пример #18
0
static void _rtgui_plot_curve_onpaint(
    struct rtgui_dc *dc,
    struct rtgui_plot *plot,
    struct rtgui_plot_curve *curve,
    rt_uint16_t start_idx,
    rt_uint16_t stop_idx)
{
    struct rtgui_rect rect;
    rt_uint16_t height;
    int last_x, last_y;
    rtgui_color_t old_color;
    rtgui_plot_curve_dtype *x_data, *y_data;

    rtgui_dc_get_rect(dc, &rect);
    height = rtgui_rect_height(rect);

    old_color = RTGUI_DC_FC(dc);
    RTGUI_DC_FC(dc) = curve->color;

    x_data = rtgui_plot_curve_get_x(curve);
    y_data = rtgui_plot_curve_get_y(curve);
    if (x_data)
    {
        rt_size_t i;

        last_x = _rtgui_plot_curve_calc_x(plot, x_data[start_idx]);
        last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
        for (i = start_idx + 1; i < stop_idx; i++)
        {
            int cur_x = _rtgui_plot_curve_calc_x(plot, x_data[i]);
            int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
            rtgui_dc_draw_line(dc,
                               last_x, last_y,
                               cur_x, cur_y);
            last_x = cur_x;
            last_y = cur_y;
        }
    }
    else
    {
        rt_size_t i;

        last_x = _rtgui_plot_curve_calc_x(plot, start_idx);
        last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
        for (i = start_idx + 1; i < stop_idx; i++)
        {
            int cur_x = _rtgui_plot_curve_calc_x(plot, i);
            int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
            rtgui_dc_draw_line(dc,
                               last_x, last_y,
                               cur_x, cur_y);
            last_x = cur_x;
            last_y = cur_y;
        }
    }
    RTGUI_DC_FC(dc) = old_color;
}
Пример #19
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;
        }
    }
}
Пример #20
0
static void _rtgui_listctrl_get_scrollbar_rect(struct rtgui_listctrl* ctrl, rtgui_rect_t* rect)
{
	rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
	if (ctrl->items_count > rtgui_rect_height(*rect)/rtgui_theme_get_selected_height())
	{
		rect->x1 = rect->x2 - 8;
	}
	else
	{
		/* no scrollbar */
		rt_memset(rect, 0, sizeof(rtgui_rect_t));
	}
}
Пример #21
0
void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count)
{
	rtgui_rect_t rect;
	
	box->items = items;
	box->items_count = count;
	box->current_item = 0;

	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	box->page_items = rtgui_rect_height(rect) / (2 + rtgui_theme_get_selected_height());

	rtgui_widget_update(RTGUI_WIDGET(box));
}
Пример #22
0
void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count)
{
	rtgui_rect_t rect;
	
	ctrl->items = items;
	ctrl->items_count = count;
	ctrl->current_item = 0;

	rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
	ctrl->page_items = rtgui_rect_height(rect) / (2 + rtgui_theme_get_selected_height());

	rtgui_widget_update(RTGUI_WIDGET(ctrl));
}
Пример #23
0
struct rtgui_dc*
rtgui_graphic_driver_get_rect_buffer(const struct rtgui_graphic_driver *driver,
                                     struct rtgui_rect *r)
{
    int w, h;
    struct rtgui_dc_buffer *buffer;
    rt_uint8_t *pixel, *dst;
    struct rtgui_rect src, rect;

    /* use virtual framebuffer in default */
    if (driver == RT_NULL) driver = _current_driver;

    if (r == RT_NULL)
    {
        rtgui_graphic_driver_get_rect(driver, &rect);
    }
    else
    {
        rtgui_graphic_driver_get_rect(driver, &src);
        rect = *r;
        rtgui_rect_intersect(&src, &rect);
    }

    w = rtgui_rect_width (rect);
    h = rtgui_rect_height(rect);
    if (!(w && h) || driver->framebuffer == RT_NULL)
        return RT_NULL;

    /* create buffer DC */
    buffer = (struct rtgui_dc_buffer*)rtgui_dc_buffer_create_pixformat(driver->pixel_format, w, h);
    if (buffer == RT_NULL)
        return (struct rtgui_dc*)buffer;

    /* get source pixel */
    pixel = (rt_uint8_t*)driver->framebuffer
            + rect.y1 * driver->pitch
            + rect.x1 * rtgui_color_get_bpp(driver->pixel_format);

    dst = buffer->pixel;

    while (h--)
    {
        memcpy(dst, pixel, buffer->pitch);

        dst += buffer->pitch;
        pixel += driver->pitch;
    }

    return (struct rtgui_dc*)buffer;
}
Пример #24
0
static void _rtgui_plot_update_scale(struct rtgui_plot *plot)
{
    struct rtgui_plot_curve *curve;
    struct rtgui_rect rect;
    rtgui_plot_curve_dtype max_x = 0;
    rtgui_plot_curve_dtype min_x = 0;
    rtgui_plot_curve_dtype max_y = 0;
    rtgui_plot_curve_dtype min_y = 0;
    rt_uint32_t iter = 0;

    rtgui_widget_get_rect(RTGUI_WIDGET(plot), &rect);

    curve = RTGUI_PLOT_CURVE(
                rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter));
    max_x = curve->max_x;
    min_x = curve->min_x;
    max_y = curve->max_y;
    min_y = curve->min_y;

    while (curve)
    {
        if (curve->max_x > max_x)
            max_x = curve->max_x;
        if (curve->min_x < min_x)
            min_x = curve->min_x;
        if (curve->max_y > max_y)
            max_y = curve->max_y;
        if (curve->min_y < min_y)
            min_y = curve->min_y;

        curve = RTGUI_PLOT_CURVE(
                    rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter));
    }

    plot->scale_x = (max_x - min_x + rtgui_rect_width(rect)) / rtgui_rect_width(rect);
    plot->scale_y = (max_y - min_y + rtgui_rect_height(rect)) / rtgui_rect_height(rect);
}
Пример #25
0
struct rtgui_radiobox *rtgui_radiobox_create(const char *label, int orient, char **radio_items, int number)
{
    struct rtgui_radiobox *radiobox;

    radiobox = (struct rtgui_radiobox *) rtgui_widget_create(RTGUI_RADIOBOX_TYPE);
    if (radiobox != RT_NULL)
    {
        rt_uint8_t board_size;
        struct rtgui_rect rect;

        radiobox->items = radio_items;
        radiobox->item_count = number;
        radiobox->item_selection = -1;
        radiobox->text = rt_strdup(label);

        /* set proper of control */
        rtgui_radiobox_set_orientation(radiobox, orient);
        rtgui_font_get_metrics(RTGUI_WIDGET_FONT(radiobox), "H", &rect);
        board_size = rtgui_rect_height(rect);

        if (orient == RTGUI_VERTICAL)
        {
            radiobox->item_size = board_size;
        }
        else
        {
            int index;
            struct rtgui_font *font;
            struct rtgui_rect rect;

            /* set init item size */
            radiobox->item_size = 0;

            font = RTGUI_WIDGET_FONT(radiobox);
            for (index = 0; index < number; index ++)
            {
                rtgui_font_get_metrics(font, radio_items[index], &rect);
                if ((board_size + 3 + rtgui_rect_width(rect)) > radiobox->item_size)
                    radiobox->item_size = board_size + 3 + rtgui_rect_width(rect);
            }
        }

        if (radiobox->item_size < RADIO_BOX_H + 2)
            radiobox->item_size = RADIO_BOX_H + 2;
    }

    return radiobox;
}
Пример #26
0
struct rtgui_container* demo_plot(void)
{
    struct rtgui_container *cnt;
    struct rtgui_plot_curve *curve1, *curve2, *curve3;
    struct rtgui_plot *plot;
    struct rtgui_rect rect;

    cnt = demo_view("ÇúÏß»æͼ");

    plot = rtgui_plot_create();

    curve1 = rtgui_plot_curve_create();
    rtgui_plot_curve_set_y(curve1, sin_ydata);
    RTGUI_MV_MODEL(curve1)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
    curve1->min_x = 0;
    curve1->max_x = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
    curve1->min_y = -100;
    curve1->min_y = 100;
    curve1->color = red;
    rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve1), RTGUI_MV_VIEW(plot));

    curve2 = rtgui_plot_curve_create();
    rtgui_plot_curve_set_y(curve2, cos_ydata);
    RTGUI_MV_MODEL(curve2)->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
    curve2->min_x = 0;
    curve2->max_x = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
    curve1->min_y = -50;
    curve1->min_y = 50;
    curve2->color = blue;
    rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve2), RTGUI_MV_VIEW(plot));

    curve3 = rtgui_plot_curve_create();
    rtgui_plot_curve_set_x(curve3, cos_ydata);
    rtgui_plot_curve_set_y(curve3, sin_ydata);
    RTGUI_MV_MODEL(curve3)->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
    curve3->color = black;
    rtgui_mv_model_add_view(RTGUI_MV_MODEL(curve3), RTGUI_MV_VIEW(plot));

    rtgui_widget_get_rect(RTGUI_WIDGET(cnt), &rect);
    rtgui_widget_set_rect(RTGUI_WIDGET(plot), &rect);
    rtgui_plot_set_base(plot,
            -rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2);

    rtgui_container_add_child(cnt, RTGUI_WIDGET(plot));

    return cnt;
}
Пример #27
0
static void rtgui_slider_onmouse(struct rtgui_slider* slider, struct rtgui_event_mouse* event)
{
	RT_ASSERT(slider != RT_NULL);
	RT_ASSERT(event  != RT_NULL);

	if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
		event->button & RTGUI_MOUSE_BUTTON_LEFT)
	{
		int sel;
		int range = slider->max - slider->min;
		int x0, xsize;
		int x;
		x0 = 1 + slider->thumb_width/2;

		if (slider->orient == RTGUI_VERTICAL)
		{
			x = event->y - RTGUI_WIDGET(slider)->extent.y1;
			x -= x0;
			xsize = rtgui_rect_height(RTGUI_WIDGET(slider)->extent) - 2 * x0;
		}
		else
		{
			x = event->x - RTGUI_WIDGET(slider)->extent.x1;
			x -= x0;
			xsize = rtgui_rect_width(RTGUI_WIDGET(slider)->extent) - 2 * x0;
		}

		if (x <= 0)
		{
			sel = slider->min;
		}
		else if (x >= xsize)
		{
			sel = slider->max;
		}
		else
		{
			sel = ((range * x) + xsize/2) / xsize;
			sel += slider->min;
		}

		rtgui_widget_focus(RTGUI_WIDGET(slider));
		rtgui_slider_set_value(slider, sel);
		if (slider->on_changed != RT_NULL) /* invoke callback function */
			slider->on_changed(RTGUI_WIDGET(slider), RT_NULL);
	}
}
Пример #28
0
Файл: edit.c Проект: amsl/RTGUI
void _rtgui_edit_constructor(struct rtgui_edit *edit)
{
	rtgui_rect_t font_rect;
	RTGUI_WIDGET_FLAG(edit) |= RTGUI_WIDGET_FLAG_FOCUSABLE;

	rtgui_widget_set_event_handler(edit, rtgui_edit_event_handler);
	rtgui_widget_set_onfocus(edit, rtgui_edit_onfocus);
	rtgui_widget_set_onunfocus(edit, rtgui_edit_onunfocus);
	
	RTGUI_WIDGET_FC(edit) = theme.foreground;
	RTGUI_WIDGET_BC(edit) = theme.blankspace;
	/* set default text align */
	RTGUI_WIDGET_TEXTALIGN(edit) = RTGUI_ALIGN_CENTER_VERTICAL;
	/* set proper of control */
	edit->caret_timer = RT_NULL;
	edit->caret = RT_NULL;

	edit->tabsize = 4;
	edit->margin  = 1;
	edit->max_rows = edit->max_cols = 0;
	edit->visual.x = edit->visual.y = 0;
	edit->upleft.x = edit->upleft.y = 0;
	edit->row_per_page = edit->col_per_page = 0;

	edit->update_buf = RT_NULL;
	edit->flag = RTGUI_EDIT_NONE;
#ifdef RTGUI_EDIT_USING_SCROLL
	edit->flag |= RTGUI_EDIT_VSCROLL;
	edit->flag |= RTGUI_EDIT_HSCROLL;
#endif
	/* allocate default line buffer */
	edit->bzsize = 16;
	
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(edit), "H", &font_rect);
	edit->font_width = rtgui_rect_width(font_rect);
	edit->font_height = rtgui_rect_height(font_rect);

	edit->dbl_buf = rtgui_dc_buffer_create(edit->font_width*2+1, edit->font_height+1);
	
	edit->head = RT_NULL;
	edit->tail = RT_NULL;
	edit->first_line = RT_NULL;
#ifdef RTGUI_EDIT_USING_SCROLL	
	edit->hscroll = RT_NULL;
	edit->vscroll = RT_NULL;
#endif
}
Пример #29
0
static void rtgui_radiobox_onmouse(struct rtgui_radiobox *radiobox, struct rtgui_event_mouse *event)
{
    RT_ASSERT(radiobox != RT_NULL);
    RT_ASSERT(event  != RT_NULL);

    /* widget is hide, return */
    if (RTGUI_WIDGET_IS_HIDE(radiobox) ||
            !RTGUI_WIDGET_IS_ENABLE(radiobox)) return;

    if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
            event->button & RTGUI_MOUSE_BUTTON_LEFT)
    {
        int bord_size;
        struct rtgui_rect rect;

        /* focus widgets */
        rtgui_widget_focus(RTGUI_WIDGET(radiobox));

        /* get widget physical rect */
        rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
        rtgui_widget_rect_to_device(RTGUI_WIDGET(radiobox), &rect);

        /* get board size */
        if (radiobox->orient == RTGUI_VERTICAL)
            bord_size = radiobox->item_size;
        else
        {
            struct rtgui_rect bord_rect;

            rtgui_font_get_metrics(RTGUI_WIDGET_FONT(radiobox), "H", &bord_rect);
            bord_size = rtgui_rect_height(bord_rect);
        }
        rtgui_rect_inflate(&rect, - bord_size);
        if (rtgui_rect_contains_point(&rect, event->x, event->y) != RT_EOK) return;

        if (radiobox->orient == RTGUI_VERTICAL)
        {
            int delta_y = event->y - rect.y1;
            rtgui_radiobox_set_selection(radiobox, delta_y / radiobox->item_size);
        }
        else
        {
            int delta_x = event->x - rect.x1;
            rtgui_radiobox_set_selection(radiobox, delta_x / radiobox->item_size);
        }
    }
}
Пример #30
0
static void _rtgui_listctrl_scrollbar_ondraw(struct rtgui_listctrl* ctrl, struct rtgui_dc* dc)
{
	rtgui_rect_t rect;
	rt_uint32_t height, y1;

	/* get scrollbar rect */
	_rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
	rtgui_dc_fill_rect(dc, &rect);

	height = rtgui_rect_height(rect);

	height = height / ((ctrl->items_count + (ctrl->page_items - 1))/ctrl->page_items);
	y1 = (ctrl->current_item / ctrl->page_items) * height;

	rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height;
	rtgui_theme_draw_selected(dc, &rect);
}