コード例 #1
0
void ToolBar_Impl::on_render(Canvas &canvas, const Rect &update_rect)
{
    update_layout(canvas);

    Rect rect = toolbar->get_size();

    std::vector<ToolBarItem>::size_type index, size;
    size = items.size();
    for (index = 0; index < size; index++)
    {
        ToolBarItem &item = items[index];

        GUIThemePart part_item = part_item_normal;
        if (index == index_hot_item)
            part_item = part_item_hot;
        if (index == index_pressed_item || items[index].impl->pressed)
            part_item = part_item_pressed;

        Rect item_content = part_item.get_content_box(item.impl->position);
        part_item.render_box(canvas, item.impl->position);

        Rect icon_pos = item.impl->icon_pos;
        icon_pos.translate(item_content.left, item_content.top);

        Point pressed_offset(0,0);
        if (index == index_pressed_item)
            pressed_offset = Point(0,0); // To do: Read this from css properties or remove feature totally

        if (!item.impl->icon.is_null())
        {
            icon_pos.translate(pressed_offset);
            item.impl->icon.set_frame(item.impl->frame);
            item.impl->icon.draw(canvas, icon_pos);
        }

        //FIXME: toolbar->push_cliprect(canvas, item_content);
        //canvas.fill_rect(item_content, Colorf::gray);
        // FIXME: Added 256 as a hack .. until someone fixes this class
        part_item_normal.render_text(canvas, item.impl->text, Rect(item_content.left + item.impl->text_pos.x + pressed_offset.x, item_content.top + item.impl->text_pos.y + pressed_offset.y, item_content.right+256, item_content.bottom+256));
        //toolbar->pop_cliprect(canvas);
    }
}
コード例 #2
0
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();
}