Exemplo n.º 1
0
/* 触发文件列表视图的按钮回调函数 */
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
	rtgui_filelist_view_t *view;
	rtgui_workbench_t *workbench;
	rtgui_rect_t rect;

	/* 获得顶层的workbench对象 */
	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);

	/* 针对Win32平台和其他平台做的不同的其实目录位置 */
#ifdef _WIN32
	view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
#else
	view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
#endif

	/* 采用模式形式显示文件列表视图 */
	if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK) {
		char path[32];

		/* 在文件列表视图中成功选择文件,这里获得相应的路径名 */
		rtgui_filelist_view_get_fullpath(view, path, sizeof(path));

		/* 设置文件路径到文本标签 */
		rtgui_label_set_text(label, path);
	}

	/* 删除 文件列表 视图 */
	rtgui_view_destroy(RTGUI_VIEW(view));
}
Exemplo n.º 2
0
void rtgui_workbench_hide_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
{
	RT_ASSERT(workbench != RT_NULL);
	RT_ASSERT(view != RT_NULL);

	/* hide view */
	RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));

	if (view == workbench->current_view)
	{
		rtgui_view_t *next_view;

		workbench->current_view = RT_NULL;

		next_view = RTGUI_VIEW(rtgui_widget_get_next_sibling(RTGUI_WIDGET(view)));
		if (next_view == RT_NULL)
			next_view = RTGUI_VIEW(rtgui_widget_get_prev_sibling(RTGUI_WIDGET(view)));

		if (next_view != RT_NULL)
		{
			rtgui_view_show(next_view, RT_FALSE);
		}
		else
		{
			/* update workbench clip */
			rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
		}
	}
}
Exemplo n.º 3
0
static void station_list_selected(struct rtgui_widget* widget, void* parameter)
{
	rtgui_list_view_t *view;

	view = RTGUI_LIST_VIEW(parameter);

	if (view->current_item != 0)
		rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
	else
		rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL);
}
Exemplo n.º 4
0
/* 打开按钮的回调函数 */
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
	rtgui_filelist_view_t *view;
	rtgui_workbench_t *workbench;
	rtgui_rect_t rect;

	/* 获得顶层的workbench */
	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);

	/* WIN32平台上和真实设备上的初始路径处理 */
#ifdef _WIN32
	view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
#else
	view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
#endif
	/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
	if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
	{
		char path[32], image_type[8];

		/* 设置文件路径的标签 */
		rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
		if (image != RT_NULL) 
		{
			rtgui_image_destroy(image);
			image = RT_NULL;
		}

		rt_memset(image_type, 0, sizeof(image_type));

		/* 获得图像的类型 */
		if (rt_strstr(path, ".bmp") != RT_NULL ||
			rt_strstr(path, ".BMP") != RT_NULL)
			strcat(image_type, "bmp");
		if (rt_strstr(path, ".png") != RT_NULL ||
			rt_strstr(path, ".PNG") != RT_NULL)
			strcat(image_type, "png");
		if (rt_strstr(path, ".jpg") != RT_NULL ||
			rt_strstr(path, ".JPG") != RT_NULL)
			strcat(image_type, "jpeg");
		if (rt_strstr(path, ".hdc") != RT_NULL ||
			rt_strstr(path, ".HDC") != RT_NULL)
			strcat(image_type, "hdc");

		/* 如果图像文件有效,创建相应的rtgui_image对象 */
		if (image_type[0] != '\0')
			image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
	}

	/* 删除 文件列表 视图 */
	rtgui_view_destroy(RTGUI_VIEW(view));
	rtgui_view_show(_view, RT_FALSE);
}
Exemplo n.º 5
0
/* select a station from list */
struct station_item* station_list_select(struct station_list* list, struct rtgui_workbench* workbench)
{
	rt_size_t index;
	rtgui_rect_t rect;
	rtgui_list_view_t *view;
	struct rtgui_list_item* items;
	struct station_item* station;
	char exit_str[] = "их╗п..";

	RT_ASSERT(list != RT_NULL);
	RT_ASSERT(workbench != RT_NULL);

	station = RT_NULL;

	items = (struct rtgui_list_item*) rt_malloc (sizeof(struct rtgui_list_item) * (list->count + 1));
	if (items == RT_NULL) return RT_NULL; /* no memory */

	/* create view */
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
	view = rtgui_list_view_create(items, list->count + 1, &rect, RTGUI_LIST_VIEW_LIST);

	items[0].image = RT_NULL;
	items[0].action = station_list_selected;
	items[0].name = exit_str;
	items[0].parameter = view;

	for (index = 1; index < list->count + 1; index ++)
	{
		items[index].image = RT_NULL;
		items[index].action = station_list_selected;
		items[index].name = list->items[index - 1].title;
		items[index].parameter = view;
	}

	/* add view to workbench */
	rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));

	/* show view as modal */
	if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
	{
		station = &list->items[view->current_item - 1];
	}

	/* destroy view */
	rtgui_list_view_destroy(view);
	/* release items */
	rt_free(items);

	return station;
}
Exemplo n.º 6
0
void setting_ui(rtgui_workbench_t* workbench)
{
    rtgui_rect_t rect;

    father_workbench = workbench;

    /* add function view */
    rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
    function_view = rtgui_list_view_create(function_list,
                                           sizeof(function_list) / sizeof(struct rtgui_list_item),
                                           &rect,
                                           RTGUI_LIST_VIEW_LIST);
    rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view));
    rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
}
Exemplo n.º 7
0
rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
{
    if (event->type == RTGUI_EVENT_KBD)
    {
        struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
        if (((ekbd->type == RTGUI_KEYUP) && ekbd->key == RTGUIK_HOME)
                && !RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
        {
            /* active home view */
            if (workbench->current_view != home_view)
            {
                rtgui_view_show(home_view, RT_FALSE);
                return RT_TRUE;
            }
        }
    }
	else if (event->type == RTGUI_EVENT_COMMAND)
	{
        struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;

		if ((ecmd->command_id == PLAYER_REQUEST_FUNCTION_VIEW) &&
			!RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
		{
			rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
			return RT_TRUE;
		}
		else
		{
			/* let default workbench event handler to handle it */
			return rtgui_workbench_event_handler(widget, event);
		}
	}

    return rtgui_workbench_event_handler(widget, event);
}
static rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		rtgui_rect_t rect;

		/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
		rtgui_view_event_handler(widget, event);

		/* 获得控件所属的DC */
		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
			return RT_FALSE;

        /* 获得demo view允许绘图的区域 */
        demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);

		/* 绘图 */
		rect = text_rect;
		rtgui_rect_inflate(&rect, +1);
		rtgui_dc_blit(dc_buffer, NULL, dc, &rect);

		/* 绘图完成 */
		rtgui_dc_end_drawing(dc);
	}
	else
	{
		/* 调用默认的事件处理函数 */
		return rtgui_view_event_handler(widget, event);
	}

	return RT_FALSE;
}
Exemplo n.º 9
0
static void save_handler(struct rtgui_widget* widget, rtgui_event_t* event)
{
    extern void brightness_set(unsigned int value);

    rt_uint32_t vol, bri;
    vol = rtgui_slider_get_value(slider_volume);
    bri = rtgui_slider_get_value(slider_brightness);

    //更新背光
    brightness_set(bri);

    //更新音量
    {
        rt_device_t dev = RT_NULL;
        dev = rt_device_find("snd");
        dev->control(dev, CODEC_CMD_VOLUME, &vol);
    }

    //保存配置
    radio_setup.default_volume = vol;
    radio_setup.lcd_brightness = bri;
    save_setup();

    //保存完毕,销毁本界面
    {
        rtgui_view_t* view;
        rtgui_workbench_t* workbench;

        /* remove view in workbench */
        view = RTGUI_VIEW(widget->parent);
        workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
        rtgui_workbench_remove_view(workbench, view);
        rtgui_view_destroy(view);
    }
}
Exemplo n.º 10
0
/* 演示视图的事件处理函数 */
static rt_bool_t demo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
	rt_bool_t result;

	/* 先调用默认的事件处理函数(这里只关心PAINT事件,但演示视图还有本身的一些控件) */
	result = rtgui_view_event_handler(widget, event);

	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		rtgui_rect_t rect;

		/* 获得控件所属的DC */
		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL)
			/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
			return RT_FALSE;

		/* 获得demo view允许绘图的区域 */
		demo_view_get_rect(RTGUI_VIEW(widget), &rect);

		/* 获得图像显示区域 */
		rect.x1 += 5; rect.x2 -= 5;
		rect.y1 += 30;

		if (image != RT_NULL)
			rtgui_image_blit(image, dc, &rect);

		/* 绘图完成 */
		rtgui_dc_end_drawing(dc);
	}

	return result;
}
Exemplo n.º 11
0
static void cancel_handler(struct rtgui_widget* widget, rtgui_event_t* event)
{
    rtgui_view_t* view;
    rtgui_workbench_t* workbench;

    /* remove view in workbench */
    view = RTGUI_VIEW(widget->parent);
    workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
    rtgui_workbench_remove_view(workbench, view);
    rtgui_view_destroy(view);
}
/* 打开列表视图用的按钮触发函数 */
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
	rtgui_rect_t rect;
	rt_uint32_t index;

	/* 获得顶层的workbench */
	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);

	/* 初始化图标列表 */
	if (items == RT_NULL)
	{
		char item_name[32];

		items = (struct rtgui_list_item *) rtgui_malloc((ITEM_MAX + 1) * sizeof(struct rtgui_list_item));
		for (index = 0; index < ITEM_MAX; index ++)
		{
			rt_snprintf(item_name, sizeof(item_name), "图标%d", index);
			items[index].action = listitem_action;
			items[index].image = item_icon;
			items[index].name = rt_strdup(item_name);
			items[index].parameter = (void*) index;
		}

		items[ITEM_MAX].action = return_action;
		items[ITEM_MAX].image = exit_icon;
		items[ITEM_MAX].name = "退出";
		items[ITEM_MAX].parameter = RT_NULL;
	}

	/* 创建一个列表视图, 项指定为items */
	_view = rtgui_list_view_create(items, ITEM_MAX + 1, &rect, RTGUI_LIST_VIEW_ICON);
	/* 在workbench中添加相应的视图 */
	rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view));

	/* 模式显示视图 */
	rtgui_view_show(RTGUI_VIEW(_view), RT_TRUE);
	rtgui_view_destroy(RTGUI_VIEW(_view));

	_view = RT_NULL;
}
Exemplo n.º 13
0
static void player_entry(void* parameter)
{
    rt_mq_t mq;
    rtgui_rect_t rect;

    mq = rt_mq_create("ply_ui", 256, 4, RT_IPC_FLAG_FIFO);
    rtgui_thread_register(rt_thread_self(), mq);

    /* create information timer */
    info_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC, info_timer_timeout, RT_NULL);

    workbench = rtgui_workbench_create("main", "workbench");
    if (workbench == RT_NULL) return;
    rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), player_workbench_event_handler);

    /* add home view */
    home_view = rtgui_view_create("Home");
    rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler);

    rtgui_workbench_add_view(workbench, home_view);
    /* this view can be focused */
    RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
    /* set widget focus */
    rtgui_widget_focus(RTGUI_WIDGET(home_view));

	rtgui_widget_get_rect(RTGUI_WIDGET(home_view), &rect);
	rect.x1 += 6; rect.y1 += 150 + 25;
	rect.x2 = rect.x1 + 228; rect.y2 = rect.y1 + 145;
	music_listbox = rtgui_listbox_create(RT_NULL, 0, &rect);
	/* none focusable widget */
	RTGUI_WIDGET(music_listbox)->flag &= ~RTGUI_WIDGET_FLAG_FOCUSABLE;
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(music_listbox)) = black;
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(music_listbox)) = white;
	rtgui_container_add_child(RTGUI_CONTAINER(home_view), RTGUI_WIDGET(music_listbox));
	rtgui_listbox_set_onitem(music_listbox, player_play_list_onitem);

    rtgui_view_show(home_view, RT_FALSE);

    /* add function view */
    rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
    function_view = rtgui_list_view_create(function_list,
                                           sizeof(function_list)/sizeof(struct rtgui_list_item),
                                           &rect,
										   RTGUI_LIST_VIEW_LIST);
    rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view));

    rtgui_workbench_event_loop(workbench);

    rtgui_thread_deregister(rt_thread_self());
    rt_mq_delete(mq);
}
Exemplo n.º 14
0
/* 打开按钮的回调函数 */
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
	rtgui_filelist_view_t *view;
	rtgui_workbench_t *workbench;
	rtgui_rect_t rect;

	/* 获得顶层的workbench */
	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);

	/* WIN32平台上和真实设备上的初始路径处理 */
#ifdef _WIN32
	view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
#else
	view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
#endif
	/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
	if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
	{
		char path[32], name[8];

		/* 设置文件路径的标签 */
		rtgui_filelist_view_get_fullpath(view, path, sizeof(path));

		rt_memset(name, 0, sizeof(name));

		/* 获得应用模块的类型 */
		if (rt_strstr(path, ".mo") != RT_NULL || rt_strstr(path, ".so") != RT_NULL)
		{
			rt_module_open(path);
		}	
	}

	/* 删除 文件列表 视图 */
	rtgui_view_destroy(RTGUI_VIEW(view));
	rtgui_view_show(_view, RT_FALSE);
}
static void timeout(struct rtgui_timer* timer, void* parameter)
{
	struct rtgui_dc* dc;
	rtgui_rect_t rect;
	rtgui_widget_t *widget;

	/* 控件(view)通过parameter参数传递给定时器 */
	widget = (rtgui_widget_t*)parameter;

	/* 获得控件所属的DC */
	dc = rtgui_dc_begin_drawing(widget);
	if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
		return ;

	/* 获得demo view允许绘图的区域,主要用于判断边界 */
	demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
	rect.y2 -= 5;

	/* 判断是否是第一次绘图 */
	if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
	{
		rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
	}

    /* 设置dx和dy */
	if (text_rect.x2 >= rect.x2) dx = -1;
	if (text_rect.x1 < rect.x1)  dx = 1;
	if (text_rect.y2 >= rect.y2) dy = -1;
	if (text_rect.y1 < rect.y1) dy = 1;

    /* 移动文本框的位置 */
	text_rect.x1 += dx; text_rect.x2 += dx;
	text_rect.y1 += dy; text_rect.y2 += dy;

    /* 绘图 */
	rect = text_rect;
	rect.x2 += 2; rect.y2 += 2;
	rtgui_dc_blit(dc_buffer, NULL, dc, &rect);

	/* 绘图完成 */
	rtgui_dc_end_drawing(dc);
}
/*
 * view的事件处理函数
 */
static rt_bool_t dc_buffer_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{

	/* 仅对PAINT事件进行处理 */
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		rtgui_rect_t rect;

		/*
		 * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
		 * 先绘图
		 */
		rtgui_view_event_handler(widget, event);

		/* 获得控件所属的DC */
		dc = rtgui_dc_begin_drawing(widget);
		/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
		if (dc == RT_NULL)
			return RT_FALSE;

		/* 获得demo view允许绘图的区域 */
		demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);

		rect.x1 += 10;
		rect.y1 += 10;
		rtgui_dc_blit(dc_buffer, NULL, dc, &rect);

		/* 绘图完成 */
		rtgui_dc_end_drawing(dc);
	}
	else
	{
		/* 其他事件,调用默认的事件处理函数 */
		return rtgui_view_event_handler(widget, event);
	}

	return RT_FALSE;
}
Exemplo n.º 17
0
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
    if (event->type == RTGUI_EVENT_KBD)
    {
        struct rtgui_event_kbd* ekbd;
        ekbd = (struct rtgui_event_kbd*) event;

        if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN)
        {
            rtgui_view_t* view;
            rtgui_workbench_t* workbench;

            /* remove view in workbench */
            view = RTGUI_VIEW(widget);
            workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
            rtgui_workbench_remove_view(workbench, view);
            rtgui_view_destroy(view);
            return RT_TRUE;
        }
        return RT_FALSE;
    }
    return rtgui_view_event_handler(widget, event);
}
static void return_action(void* parameter)
#endif
{
	/* 退出模态显示 */
	rtgui_view_end_modal(RTGUI_VIEW(_view), RTGUI_MODAL_OK);
}
Exemplo n.º 19
0
/*
 * view的事件处理函数
 */
rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
	/* 仅对PAINT事件进行处理 */
	if (event->type == RTGUI_EVENT_PAINT) {
		struct rtgui_dc* dc;
		rtgui_rect_t rect;
		/*		const int vx[] = {20, 50, 60, 45, 60, 20};
				const int vy[] = {150, 50, 90, 60, 45, 50};
		*/
		/*
		 * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
		 * 先绘图
		 */
		rtgui_view_event_handler(widget, event);

		/************************************************************************/
		/* 下面的是DC的操作                                                     */
		/************************************************************************/

		/* 获得控件所属的DC */
		dc = rtgui_dc_begin_drawing(widget);
		/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
		if (dc == RT_NULL)
			return RT_FALSE;

		/* 获得demo view允许绘图的区域 */
		demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);

		RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
		/* 显示GUI的版本信息 */
#ifdef RTGUI_USING_SMALL_SIZE
		rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
#else
		rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
#endif

		{
			rtgui_rect_t rect = {0, 0, 0x1c, 0x16};
			rtgui_rect_moveto(&rect, 80, 80);
			rtgui_image_blit((rtgui_image_t*)&play_image, dc, &rect);

			rect.x1 = 0;
			rect.y1 = 0;
			rect.x2 = 0x1c;
			rect.y2 = 0x16;
			rtgui_rect_moveto(&rect, 130, 80);
			rtgui_image_blit((rtgui_image_t*)&stop_image, dc, &rect);
		}
		/* 绘制一个圆形 */
		RTGUI_DC_FC(dc) = red;
		rtgui_dc_draw_circle(dc, rect.x1 + 10, rect.y1 + 10, 10);

		/* 填充一个圆形 */
		RTGUI_DC_FC(dc) = green;
		rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10);
#if 0
		/* 画一个圆角矩形 */
		rect.x1 = 150;
		rect.y1 = 180;
		rect.x2 = 210;
		rect.y2 = 260;
		RTGUI_DC_FC(dc) = RTGUI_RGB(25, 70, 150);
		rtgui_dc_draw_round_rect(dc, &rect, 10);

		rect.x1 = 160;
		rect.y1 = 190;
		rect.x2 = 200;
		rect.y2 = 250;
		RTGUI_DC_FC(dc) = RTGUI_RGB(170, 7, 80);
		rtgui_dc_fill_round_rect(dc, &rect, 7);

		/* 画一个圆弧 */
		RTGUI_DC_FC(dc) = RTGUI_RGB(250, 120, 120);
		rtgui_dc_draw_arc(dc, rect.x1 + 120, rect.y1 + 60, 30, 0, 120);

		/* 画一个扇形圆环 */
		RTGUI_DC_FC(dc) = RTGUI_RGB(150, 23, 100);
		rtgui_dc_draw_annulus(dc, 180, 170, 30, 50, 210, 330);

		/* 多边形 */
		RTGUI_DC_FC(dc) = blue;
		rtgui_dc_draw_polygon(dc, vx, vy, 6);

#endif
		RTGUI_DC_FC(dc) = blue;

		/* 绘制不同的边框 */
		{
			rtgui_rect_t rect = {0, 0, 16, 16};
			rtgui_rect_moveto(&rect, 30, 120);

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "raise", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SIMPLE);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "simple", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "sunken", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "box", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "static", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_EXTRA);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "extera", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;
		}

		/* 绘图完成 */
		rtgui_dc_end_drawing(dc);
	} else {
		/* 其他事件,调用默认的事件处理函数 */
		return rtgui_view_event_handler(widget, event);
	}

	return RT_FALSE;
}
Exemplo n.º 20
0
static rt_bool_t picture_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;
		struct rtgui_image* image;
		char fn[32];

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

		/* open image */
		rt_snprintf(fn, sizeof(fn), "%s/%s", PICTURE_DIR, current_fn);
		image = rtgui_image_create_from_file("hdc",
			fn, RT_FALSE);
		if (image != RT_NULL)
		{
			/* blit image */
			rtgui_image_blit(image, dc, &rect);
			/* destroy image */
			rtgui_image_destroy(image);
		}
		else
		{
			rtgui_dc_fill_rect(dc, &rect);
			rtgui_dc_draw_text(dc, "没有文件被打开", &rect);
		}
		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
	else if (event->type == RTGUI_EVENT_KBD)
	{
		struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
		if (ekbd->type == RTGUI_KEYDOWN)
		{
			switch (ekbd->key)
			{
			case RTGUIK_RIGHT:
				if (view_mode == VIEW_DIR_MODE) picture_show_next();
				else if (view_mode == VIEW_FN_LIST_MODE)
				{
					picture_fn_list_current ++;
					if (picture_fn_list_current == picture_fn_list_size)
					{
						picture_fn_list_current = 0;
					}
					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
					rtgui_widget_update(RTGUI_WIDGET(picture_view));
				}
				break;
			case RTGUIK_LEFT:
				if (view_mode == VIEW_DIR_MODE) picture_show_prev();
				else if (view_mode == VIEW_FN_LIST_MODE)
				{
					if (picture_fn_list_current == 0)
					{
						picture_fn_list_current = picture_fn_list_size - 1;
					}
					else picture_fn_list_current --;

					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
					rtgui_widget_update(RTGUI_WIDGET(picture_view));
				}
				break;
			case RTGUIK_RETURN:
			{
				rtgui_view_t* view;

				view = RTGUI_VIEW(widget);

				/* close this view */
				current_fn[0] = '\0';

				/* end of modal */
			    rtgui_view_end_modal(view, RTGUI_MODAL_OK);
			    picture_view = RT_NULL;
			}
				break;
			}
		}
		return RT_FALSE;
	}

	return rtgui_view_event_handler(widget, event);
}
Exemplo n.º 21
0
//销毁本view返回上级菜单
static void function_action_return(struct rtgui_widget* widget, void* paramter)
{
    rtgui_workbench_remove_view(father_workbench, RTGUI_VIEW(function_view));
    rtgui_view_destroy(RTGUI_VIEW(function_view));
    function_view = RT_NULL;
}
Exemplo n.º 22
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);
}
/*
 * view的事件处理函数
 */
rt_bool_t instrument_panel_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
    char ac[4];
    int i;
    int x0 = 120;
    int y0 = 170;
    int x, y;
    int default_color;

    /* 仅对PAINT事件进行处理 */
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc* dc;
        rtgui_rect_t rect;
        const int arrowx[] = {120+75, 120+75, 120+85};
        const int arrowy[] = {170-5,  170+5,  170};

        /*
         * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
         * 先绘图
         */
        rtgui_view_event_handler(widget, event);

        /************************************************************************/
        /* 下面的是DC的操作                                                     */
        /************************************************************************/

        /* 获得控件所属的DC */
        dc = rtgui_dc_begin_drawing(widget);
        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
        if (dc == RT_NULL)
            return RT_FALSE;

        /* 获得demo view允许绘图的区域 */
        demo_view_get_rect(RTGUI_VIEW(widget), &rect);

        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
        /* 显示GUI的版本信息 */
#ifdef RTGUI_USING_SMALL_SIZE
        rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
#else
        rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
#endif


        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL;
        RTGUI_DC_FC(dc) = blue;
        rect.y2 = 270;
        rtgui_dc_draw_text(dc, "rtgui-panel", &rect);

        for(i = 0; i < 6; i++)
        {
            rtgui_dc_draw_arc(dc, x0, y0, 117-i, 150, 30);
        }

        RTGUI_DC_FC(dc) = black;

        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT;
        for(i = 0; i <= 23; i++)
        {
            if(i < 12)
            {
                x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180);
                y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180);
                rect.x1 = x;
                rect.y1 = y;
                rect.x2 = rect.x1 + 12 * 3;
                rect.y2 = rect.y1 + 12;
                rt_sprintf(ac, "%d", 10 * i);
                rtgui_dc_draw_text(dc, ac, &rect);
            }
            else
            {
                RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT;

                x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180);
                y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180);

                rect.x1 = x  - 12 * 3;
                rect.y1 = y;
                rect.x2 = rect.x1 + 12 * 3;
                rect.y2 = rect.y1 + 12;
                rt_sprintf(ac, "%d", 10 * i);
                rtgui_dc_draw_text(dc, ac, &rect);
            }

            x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180);
            y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180);
            rtgui_dc_fill_circle(dc, x, y, 3);
        }
        RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166);
        rtgui_dc_fill_circle(dc, x0, y0, 3);
        RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30);
        rtgui_dc_draw_circle(dc, x0, y0, 5);

        default_color = RTGUI_DC_BC(dc);
        RTGUI_DC_BC(dc) = red;
        rect.x1 = x0 + 7;
        rect.y1 = y0 - 1;
        rect.x2 = x0 + 75;
        rect.y2 = y0 + 1;
        rtgui_dc_fill_rect(dc, &rect);

        RTGUI_DC_BC(dc) = default_color;

        rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3);

        /* 绘图完成 */
        rtgui_dc_end_drawing(dc);
    }
    else
    {
        /* 其他事件,调用默认的事件处理函数 */
        return rtgui_view_event_handler(widget, event);
    }

    return RT_FALSE;
}
Exemplo n.º 24
0
static void function_filelist(struct rtgui_widget* widget, void* parameter)
{
    rtgui_rect_t rect;
    rtgui_filelist_view_t *view;

    rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
    view = rtgui_filelist_view_create(workbench, "/SD", "*.*", &rect);
    if (view != RT_NULL)
    {
        if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
        {
        	int type;
            char fn[64];

            /* get file */
			rtgui_filelist_view_get_fullpath(view, fn, sizeof(fn));
			type = media_type(fn);

			/* stop playing */
			player_stop();

			/* check whether it's a folder */
			if (is_directory(fn) == RT_TRUE)
			{
				play_list_append_directory(fn);
                if (play_list_items() > 0)
                {
                    player_play_item(play_list_start());
                }
			}
            else if (type == MEDIA_WAV || type == MEDIA_MP3)
            {
                /* clear old play list */
                play_list_clear();
				/* append file */
                play_list_append(fn);

				player_play_item(play_list_start());
            }
            else if (type == MEDIA_M3U)
            {
            	/* append m3u filelist */
            	play_list_append_m3u(fn);
                if (play_list_items() > 0)
                {
                    player_play_item(play_list_start());
                }
            }

			player_update_list();
        }

        /* destroy view */
        rtgui_filelist_view_destroy(view);
    }

	/* show home view */
	rtgui_view_show(home_view, RT_FALSE);

    return;
}