TabPage::TabPage(clan::GUIManager &manager) : clan::GUIComponent(&manager, clan::GUITopLevelDescription("Tab Page", clan::Rect(32 + 256*3, 256*1 + 180*2 + 32, clan::Size(256, 180)), false), "window") { clan::Rect client_area = get_content_box(); tab = new clan::Tab(this); tab->set_geometry(clan::Rect(client_area.left + 16, client_area.top + 10, clan::Size(220, 110))); // tab 1 clan::TabPage *tab_page_1 = tab->add_page("foo"); label_p1 = new clan::Label(tab_page_1); label_p1->set_geometry(clan::Rect(clan::Point(10,10),clan::Size(130,20))); label_p1->set_text("tab page 1"); btn_p1 = new clan::PushButton(tab_page_1); btn_p1->set_geometry(clan::Rect(clan::Point(10,30),clan::Size(130,20))); btn_p1->set_text("Button Foo"); // tab 2 clan::TabPage *tab_page_2 = tab->add_page("bar"); label_p2 = new clan::Label(tab_page_2); label_p2->set_geometry(clan::Rect(clan::Point(10,10),clan::Size(130,20))); label_p2->set_text("tab page 2"); btn_p2 = new clan::PushButton(tab_page_2); btn_p2->set_geometry(clan::Rect(clan::Point(10,30),clan::Size(80,26))); btn_p2->set_text("Button Bar"); // tab 3 clan::TabPage *tab_page_3 = tab->add_page("p3"); }
void MainWindow::on_resized() { clan::Rect client_area = get_content_box(); menubar->set_geometry(clan::Rect(client_area.left, client_area.top, client_area.right, client_area.top + 22)); workspace->set_geometry(clan::Rect(client_area.left, client_area.top + 22, client_area.right, client_area.bottom)); }
Rect GUIComponent::render_text( Canvas &canvas, const std::string &text ) { Rect content_box = get_content_box(); Font font = impl->element.get_font(canvas, get_resources()); int baseline = content_box.top + font.get_font_metrics().get_ascent(); return impl->element.render_text(canvas, font, text, content_box, baseline, false ); }
Rect PopupMenuWindow::get_item_rect(int index) { int count = menu.get_item_count(); int row_height = part_item_row.get_css_height(); int separator_height = part_separator.get_css_height(); PopupMenuItem item = menu.get_item_at(index); Rect content_area = get_content_box(); int w = content_area.get_width(); int y = content_area.top; for (int i = 0; i < count; i++) { if (i == index) break; if (menu.get_item_at(i).is_separator()) y += separator_height; else y += row_height; } Rect rect(0, y, w, y+row_height); return rect; }
Rect GUIComponent::render_text( Canvas &canvas, const std::string &text, int xpos, int baseline ) { Rect content_box = get_content_box(); content_box.left += xpos; content_box.top += baseline; Font font = impl->element.get_font(canvas, get_resources()); return impl->element.render_text(canvas, font, text, content_box, baseline, false ); }
void PopupMenuWindow::on_render(Canvas &canvas, const Rect &update_rect) { Rect rect = get_geometry().get_size(); if (menu.impl->joiner_width > 0) { Rect joiner_rect(0, 0, menu.impl->joiner_width, part_menubar_joiner.get_css_height()); part_menubar_joiner.render_box(canvas, joiner_rect); } Rect client_box = get_content_box(); int offset = 0; int count = menu.get_item_count(); for (int index = 0; index < count; index++) { PopupMenuItem item = menu.get_item_at(index); bool is_selected = (index == selected); int row_height = 0; if (item.is_separator()) { row_height = part_separator.get_css_height(); Rect separator_render_rect(client_box.left, offset, client_box.right, offset+row_height); Rect separator_content_rect = part_separator.get_content_box(separator_render_rect); separator_content_rect.right -= 4; // This thing is already a hack (render to content to render content as render, wtf? :)) separator_content_rect.top += 3; // More hacks.. separator_content_rect.bottom += 3; // Something is really wrong about this stuff. But it fixes the visual layout. part_separator.render_box(canvas, separator_content_rect); } else { part_item_row.set_pseudo_class(CssStr::selected, is_selected); part_item_icon.set_pseudo_class(CssStr::selected, is_selected); part_item_label.set_pseudo_class(CssStr::selected, is_selected); part_item_row.set_pseudo_class(CssStr::disabled, item.is_disabled()); part_item_icon.set_pseudo_class(CssStr::disabled, item.is_disabled()); part_item_check.set_pseudo_class(CssStr::disabled, item.is_disabled()); part_item_label.set_pseudo_class(CssStr::disabled, item.is_disabled()); part_item_accel_label.set_pseudo_class(CssStr::disabled, item.is_disabled()); row_height = part_item_row.get_css_height(); // row rect Rect row_rect(Point(client_box.left, client_box.top + offset), Size(client_box.right, row_height)); part_item_row.render_box(canvas, row_rect); Rect row_box = part_item_row.get_content_box(row_rect); // icon or check if (item.is_checkable()) { if (item.is_checked()) { Rect rect(Point(row_box.left, (row_box.top + row_box.bottom)/2 - check_size.height/2), check_size); part_item_check.render_box(canvas, rect); } } else { PixelBuffer pbuf_icon = item.get_icon(); if (!pbuf_icon.is_null()) { Size icon_size = pbuf_icon.get_size(); Rect rect(Point(row_box.left, (row_box.top + row_box.bottom)/2 - icon_size.height/2), icon_size); Image image(canvas, pbuf_icon, pbuf_icon.get_size()); //TODO: This is slow, and probably should be cached image.set_linear_filter(false); Colorf color = Colorf::white; if (item.is_disabled()) image.set_alpha(0.25f); image.draw(canvas, rect); } } // item text Size text_size = part_item_label.get_render_text_size(canvas, item.get_text()); Size text_full_size = part_item_label.get_border_box(text_size).get_size(); Rect label_render_rect(row_box.left + icon_column_width, row_box.top, row_box.left + icon_column_width + text_full_size.width, row_box.bottom); Rect label_content_rect = part_item_label.get_content_box(label_render_rect); part_item_label.render_box(canvas, label_render_rect); part_item_label.render_text(canvas, item.get_text(), label_content_rect); int center_y = row_box.get_center().y; int arrow_width = part_submenu_arrow.get_css_width(); int arrow_height = part_submenu_arrow.get_css_height(); if (item.has_submenu()) { Rect arrow_rect( row_box.right - arrow_width, center_y - arrow_height/2, row_box.right, center_y + arrow_height/2); Rect arrow_content = part_submenu_arrow.get_content_box(arrow_rect); part_submenu_arrow.render_box(canvas, arrow_content); } else if (!item.get_accelerator_text().empty()) { // accelerator text Size accel_text_size = part_item_accel_label.get_render_text_size(canvas, item.get_accelerator_text()); Size accel_text_full_size = part_item_accel_label.get_border_box(accel_text_size).get_size(); Rect accel_render_rect( row_box.right-arrow_width-accel_text_full_size.width, label_content_rect.top, row_box.right-arrow_width, label_content_rect.bottom); Rect accel_content_rect = part_item_accel_label.get_content_box(accel_render_rect); part_item_accel_label.render_text( canvas, item.get_accelerator_text(), accel_content_rect); } } offset += row_height; } }
VerticalTextPosition GUIComponent::get_vertical_text_align(Canvas &canvas) { return get_vertical_text_align(canvas, get_content_box()); }
Size GUIComponent::get_render_text_size( Canvas &canvas, const std::string &str ) const { return impl->element.get_render_text_box(canvas, str, get_content_box(), get_resources()).get_size(); }
ProgressBar::ProgressBar(clan::GUIManager &manager) : clan::GUIComponent(&manager, clan::GUITopLevelDescription("Progress Bar", clan::Rect(24 + 256*2, 256*1 + 180*2 + 32, clan::Size(256, 180)), false), "window") { clan::Rect client_area = get_content_box(); progressbar1 = new clan::ProgressBar(this); progressbar1->set_geometry(clan::Rect(client_area.left + 5, client_area.top + 5, clan::Size(128, 32))); progressbar1->set_min(0); progressbar1->set_max(100); progressbar1->set_step_size(10); progressbar1->set_position(20); progressbar1->set_marquee_animation_speed(1000); progressbar1->set_marquee_mode(false); clan::Size lineedit_size(48, 20); clan::Size label_size(50, 15); int lineedit_xpos = client_area.left + 5; int lineedit_ypos = client_area.top + 40; int label_xpos = client_area.left + 55; const int lineedit_gap = 25; lineedit_min = new clan::LineEdit(this); lineedit_min->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, lineedit_size)); lineedit_min->set_text("0"); lineedit_min->set_numeric_mode(true); lineedit_min->func_enter_pressed().set(this, &ProgressBar::on_min_enter_pressed, lineedit_min); lineedit_label_min = new clan::Label(this); lineedit_label_min->set_geometry(clan::Rect(label_xpos, lineedit_ypos, label_size)); lineedit_label_min->set_text("Min"); lineedit_ypos += lineedit_gap; lineedit_max = new clan::LineEdit(this); lineedit_max->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, lineedit_size)); lineedit_max->set_text("100"); lineedit_max->set_numeric_mode(true); lineedit_max->func_enter_pressed().set(this, &ProgressBar::on_max_enter_pressed, lineedit_max); lineedit_label_max = new clan::Label(this); lineedit_label_max->set_geometry(clan::Rect(label_xpos, lineedit_ypos, label_size)); lineedit_label_max->set_text("Max"); lineedit_ypos += lineedit_gap; lineedit_step_size = new clan::LineEdit(this); lineedit_step_size->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, lineedit_size)); lineedit_step_size->set_text("10"); lineedit_step_size->func_enter_pressed().set(this, &ProgressBar::on_step_size_enter_pressed, lineedit_step_size); lineedit_label_step_size = new clan::Label(this); lineedit_label_step_size->set_geometry(clan::Rect(label_xpos, lineedit_ypos, label_size)); lineedit_label_step_size->set_text("Step Size"); lineedit_ypos += lineedit_gap; lineedit_position = new clan::LineEdit(this); lineedit_position->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, lineedit_size)); lineedit_position->set_text("20"); lineedit_position->func_enter_pressed().set(this, &ProgressBar::on_position_enter_pressed, lineedit_position); lineedit_label_position = new clan::Label(this); lineedit_label_position->set_geometry(clan::Rect(label_xpos, lineedit_ypos, label_size)); lineedit_label_position->set_text("Position"); lineedit_ypos += lineedit_gap; lineedit_xpos = client_area.left + 110; lineedit_ypos = client_area.top + 40; label_xpos = client_area.left + 160; checkbox_marquee_mode = new clan::CheckBox(this); checkbox_marquee_mode->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, clan::Size(100, 15))); checkbox_marquee_mode->func_checked().set(this, &ProgressBar::on_checked_marquee_mode, checkbox_marquee_mode); checkbox_marquee_mode->func_unchecked().set(this, &ProgressBar::on_unchecked_marquee_mode, checkbox_marquee_mode); checkbox_marquee_mode->set_text("Marquee Mode"); lineedit_ypos += lineedit_gap; lineedit_marquee_speed = new clan::LineEdit(this); lineedit_marquee_speed->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, lineedit_size)); lineedit_marquee_speed->set_text("1000"); lineedit_marquee_speed->func_enter_pressed().set(this, &ProgressBar::on_marquee_speed_enter_pressed, lineedit_marquee_speed); lineedit_label_marquee_speed = new clan::Label(this); lineedit_label_marquee_speed->set_geometry(clan::Rect(label_xpos, lineedit_ypos, label_size)); lineedit_label_marquee_speed->set_text("Marquee Speed"); lineedit_ypos += lineedit_gap; lineedit_marquee_speed->set_enabled(false); pushbutton_apply = new clan::PushButton(this); pushbutton_apply->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, clan::Size(48, 20))); pushbutton_apply->set_text("Apply"); pushbutton_apply->func_clicked().set(this, &ProgressBar::on_apply_clicked, pushbutton_apply); lineedit_ypos += lineedit_gap; pushbutton_step_position = new clan::PushButton(this); pushbutton_step_position->set_geometry(clan::Rect(lineedit_xpos, lineedit_ypos, clan::Size(92, 20))); pushbutton_step_position->set_text("Step Position"); pushbutton_step_position->func_clicked().set(this, &ProgressBar::on_step_position_clicked, pushbutton_step_position); }