void rtgui_textbox_ondraw(rtgui_textbox_t *box) { /* draw button */ rtgui_rect_t rect; struct rtgui_dc *dc; rtgui_color_t fc; RT_ASSERT(box != RT_NULL); /* begin drawing */ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box)); if (dc == RT_NULL) return; /* get widget rect */ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect); fc = RTGUI_WIDGET_FOREGROUND(box); rtgui_rect_inflate(&rect, -1); /* fill widget rect with white color */ RTGUI_WIDGET_BACKGROUND(box) = white; rtgui_dc_fill_rect(dc, &rect); rtgui_rect_inflate(&rect, 1); /* draw border */ RTGUI_WIDGET_FOREGROUND(box) = RTGUI_RGB(123, 158, 189); rtgui_dc_draw_rect(dc, &rect); /* draw text */ RTGUI_WIDGET_FOREGROUND(box) = fc; if (box->text != RT_NULL) { rect.x1 += RTGUI_WIDGET_DEFAULT_MARGIN; /* draw single text */ if (box->flag & RTGUI_TEXTBOX_MASK) { /* draw mask char */ rt_size_t len = rt_strlen(box->text); if (len > 0) { char *text_mask = rtgui_malloc(len + 1); rt_memset(text_mask, box->mask_char, len + 1); text_mask[len] = 0; rtgui_dc_draw_text(dc, text_mask+box->first_pos, &rect); rtgui_free(text_mask); } } else { rtgui_dc_draw_text(dc, box->text+box->first_pos, &rect); } } rtgui_dc_end_drawing(dc); }
void tetris_refreshmap(struct rtgui_dc *dc) //刷新地图 { rt_uint8_t i, j; rt_uint8_t buf[5]; rtgui_rect_t rect = {XOFFSET, YOFFSET, XOFFSET + 240, YOFFSET + 400}; RTGUI_DC_FC(dc) = RTGUI_RGB(0x55, 0x55, 0x55); rtgui_dc_fill_rect_forecolor(dc, &rect); rect.x1 -= 10; rect.x2 += 150; rect.y1 -= 10; rect.y2 += 10; RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0xff); rtgui_dc_draw_rect(dc, &rect); rect.x1 += 290; rect.x2 -= 30; rect.y1 += 40; rect.y2 -= 360; RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0x00); rtgui_dc_draw_text(dc, "下一个", &rect); rect.y1 += 130; rect.y2 += 130; rtgui_dc_draw_text(dc, "总得分", &rect); rect.y1 += 80; rect.y2 += 80; rtgui_dc_draw_text(dc, "LEVEL", &rect); RTGUI_DC_FC(dc) = RTGUI_RGB(0xff, 0x00, 0x00); rect.x1 += 20; rect.x2 += 20; rect.y1 -= 60; rect.y2 -= 60; rt_sprintf(buf, "%d", score); rtgui_dc_fill_rect(dc, &rect); rtgui_dc_draw_text(dc, buf, &rect); rect.y1 += 80; rect.y2 += 80; rt_sprintf(buf, "%d", level); rtgui_dc_fill_rect(dc, &rect); rtgui_dc_draw_text(dc, buf, &rect); for (i = 0; i < 25; i++) { for (j = 0; j < 15; j++) { if (tetris_map[j][i] != 0) { tetris_drawbox(dc, j, i, tetris_colors[tetris_map[j][i]]); } } } }
static void rtgui_combobox_ondraw(struct rtgui_combobox* box) { /* draw button */ rtgui_color_t bc; struct rtgui_dc* dc; struct rtgui_rect rect, r; /* begin drawing */ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box)); if (dc == RT_NULL) return; bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)); /* get widget rect */ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect); RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = white; /* fill widget rect with background color */ rtgui_dc_fill_rect(dc, &rect); rtgui_dc_draw_rect(dc, &rect); /* draw current item */ if (box->current_item < box->items_count) { rect.x1 += 5; rtgui_dc_draw_text(dc, box->items[box->current_item].name, &rect); } /* restore background color */ RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = bc; /* draw pull down button */ rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH; rtgui_rect_inflate(&rect, -1); rtgui_dc_fill_rect(dc, &rect); if (box->pd_pressed == RT_TRUE) rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN); else rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE); r.x1 = 0; r.y1 = 0; r.x2 = 8; r.y2 = 4; rtgui_rect_moveto_align(&rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); rtgui_dc_draw_byte(dc, r.x1, r.y1, 4, down_arrow); /* end drawing */ rtgui_dc_end_drawing(dc); return; }
void tetris_drawbox(struct rtgui_dc *dc, rt_uint16_t bx, rt_uint16_t by, rtgui_color_t bcolor) { rtgui_rect_t rect = (rtgui_rect_t) { bx * 16 + XOFFSET, by * 16 + YOFFSET, bx * 16 + 15 + XOFFSET, by * 16 + 15 + YOFFSET }; RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0xff); rtgui_dc_draw_rect(dc, &rect); rect.x1++; rect.x2--; rect.y1++; rect.y2--; RTGUI_DC_FC(dc) = bcolor; rtgui_dc_fill_rect_forecolor(dc, &rect); }
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_textbox(rtgui_textbox_t* box) { /* draw button */ struct rtgui_dc* dc; struct rtgui_rect rect; rtgui_color_t fc; /* begin drawing */ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box)); if (dc == RT_NULL) return; /* get widget rect */ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect); fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(box)); /* fill widget rect with white color */ RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = white; rtgui_dc_fill_rect(dc, &rect); /* draw border */ RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(box)) = RTGUI_RGB(123, 158, 189); rtgui_dc_draw_rect(dc, &rect); /* draw text */ RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(box)) = fc; if (box->text != RT_NULL) { rect.x1 += RTGUI_TEXTBOX_MARGIN; if (box->flag & RTGUI_TEXTBOX_MASK) { /* draw '*' */ rt_size_t len = rt_strlen(box->text); if (len > 0) { char *text_mask = rtgui_malloc(len + 1); rt_memset(text_mask, '*', len + 1); text_mask[len] = 0; rtgui_dc_draw_text(dc, text_mask, &rect); rt_free(text_mask); } } else { rtgui_dc_draw_text(dc, box->text, &rect); } /* draw caret */ if (box->flag & RTGUI_TEXTBOX_CARET_SHOW) { rect.x1 += box->position * box->font_width; rect.x2 = rect.x1 + box->font_width; rect.y2 -= 2; rect.y1 = rect.y2 - 3; RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = black; rtgui_dc_fill_rect(dc, &rect); } } /* end drawing */ rtgui_dc_end_drawing(dc); }
/* 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); }
/* * Device Information View * Device: Win32 or Cortex-M3 etc * Memory: * Thread: * IP Address: * Gateway: * DNS: */ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { switch (event->type) { case RTGUI_EVENT_PAINT: { struct rtgui_dc* dc; struct rtgui_rect rect; char* line; rt_uint32_t total, used, max_used; line = rtgui_malloc(256); if (line == RT_NULL) return RT_FALSE; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) { rtgui_free(line); return RT_FALSE; } rtgui_widget_get_rect(widget, &rect); /* fill background */ rtgui_dc_fill_rect(dc, &rect); rect.y2 = rect.y1 + 18; { rt_uint32_t dev_index, rev_index; dev_index = DBGMCU_GetDEVID(); dev_index = (dev_index - 0x410)/2; rev_index = DBGMCU_GetREVID(); switch (rev_index) { case 0x1000: case 0x0000: rev_index = 0; /* Revision A */ break; case 0x1001: case 0x2001: rev_index = 3; /* Revision Z */ break; case 0x2000: rev_index = 1; /* Revision B */ break; case 0x2002: rev_index = 2; /* Revision Y */ break; default: rev_index = 4; /* Unknown */ break; }; /* check device index */ if (dev_index > 4) dev_index = 3; /* draw each information */ sprintf(line, "设备: %s %s", stm32_devname[dev_index], stm32_revname[rev_index]); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; } rt_memory_info(&total, &used, &max_used); sprintf(line, "内存: 当前使用 %d 字节", used); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; { rt_uint16_t rect_width; rtgui_color_t saved; rtgui_rect_t mem_rect = rect; rtgui_rect_inflate(&mem_rect, -2); rtgui_dc_draw_rect(dc, &mem_rect); rtgui_rect_inflate(&mem_rect, -1); rect_width = rtgui_rect_width(mem_rect); saved = RTGUI_WIDGET_BACKGROUND(widget); RTGUI_WIDGET_BACKGROUND(widget) = light_grey; mem_rect.x2 = mem_rect.x1 + (max_used * rect_width / total); rtgui_dc_fill_rect(dc, &mem_rect); RTGUI_WIDGET_BACKGROUND(widget) = blue; mem_rect.x2 = mem_rect.x1 + (used * rect_width / total); rtgui_dc_fill_rect(dc, &mem_rect); /* restore color */ RTGUI_WIDGET_BACKGROUND(widget) = saved; } rect.y1 += 18; rect.y2 += 18; sprintf(line, "线程数: %d", get_thread_cnt()); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #ifdef RT_USING_LWIP { struct ip_addr ip_addr; struct _ip_addr { rt_uint8_t addr0, addr1, addr2, addr3; } *addr; addr = (struct _ip_addr*)&netif_default->ip_addr.addr; sprintf(line, "IP地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; addr = (struct _ip_addr*)&netif_default->gw.addr; sprintf(line, "网关地址: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; addr = (struct _ip_addr*)&netif_default->netmask.addr; sprintf(line, "网络掩码: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #if LWIP_DNS ip_addr = dns_getserver(0); addr = (struct _ip_addr*)&ip_addr; sprintf(line, "DNS地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #endif } #endif rtgui_dc_end_drawing(dc); rtgui_free(line); return RT_FALSE; } case RTGUI_EVENT_KBD: { struct rtgui_event_kbd* ekbd; ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN) { rtgui_workbench_t* workbench; workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(device_view)->parent); rtgui_workbench_remove_view(workbench, device_view); rtgui_view_destroy(device_view); device_view = RT_NULL; } } return RT_FALSE; } /* use parent event handler */ return rtgui_view_event_handler(widget, event); }
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; }