Exemplo n.º 1
0
static void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
{
    struct rtgui_dc* dc;
    rtgui_color_t saved;

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

    saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));

    RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(206, 231, 255);
    rtgui_dc_draw_hline(dc, 14, 14	+ (tinfo.position * 212) / tinfo.duration, 75);

    if ((player_mode == PLAYER_PLAY_RADIO) && ((tinfo.position * 212 + 14)/tinfo.duration) < 226)
    {
		tinfo.position = net_buf_get_usage();

        RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
        rtgui_dc_draw_hline(dc, 14  + (tinfo.position * 212) / tinfo.duration, 226, 75);
    }
    RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;

    if (player_mode == PLAYER_PLAY_FILE)
    {
    	rtgui_color_t saved;
        rtgui_rect_t rect;
        char line[32];

        play_time++;
        rt_snprintf(line, sizeof(line), "%3d:%02d", play_time / 60, play_time % 60);

        rect.x1 = 172;
        rect.y1 = 48;
        rect.x2 = 220;
        rect.y2 = rect.y1 + 16;

		saved = RTGUI_DC_BC(dc);
		RTGUI_DC_BC(dc) = RTGUI_RGB(0, 125, 198);
		rtgui_dc_fill_rect(dc, &rect);
        rtgui_dc_draw_text(dc, line, &rect);
		RTGUI_DC_BC(dc) = saved;
    }

    rtgui_dc_end_drawing(dc);
}
void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect)
{
	rtgui_color_t bc;
	rt_uint16_t index;
	
	bc = RTGUI_DC_FC(dc);
	RTGUI_DC_FC(dc) = selected_color;

	rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, rect->y1 + 1);
	rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, rect->y2 - 2);

	rtgui_dc_draw_vline(dc, rect->x1 + 2, rect->y1 + 2, rect->y2 - 2);
	rtgui_dc_draw_vline(dc, rect->x2 - 2, rect->y1 + 2, rect->y2 - 2);

	for (index = rect->y1 + 1; index < rect->y2 - 2; index ++)
		rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, index);

	RTGUI_DC_FC(dc) = bc;
}
Exemplo n.º 3
0
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;
		rtgui_image_t *image;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) return RT_FALSE;
		rtgui_widget_get_rect(widget, &rect);

		rtgui_dc_fill_rect(dc, &rect);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2 - 1);

		/* draw RT-Thread logo */
		image = rtgui_image_create_from_file("hdc",
			"/resource/RTT.hdc", RT_FALSE);
		if (image != RT_NULL)
		{
			rtgui_image_blit(image, dc, &rect);
			rtgui_image_destroy(image);
			
			image = RT_NULL;
		}

        if (network_image != RT_NULL)
        {
            rect.x1 = rect.x2 - (network_image->w + 2);
            rtgui_image_blit(network_image, dc, &rect);
        }

		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
	else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
	{
		struct rtgui_rect rect;
		struct rtgui_event_mouse* emouse; 

		emouse = (struct rtgui_event_mouse*) event;
		rtgui_widget_get_rect(widget, &rect);

		rect.y2 = rect.y1 + 100;
		if (emouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP) &&
			(rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK))
		{
			/* enter function view */
			player_notfiy_functionview();
		}
	}

	return rtgui_view_event_handler(widget, event);
}
/* 控件绘图函数 */
static void rtgui_mywidget_ondraw(struct rtgui_mywidget* me)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
	rt_uint16_t x, y;

	/* 获得目标DC,开始绘�?*/
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(me));
	if (dc == RT_NULL) return;

	/* 获得窗口的尺�?*/
	rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
	/* 绘制背景�?*/
	RTGUI_DC_BC(dc) = white;
	rtgui_dc_fill_rect(dc, &rect);

	/* 计算中心原点 */
	x = (rect.x2 + rect.x1)/2;
	y = (rect.y2 + rect.y1)/2;

	/* 绘制十字�?*/
	RTGUI_DC_FC(dc) = black;
	rtgui_dc_draw_hline(dc, rect.x1, rect.x2, y);
	rtgui_dc_draw_vline(dc, x, rect.y1, rect.y2);

	/* 根据状态绘制圆�?*/
	if (me->status == MYWIDGET_STATUS_ON)
		RTGUI_DC_FC(dc) = green;
	else
		RTGUI_DC_FC(dc) = red;
	rtgui_dc_fill_circle(dc, x, y, 5);

	/* 结束绘图 */
	rtgui_dc_end_drawing(dc);
	return;
}
Exemplo n.º 5
0
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) 
            return RT_FALSE;
		rtgui_widget_get_rect(widget, &rect);

		rtgui_dc_fill_rect(dc, &rect);
		rect.x2 -= 1; rect.y2 -= 1;
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
		rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);

		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
		rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2 + 1);
        
        /* shrink border */
		rtgui_rect_inflate(&rect, -1);
        
		/* draw text */
        rtgui_widget_get_rect(widget, &rect);
        rect.y1 += 25;        
        rtgui_dc_draw_text(dc, "  FM3 Easy Kit Demo", &rect);
        rect.y1 += 10;
        rtgui_dc_draw_text(dc, "  rt-thread / RTGUI", &rect);
		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
    else if (event->type == RTGUI_EVENT_KBD)
    {
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
            char key_str[16];
            switch (ekbd->key)
            {
                case RTGUIK_LEFT:
                rt_sprintf(key_str, "%s", "L");
                break;
                case RTGUIK_RIGHT:
                rt_sprintf(key_str, "%s", "R");
                break;
                case RTGUIK_DOWN:
                rt_sprintf(key_str, "%s", "D");
                break;
                case RTGUIK_UP:
                rt_sprintf(key_str, "%s", "U");
                break;                
                default:
                rt_sprintf(key_str, "%s", "S");
                break;
            }
            dc = rtgui_dc_begin_drawing(widget);
            if (dc == RT_NULL) 
                return RT_FALSE;
            rect.x1 = 118;
            rect.y1 = 1;  
            rect.x2 = 127;
            rect.y2 = 10;       
            rtgui_dc_fill_rect(dc, &rect);
            rtgui_dc_draw_text(dc, key_str, &rect);
            rtgui_dc_end_drawing(dc);
        }
        else if (ekbd->type == RTGUI_KEYUP)
        {
            dc = rtgui_dc_begin_drawing(widget);
            if (dc == RT_NULL) 
                return RT_FALSE;
            rect.x1 = 118;
            rect.y1 = 1;  
            rect.x2 = 127;
            rect.y2 = 10;       
            rtgui_dc_fill_rect(dc, &rect);
            //rtgui_dc_draw_text(dc, key_str, &rect);
            rtgui_dc_end_drawing(dc);
        }
    }
    else if (event->type == RTGUI_EVENT_COMMAND)
    {
        char str[16];
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        struct rtgui_event_command* ecmd;
        rt_uint8_t major,minor;
        dc = rtgui_dc_begin_drawing(widget);
        if (dc == RT_NULL) 
            return RT_FALSE;
            
        ecmd = (struct rtgui_event_command*)event;
        switch (ecmd->command_id)
        {   
            case ADC_UPDATE:
                rect.x1 = 1;
                rect.y1 = 1;  
                rect.x2 = 117;
                rect.y2 = 10;       
                rtgui_dc_fill_rect(dc, &rect);     
			    rt_sprintf(str, "ADC = %d mv", adc_value);
			    rtgui_dc_draw_text(dc, str, &rect);	
            break;
            case CPU_UPDATE:
                cpu_usage_get(&major, &minor);
                rect.x1 = 1;
                rect.y1 = 12;  
                rect.x2 = 127;
                rect.y2 = 22;       
                rtgui_dc_fill_rect(dc, &rect);     
			    rt_sprintf(str, "CPU : %d.%d%", major, minor);
			    rtgui_dc_draw_text(dc, str, &rect);

                rect.y1 = 23;  
                rect.y2 = 63;                 
                index++;
                if (index == 127)
                {    
                    index = 1;
                    rtgui_dc_fill_rect(dc, &rect);     
                }
                if (major>40)
                    rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
                else
                    rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
                break;
        }
        rtgui_dc_end_drawing(dc); 
    }

	return rtgui_view_event_handler(widget, event);
}
Exemplo n.º 6
0
rt_bool_t calibration_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) break;

		/* get rect information */
		rtgui_widget_get_rect(widget, &rect);

		/* clear whole window */
		RTGUI_WIDGET_BACKGROUND(widget) = white;
		rtgui_dc_fill_rect(dc, &rect);

		/* reset color */
		RTGUI_WIDGET_BACKGROUND(widget) = green;
		RTGUI_WIDGET_FOREGROUND(widget) = black;

		switch (calibration_ptr->step)
		{
			case CALIBRATION_STEP_LEFTTOP:
				rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_RIGHTTOP:
				rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
					calibration_ptr->width, CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_LEFTBOTTOM:
				rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_RIGHTBOTTOM:
				rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
					calibration_ptr->width, calibration_ptr->height - CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_CENTER:
				rtgui_dc_draw_hline(dc, calibration_ptr->width/2 - CALIBRATION_WIDTH, calibration_ptr->width/2 + CALIBRATION_WIDTH, calibration_ptr->height/2);
				rtgui_dc_draw_vline(dc, calibration_ptr->width/2, calibration_ptr->height/2 - CALIBRATION_HEIGHT, calibration_ptr->height/2 + CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width/2, calibration_ptr->height/2, 4);
				break;
		}
		rtgui_dc_end_drawing(dc);
	}
		break;

	case RTGUI_EVENT_COMMAND:
		{
			struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;

			switch (ecmd->command_id)
			{
			case TOUCH_WIN_UPDATE:
				rtgui_widget_update(widget);
				break;
			case TOUCH_WIN_CLOSE:
				rtgui_win_close(RTGUI_WIN(widget));
				break;
			}
		}
		return RT_TRUE;

	default:
		rtgui_win_event_handler(widget, event);
	}

	return RT_FALSE;
}
void rtgui_theme_draw_slider(struct rtgui_slider* slider)
{
	/* draw button */
	struct rtgui_dc* dc;
	int i, xsize, x0;
	rtgui_rect_t r, focus_rect, slider_rect, slot_rect;

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

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(slider), &focus_rect);
	/* fill widget rect with background color */
	rtgui_dc_fill_rect(dc, &focus_rect);
	r = focus_rect;

	if (slider->orient == RTGUI_VERTICAL)
	{
		rtgui_rect_inflate(&r, -1);
		xsize = r.y2 - r.y1  + 1 - slider->thumb_width;
		x0 = r.y1 + slider->thumb_width / 2;

		/* calculate thumb position */
		slider_rect = r;
		slider_rect.x1 = 5;
		slider_rect.y1 = x0 + xsize * (slider->value - slider->min) / (slider->max - slider->min) - slider->thumb_width/2;
		slider_rect.y2  = slider_rect.y1 + slider->thumb_width;

		/* calculate slot position */
		slot_rect.y1 = x0;
		slot_rect.y2 = x0 + xsize;
		slot_rect.x1 = (slider_rect.x1 + slider_rect.x2) /2 -1;
		slot_rect.x2 = slot_rect.x1 +3;
		/* draw slot */
		rtgui_dc_draw_border(dc, &slot_rect, RTGUI_BORDER_RAISE);

		/* draw the ticks */
		for (i = 0; i <= slider->ticks; i++)
		{
			int x = x0 + xsize * i / slider->ticks;
			rtgui_dc_draw_hline(dc, 1, 3, x);
		}

		/* draw the thumb */
		rtgui_dc_fill_rect(dc, &slider_rect);
		rtgui_dc_draw_border(dc, &slider_rect, RTGUI_BORDER_RAISE);
	}
	else
	{
		rtgui_rect_inflate(&r, -1);
		xsize = r.x2 - r.x1  + 1 - slider->thumb_width;
		x0 = r.x1 + slider->thumb_width / 2;

		/* calculate thumb position */
		slider_rect = r;
		slider_rect.y1 = 5;
		slider_rect.x1 = x0 + xsize * (slider->value - slider->min) / (slider->max - slider->min) - slider->thumb_width/2;
		slider_rect.x2  = slider_rect.x1 + slider->thumb_width;

		/* calculate slot position */
		slot_rect.x1 = x0;
		slot_rect.x2 = x0 + xsize;
		slot_rect.y1 = (slider_rect.y1 + slider_rect.y2) /2 -1;
		slot_rect.y2 = slot_rect.y1 +3;
		/* draw slot */
		rtgui_dc_draw_border(dc, &slot_rect, RTGUI_BORDER_RAISE);

		/* draw the ticks */
		for (i = 0; i <= slider->ticks; i++)
		{
			int x = x0 + xsize * i / slider->ticks;
			rtgui_dc_draw_vline(dc, x, 1, 3);
		}

		/* draw the thumb */
		rtgui_dc_fill_rect(dc, &slider_rect);
		rtgui_dc_draw_border(dc, &slider_rect, RTGUI_BORDER_RAISE);
	}

	/* draw focus */
	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(slider)))
	{
		rtgui_dc_draw_focus_rect(dc, &focus_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);
}
/* 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);
}
Exemplo n.º 10
0
static void player_update_tag_info()
{
    char line[32];
	struct rtgui_dc* dc;
    rtgui_color_t bc, fc;

    rtgui_rect_t rect;
	rtgui_image_t *button;

	/* get dc */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
	if (dc == RT_NULL) return;

	/* save old foreground and background color */
    fc = RTGUI_DC_FC(dc);
	bc = RTGUI_DC_BC(dc);

    /* draw playing information */
    rect.x1 = 25;
    rect.y1 = 20;
    rect.x2 = 220;
    rect.y2 = rect.y1 + 16;
	RTGUI_DC_BC(dc) = RTGUI_RGB(0, 134, 206);
	rtgui_dc_fill_rect(dc, &rect);

    RTGUI_DC_FC(dc) = black;
    if (player_mode == PLAYER_STOP)
    {
        rt_snprintf(line, sizeof(line), "网络收音机");
        rtgui_dc_draw_text(dc, line, &rect);
    }
    else
        rtgui_dc_draw_text(dc, tinfo.title, &rect);

	/* reset progress bar */
#if 0
	if (tinfo.position != 0)
	{
		rt_snprintf(line, sizeof(line), "%3d:%02d", item->duration / 60, item->duration % 60);
	}
	else
#endif
	{
		RTGUI_DC_FC(dc) = RTGUI_RGB(82, 199, 16);
		rtgui_dc_draw_hline(dc, 14, 226, 75);
	}

    rect.x1 = 25;
    rect.y1 = 48;
    rect.x2 = 220;
    rect.y2 = rect.y1 + 16;
	RTGUI_DC_BC(dc) = RTGUI_RGB(0, 125, 198);
	rtgui_dc_fill_rect(dc, &rect);

    RTGUI_DC_FC(dc) = black;
    if (player_mode == PLAYER_STOP)
    {
        rt_snprintf(line, sizeof(line), "radio.rt-thread.org");
        rtgui_dc_draw_text(dc, line, &rect);
    }
    else
    {
        rtgui_dc_draw_text(dc, tinfo.artist, &rect);
    }

    if ((tinfo.duration != 0) && player_mode == PLAYER_PLAY_FILE)
    {
        play_time = 0;

        rect.x1 = 172;
        rt_snprintf(line, sizeof(line), "  0:00");
        rtgui_dc_draw_text(dc, line, &rect);
    }

	/* update playing button */
	if (player_mode == PLAYER_STOP)
		button = (rtgui_image_t*)&stop_image;
	else
		button = (rtgui_image_t*)&play_image;

	rect.x1 = 32;
	rect.y1 = 92;
	rect.x2 = 61;
	rect.y2 = 114;
	rtgui_image_blit(button, dc, &rect);

    RTGUI_DC_FC(dc) = fc;
	RTGUI_DC_BC(dc) = bc;

	rtgui_dc_end_drawing(dc);
}