void Window_Impl::on_render(Canvas &canvas, const Rect &update_rect) { if (!has_frame) return; Rect rect = window->get_size(); int caption_height = part_caption.get_css_height(); int frameleft_width = part_frameleft.get_css_width(); int frameright_width = part_frameright.get_css_width(); int framebottom_height = part_framebottom.get_css_height(); Rect caption_rect = Rect(rect.left, rect.top, rect.right, rect.top + caption_height); part_caption.render_box(canvas, caption_rect); Rect frameleft_rect = Rect(rect.left, rect.top + caption_height, rect.left + frameleft_width, rect.bottom - framebottom_height); part_frameleft.render_box(canvas, frameleft_rect); Rect frameright_rect = Rect(rect.right - frameright_width, rect.top + caption_height, rect.right, rect.bottom - framebottom_height); part_frameright.render_box(canvas, frameright_rect); Rect framebottom_rect = Rect(rect.left, rect.bottom - framebottom_height, rect.right, rect.bottom); part_framebottom.render_box(canvas, framebottom_rect); Rect part_buttonclose_rect = get_part_buttonclose_rect(); part_buttonclose.render_box(canvas, part_buttonclose_rect); Size text_size = window->get_render_text_size(canvas, title); window->render_text(canvas, title, caption_rect.left + 10, caption_rect.top + caption_rect.get_height()/2 + text_size.height/2 - 2); }
Rect Window_Impl::get_client_area() const { Rect rect = window->get_size(); if (!has_frame) return rect; int caption_height = part_caption.get_css_height(); int frameleft_width = part_frameleft.get_css_width(); int frameright_width = part_frameright.get_css_width(); int framebottom_height = part_framebottom.get_css_height(); return Rect(rect.left + frameleft_width, rect.top + caption_height, rect.right - frameright_width, rect.bottom - framebottom_height); }
void Window_Impl::check_move_window(std::shared_ptr<GUIMessage> &msg) { if (draggable == false) { drag_start = false; return; } std::shared_ptr<GUIMessage_Pointer> pointer = std::dynamic_pointer_cast<GUIMessage_Pointer>(msg); if (pointer) { msg->consumed = true; } std::shared_ptr<GUIMessage_Input> input_msg = std::dynamic_pointer_cast<GUIMessage_Input>(msg); if (input_msg) { InputEvent &e = input_msg->input_event; if (e.type == InputEvent::pressed && e.id == mouse_left) { window->bring_to_front(); Rect rect = window->get_size(); int caption_height = part_caption.get_css_height(); Rect caption_rect = Rect(rect.left, rect.top, rect.right, rect.top + caption_height); if (caption_rect.contains(e.mouse_pos)) { drag_start = true; window->capture_mouse(true); last_mouse_pos = e.mouse_pos; } } else if (e.type == InputEvent::released && e.id == mouse_left) { if(drag_start) { drag_start = false; window->capture_mouse(false); } } else if (e.type == InputEvent::pointer_moved && drag_start == true) { if (window->get_parent_component()) { Rect geometry = window->get_geometry(); geometry.translate(e.mouse_pos.x - last_mouse_pos.x, e.mouse_pos.y - last_mouse_pos.y); window->set_geometry(geometry); } else { Rect geometry = window->get_window_geometry(); geometry.translate(e.mouse_pos.x - last_mouse_pos.x, e.mouse_pos.y - last_mouse_pos.y); window->set_window_geometry(geometry); } } } }
Rect Window_Impl::get_part_buttonclose_rect() const { Rect rect = window->get_size(); Size part_buttonclose_size = part_buttonclose.get_css_size(); int frameright_width = part_frameright.get_css_width(); int caption_height = part_caption.get_css_height(); return Rect(rect.right - part_buttonclose_size.width - frameright_width - 2, rect.top + caption_height - part_buttonclose_size.height - 3, rect.right - frameright_width - 2, rect.top + caption_height - 3); }
void ToolBar_Impl::update_layout(Canvas &canvas) { if (need_layout_update == false) return; need_layout_update = false; Rect rect = toolbar->get_size(); Rect component_content = toolbar->get_content_box(); Rect item_content = part_item_normal.get_content_box(component_content); int original_text_gap = part_item_normal.get_property_int(CssStr::text_gap, "3"); if (horizontal) { int x = component_content.left; int center_y = item_content.get_center().y; int item_size = part_item_normal.get_css_width(); std::vector<ToolBarItem>::size_type index, size; size = items.size(); for (index = 0; index < size; index++) { ToolBarItem &item = items[index]; item_content.left = x; Size text_size = toolbar->get_render_text_size(canvas, item.impl->text); int text_gap = original_text_gap; if (text_size.width == 0) text_gap = 0; if (layout == layout_left) { item.impl->icon_pos = Rect(Point(0, center_y-size_icon.height/2-item_content.top), size_icon); item_content.right = item_content.left + item.impl->icon_pos.get_width() + text_gap + text_size.width; item.impl->text_pos = Point(item.impl->icon_pos.right + text_gap, part_item_normal.get_vertical_text_align(canvas, item_content).baseline-item_content.top); } else if (layout == layout_center) { item.impl->icon_pos = Rect(Point(item_size/2-size_icon.width/2, 0), size_icon); item.impl->text_pos = Point(item_size/2-text_size.width/2, item.impl->icon_pos.bottom + text_gap + text_size.height); item_content.right = item_content.left + item_size; } Rect item_render = part_item_normal.get_border_box(item_content); Rect shrink_box = part_item_normal.get_content_shrink_box(); item_render.translate(shrink_box.left,0); item.impl->position = item_render; x = item_render.right; } } else { int y = component_content.top; int center_x = item_content.get_center().x; int size_item = part_item_normal.get_css_height(); std::vector<ToolBarItem>::size_type index, size; size = items.size(); for (index = 0; index < size; index++) { ToolBarItem &item = items[index]; item_content.top = y; Size text_size = toolbar->get_render_text_size(canvas, item.impl->text); int text_gap = original_text_gap; if (text_size.width == 0) text_gap = 0; if (layout == layout_left) { item.impl->icon_pos = Rect(Point(0,0), size_icon); item.impl->text_pos = Point(item.impl->icon_pos.right + text_gap, size_item/2+text_size.height/2); item_content.bottom = item_content.top + size_item; } else if (layout == layout_center) { item.impl->icon_pos = Rect(Point(center_x-size_icon.width/2, 0), size_icon); item.impl->text_pos = Point(center_x-text_size.width/2, item.impl->icon_pos.bottom + text_gap + text_size.height); item_content.bottom = item_content.top + item.impl->icon_pos.get_height() + text_gap + text_size.height; } Rect item_render = part_item_normal.get_border_box(item_content); Rect shrink_box = part_item_normal.get_content_shrink_box(); item_render.translate(0, shrink_box.top); item.impl->position = item_render; y = item_render.bottom; } } // toolbar->request_repaint(); }