示例#1
0
void rtgui_form_ondraw(struct rtgui_form *form)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, row_rect;
	const struct rtgui_font *font;
	char *buf;
	char *pch1;
	int i, j;

	if (NULL == form) {
		form_debug(("fun:%s(), param error!\n", __FUNCTION__));
		return;
	}

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

	buf = rt_malloc(form->bytes_of_row);
	if (NULL == buf) {
		form_debug(("fun:%s(), line:%d:%d malloc fail!\n", __FUNCTION__, __LINE__, form->bytes_of_row));
		rtgui_dc_end_drawing(dc);
		return;
	}

	rtgui_widget_get_rect(RTGUI_WIDGET(form), &rect);
	rtgui_dc_fill_rect(dc, &rect);
	font = RTGUI_DC_FONT(dc);
	if (font == RT_NULL)
		font = rtgui_font_default();

	draw_form_head(form, font, dc, &rect, &row_rect, buf);

	j = form->row_cnt_of_fbody;
	pch1 = form->fbody;
	for (i=0; i<j; ++i) {
		row_rect.y1 += font->height + GAG_BETWEEN_ROW;
		row_rect.y2 += font->height + GAG_BETWEEN_ROW;
		rtgui_dc_draw_text(dc, pch1, &row_rect);

		form_debug(("fun:%s(), %dth line:%s!\n", __FUNCTION__, i, pch1));

		pch1 += form->bytes_of_row;
	}

	rtgui_dc_end_drawing(dc);

	rt_free(buf);
	return;
}
示例#2
0
void rtgui_form_update_row(struct rtgui_form *form, int row)
{
	struct rtgui_dc* dc;
	struct rtgui_rect row_rect;
	const struct rtgui_font *font;
	char *pch1;
	int i;

	if (NULL==form || row<=0) {
		form_debug(("fun:%s(), param error(%x, %d)!\n", __FUNCTION__, form, row));
		return;
	}
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(form));
	if (dc == RT_NULL) return;

	if (0xffff == form->form_rect.x1)
		return;

	font = RTGUI_DC_FONT(dc);
	if (font == RT_NULL) {
		/* use system default font */
		font = rtgui_font_default();
	}

	i = (row * (font->height + GAG_BETWEEN_ROW));
	row_rect.x1 = form->form_rect.x1;
	row_rect.y1 = form->form_rect.y1 + i;
	row_rect.x2 = form->form_rect.x2;
	row_rect.y2 = form->form_rect.y2 + i;

	pch1 = form->fbody + (row - 1) * form->bytes_of_row;
	rtgui_dc_draw_text(dc, pch1, &row_rect);

	rtgui_dc_end_drawing(dc);

	return;
}
示例#3
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);
}
示例#4
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_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);
}
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);
}