void ImageBox::Draw() { if (!shown) return; int x = 0; int y = 0; int w = rect.w; int h = rect.h; int img_w = picture.Width(); int img_h = picture.Height(); Rect box_rect(x,y,w,h); // draw the picture (if any) if (picture.Width()) { Rect irect = CalcPictureRect(); DrawBitmap(irect.x, irect.y, irect.x + irect.w, irect.y + irect.h, &picture, blend_mode); } // draw the border: DrawStyleRect(0, 0, w, h, style); // draw text here: if (font && text.length()) { int border_size = 4; if (style & WIN_RAISED_FRAME && style & WIN_SUNK_FRAME) border_size = 8; Rect label_rect = CalcLabelRect(img_w,img_h); int vert_space = label_rect.h; int horz_space = label_rect.w; DrawText(text.data(), 0, label_rect, DT_CALCRECT | DT_WORDBREAK | DT_CENTER); vert_space = (vert_space - label_rect.h)/2; label_rect.w = horz_space; if (vert_space > 0) label_rect.y += vert_space; Color fore = ShadeColor(fore_color, 1); font->SetColor(fore); DrawText(text.data(), 0, label_rect, DT_WORDBREAK | DT_CENTER); } }
void ActiveWindow::Draw() { int w = rect.w; int h = rect.h; if (w < 1 || h < 1 || !shown) return; float old_alpha = alpha; if (!enabled) SetAlpha(0.5); if (!transparent) { if (texture && texture->Width()) { DrawTextureGrid(); } else { FillRect(0, 0, w, h, ShadeColor(back_color, 1.0)); } } if (enabled && view_list.size()) { ListIter<View> v = view_list; while (++v) v->Refresh(); } if (!transparent) { DrawStyleRect(0, 0, w, h, style); } // draw text here: DrawTabbedText(); if (!enabled) SetAlpha(old_alpha); // update children windows: ListIter<ActiveWindow> iter = children; while (++iter) { ActiveWindow* child = iter.value(); child->Draw(); } }
void ActiveWindow::DrawStyleRect(const Rect& r, int style) { DrawStyleRect(r.x, r.y, r.x+r.w, r.y+r.h, style); }
void ListBox::DrawContent(const Rect& ctrl_rect) { SizeColumns(); Rect item_rect = ctrl_rect; item_rect.h = line_height; int h = rect.h; // draw headings at top, if needed: if (show_headings) { Color save_color = back_color; back_color = ShadeColor(back_color, 1.3); font->SetColor(fore_color); int max_column = columns.size()-1; item_rect.h += HEADING_EXTRA; page_size = (h-item_rect.h) / (line_height + leading); for (int column = 0; column <= max_column; column++) { item_rect.w = GetColumnWidth(column); // draw heading button FillRect(item_rect, back_color); DrawStyleRect(item_rect, WIN_RAISED_FRAME); Rect title_rect = item_rect; title_rect.Deflate(3,3); DrawText(GetColumnTitle(column), 0, title_rect, DT_CENTER|DT_SINGLELINE); item_rect.x += item_rect.w; } item_rect.y += item_rect.h; back_color = save_color; item_rect.h = line_height; } int index = 0; ListIter<ListBoxItem> iter = items; while (++iter && item_rect.y < h) { ListBoxItem* item = iter.value(); if (index++ >= top_index) { // draw main item: int column = 0; item_rect.x = ctrl_rect.x; item_rect.w = GetColumnWidth(column) - 2; if (item_rect.y + item_rect.h > h) { item_rect.h = h - item_rect.y - 1; } Color item_color = GetItemColor(index-1, 0); if (item->selected) { font->SetColor(selected_color); if (seln_style == LIST_ITEM_STYLE_FILLED_BOX) FillRect(item_rect, selected_color * 0.25); if (seln_style >= LIST_ITEM_STYLE_BOX) DrawRect(item_rect, selected_color); } else { font->SetColor(item_color); if (item_style == LIST_ITEM_STYLE_FILLED_BOX) FillRect(item_rect, item_color * 0.25); if (item_style >= LIST_ITEM_STYLE_BOX) DrawRect(item_rect, item_color); } Rect text_rect = item_rect; if (item->image && item->image->Width() > 0 && item->image->Height() > 0) { DrawBitmap(text_rect.x, text_rect.y, text_rect.x + text_rect.w, text_rect.y + line_height, item->image); } else { text_rect.Deflate(2,0); DrawText(item->text.data(), item->text.length(), text_rect, GetColumnAlign(column)|DT_SINGLELINE); } // draw subitems: ListIter<ListBoxCell> sub_iter = item->subitems; while (++sub_iter) { ListBoxCell* sub = sub_iter.value(); column++; item_rect.x += item_rect.w + 2; item_rect.w = GetColumnWidth(column) - 2; if (item->selected) { if (seln_style == LIST_ITEM_STYLE_FILLED_BOX) FillRect(item_rect, selected_color * 0.25); if (seln_style >= LIST_ITEM_STYLE_BOX) DrawRect(item_rect, selected_color); } else { if (item_style == LIST_ITEM_STYLE_FILLED_BOX) FillRect(item_rect, item_color * 0.25); if (item_style >= LIST_ITEM_STYLE_BOX) DrawRect(item_rect, item_color); } if (item->selected) font->SetColor(selected_color); else font->SetColor(GetItemColor(index-1, column)); Rect text_rect = item_rect; if (sub->image && sub->image->Width() > 0 && sub->image->Height() > 0) { DrawBitmap(text_rect.x, text_rect.y, text_rect.x + text_rect.w, text_rect.y + line_height, sub->image); } else { text_rect.Deflate(2,0); DrawText(sub->text.data(), sub->text.length(), text_rect, GetColumnAlign(column)|DT_SINGLELINE); } } item_rect.y += line_height + leading; } } }
void Button::Draw() { if (!IsShown()) return; int x = 0; int y = 0; int w = rect.w; int h = rect.h; int img_w = picture.Width(); int img_h = picture.Height(); float old_alpha = alpha; if (!enabled) SetAlpha(0.35); Rect btn_rect(x,y,w,h); if (!transparent) { if (standard_image) { if (!enabled) { texture = standard_image; } else { switch (button_state) { case -1: texture = activated_image; break; default: case 0: texture = standard_image; break; case 1: if (sticky) texture = activated_image; else texture = transition_image; break; case 2: texture = transition_image; break; } } if (!texture) texture = standard_image; DrawTextureGrid(); } else { FillRect(0, 0, w, h, ShadeColor(back_color, 1.0)); DrawStyleRect(0, 0, w, h, style); } } // draw the picture (if any) if (picture.Width()) { Rect irect = CalcPictureRect(); DrawImage(&picture, irect); } // draw text here: if (font && text.length()) { Rect label_rect = CalcLabelRect(img_w,img_h); int vert_space = label_rect.h; int horz_space = label_rect.w; int align = DT_WORDBREAK | text_align; DrawText(text.data(), 0, label_rect, DT_CALCRECT | align); vert_space = (vert_space - label_rect.h)/2; label_rect.w = horz_space; if (vert_space > 0) label_rect.y += vert_space; if (animated && button_state > 0) { label_rect.x += button_state; label_rect.y += button_state; } if (drop_shadow) { label_rect.x++; label_rect.y++; font->SetColor(back_color); DrawText(text.data(), text.length(), label_rect, align); label_rect.x--; label_rect.y--; } font->SetColor(fore_color); DrawText(text.data(), text.length(), label_rect, align); } if (!enabled) SetAlpha(old_alpha); }