예제 #1
0
파일: textbox.c 프로젝트: xiiing/RTGUI
static void rtgui_textbox_init_caret(rtgui_textbox_t *box, rt_uint16_t position)
{
	int x, y;
	rtgui_color_t color;
	rtgui_rect_t rect;
	int ofs = 0;

	RT_ASSERT(box != RT_NULL);

	if (!RTGUI_WIDGET_IS_FOCUSED(box))
		return;

	rtgui_textbox_get_caret_rect(box, &box->caret_rect, position);
	rect = box->caret_rect;
	rtgui_widget_rect_to_device(RTGUI_WIDGET(box), &rect);

	if (box->caret == RT_NULL)
		box->caret = rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect) * sizeof(rtgui_color_t));

	for (x = rect.x1; x < rect.x2; x++)
	{
		for (y = rect.y1; y < rect.y2; y++)
		{
			rtgui_graphic_driver_get_default()->ops->get_pixel(&color, x, y);
			*(box->caret + ofs) = color;
			ofs++;
		}
	}
}
예제 #2
0
파일: edit.c 프로젝트: amsl/RTGUI
static void rtgui_edit_init_caret(struct rtgui_edit *edit, rtgui_point_t visual)
{
	struct rtgui_gdev *grp = rtgui_gdev_get();
	int x, y;
	rtgui_color_t color;
	rtgui_rect_t rect;
	int ofs=0;

	RT_ASSERT(edit != RT_NULL);
	if(!RTGUI_WIDGET_IS_FOCUSED(edit)) return;

	rtgui_edit_get_caret_rect(edit, &edit->caret_rect, visual);
	rect = edit->caret_rect;
	rtgui_widget_rect_to_device(RTGUI_WIDGET(edit), &rect);

	if(edit->caret == RT_NULL)
		edit->caret = (rtgui_color_t*)rtgui_malloc(RC_W(rect) * RC_H(rect)*sizeof(rtgui_color_t));
	rtgui_timer_stop(edit->caret_timer);

	for(x=rect.x1; x<rect.x2; x++)
	{
		for(y=rect.y1; y<rect.y2; y++)
		{
			grp->ops->get_pixel(&color,x,y);
			*(edit->caret + ofs++) = color;
		}
	}

	rtgui_timer_start(edit->caret_timer);
}
예제 #3
0
static rt_bool_t rtgui_slider_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
{
	rtgui_rect_t rect;
	rtgui_widget_t *widget;
	struct rtgui_dc *dc;

	RT_ASSERT(object);
	widget = RTGUI_WIDGET(object);

	dc = rtgui_dc_begin_drawing(widget);
	if(dc == RT_NULL) return RT_FALSE;

	rtgui_widget_get_rect(widget, &rect);

	if(!RTGUI_WIDGET_IS_FOCUSED(widget))
	{
		/* only clear focus rect */
		rtgui_color_t color = RTGUI_DC_FC(dc);
		RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
		rtgui_dc_draw_focus_rect(dc, &rect);
		RTGUI_DC_FC(dc) = color;
	}

	rtgui_dc_end_drawing(dc);
	return RT_TRUE;
}
예제 #4
0
void rtgui_listbox_ondraw(struct rtgui_listbox* box)
{
	struct rtgui_rect rect, item_rect;
	struct rtgui_dc* dc;
	rt_uint16_t page_index, index;
	const struct rtgui_listbox_item* item;

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

	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	rtgui_dc_fill_rect(dc, &rect);

	rect.x2 -= 1; rect.y2 -= 1;
	/* draw focused border */
	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(box)))
		rtgui_dc_draw_focus_rect(dc, &rect);

	/* get item base rect */
	item_rect = rect;
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* get current page */
	page_index = (box->current_item / box->page_items) * box->page_items;
	for (index = 0; index < box->page_items; index ++)
	{
		if (page_index + index >= box->items_count) break;

		item = &(box->items[page_index + index]);

		if (page_index + index == box->current_item)
		{
			rtgui_theme_draw_selected(dc, &item_rect);
		}
		item_rect.x1 += LIST_MARGIN;

		if (item->image != RT_NULL)
		{
			rtgui_image_blit(item->image, dc, &item_rect);
			item_rect.x1 += item->image->w + 2;
		}
        /* draw text */
		rtgui_dc_draw_text(dc, item->name, &item_rect);

        if (item->image != RT_NULL)
            item_rect.x1 -= (item->image->w + 2);
		item_rect.x1 -= LIST_MARGIN;

        /* move to next item position */
		item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
		item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
	}
	rtgui_dc_end_drawing(dc);
}
예제 #5
0
파일: fileview.c 프로젝트: amsl/RTGUI
static rt_bool_t rtgui_fileview_onunfocus(pvoid wdt, rtgui_event_t* event)
{
	rtgui_fileview_t *fview = RTGUI_FILEVIEW(wdt);

	if(fview == RT_NULL) return RT_FALSE;

	if(!RTGUI_WIDGET_IS_FOCUSED(fview))
	{
		/* clear focus rect */
		rtgui_fileview_update_current(fview);
	}

	return RT_TRUE;
}
예제 #6
0
static rt_bool_t rtgui_form_event_handler(struct rtgui_widget *widget, struct rtgui_event *event)
{
	struct rtgui_form* form;
	//struct rtgui_event_command* ecmd;

	form = RTGUI_FORM(widget);

	switch (event->type) {
	case RTGUI_EVENT_PAINT:
		rtgui_form_ondraw(form);
		break;
#if 0
	case RTGUI_EVENT_COMMAND:
		ecmd = (struct rtgui_event_command*)event;
		switch (ecmd->command_id) {
		case SE_FORM_UPDATE:
			if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(se_form)))
				rtgui_widget_update(RTGUI_WIDGET(se_form));
			break;

		case RE_FORM_UPDATE:
			rtgui_widget_update(RTGUI_WIDGET(re_form));
			break;

		case SYS_FORM_UPDATE:
			rtgui_widget_update(RTGUI_WIDGET(sys_form));
			break;
		}
		break;
#endif
	default:
		/* use form event handler */
		return rtgui_widget_event_handler(widget, event);
	}

	return RT_FALSE;
}
예제 #7
0
파일: fileview.c 프로젝트: amsl/RTGUI
/* update fileview */
void rtgui_fileview_update_current(rtgui_fileview_t* fview)
{
	rtgui_fileview_item_t *item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t *dc;

	RT_ASSERT(fview != RT_NULL);

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

	/* if directory is null, no dispost */
	if(fview->items==RT_NULL)return;

	rtgui_widget_get_rect(fview, &rect);
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	if((fview->old_item >= fview->first_item) &&
	        (fview->old_item < fview->first_item+fview->item_per_page) &&
	        (fview->old_item != fview->now_item))
	{
		/* these condition dispell blinked when drawed */
		/* get old item rect */
		item_rect = rect;
		item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += ((fview->old_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
		item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

		/* get image rect */
		image_rect.x1 = RTGUI_MARGIN;
		image_rect.y1 = 0;
		image_rect.x2 = RTGUI_MARGIN + file_image->w;
		image_rect.y2 = file_image->h;
		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

		/* draw old item */
		item = &(fview->items[fview->old_item]);
		if(item->type == RTGUI_FITEM_FILE) /* draw item image */
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect,Black);

		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		RTGUI_DC_BC(dc) = theme.blankspace;
		RTGUI_DC_FC(dc) = theme.foreground;
		rtgui_dc_fill_rect(dc,&item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}
	/* draw current item */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += ((fview->now_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_MARGIN + file_image->w;
	image_rect.y2 = file_image->h;
	rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

	item = &(fview->items[fview->now_item]);
	if(item->type == RTGUI_FITEM_FILE) /* draw item image */
		rtgui_image_paste(file_image, dc, &image_rect, Black);
	else
		rtgui_image_paste(folder_image, dc, &image_rect, Black);

	if(fview->dlg != RT_NULL)
	{
		if(fview->dlg->filename != RT_NULL)
		{
			rt_free(fview->dlg->filename);
			fview->dlg->filename = RT_NULL;
		}
		fview->dlg->filename = rt_strdup(item->name);
	}

	item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
	item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);

	{
		if(RTGUI_WIDGET_IS_FOCUSED(fview))
		{
			RTGUI_DC_BC(dc) = DarkBlue;
			RTGUI_DC_FC(dc) = theme.blankspace;
		}
		else
		{
			RTGUI_DC_BC(dc) = Gray;
			RTGUI_DC_FC(dc) = theme.foreground;
		}
		rtgui_dc_fill_rect(dc, &item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}

	if(fview->dlg != RT_NULL)
	{
		if(item->type == RTGUI_FITEM_FILE)
		{
			if(fview->dlg->tbox_filename != RT_NULL)
			{
				rtgui_textbox_set_value(fview->dlg->tbox_filename,fview->dlg->filename);
				RTGUI_DC_FC(dc) = theme.foreground;
				rtgui_textbox_ondraw(fview->dlg->tbox_filename);
			}
		}
	}

	rtgui_dc_end_drawing(dc);
}
예제 #8
0
파일: fileview.c 프로젝트: amsl/RTGUI
void rtgui_fileview_ondraw(rtgui_fileview_t* fview)
{
	rt_uint16_t first, i,rx2;
	rtgui_fileview_item_t* item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t* dc;

	RT_ASSERT(fview != RT_NULL);

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

	rtgui_widget_get_rect(fview, &rect);
	rtgui_dc_draw_border(dc, &rect,RTGUI_WIDGET_BORDER_STYLE(fview));
	rtgui_rect_inflate(&rect,-RTGUI_WIDGET_BORDER_SIZE(fview));
	RTGUI_DC_BC(dc) = theme.blankspace;
	rtgui_dc_fill_rect(dc,&rect);
	rtgui_rect_inflate(&rect,RTGUI_WIDGET_BORDER_SIZE(fview));
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	rect.x2 -=1;
	rect.y2 -= 1;

	/* get item base rect */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	rx2 = item_rect.x2;
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_MARGIN + file_image->w;
	image_rect.y2 = file_image->h;
	rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

	/* get current page */
	first = fview->first_item;
	for(i = 0; i < fview->item_per_page; i ++)
	{
		char str_size[32];

		if(first + i >= fview->item_count) break;

		item = &(fview->items[first + i]);

		/* draw item image */
		if(item->type == RTGUI_FITEM_FILE)
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect, Black);

		/* draw text */
		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		if(first + i == fview->now_item)
		{
			if(RTGUI_WIDGET_IS_FOCUSED(fview))
			{
				RTGUI_DC_BC(dc) = DarkBlue;
				RTGUI_DC_FC(dc) = theme.blankspace;
			}
			else
			{
				RTGUI_DC_BC(dc) = Gray;
				RTGUI_DC_FC(dc) = theme.foreground;
			}
			rtgui_dc_fill_rect(dc, &item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}
		else
		{
			/* draw background */
			RTGUI_DC_BC(dc) = theme.blankspace;
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_fill_rect(dc,&item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}

#if (1) /* please turn off it when need. */
		if(item->type == RTGUI_FITEM_FILE)
		{
			rtgui_rect_t rect=item_rect;
			/* print file information */
			rt_snprintf(str_size, 16, "(%dB)",item->size);
			rect.x1 = rect.x2 + RTGUI_MARGIN;
			rect.x2 = rect.x1 + rt_strlen(str_size) * FONT_W(RTGUI_WIDGET_FONT(fview));
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_draw_text(dc, str_size, &rect);
		}
#endif
		item_rect.x1 -= RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = rx2;
		/* move to next item position */
		item_rect.y1 += (RTGUI_SEL_H + 1);
		item_rect.y2 += (RTGUI_SEL_H + 1);

		image_rect.y1 += (RTGUI_SEL_H + 1);
		image_rect.y2 += (RTGUI_SEL_H + 1);
	}

	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
	{
		rtgui_scrollbar_ondraw(fview->sbar);
	}

	rtgui_dc_end_drawing(dc);
}
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;
}
예제 #10
0
void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, item_rect;
	int item_size, bord_size, index;
	rtgui_color_t fc;

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

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
	rtgui_dc_fill_rect(dc, &rect);

	item_size = radiobox->item_size;
	/* get board size */
	if (radiobox->orient == RTGUI_VERTICAL)
		bord_size = item_size;
	else
	{
		rtgui_font_get_metrics(RTGUI_DC_FONT(dc), "H", &item_rect);
		bord_size = rtgui_rect_height(item_rect);
	}

	/* draw box */
	rtgui_rect_inflate(&rect, -bord_size/2);
	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox));

	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = white;
	rect.x1 ++; rect.y1 ++; rect.x2 ++; rect.y2 ++;
	rtgui_dc_draw_rect(dc, &rect);

	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = RTGUI_RGB(128, 128, 128);
	rect.x1 --; rect.y1 --; rect.x2 --; rect.y2 --;
	rtgui_dc_draw_rect(dc, &rect);

	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = fc;

	rtgui_rect_inflate(&rect, bord_size/2);
	if (radiobox->text != RT_NULL)
	{
		struct rtgui_rect text_rect;

		/* draw group text */
		rtgui_font_get_metrics(RTGUI_DC_FONT(dc), radiobox->text, &text_rect);
		rtgui_rect_moveto(&text_rect, rect.x1 + bord_size + 5, rect.y1);
		rect.x1 -= 5; rect.x2 += 5;
		rtgui_dc_fill_rect(dc, &text_rect);
		rect.x1 += 5; rect.x2 -= 5;
		rtgui_dc_draw_text(dc, radiobox->text, &text_rect);
	}

	/* set init item rect */
	item_rect = rect;
	rtgui_rect_inflate(&item_rect, - bord_size);

	if (radiobox->orient == RTGUI_VERTICAL)
	{
		rt_uint16_t offset;
		
		/* set the first text rect */
		item_rect.y2 = item_rect.y1 + item_size;

		offset = (item_size - RADIO_BOX_H) / 2;
		/* draw each radio button */
		for (index = 0; index < radiobox->item_count; index ++)
		{
			if (item_rect.y2 > rect.y2 - item_size) break;

			/* draw radio */
			if (radiobox->item_selection == index)
			{
				if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
					rtgui_dc_draw_focus_rect(dc, &item_rect);

				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + offset, RADIO_BOX_H, radio_checked_byte);
			}
			else
			{
				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + offset, RADIO_BOX_H, radio_unchecked_byte);
			}

			/* draw text */
			item_rect.x1 += item_size + 3;
			rtgui_dc_draw_text(dc, radiobox->items[index], &item_rect);
			item_rect.x1 -= item_size + 3;

			item_rect.y1 += item_size;
			item_rect.y2 += item_size;
		}
	}
	else
	{
		/* set the first text rect */
		item_rect.x2 = item_rect.x1 + item_size;
		item_rect.y2 = item_rect.y1 + bord_size;

		/* draw each radio button */
		for (index = 0; index < radiobox->item_count; index ++)
		{
			if (item_rect.x2 > rect.x2 - item_size) break;

			/* draw radio */
			if (radiobox->item_selection == index)
			{
				if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
					rtgui_dc_draw_focus_rect(dc, &item_rect);
				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_checked_byte);
			}
			else
			{
				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_unchecked_byte);
			}

			/* draw text */
			item_rect.x1 += bord_size + 3;
			rtgui_dc_draw_text(dc, radiobox->items[index], &item_rect);
			item_rect.x1 -= bord_size + 3;

			item_rect.x1 += item_size;
			item_rect.x2 += (item_size - 1);
		}
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
}
예제 #11
0
void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t item)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, item_rect;
	int item_size, bord_size;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(radiobox));
	if (dc == RT_NULL) return;
	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);

	item_size = radiobox->item_size;
	/* get board size */
	if (radiobox->orient == RTGUI_VERTICAL)
		bord_size = item_size;
	else
	{
		rtgui_font_get_metrics(RTGUI_DC_FONT(dc), "H", &item_rect);
		bord_size = rtgui_rect_height(item_rect);
	}

	item_rect = rect;
	rtgui_rect_inflate(&item_rect, - bord_size);
	if (radiobox->orient == RTGUI_VERTICAL)
	{
		/* set the first text rect */
		item_rect.y1 += item * item_size;
		item_rect.y2 = item_rect.y1 + item_size;

		/* draw radio */
		if (radiobox->item_selection == item)
		{
			if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
				rtgui_dc_draw_focus_rect(dc, &item_rect);

			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + (item_size - RADIO_BOX_H) / 2, 
				RADIO_BOX_H, radio_checked_byte);
		}
		else
		{
			item_rect.x2 += 1; item_rect.y2 += 1;
			rtgui_dc_fill_rect(dc, &item_rect);
			item_rect.x2 -= 1; item_rect.y2 -= 1;
			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + (item_size - RADIO_BOX_H) / 2, 
				RADIO_BOX_H, radio_unchecked_byte);
		}

		/* draw text */
		item_rect.x1 += item_size + 3;
		rtgui_dc_draw_text(dc, radiobox->items[item], &item_rect);
	}
	else
	{
		item_rect.x1 += item * item_size;

		/* set the first text rect */
		item_rect.x2 = item_rect.x1 + item_size - 1;
		item_rect.y2 = item_rect.y1 + bord_size;

		/* draw radio */
		if (radiobox->item_selection == item)
		{
			if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
				rtgui_dc_draw_focus_rect(dc, &item_rect);
			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_checked_byte);
		}
		else
		{
			item_rect.x2 += 1; item_rect.y2 += 1;
			rtgui_dc_fill_rect(dc, &item_rect);
			item_rect.x2 -= 1; item_rect.y2 -= 1;
			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_unchecked_byte);
		}

		/* draw text */
		item_rect.x1 += bord_size + 3;
		rtgui_dc_draw_text(dc, radiobox->items[item], &item_rect);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
}
예제 #12
0
void rtgui_theme_draw_checkbox(struct rtgui_checkbox* checkbox)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, box_rect;
	rtgui_color_t bc, fc;

	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox));
	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox));

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

	/* get rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(checkbox), &rect);

    /* fill rect */
	rtgui_dc_fill_rect(dc, &rect);

	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(checkbox)))
	{
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = black;

		/* draw focused border */
		rtgui_rect_inflate(&rect, -1);
		rtgui_dc_draw_focus_rect(dc, &rect);

		rtgui_rect_inflate(&rect, 1);
	}

	/* draw check box */
	box_rect.x1 = 0;
	box_rect.y1 = 0;
	box_rect.x2 = CHECK_BOX_W;
	box_rect.y2 = CHECK_BOX_H;
	rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL);
	box_rect.x1 += 2; box_rect.x2 += 2;

	rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_BOX);
	rtgui_rect_inflate(&box_rect, -1);
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox)) = RTGUI_RGB(247, 247, 246);
	rtgui_dc_fill_rect(dc, &box_rect);
	if (checkbox->status_down == RTGUI_CHECKBOX_STATUS_CHECKED)
	{
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = RTGUI_RGB(33, 161, 33);
		rtgui_dc_draw_byte(dc, box_rect.x1 + 2, box_rect.y1 + 2, 7, checked_byte);
	}

	/* restore saved color */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox)) = bc;
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = fc;

	/* draw text */
	rect.x1 += rtgui_rect_height(rect) - 4 + 5;
	rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(checkbox)), &rect);

	/* end drawing */
	rtgui_dc_end_drawing(dc);

	return;
}
예제 #13
0
/* 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);
}
예제 #14
0
파일: edit.c 프로젝트: amsl/RTGUI
static rt_bool_t rtgui_edit_onkey(pvoid wdt, rtgui_event_t* event)
{
	enum { EDIT_NONE, EDIT_ONDRAW, EDIT_UPDATE };
	struct rtgui_edit *edit = RTGUI_EDIT(wdt);
	struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*)event;
	struct edit_line *line=RT_NULL;
	rt_bool_t update_type = EDIT_NONE;
	
	RT_ASSERT(edit != RT_NULL);
	RT_ASSERT(ekbd != RT_NULL);

	if (RTGUI_KBD_IS_UP(ekbd))
	{	/* reset function key */
		if(ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
			edit->flag &= ~RTGUI_EDIT_CTRL;
		else if(ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
			edit->flag &= ~RTGUI_EDIT_ALT;
		else if(ekbd->key == RTGUIK_RSHIFT || ekbd->key == RTGUIK_LSHIFT)
			edit->flag &= ~RTGUI_EDIT_SHIFT;
		else if(ekbd->key == RTGUIK_CAPSLOCK)
			edit->flag &= ~RTGUI_EDIT_CAPSLOCK;
		else if(ekbd->key == RTGUIK_NUMLOCK)
			edit->flag &= ~RTGUI_EDIT_NUMLOCK;
		return RT_TRUE;
	}
	
	line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
	if(line == RT_NULL) 
		return RT_FALSE;

	/* rt_kprintf("key=%04X ",ekbd->key); */
	if(ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
	{	/* use CTRL key */
		edit->flag |= RTGUI_EDIT_CTRL;
		return RT_FALSE;
	}
	else if(ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
	{	/* use ALT key */
		edit->flag |= RTGUI_EDIT_ALT;
		return RT_FALSE;
	}
	else if(ekbd->key == RTGUIK_RSHIFT || ekbd->key == RTGUIK_LSHIFT)
	{	/* use SHIFT key */
		edit->flag |= RTGUI_EDIT_SHIFT;
		return RT_FALSE;
	}
	else if(ekbd->key == RTGUIK_CAPSLOCK)
	{
		edit->flag |= RTGUI_EDIT_CAPSLOCK;
		return RT_FALSE;
	}
	else if(ekbd->key == RTGUIK_NUMLOCK)
	{
		edit->flag |= RTGUI_EDIT_NUMLOCK;
		return RT_FALSE;
	}
	else if(ekbd->key == RTGUIK_DELETE)
	{	/* delete latter character */
		int ofs = edit->upleft.x + edit->visual.x;
		if(ofs > line->len - 1 || (ofs==0 && line->len==0))
		{	/* will the next line marges into the current line */
			struct edit_line* next_line = line->next;
			if(next_line != RT_NULL)
			{
				struct edit_line *update_end_line;
				
				update_type = EDIT_UPDATE;
				edit->update.start = edit->visual;

				rtgui_edit_connect_line(edit, line, next_line);
				rtgui_edit_delete_line(edit, next_line);

				if(edit->max_rows-edit->upleft.y > edit->row_per_page)
				{
					update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page);
					if(update_end_line != RT_NULL)
					{
						edit->update.end.x = edit->col_per_page;
						edit->update.end.y = edit->upleft.y + edit->row_per_page;
					}
				}
				else
				{
					int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
					edit->update.end.x = edit->col_per_page;
					edit->update.end.y = update_end_index+1;
				}
			}
			line->len = rtgui_edit_line_strlen(line->text);
			goto _edit_exit;
		}
		else if(ofs == line->len - 1)
		{
			line->text[ofs] = '\0';
		}
		else
		{
			char *c;
			rt_uint32_t tmp_pos=1;
			identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
			/* remove character */
			for(c = &line->text[ofs]; c[tmp_pos] != '\0'; c++)
				*c = c[tmp_pos];
			*c = '\0';
		}
		update_type = EDIT_UPDATE;
		edit->update.start = edit->visual;
		edit->update.end.x = line->len-edit->upleft.x;
		if (edit->update.end.x > edit->col_per_page)
			edit->update.end.x = edit->col_per_page;
		edit->update.end.y = edit->visual.y;
	}
	else if(ekbd->key == RTGUIK_BACKSPACE)
	{	
		if(edit->visual.x == 0)
		{   /* incorporated into prev line */
			struct rtgui_event_kbd event_kbd;
			struct edit_line* prev_line = line->prev;
			if(prev_line != RT_NULL)
			{
				struct edit_line *update_end_line;
				
				update_type = EDIT_UPDATE;
				edit->visual.x = prev_line->len;

				rtgui_edit_connect_line(edit, prev_line, line);
				kbd_event_set_key(&event_kbd, RTGUIK_UP);
				rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
				rtgui_edit_delete_line(edit, line);

				edit->update.start = edit->visual; /* update.start.y is changed */
				if(edit->max_rows-edit->upleft.y > edit->row_per_page)
				{
					update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page);
					if(update_end_line != RT_NULL)
					{
						edit->update.end.x = edit->col_per_page;
						edit->update.end.y = edit->upleft.y + edit->row_per_page;
					}
				}
				else
				{
					int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
					edit->update.end.x = edit->col_per_page;
					edit->update.end.y = update_end_index+1;
				}
			}
			goto _edit_exit;
		}
		
		/* delete front character */
		if(edit->visual.x == line->len)
		{
			rt_uint32_t tmp_pos=1;
			identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
			line->text[edit->visual.x-tmp_pos] = '\0';
			edit->visual.x -= tmp_pos;
		}
		else if(edit->visual.x != 0)
		{	/* remove current character */
			char *c;
			rt_uint32_t tmp_pos=1;
			identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
			/* remove character */
			for(c = &line->text[edit->visual.x - tmp_pos]; c[tmp_pos] != '\0'; c++)
			{
				*c = c[tmp_pos];
			}
			*c = '\0';
			edit->visual.x -= tmp_pos;
		}
		/* adjusted line buffer length */
		if(rtgui_edit_alloc_len(edit->bzsize, line->len+2) < line->zsize)
		{	
			line->zsize = rtgui_edit_alloc_len(edit->bzsize, line->len+1);
			line->text = rt_realloc(line->text, line->zsize);
		}
		update_type = EDIT_UPDATE;
		edit->update.start = edit->visual; 
		edit->update.end.x = line->len;
		edit->update.end.y = edit->visual.y;
	}
	else if(ekbd->key == RTGUIK_UP)
	{	/* move to prev line */
		struct edit_line* prev_line;
		if(edit->visual.y > 0)
			edit->visual.y --;
		else
		{
			/* change first row */
			if(edit->upleft.y > 0)
			{
				edit->upleft.y --;
				if(edit->first_line->prev != RT_NULL)
					edit->first_line = edit->first_line->prev;
				update_type = EDIT_ONDRAW;
			}
		}
		
		/* The position of the recount X */
		prev_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->visual.y);
		if(prev_line == RT_NULL)
			return RT_FALSE;

		if(edit->upleft.x > 0)
		{
			if(prev_line->len <= edit->upleft.x)
			{
				if(prev_line->len <= edit->col_per_page)
				{
					edit->upleft.x = 0;
					edit->visual.x = prev_line->len;
				}
				else
				{
					edit->upleft.x = prev_line->len - (edit->col_per_page-1);
					edit->visual.x = edit->col_per_page-1;
				}
				update_type = EDIT_ONDRAW;
			}
			else if(prev_line->len - edit->upleft.x < edit->col_per_page)
			{
				if(edit->visual.x > prev_line->len - edit->upleft.x)
					edit->visual.x = prev_line->len - edit->upleft.x;
				else
				{
					rt_uint32_t tmp_pos=0;
					if(identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
						edit->visual.x -= (2-tmp_pos);
				}
			}
		}
		else if(edit->visual.x > prev_line->len)
			edit->visual.x = prev_line->len;
		else if(prev_line->len >= 2)
		{
			rt_uint32_t tmp_pos=0;
			if(identify_double_byte(edit, prev_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
				edit->visual.x -= (2-tmp_pos);
		}

#ifdef RTGUI_EDIT_USING_SCROLL		
		/* update vscroll */
		if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
		{
			if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
				rtgui_scrollbar_set_value(edit->vscroll,edit->upleft.y);
		}
#endif
	}
	else if(ekbd->key == RTGUIK_DOWN)
	{	
		struct edit_line *tail_line, *next_line;
		tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
		if(tail_line != RT_NULL)
		{	/* it is tail line */
			if(tail_line == edit->tail) return RT_FALSE;
		}
		/* move to next line */
		if(edit->visual.y < edit->row_per_page - 2)
		{
			edit->visual.y ++;
		}
		else if(edit->visual.y+edit->upleft.y < edit->max_rows-1)
		{
			/* change first row */
			edit->upleft.y++;
			if(edit->first_line->next != RT_NULL)
				edit->first_line = edit->first_line->next;
			update_type = EDIT_ONDRAW;
		}
		
		/* adjust next line end position */
		next_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->visual.y);
		if(next_line == RT_NULL)	
			return RT_FALSE;
		
		if(edit->upleft.x > 0)
		{
			if(next_line->len <= edit->upleft.x)
			{
				if(next_line->len <= edit->col_per_page)
				{
					edit->upleft.x = 0;
					edit->visual.x = next_line->len;
				}
				else
				{
					edit->upleft.x = next_line->len - (edit->col_per_page-1);
					edit->visual.x = edit->col_per_page-1;
				}
				update_type = EDIT_ONDRAW;
			}
			else if(next_line->len - edit->upleft.x < edit->col_per_page)
			{
				if(edit->visual.x > next_line->len - edit->upleft.x)
					edit->visual.x = next_line->len - edit->upleft.x;
				else
				{
					rt_uint32_t tmp_pos=0;
					if(identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
						edit->visual.x -= (2-tmp_pos);
				}
			}
		}
		else if(edit->visual.x > next_line->len)
			edit->visual.x = next_line->len;
		else if(next_line->len >= 2)
		{
			rt_uint32_t tmp_pos=0;
			if(identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
				edit->visual.x -= (2-tmp_pos);
		}

#ifdef RTGUI_EDIT_USING_SCROLL		
		/* update vscroll */
		if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
		{
			if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
				rtgui_scrollbar_set_value(edit->vscroll,edit->upleft.y);
		}
#endif
	}
	else if(ekbd->key == RTGUIK_LEFT)
	{	/* move to prev char */
		if(edit->visual.x > 0)
		{
			rt_uint32_t tmp_pos=1;
			identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
			edit->visual.x -= tmp_pos;
			if(edit->visual.x == -1)
			{
				edit->visual.x = 0;
				edit->upleft.x -= 1;
				update_type = EDIT_ONDRAW;
			}
		}
		else
		{
			if(edit->upleft.x > 0)
			{
				rt_uint32_t tmp_pos=1;
				identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
				edit->upleft.x -= tmp_pos;
				update_type = EDIT_ONDRAW;
			}
			else
			{	
				struct rtgui_event_kbd event_kbd;
				struct edit_line* first_line;
				first_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
				if(first_line != RT_NULL)
				{	/* it is head line */
					if(first_line == edit->head) return RT_FALSE;
				}
				/* move the caret to the prev line end */
				kbd_event_set_key(&event_kbd, RTGUIK_UP);
				rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
				kbd_event_set_key(&event_kbd, RTGUIK_END);
				rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
			}
		}
	}
	else if(ekbd->key == RTGUIK_RIGHT)
	{	/* move to next char */
		if(line->len >= edit->col_per_page)
		{
			if(edit->upleft.x+edit->col_per_page <= line->len)
			{
				if(edit->visual.x < edit->col_per_page-1)
				{
					rt_uint32_t tmp_pos=1;
					identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
					edit->visual.x += tmp_pos;
				}
				else if(edit->visual.x == edit->col_per_page-1)
				{
					if(edit->upleft.x+edit->col_per_page < line->len)
						edit->upleft.x ++;
					else
						edit->upleft.x = line->len - edit->col_per_page + 1;
					update_type = EDIT_ONDRAW;
				}
			}
			else
			{
				struct rtgui_event_kbd event_kbd;
				/* move to next head */
				kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
				rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
				kbd_event_set_key(&event_kbd, RTGUIK_HOME);
				rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
			}
		}
		else
		{
			if(edit->visual.x < line->len)
			{
				rt_uint32_t tmp_pos=1;
				identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
				edit->visual.x += tmp_pos;
			}
			else
			{
				struct rtgui_event_kbd event_kbd;
				struct edit_line* tail_line;
				tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
				if(tail_line != RT_NULL)
				{	/* it is tail line */
					if(tail_line == edit->tail) return RT_FALSE;
				}
				/* move the caret to the next line head */
				kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
				rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
				kbd_event_set_key(&event_kbd, RTGUIK_HOME);
				rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
			}
		}
	}
	else if(ekbd->key == RTGUIK_HOME)
	{	/* move cursor to line head */
		edit->visual.x = 0;
		if(edit->upleft.x > 0)
		{
			edit->upleft.x = 0;
			update_type = EDIT_ONDRAW;
		}
	}
	else if(ekbd->key == RTGUIK_END)
	{	/* move cursor to line tail */
		if(line->len >= edit->col_per_page)
		{
			edit->visual.x = edit->col_per_page - 1;
			edit->upleft.x = line->len - (edit->col_per_page-1);
			update_type = EDIT_ONDRAW;
		}
		else
			edit->visual.x = line->len;
	}
	else if(ekbd->key == RTGUIK_TAB)
	{
		int space_nums;
		struct rtgui_event_kbd event_kbd;

		/* using spaces to replace TAB */
		space_nums = edit->tabsize - (edit->upleft.x+edit->visual.x) % edit->tabsize;
		while(space_nums--)
		{
			kbd_event_set_key(&event_kbd, RTGUIK_SPACE);
			rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
		}
	}
	else if(ekbd->key == RTGUIK_PAGEUP)
	{
		if(edit->max_rows <= edit->row_per_page)
			return RT_FALSE;
	}
	else if(ekbd->key == RTGUIK_PAGEDOWN)
	{
		if(edit->max_rows <= edit->row_per_page)
			return RT_FALSE;
	}
	else if(ekbd->key == RTGUIK_RETURN)
	{
		struct edit_line *update_end_line;
		struct rtgui_event_kbd event_kbd;
	
		/* insert a new line buffer */
		rtgui_edit_insert_line(edit, line, line->text + edit->upleft.x + edit->visual.x);
		line->text[edit->upleft.x + edit->visual.x] = '\0';
		line->len = rtgui_edit_line_strlen(line->text);
		
		/* adjust update line end position */
		if((edit->max_rows-edit->upleft.y) > edit->row_per_page)
		{
			update_type = EDIT_UPDATE;
			edit->update.start = edit->visual;
			update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page-1);
			if(update_end_line != RT_NULL)
			{
				edit->update.end.x = update_end_line->len;
				edit->update.end.y = edit->upleft.y + edit->row_per_page;
			}
		}
		else if((edit->max_rows-edit->upleft.y) < edit->row_per_page)
		{
			int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
			update_type = EDIT_UPDATE;
			edit->update.start = edit->visual;
			edit->update.end.x = edit->tail->len;
			edit->update.end.y = update_end_index;
		}
		
		/* move the caret to the next line head */
		kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
		rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
		kbd_event_set_key(&event_kbd, RTGUIK_HOME);
		rtgui_edit_onkey(edit, (rtgui_event_t*)&event_kbd);
	}
	else
	{
		if(isprint((unsigned char)ekbd->key))
		{	/* it's may print character */
			update_type = EDIT_UPDATE;
			edit->update.start = edit->visual;
			
			if(edit->flag & RTGUI_EDIT_SHIFT)
				ekbd->key = query_shift_code(ekbd->key);
			if(edit->flag & RTGUI_EDIT_CAPSLOCK)
				ekbd->key = query_caps_code(ekbd->key);

			if(line->len < line->zsize-1)
			{
				int ofs = edit->upleft.x + edit->visual.x;
				if(edit->visual.x >= edit->col_per_page-1)
				{
					edit->upleft.x ++;
					update_type = EDIT_ONDRAW;
				}

				if(ofs < line->len)
				{
					char* c;
					for(c = &line->text[line->len]; c != &line->text[ofs]; c--)
						*c = *(c-1);
				}
				line->text[ofs] = ekbd->key;
				if(edit->visual.x < edit->col_per_page-1)
					edit->visual.x ++;
				line->text[line->len+1] = '\0';
				line->len = rtgui_edit_line_strlen(line->text);
				edit->update.end.x = line->len;
				if(edit->update.end.x > edit->col_per_page)
					edit->update.end.x = edit->col_per_page;
				edit->update.end.y = edit->visual.y;
			}
			else
			{	/* adjust line buffer's zone size */
				line->zsize = rtgui_edit_alloc_len(edit->bzsize, line->len+1);
				line->text = rt_realloc(line->text, line->zsize);
				rtgui_edit_onkey(edit, event); /* reentry */
			}
		}
		else
		{
			/* Is small keyboard ? */
			if(edit->flag & RTGUI_EDIT_NUMLOCK)
			{
				if(is_small_keyboard(&ekbd->key))
					rtgui_edit_onkey(edit, event);
				/* small keyboard another value reserved */
			}
		}
	}
	line->len = rtgui_edit_line_strlen(line->text); 

_edit_exit:
	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);/* refresh it */
		if(edit->caret_timer != RT_NULL)
			rtgui_timer_start(edit->caret_timer);
	}

	/* re-draw edit widget */
	if(update_type == EDIT_ONDRAW)
		rtgui_edit_ondraw(edit);
	else if(update_type == EDIT_UPDATE)
		rtgui_edit_update(edit);

	if(RTGUI_WIDGET_IS_FOCUSED(edit))
	{
		rtgui_edit_init_caret(edit, edit->visual);
		edit->flag |= RTGUI_EDIT_CARET;
		rtgui_edit_draw_caret(edit);
	}
	return RT_TRUE;
}
예제 #15
0
파일: edit.c 프로젝트: 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
		}
	}		
}
예제 #16
0
rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_listbox* box = RT_NULL;

	box = RTGUI_LISTBOX(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_listbox_ondraw(box);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

            /* recalculate page items */
			box->page_items = resize->h  / (2 + rtgui_theme_get_selected_height());
        }
        break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			rtgui_rect_t rect;
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;

			/* calculate selected item */

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

			if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && (box->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

				/* set focus */
				rtgui_widget_focus(widget);
				{
					struct rtgui_rect rect;
					struct rtgui_dc* dc;

					dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
					if (dc != RT_NULL)
					{
						/* get widget rect */
						rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
						/* update focus border */
						rect.x2 -= 1; rect.y2 -= 1;
						/* draw focused border */
						if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(box)))
							rtgui_dc_draw_focus_rect(dc, &rect);
						rtgui_dc_end_drawing(dc);
					}
				}

				if ((index < box->items_count) && (index < box->page_items))
				{
					rt_uint16_t old_item;

					old_item = box->current_item;

					/* set selected item */
					box->current_item = (box->current_item/box->page_items) * box->page_items + index;
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						/* down event */
						rtgui_listbox_update_current(box, old_item);
					}
					else
					{
						/* up event */
						if (box->on_item != RT_NULL)
						{
							box->on_item(RTGUI_WIDGET(box), RT_NULL);
						}
					}
				}
			}

			return RT_TRUE;
		}

    case RTGUI_EVENT_KBD:
        {
            struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
            if ((ekbd->type == RTGUI_KEYDOWN) && (box->items_count > 0))
            {
				rt_uint16_t old_item;

				old_item = box->current_item;
                switch (ekbd->key)
                {
				case RTGUIK_LEFT:
					if (box->current_item - box->page_items >= 0)
						box->current_item -= box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_UP:
					if (box->current_item > 0)
						box->current_item --;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RIGHT:
					if (box->current_item + box->page_items < box->items_count - 1)
						box->current_item += box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (box->current_item < box->items_count - 1)
						box->current_item ++;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (box->on_item != RT_NULL)
					{
						box->on_item(RTGUI_WIDGET(box), RT_NULL);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use box event handler */
    return rtgui_widget_event_handler(widget, event);
}