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); }
static void rtgui_list_view_onicondraw(struct rtgui_list_view *view, struct rtgui_dc *dc) { struct rtgui_rect rect, item_rect, drawing_rect; rt_ubase_t c, r, item_index; /* col and row index */ rt_ubase_t item_width, item_height; rtgui_image_t *image; if (view->items_count == 0) return; rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); item_index = (view->current_item / view->page_items) * view->page_items; item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / view->col_items; item_height = (rtgui_rect_height(rect) - 4) / view->row_items; image = view->items[0].image; for (r = 0; r < view->row_items; r ++) { for (c = 0; c < view->col_items; c ++) { if (item_index < view->items_count) { item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height; item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width; item_rect.x2 = item_rect.x1 + item_width; item_rect.y2 = item_rect.y1 + item_height; if (item_index == view->current_item) { rtgui_theme_draw_selected(dc, &item_rect); } drawing_rect.x1 = drawing_rect.y1 = 0; drawing_rect.x2 = image->w; drawing_rect.y2 = image->h; rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); drawing_rect.y1 += 5; drawing_rect.y2 += 5; rtgui_image_blit(view->items[item_index].image, dc, &drawing_rect); item_rect.y1 = drawing_rect.y2 + LIST_MARGIN; item_rect.x1 += 3; item_rect.x2 -= 3; rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[item_index].name, &drawing_rect); rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); rtgui_dc_draw_text(dc, view->items[item_index].name, &drawing_rect); item_index ++; } else break; } } }
static void rtgui_list_view_onlistdraw(struct rtgui_list_view *view, struct rtgui_dc *dc) { rt_ubase_t index, page_index; rtgui_rect_t rect, item_rect, image_rect; const struct rtgui_list_item *item; rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); /* get item base rect */ item_rect = rect; item_rect.y1 += 2; item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); /* get current page */ page_index = (view->current_item / view->page_items) * view->page_items; for (index = 0; index < view->page_items; index ++) { if (page_index + index >= view->items_count) break; item = &(view->items[page_index + index]); if (page_index + index == view->current_item) { rtgui_theme_draw_selected(dc, &item_rect); } item_rect.x1 += LIST_MARGIN; if (item->image != RT_NULL) { /* blit on center */ image_rect.x1 = 0; image_rect.y1 = 0; image_rect.x2 = item->image->w; image_rect.y2 = item->image->h; rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL); rtgui_image_blit(item->image, dc, &image_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); } }
static void rtgui_listctrl_update_current(struct rtgui_listctrl *ctrl, rt_uint16_t old_item) { struct rtgui_dc *dc; rtgui_rect_t rect, item_rect; if (old_item / ctrl->page_items != ctrl->current_item / ctrl->page_items) { /* it's not a same page, update all */ rtgui_widget_update(RTGUI_WIDGET(ctrl)); return; } dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl)); if (dc == RT_NULL) return; _rtgui_listctrl_get_rect(ctrl, &rect); rect.x2 -= 1; rect.y2 -= 1; item_rect = rect; /* get old item's rect */ item_rect.x1 += 1; item_rect.x2 -= 1; item_rect.y1 += 2; item_rect.y1 += (old_item % ctrl->page_items) * (2 + ctrl->item_height); item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height); /* draw old item */ rtgui_dc_fill_rect(dc, &item_rect); if (ctrl->on_item_draw != RT_NULL) ctrl->on_item_draw(ctrl, dc, &item_rect, old_item); /* draw current item */ item_rect = rect; /* get current item's rect */ item_rect.x1 += 1; item_rect.x2 -= 1; item_rect.y1 += 2; item_rect.y1 += (ctrl->current_item % ctrl->page_items) * (2 + ctrl->item_height); item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height); /* draw current item */ rtgui_theme_draw_selected(dc, &item_rect); if (ctrl->on_item_draw != RT_NULL) ctrl->on_item_draw(ctrl, dc, &item_rect, ctrl->current_item); rtgui_dc_end_drawing(dc); }
static void _rtgui_listctrl_ondraw(struct rtgui_listctrl *ctrl) { struct rtgui_rect rect, item_rect; struct rtgui_dc *dc; rt_uint16_t page_index, index; dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl)); if (dc == RT_NULL) return; _rtgui_listctrl_get_rect(ctrl, &rect); rtgui_dc_fill_rect(dc, &rect); rect.x2 -= 1; rect.y2 -= 1; /* 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 + ctrl->item_height); /* get current page */ page_index = (ctrl->current_item / ctrl->page_items) * ctrl->page_items; for (index = 0; index < ctrl->page_items; index ++) { if (page_index + index >= ctrl->items_count) break; if (page_index + index == ctrl->current_item) { rtgui_theme_draw_selected(dc, &item_rect); } if (ctrl->on_item_draw != RT_NULL) { ctrl->on_item_draw(ctrl, dc, &item_rect, page_index + index); } /* move to next item position */ item_rect.y1 += (ctrl->item_height + 2); item_rect.y2 += (ctrl->item_height + 2); } /* draw scrollbar */ _rtgui_listctrl_scrollbar_ondraw(ctrl, dc); rtgui_dc_end_drawing(dc); }
static void _rtgui_listctrl_scrollbar_ondraw(struct rtgui_listctrl* ctrl, struct rtgui_dc* dc) { rtgui_rect_t rect; rt_uint32_t height, y1; /* get scrollbar rect */ _rtgui_listctrl_get_scrollbar_rect(ctrl, &rect); rtgui_dc_fill_rect(dc, &rect); height = rtgui_rect_height(rect); height = height / ((ctrl->items_count + (ctrl->page_items - 1))/ctrl->page_items); y1 = (ctrl->current_item / ctrl->page_items) * height; rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height; rtgui_theme_draw_selected(dc, &rect); }
void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_uint16_t old_item) { struct rtgui_dc* dc; const struct rtgui_list_item* item; rtgui_rect_t rect, item_rect; if (old_item/view->page_items != view->current_item/view->page_items) { /* it's not a same page, update all */ rtgui_widget_update(RTGUI_WIDGET(view)); return; } dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); if (dc == RT_NULL) return; rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); /* get old item's rect and draw old item */ item_rect.x1 = rect.x1; item_rect.x2 = rect.x2; item_rect.y1 = rect.y1 + 2; item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height()); item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); rtgui_dc_fill_rect(dc, &item_rect); item_rect.x1 += LIST_MARGIN; item = &(view->items[old_item]); if (item->image != RT_NULL) { struct rtgui_rect image_rect; /* blit on center */ image_rect.x1 = 0; image_rect.y1 = 0; image_rect.x2 = item->image->w; image_rect.y2 = item->image->h; rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL); rtgui_image_blit(item->image, dc, &image_rect); item_rect.x1 += item->image->w + 2; } rtgui_dc_draw_text(dc, item->name, &item_rect); /* draw current item */ item_rect = rect; /* get current item's rect */ item_rect.y1 += 2; item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height()); item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); /* draw current item */ rtgui_theme_draw_selected(dc, &item_rect); item_rect.x1 += LIST_MARGIN; item = &(view->items[view->current_item]); if (item->image != RT_NULL) { struct rtgui_rect image_rect; /* blit on center */ image_rect.x1 = 0; image_rect.y1 = 0; image_rect.x2 = item->image->w; image_rect.y2 = item->image->h; rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL); rtgui_image_blit(item->image, dc, &image_rect); item_rect.x1 += (item->image->w + 2); } rtgui_dc_draw_text(dc, item->name, &item_rect); rtgui_dc_end_drawing(dc); }
static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_uint16_t old_item) { struct rtgui_rect rect, item_rect, drawing_rect; rt_ubase_t c, r; /* col and row index */ rt_ubase_t item_width, item_height; rtgui_image_t* image; struct rtgui_dc* dc; if ((view->items_count == 0) || (old_item == view->current_item)) return; if (old_item/view->page_items != view->current_item/view->page_items) { /* it's not a same page, update all */ rtgui_widget_update(RTGUI_WIDGET(view)); return; } dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); if (dc == RT_NULL) return; rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN)/view->col_items; item_height = (rtgui_rect_height(rect) - 4)/view->row_items; image = view->items[0].image; /* update old item */ r = (old_item % view->page_items)/ view->col_items; c = (old_item % view->page_items)% view->col_items; item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height; item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width; item_rect.x2 = item_rect.x1 + item_width; item_rect.y2 = item_rect.y1 + item_height; rtgui_dc_fill_rect(dc, &item_rect); /* draw image */ drawing_rect.x1 = drawing_rect.y1 = 0; drawing_rect.x2 = image->w; drawing_rect.y2 = image->h; rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); drawing_rect.y1 += 3; drawing_rect.y2 += 3; rtgui_image_blit(view->items[old_item].image, dc, &drawing_rect); /* draw text */ item_rect.y1 = drawing_rect.y2 + LIST_MARGIN; item_rect.x1 += 3; item_rect.x2 -=3; rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), view->items[old_item].name, &drawing_rect); rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); rtgui_dc_draw_text(dc, view->items[old_item].name, &drawing_rect); /* update new item as selected */ r = (view->current_item % view->page_items) / view->col_items; c = (view->current_item % view->page_items) % view->col_items; item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height; item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width; item_rect.x2 = item_rect.x1 + item_width; item_rect.y2 = item_rect.y1 + item_height; rtgui_theme_draw_selected(dc, &item_rect); /* draw image */ drawing_rect.x1 = 0; drawing_rect.y1 = 3; drawing_rect.x2 = image->w; drawing_rect.y2 = 3 + image->h; rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); rtgui_image_blit(view->items[view->current_item].image, dc, &drawing_rect); /* draw text */ item_rect.y1 = drawing_rect.y2 + LIST_MARGIN; item_rect.x1 += 3; item_rect.x2 -=3; rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), view->items[view->current_item].name, &drawing_rect); rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); rtgui_dc_draw_text(dc, view->items[view->current_item].name, &drawing_rect); rtgui_dc_end_drawing(dc); }
void rtgui_filelist_view_update_current(struct rtgui_filelist_view *view, rt_uint16_t old_item) { struct rtgui_dc *dc; struct rtgui_file_item *item; rtgui_rect_t rect, item_rect, image_rect; if (old_item / view->page_items != view->current_item / view->page_items) { /* it's not a same page, update all */ rtgui_widget_update(RTGUI_WIDGET(view)); return; } dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); if (dc == RT_NULL) return; rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); /* get old item rect */ item_rect = rect; item_rect.y1 += 1; item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height()); item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height()); /* get image rect */ image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0; image_rect.x2 = RTGUI_FILELIST_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 */ rtgui_dc_fill_rect(dc, &item_rect); item = &(view->items[old_item]); if (item->type == RTGUI_FITEM_FILE) /* draw item image */ rtgui_image_blit(file_image, dc, &image_rect); else rtgui_image_blit(folder_image, dc, &image_rect); item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2; rtgui_dc_draw_text(dc, item->name, &item_rect); /* draw current item */ item_rect = rect; item_rect.y1 += 1; item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height()); item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height()); rtgui_theme_draw_selected(dc, &item_rect); /* get image base rect */ image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0; image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h; rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL); item = &(view->items[view->current_item]); if (item->type == RTGUI_FITEM_FILE) /* draw item image */ rtgui_image_blit(file_image, dc, &image_rect); else rtgui_image_blit(folder_image, dc, &image_rect); item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2; rtgui_dc_draw_text(dc, item->name, &item_rect); if(view->on_changed!=RT_NULL) { view->on_changed(RTGUI_OBJECT(view),RT_NULL); } rtgui_dc_end_drawing(dc); }
void rtgui_filelist_view_ondraw(struct rtgui_filelist_view *view) { struct rtgui_dc *dc; rt_uint16_t page_index, index; struct rtgui_file_item *item; struct rtgui_rect rect, item_rect, image_rect; dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); if (dc == RT_NULL) return; rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); rtgui_dc_fill_rect(dc, &rect); /* get item base rect */ item_rect = rect; item_rect.y1 += 1; item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height()); /* get image base rect */ image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0; image_rect.x2 = RTGUI_FILELIST_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 */ page_index = (view->current_item / view->page_items) * view->page_items; for (index = 0; index < view->page_items; index ++) { if (page_index + index >= view->items_count) break; item = &(view->items[page_index + index]); if (page_index + index == view->current_item) { rtgui_theme_draw_selected(dc, &item_rect); } else { /* draw background */ rtgui_dc_fill_rect(dc, &item_rect); } /* draw item */ if (item->type == RTGUI_FITEM_FILE) rtgui_image_blit(file_image, dc, &image_rect); else rtgui_image_blit(folder_image, dc, &image_rect); /* draw text */ item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2; rtgui_dc_draw_text(dc, item->name, &item_rect); item_rect.x1 -= RTGUI_FILELIST_MARGIN + file_image->w + 2; /* move to next item position */ item_rect.y1 += (rtgui_theme_get_selected_height() + 1); item_rect.y2 += (rtgui_theme_get_selected_height() + 1); image_rect.y1 += (rtgui_theme_get_selected_height() + 1); image_rect.y2 += (rtgui_theme_get_selected_height() + 1); } rtgui_dc_end_drawing(dc); }
void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_uint16_t old_item) { struct rtgui_dc* dc; const struct rtgui_listbox_item* item; rtgui_rect_t rect, item_rect; if (old_item/box->page_items != box->current_item/box->page_items) { /* it's not a same page, update all */ rtgui_widget_update(RTGUI_WIDGET(box)); return; } dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box)); if (dc == RT_NULL) return; rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect); rect.x2 -= 1; rect.y2 -= 1; item_rect = rect; /* get old item's rect */ item_rect.x1 += 1; item_rect.x2 -= 1; item_rect.y1 += 2; item_rect.y1 += (old_item % box->page_items) * (2 + rtgui_theme_get_selected_height()); item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); /* draw old item */ rtgui_dc_fill_rect(dc, &item_rect); item_rect.x1 += LIST_MARGIN; item = &(box->items[old_item]); if (item->image != RT_NULL) { rtgui_image_blit(item->image, dc, &item_rect); item_rect.x1 += item->image->w + 2; } rtgui_dc_draw_text(dc, item->name, &item_rect); /* draw current item */ item_rect = rect; /* get current item's rect */ item_rect.x1 += 1; item_rect.x2 -= 1; item_rect.y1 += 2; item_rect.y1 += (box->current_item % box->page_items) * (2 + rtgui_theme_get_selected_height()); item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); /* draw current item */ rtgui_theme_draw_selected(dc, &item_rect); item_rect.x1 += LIST_MARGIN; item = &(box->items[box->current_item]); if (item->image != RT_NULL) { rtgui_image_blit(item->image, dc, &item_rect); item_rect.x1 += (item->image->w + 2); } rtgui_dc_draw_text(dc, item->name, &item_rect); rtgui_dc_end_drawing(dc); }