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::DrawTabbedText() { if (shown && font && text.length()) { Rect label_rect; if (text_insets.left) { label_rect.w = rect.w; label_rect.h = rect.h; label_rect.Inset(text_insets.left, text_insets.right, text_insets.top, text_insets.bottom); } else { int border_size = 4; if (style & WIN_RAISED_FRAME && style & WIN_SUNK_FRAME) border_size = 8; label_rect.x = border_size; label_rect.y = border_size; label_rect.w = rect.w - border_size * 2; label_rect.h = rect.h - border_size * 2; } font->SetAlpha(alpha); // no tabs set: if (tab[0] == 0) { DWORD text_flags = DT_WORDBREAK | text_align; if (single_line) text_flags = text_flags | DT_SINGLELINE; if (style & WIN_TEXT_SHADOW) { label_rect.x++; label_rect.y++; if (transparent) { font->SetColor(back_color); DrawText(text.data(), 0, label_rect, text_flags); } else { Color shadow = ShadeColor(back_color, 1.6); font->SetColor(shadow); DrawText(text.data(), 0, label_rect, text_flags); } label_rect.x--; label_rect.y--; } Color fore = ShadeColor(fore_color, 1); font->SetColor(fore); DrawText(text.data(), 0, label_rect, text_flags); } // use tabs: else { } font->SetAlpha(1); } }
void ActiveWindow::DrawStyleRect(int x1, int y1, int x2, int y2, int style) { if (style & WIN_THIN_FRAME) { DrawRect(x1,y1,x2-1,y2-1, ShadeColor(fore_color, 1.0)); } else if (style & WIN_THICK_FRAME) { DrawRect(x1+0,y1+0,x2-1,y2-1, ShadeColor(fore_color, 1.0)); DrawRect(x1+1,y1+1,x2-2,y2-2, ShadeColor(fore_color, 1.0)); DrawRect(x1+2,y1+2,x2-3,y2-3, ShadeColor(fore_color, 1.0)); } else { // draw bevel: if ((style & WIN_RAISED_FRAME) && (style & WIN_SUNK_FRAME)) { Color c = ShadeColor(back_color, 1.6); // full highlight DrawLine(x1, y1, x2-1, y1, c); DrawLine(x1, y1, x1, y2-1, c); c = ShadeColor(back_color, 1.3); // soft highlight DrawLine(x1+1,y1+1, x2-2, y1+1, c); DrawLine(x1+1,y1+1, x1+1, y2-2, c); c = ShadeColor(back_color, 0.6); // soft shadow DrawLine(x2-2,y1+1, x2-2,y2-1, c); DrawLine(x1+1,y2-2, x2-1,y2-2, c); c = ShadeColor(back_color, 0.3); // full shadow DrawLine(x2-1,y1, x2-1,y2, c); DrawLine(x1 ,y2-1, x2,y2-1, c); DrawRect(x1+4,y1+4, x2-5,y2-5, ShadeColor(back_color, 0.6)); // soft shadow DrawRect(x1+5,y1+5, x2-6,y2-6, ShadeColor(back_color, 0.3)); // full shadow DrawLine(x1+5,y2-6, x2-5,y2-6, ShadeColor(back_color, 1.3)); // soft highlight (bottom) DrawLine(x2-6,y1+5, x2-6,y2-6, ShadeColor(back_color, 1.3)); // soft highlight (side) DrawLine(x1+4,y2-5, x2-4,y2-5, ShadeColor(back_color, 1.6)); // soft highlight (bottom) DrawLine(x2-5,y1+4, x2-5,y2-5, ShadeColor(back_color, 1.6)); // soft highlight (side) } else if (style & WIN_RAISED_FRAME) { Color c = ShadeColor(back_color, 1.6); // full highlight DrawLine(x1, y1, x2-1, y1, c); DrawLine(x1, y1, x1, y2-1, c); c = ShadeColor(back_color, 1.3); // soft highlight DrawLine(x1+1,y1+1, x2-2, y1+1, c); DrawLine(x1+1,y1+1, x1+1, y2-2, c); c = ShadeColor(back_color, 0.6); // soft shadow DrawLine(x2-2,y1+1, x2-2,y2-1, c); DrawLine(x1+1,y2-2, x2-1,y2-2, c); c = ShadeColor(back_color, 0.3); // full shadow DrawLine(x2-1,y1, x2-1,y2, c); DrawLine(x1 ,y2-1, x2,y2-1, c); } else if (style & WIN_SUNK_FRAME) { Color c = ShadeColor(back_color, 0.3); // full shadow DrawLine(x1+1,y1+1, x1+1, y2, c); DrawLine(x1+1,y1+1, x2, y1+1, c); c = ShadeColor(back_color, 0.6); // soft shadow DrawLine(x1, y1, x1, y2, c); DrawLine(x1, y1, x2, y1, c); c = ShadeColor(back_color, 1.3); // soft highlight DrawLine(x2-2,y1+1, x2-2,y2-1, c); DrawLine(x1+1,y2-2, x2-1,y2-2, c); c = ShadeColor(back_color, 1.6); // full highlight DrawLine(x2-1,y1+1, x2-1,y2, c); DrawLine(x1 ,y2-1, x2,y2-1, c); } // draw frame: if (style & WIN_BLACK_FRAME) DrawRect(x1,y1,x2-1,y2-1, ShadeColor(Color::Black, 1.0)); else if (style & WIN_WHITE_FRAME) DrawRect(x1,y1,x2-1,y2-1, ShadeColor(Color::White, 1.0)); } }
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); }