Example #1
0
static void rtgui_dc_client_draw_color_point(struct rtgui_dc* self, int x, int y, rtgui_color_t color)
{
	rtgui_rect_t rect;
	rtgui_widget_t *owner;

	if (self == RT_NULL) return;

	/* get owner */
	owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
	if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;

	x = x + owner->extent.x1;
	y = y + owner->extent.y1;

	if (rtgui_region_contains_point(&(owner->clip), x, y, &rect) == RT_EOK) {
		/* draw this point */
		hw_driver->ops->set_pixel(&color, x, y);
	}
}
Example #2
0
rt_bool_t rtgui_combo_event_handler(pvoid wdt, rtgui_event_t* event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
	rtgui_combo_t* cbo = RTGUI_COMBO(wdt);


	RT_ASSERT(widget != RT_NULL);

	switch(event->type)
	{
	case RTGUI_EVENT_PAINT:
		if(widget->on_draw != RT_NULL)
			widget->on_draw(widget, event);
		else
			rtgui_combo_ondraw(cbo);
		break;

	case RTGUI_EVENT_KBD:
		if(widget->on_key != RT_NULL)
			widget->on_key(widget, event);

		return RT_TRUE;

	case RTGUI_EVENT_MOUSE_BUTTON:
	{
		rtgui_rect_t rect;
		struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
		rt_bool_t inclip=RT_EOK;

		if(!RTGUI_WIDGET_IS_ENABLE(cbo)) break;

		if(cbo->tbox->isedit == RT_TRUE)
		{
			/* only detect textbox area */
			inclip = rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect);
		}
		else
		{
			/* detect all area */
			inclip = (rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) &&
			          rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo->tbox),emouse->x,emouse->y,&rect));
		}

		if(inclip == RT_EOK)
		{
			rtgui_combo_get_downarrow_rect(cbo,&rect);
			if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
			{
				if(rtgui_rect_contains_point(&rect,emouse->x,emouse->y) == RT_EOK)
				{
					/* on pull-down button */
					cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_DOWN;
					rtgui_combo_draw_downarrow(cbo);
				}

				if(cbo->lbox != RT_NULL)
				{
					if(RTGUI_WIDGET_IS_HIDE(cbo->lbox))
					{
						/* display pupup listbox */
						RTGUI_WIDGET_SHOW(cbo->lbox);
						rtgui_widget_focus(cbo->lbox);
						rtgui_widget_update_clip_pirate(RTGUI_WIDGET_PARENT(cbo->lbox),cbo->lbox);
						/* set listbox location is 0 */
						cbo->lbox->first_item=0;
						cbo->lbox->now_item = 0;
						if(cbo->lbox->scroll != RT_NULL)
						{
							if(!RTGUI_WIDGET_IS_HIDE(cbo->lbox->scroll))
							{
								rtgui_scrollbar_set_value(cbo->lbox->scroll,cbo->lbox->first_item);
							}
						}
						rtgui_widget_update(RTGUI_WIDGET_PARENT(cbo->lbox));
					}
					else
					{
						/* hide it */
						rtgui_widget_hide(cbo->lbox);
					}
				}
			}
			else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				if(rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) == RT_EOK)
				{
					/* on upriver button */
					cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_UP;
					rtgui_combo_draw_downarrow(cbo);
				}
			}
		}
		else
			rtgui_view_event_handler(widget,event);

		return RT_TRUE;
	}

	default:
		return rtgui_view_event_handler(widget,event);
	}

	return RT_FALSE;
}
Example #3
0
File: edit.c Project: amsl/RTGUI
static void rtgui_edit_onmouse(struct rtgui_edit* edit, struct rtgui_event_mouse* emouse)
{
	rtgui_rect_t rect;

	RT_ASSERT(edit != RT_NULL);
	RT_ASSERT(emouse != RT_NULL);

	rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
	if((rtgui_region_contains_point(&(RTGUI_WIDGET(edit)->clip), emouse->x, emouse->y, &rect) == RT_EOK))
	{
		rt_uint16_t x, y;

		/* multiline text */
		x = (emouse->x - rect.x1) / (edit->font_width);
		y = (emouse->y - rect.y1) / (edit->item_height);
		if((x < edit->col_per_page) && (y < edit->row_per_page))
		{
			if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
			{
				struct edit_line *line;
				rt_uint32_t tmp_pos=0;
				
				edit->visual.x = x;
				edit->visual.y = y;
				
				line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->visual.y);
				if(line == RT_NULL)
					return;
				
				if(edit->visual.x > line->len)
					edit->visual.x = line->len;
				if(edit->upleft.x > 0)
				{
					if(edit->upleft.x >= line->len)
						edit->upleft.x = 0;
					else
						edit->visual.x -= edit->upleft.x;
					rtgui_edit_ondraw(edit);
				}
				if(identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
					edit->visual.x -= (2-tmp_pos);
				if(edit->flag & RTGUI_EDIT_CARET)
				{
					if(edit->caret_timer != RT_NULL)
						rtgui_timer_stop(edit->caret_timer);

					edit->flag &= ~RTGUI_EDIT_CARET;
					rtgui_edit_draw_caret(edit);

					if(edit->caret_timer != RT_NULL)
						rtgui_timer_start(edit->caret_timer);
				}

				/* set widget focus */
				rtgui_widget_focus(RTGUI_WIDGET(edit));

				if(RTGUI_WIDGET_IS_FOCUSED(edit))
				{
					rtgui_edit_init_caret(edit, edit->visual);
					edit->flag |= RTGUI_EDIT_CARET;
					rtgui_edit_draw_caret(edit);
				}
			}
			else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				/* please add codes at here. */
			}
#ifdef RTGUI_EDIT_USING_SCROLL			
			if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
			{
				if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
					rtgui_scrollbar_set_value(edit->vscroll,edit->upleft.y);
			}
			if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit))
			{
				if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll))
					rtgui_scrollbar_set_value(edit->hscroll,edit->upleft.x);
			}
#endif
		}
	}		
}