Example #1
0
static void
hippo_canvas_grip_paint_below_children(HippoCanvasBox  *box,
                                       cairo_t         *cr,
                                       HippoRectangle  *damaged_box)
{
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_grip_parent_class)->paint_below_children(box, cr, damaged_box);

#if 0
    HippoCanvasGrip *grip = HIPPO_CANVAS_GRIP(box);
    int x, y, w, h;

    get_grip_request(grip, &w, &h);

    hippo_canvas_box_align(box, w, h, &x, &y, &w, &h);

    cairo_rectangle(cr, x, y, w, h);
    cairo_clip(cr);

    if (grip->prelighted)
        hippo_cairo_set_source_rgba32(cr,
                                      hippo_canvas_context_get_color(box->context,
                                              HIPPO_STOCK_COLOR_BG_PRELIGHT));
    else
        hippo_cairo_set_source_rgba32(cr,
                                      hippo_canvas_context_get_color(box->context,
                                              HIPPO_STOCK_COLOR_BG_NORMAL));

    cairo_paint(cr);
#endif
}
Example #2
0
void
HippoCanvas::onPaint(WPARAM wParam, LPARAM lParam)
{
    RECT region;
    if (GetUpdateRect(window_, &region, true)) {

        int regionWidth = region.right - region.left;
        int regionHeight = region.bottom - region.top;

#if 0
        g_debug("SIZING: %p paint region %d,%d %dx%d",
                window_, region.left, region.top,
                regionWidth, regionHeight);
#endif

        // go ahead and request/resize if necessary, so we paint the right thing
        ensureRequestAndAllocation();

        PAINTSTRUCT paint;
        HDC hdc = BeginPaint(window_, &paint);

        //g_debug("paint.fErase=%d", paint.fErase);

        cairo_surface_t *surface = cairo_win32_surface_create(hdc);
        cairo_surface_t *buffer = cairo_surface_create_similar(surface,
            CAIRO_CONTENT_COLOR, regionWidth, regionHeight);
        cairo_t *cr = cairo_create(buffer);
        hippo_canvas_context_win_update_pango(context_, cr);

        // make the buffer's coordinates look like the real coordinates
        cairo_translate(cr, - region.left, - region.top);

        // Paint a background rectangle to the buffer
        cairo_rectangle(cr, region.left, region.top, regionWidth, regionHeight);
        cairo_clip(cr);
        
        // FIXME not the right background color (on linux it's the default gtk background)
        // should use system color, maybe GetThemeSysColorBrush is right. Note that 
        // this rectangle draws the little corner between the scrollbars in 
        // addition to the viewport background.
        hippo_cairo_set_source_rgba32(cr, 0xffffffff);
        cairo_paint(cr);

        // Draw canvas item to the buffer
        if (root_ != (HippoCanvasItem*) NULL) {
            RECT viewport;
            HippoRectangle viewport_hippo;
            HippoRectangle region_hippo;

            getViewport(&viewport);
            
            hippo_rectangle_from_rect(&viewport_hippo, &viewport);
            hippo_rectangle_from_rect(&region_hippo, &region);

            if (hippo_rectangle_intersect(&viewport_hippo, &region_hippo, &region_hippo)) {
                // we have to clip so we don't draw outside the viewport - the canvas
                // doesn't have its own window
                cairo_save(cr);
                cairo_rectangle(cr, region_hippo.x, region_hippo.y, region_hippo.width, region_hippo.height);
                cairo_clip(cr);

                int x, y;
                getCanvasOrigin(&x, &y);
                hippo_canvas_item_process_paint(root_, cr, &region_hippo, x, y);

                cairo_restore(cr);
            }
        }
        
        // pop the update region clip and the translation off the buffer
        cairo_destroy(cr);

        // Copy the buffer to the window
        cairo_t *window_cr = cairo_create(surface);
        cairo_rectangle(window_cr, region.left, region.top, regionWidth, regionHeight);
        cairo_clip(window_cr);
        cairo_set_source_surface(window_cr, buffer, region.left, region.top);
        cairo_paint(window_cr);
        cairo_destroy(window_cr);

        cairo_surface_destroy(buffer);
        cairo_surface_destroy(surface);

        EndPaint(window_, &paint);
    }
}
Example #3
0
static void
hippo_canvas_text_paint_below_children(HippoCanvasBox  *box,
                                       cairo_t         *cr,
                                       GdkRegion       *damaged_region)
{
    HippoCanvasText *text = HIPPO_CANVAS_TEXT(box);
    guint32 color_rgba;

    if (box->color_set) {
        color_rgba = box->color_rgba;
    } else {
        HippoCanvasStyle *style = hippo_canvas_context_get_style(HIPPO_CANVAS_CONTEXT(text));
        color_rgba = hippo_canvas_style_get_foreground_color(style);
    }
        
    /* It would seem more natural to compute whether we are ellipsized or
     * not when we are allocated to some width, but we don't have a layout
     * at that point. We could do it in get_content_height_request(), but
     * the parent could theoretically give us more width than it asked us
     * about (and there are also some quirks in HippoCanvasBox where it 
     * will call get_content_height_request() with a width if 0 at odd times),
     * so doing it here is more reliable. We use is_ellipsized only for
     * computing whether to show a tooltip, and we make the assumption that
     * if the user hasn't seen the text item drawn, they won't need a 
     * tooltip for it.
     */
    text->is_ellipsized = FALSE;

    if ((color_rgba & 0xff) != 0 && text->text != NULL) {
        PangoLayout *layout;
        int layout_width, layout_height;
        int x, y, w, h;
        int allocation_width, allocation_height;
        
        int space_left = box->border_left + box->padding_left;
        int space_right = box->border_right + box->padding_right;

        
        hippo_canvas_item_get_allocation(HIPPO_CANVAS_ITEM(box),
                                         &allocation_width, &allocation_height);
        
        layout = create_layout(text, allocation_width - space_left - space_right);
        pango_layout_get_size(layout, &layout_width, &layout_height);
        layout_width /= PANGO_SCALE;
        layout_height /= PANGO_SCALE;

        text->is_ellipsized = layout_is_ellipsized(layout);
        
        hippo_canvas_box_align(box,
                               layout_width, layout_height,
                               &x, &y, &w, &h);

        /* we can't really "fill" so we fall back to center if we seem to be
         * in fill mode
         */
        if (w > layout_width) {
            x += (w - layout_width) / 2;
        }
        if (h > layout_height) {
            y += (h - layout_height) / 2;
        }
        
        /* Clipping is needed since the layout size could exceed our
         * allocation if we got a too-small allocation.
         * FIXME It would be better to ellipsize or something instead, though.
         */
        cairo_save(cr);
        cairo_rectangle(cr, 0, 0, allocation_width, allocation_height);
        cairo_clip(cr);

        cairo_move_to (cr, x, y);
        hippo_cairo_set_source_rgba32(cr, color_rgba);
        pango_cairo_show_layout(cr, layout);
        cairo_restore(cr);
        
        g_object_unref(layout);
    }
}