Exemple #1
0
void demo_bitmap_open(struct rtgui_object* object, struct rtgui_event* event)
{
	char *str;
	rtgui_button_t *button = RTGUI_BUTTON(object);
	/* 从textbox控件中取得文件名 */
	str = (char*)rtgui_textbox_get_value(bmpdt.box);
	if(str == RT_NULL) return;
	if(*str == '/' && (rt_strstr(str, ".bmp")!=RT_NULL || rt_strstr(str, ".BMP")!=RT_NULL))
	{	/* 如果是bmp文件, 且文件名有效, 则读入图像数据 */
		if(bmpdt.filename != RT_NULL) 
			rt_free(bmpdt.filename);
		bmpdt.filename = rt_strdup(str);

		if(bmpdt.image != RT_NULL)
			rtgui_image_destroy(bmpdt.image);

		bmpdt.image = rtgui_image_create_from_file("bmp", bmpdt.filename, RT_TRUE);
		
		if(bmpdt.image != RT_NULL)
		{
			bmpdt.showimg = bmpdt.image;
			bmpdt.scale = 1.0;
			bmpdt.angle = 0.0;
			rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
		}
	}
	else
		rt_kprintf("Bad filename!");
}
void demo_image_rotate(struct rtgui_object* object, struct rtgui_event* event)
{
	rtgui_button_t *button = RTGUI_BUTTON(object);

	if (bmpdt.image == RT_NULL) return;
}
rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
	struct rtgui_widget *widget;
	struct rtgui_button *btn;

	RT_ASSERT(widget != RT_NULL);
	RT_ASSERT(event != RT_NULL);

	widget = RTGUI_WIDGET(object);
	btn = RTGUI_BUTTON(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_theme_draw_button(btn);
		break;

	case RTGUI_EVENT_KBD:
		{
			struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*) event;

			if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
			if ((ekbd->key == RTGUIK_RETURN) || (ekbd->key == RTGUIK_SPACE))
			{
				if (RTGUI_KBD_IS_DOWN(ekbd))
				{
					btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
				}
				else
				{
					btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
				}

				/* draw button */
				rtgui_theme_draw_button(btn);

				if ((btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
				{
					/* call on button handler */
					btn->on_button(RTGUI_OBJECT(widget), event);
				}
			}
		}
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;

			/* it's not this widget event, clean status */
			if (rtgui_rect_contains_point(&(RTGUI_WIDGET(btn)->extent), 
				emouse->x, emouse->y) != RT_EOK)
			{
				btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
				/* draw button */
				rtgui_theme_draw_button(btn);

				break;
			}

			if (btn->flag & RTGUI_BUTTON_TYPE_PUSH)
			{
				/* it's a push button */
				if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
				{
					if (btn->flag & RTGUI_BUTTON_FLAG_PRESS)
					{
						btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
					}
					else
					{
						btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
					}

					/* draw button */
					rtgui_theme_draw_button(btn);

					if (btn->on_button != RT_NULL)
					{
						/* call on button handler */
						btn->on_button(RTGUI_OBJECT(widget), event);
					}

#ifndef RTGUI_USING_SMALL_SIZE
					/* invokes call back */
					if (widget->on_mouseclick != RT_NULL &&
						emouse->button & RTGUI_MOUSE_BUTTON_UP)
						return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
#endif
				}
			}
			else
			{
				if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT)
				{
					/* set the last mouse event handled widget */
					struct rtgui_win* win;

					win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
					win->last_mevent_widget = RTGUI_WIDGET(btn);

					/* it's a normal button */
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
					}
					else
					{
						btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
					}

					/* draw button */
					rtgui_theme_draw_button(btn);

#ifndef RTGUI_USING_SMALL_SIZE
					/* invokes call back */
					if (widget->on_mouseclick != RT_NULL &&
						emouse->button & RTGUI_MOUSE_BUTTON_UP)
						return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
#endif

					if (!(btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
					{
						/* call on button handler */
						btn->on_button(RTGUI_OBJECT(widget), event);
					}
				}

			}

			return RT_TRUE;
		}
	}

	return RT_FALSE;
}