示例#1
0
文件: win.c 项目: Manish-cimcon/micro
void window_entry(void* parameter)
{
	rt_mq_t mq;
	char name[32];
	rtgui_win_t *win;
	rtgui_rect_t rect = {10, 30, 110, 130};

	mq = rt_mq_create("wmq", 256, 8, RT_IPC_FLAG_FIFO);
	/* 注册当前线程为GUI线程 */
	rtgui_thread_register(rt_thread_self(), mq);

	snprintf(name, sizeof(name), "win %d", (rt_uint32_t)parameter);
	win = rtgui_win_create(RT_NULL, name, &rect, RTGUI_WIN_STYLE_DEFAULT);
	/* 显示窗口 */
	rtgui_win_show(win, RT_FALSE);

	/* 执行窗口的事件循环 */
	rtgui_win_event_loop(win);

	/* 去注册GUI线程 */
	rtgui_thread_deregister(rt_thread_self());

	/* delete message queue */
	rt_mq_delete(mq);
}
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);
}
示例#3
0
void calibration_entry(void* parameter)
{
	rt_mq_t mq;
	rtgui_win_t* win;
	struct rtgui_rect rect;

	mq = rt_mq_create("cali", 40, 8, RT_IPC_FLAG_FIFO);
	if (mq == RT_NULL) return;

	rtgui_thread_register(rt_thread_self(), mq);

	rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);

	/* set screen rect */
	calibration_ptr->width = rect.x2;
	calibration_ptr->height = rect.y2;

	/* create calibration window */
	win = rtgui_win_create(RT_NULL,
		"calibration", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
	rtgui_widget_set_event_handler(RTGUI_WIDGET(win), calibration_event_handler);
	if (win != RT_NULL)
	{
		rtgui_win_show(win, RT_FALSE);
		// rtgui_widget_update(RTGUI_WIDGET(win));
		rtgui_win_event_loop(win);
	}

	rtgui_thread_deregister(rt_thread_self());
	rt_mq_delete(mq);

	/* set calibration data */
	rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION_DATA, &calibration_ptr->data);

	/* recover to normal */
	rt_device_control(calibration_ptr->device, RT_TOUCH_NORMAL, RT_NULL);

	/* release memory */
	rt_free(calibration_ptr);
	calibration_ptr = RT_NULL;
    /* tell other thread that we finished calibration */
    rt_sem_release(touch_screen_calibrated);
}
示例#4
0
rtgui_modal_code_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
{
	rtgui_modal_code_t result;

	RT_ASSERT(win != RT_NULL);
	result = RTGUI_MODAL_CANCEL;

	/* if it does not register into server, create it in server */
	if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
	{
		if (_rtgui_win_create_in_server(win) == RT_FALSE)
			return result;
	}

	if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
	{
		/* send show message to server */
		struct rtgui_event_win_show eshow;
		RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
		eshow.wid = win;

		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
			sizeof(struct rtgui_event_win_show)) != RT_EOK)
		{
			/* hide window failed */
			return result;
		}

		/* set window unhidden */
		RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
	}
	else rtgui_widget_update(RTGUI_WIDGET(win));

	if (is_modal == RT_TRUE)
	{
		if (win->parent_toplevel != RT_NULL)
		{
			rtgui_widget_t *parent_widget;

			/* set style */
			win->style |= RTGUI_WIN_STYLE_MODAL;

			/* get root toplevel */
			parent_widget = RTGUI_WIDGET(win->parent_toplevel);
			if (RTGUI_IS_WORKBENCH(parent_widget))
			{
				rtgui_workbench_t* workbench;
				workbench = RTGUI_WORKBENCH(win->parent_toplevel);
				workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
				workbench->modal_widget = RTGUI_WIDGET(win);

				rtgui_workbench_event_loop(workbench);
				result = workbench->modal_code;
				workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
				workbench->modal_widget = RT_NULL;
			}
			else if (RTGUI_IS_WIN(parent_widget))
			{
				rtgui_win_t* parent_win;
				parent_win = RTGUI_WIN(win->parent_toplevel);
				parent_win->style |= RTGUI_WIN_STYLE_UNDER_MODAL;
				parent_win->modal_widget = RTGUI_WIDGET(win);

				rtgui_win_event_loop(parent_win);
				result = parent_win->modal_code;
				parent_win->style &= ~RTGUI_WIN_STYLE_UNDER_MODAL;
				parent_win->modal_widget = RT_NULL;
			}
		}
		else
		{
			/* which is a root window */
			win->style |= RTGUI_WIN_STYLE_MODAL;
			rtgui_win_event_loop(win);

			result = win->modal_code;
			win->style &= ~RTGUI_WIN_STYLE_MODAL;
		}
	}

	return result;
}