static void _rtgui_menu_item_ondraw(struct rtgui_listctrl *list,
									struct rtgui_dc* dc,
									rtgui_rect_t* rect,
									rt_uint16_t index)
{
	rtgui_rect_t item_rect;
	struct rtgui_menu_item* item;

	item_rect = *rect;
	item_rect.x1 += 5;

	/* re-fill item */
	if (list->current_item == index)
	{
		rtgui_color_t bc;

		bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(list));
		RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(list)) = blue;
		rtgui_dc_fill_rect(dc, rect);
		RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(list)) = bc;
	}

	/* get menu item */
	item = (rtgui_menu_item_t*)list->items;
	item = &item[index];

	if (item->type == RTGUI_ITEM_SUBMENU)
	{
		rtgui_rect_t r = {0, 0, 8, 8};
		rtgui_dc_draw_text(dc, item->label, &item_rect);
		item_rect.x1 = item_rect.x2 - 16; item_rect.x2 -= 8;
		rtgui_rect_moveto_align(&item_rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, r.x1, r.y1, 8, right_arrow);
	}
	else if (item->type == RTGUI_ITEM_SEPARATOR)
	{
		rtgui_dc_draw_horizontal_line(dc, item_rect.x1, item_rect.x2, (item_rect.y2 + item_rect.y1)/2);
	}
	else if (item->type == RTGUI_ITEM_CHECK)
	{
		/* not support right now */
	}
	else
	{
		/* normal menu item */	
		rtgui_dc_draw_text(dc, item->label, &item_rect);
		if (item->image != RT_NULL)
			rtgui_image_blit(item->image, dc, &item_rect);
	}
}
예제 #2
0
static int draw_form_head(struct rtgui_form *form, const struct rtgui_font *font,
						  struct rtgui_dc* dc, struct rtgui_rect *rect, struct rtgui_rect *row_rect, char *buf)
{
	struct rtgui_rect form_rect;
	char *pch1;
	const char *pch2;
	int i, j, len;
#if 0
	form_debug(("func:%s, (%d,%d), (%d,%d),bytes:%d, h:%d, r:%d\n", __FUNCTION__,
				rect->x1, rect->y1, rect->x2, rect->y2, form->bytes_of_row, font->height, form->row_cnt_of_fbody));
#endif
	form_rect.x1 = 0;
	form_rect.y1 = 0;
	form_rect.x2 = (form->bytes_of_row + GAG_BETWEEN_COL*form->head_item_cnt) * 8;
	form_rect.y2 = (font->height + GAG_BETWEEN_ROW) * (form->row_cnt_of_fbody + 1);
	rtgui_rect_moveto_align(rect, &form_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	form_rect.y1 += GAG_BEFORE_FORM_HEAD;
	form_rect.y2 += GAG_BEFORE_FORM_HEAD;

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

	j = form->head_item_cnt;
	pch1 = buf;
	for (i=0; i<j; ++i) {
		pch2 = form->head_name[i];
		while ('\0' != *pch2)
			*pch1++ = *pch2++;

		/* 用空格填充列间隔 */
		len = GAG_BETWEEN_COL;
		while (len--)
			*pch1++ = ' ';
	}
	*--pch1 = '\0';

	row_rect->x1 = form_rect.x1;
	row_rect->y1 = form_rect.y1;
	row_rect->x2 = form_rect.x2;
	row_rect->y2 = form_rect.y1 + font->height;
#if 0
	form_debug(("func:%s, (%d,%d), (%d,%d),hic:%d, len:%d, buf:%s\n", __FUNCTION__,
				row_rect->x1, row_rect->y1, row_rect->x2,row_rect->y2,j,pch1 -buf, buf));
#endif
	rtgui_dc_draw_text(dc, buf, row_rect);
	rtgui_dc_draw_horizontal_line(dc, row_rect->x1, row_rect->x2, row_rect->y2+1);

	return SUCC;
}
void rtgui_theme_draw_staticline(struct rtgui_staticline* staticline)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
	
	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(staticline));
	if (dc == RT_NULL) return ;

	rtgui_widget_get_rect(RTGUI_WIDGET(staticline), &rect);
	rtgui_dc_fill_rect(dc, &rect);
	
	if (staticline->orient == RTGUI_HORIZONTAL)
	{
		rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2, rect.y1);
	}
	else
	{
		rtgui_dc_draw_vertical_line(dc, rect.x1, rect.y1, rect.y2);
	}
	
	rtgui_dc_end_drawing(dc);
}
예제 #4
0
static void snake_draw(struct rtgui_widget *widget)
{
    struct rtgui_dc *dc;
    struct rtgui_rect rect;
    rt_uint32_t i;

    dc = rtgui_dc_begin_drawing(widget);
    if (dc == RT_NULL)
    {
        rt_kprintf("dc == RT_NULL\r\n");
        return;
    }

    /* get room size, run once frist. */
    if ((room_size_x == 0) || (room_size_y == 0))
    {
        rt_size_t tmp;

        rtgui_widget_get_rect(widget, &rect);
        rt_kprintf("rect => x1:%d x2:%d, y1:%d y2:%d\r\n", rect.x1, rect.x2, rect.y1, rect.y2);

        room_size_x = rect.x2 - rect.x1;
        room_size_y = rect.y2 - rect.y1;
        memcpy(&room_rect, &rect, sizeof(struct rtgui_rect));
        rt_kprintf("room_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
                   room_rect.x1, room_rect.x2,
                   room_rect.y1, room_rect.y2);

        lattice_size_x = (room_rect.x2 - room_rect.x1) / LATTICE_SIZE;
        lattice_size_y = (room_rect.y2 - room_rect.y1) / LATTICE_SIZE;
        lattice_size_x -= 2;
        lattice_size_y -= 2;
        rt_kprintf("lattice_size_x:%d lattice_size_y:%d\r\n",
                   lattice_size_x,
                   lattice_size_y);

        tmp = (room_rect.x2 - room_rect.x1) - (LATTICE_SIZE * lattice_size_x);
        lattice_rect.x1 = room_rect.x1 + (tmp / 2);
        lattice_rect.x2 = lattice_rect.x1 + (LATTICE_SIZE * lattice_size_x);

        tmp = (room_rect.y2 - room_rect.y1) - (LATTICE_SIZE * lattice_size_y);
        lattice_rect.y1 = room_rect.y1 + (tmp / 2);
        lattice_rect.y2 = lattice_rect.y1 + (LATTICE_SIZE * lattice_size_y);
        rt_kprintf("lattice_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
                   lattice_rect.x1, lattice_rect.x2,
                   lattice_rect.y1, lattice_rect.y2);

        /* create snake. */
        {
            point_t start;
            map = map_init(lattice_size_x, lattice_size_y);
            if (map != RT_NULL)
            {
                start.x = snake_init_pointx;
                start.y = snake_init_pointy;
                run_state = SNAKE_DIR_DOWN;

                if (snake_init(&start, snake_length_init, run_state, map))
                {
                    food_num = 1;
                    food_init(map, food_num);
                }
                else
                {
                    map_deinit(map);
                    map = RT_NULL;
                }
            }
        }
    }

    RTGUI_DC_BC(dc) = BACKGROUND_COLOR;
    rtgui_dc_fill_rect(dc, &room_rect);

    memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
    rect.x2 += 1;
    rect.y2 += 1;
    RTGUI_DC_FC(dc) = WALL_COLOR;
    rtgui_dc_draw_rect(dc, &rect);

    for (i = 1; i < lattice_size_y; i++)
    {
        memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
        rect.x1 += 1;
        rect.x2 -= 1;
        rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2,
                                      rect.y1 + (LATTICE_SIZE * i));
    }

    for (i = 1; i < lattice_size_x; i++)
    {
        memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
        rect.y1 += 1;
        rect.y2 -= 1;
        rtgui_dc_draw_vertical_line(dc, rect.x1 + (LATTICE_SIZE * i),
                                    rect.y1, rect.y2);
    }

    /* draw snake. */
    {
        rt_int32_t x, y;
        rt_bool_t first_node = RT_TRUE;

        for (y = 0; y < map->height; y++)
        {
            for (x = 0; x < map->width; x++)
            {
                switch (map->range[y * map->width + x])
                {
                case NORMAL:
                    break;
                case FOOD:
                    snake_fill_lattice(dc, x, y, FOOD_COLOR);
                    break;
                case OVER:
                    if (first_node)
                    {
                        first_node = RT_FALSE;
                        second_node.x = x;
                        second_node.y = y;
                        snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR);
                    }
                    else
                    {
                        snake_fill_lattice(dc, x, y, SNAKE_COLOR);
                    }
                    break;
                }
            }

        }
    }

    rtgui_dc_end_drawing(dc);

    return;
}