コード例 #1
0
ファイル: rbgtkstyle.c プロジェクト: benolee/ruby-gnome2
static VALUE
style_paint_diamond(VALUE self, VALUE gdkwindow, VALUE state_type, VALUE shadow_type, VALUE area, VALUE widget, VALUE detail, VALUE x, VALUE y, VALUE width, VALUE height)
{
    gtk_paint_diamond(_SELF(self), GDK_WINDOW(RVAL2GOBJ(gdkwindow)),
                    RVAL2STATE(state_type), RVAL2SHADOW(shadow_type), RVAL2REC(area),
                    GTK_WIDGET(RVAL2GOBJ(widget)), RVAL2CSTR(detail),
                    NUM2INT(x), NUM2INT(y), NUM2INT(width), NUM2INT(height));
    return self;
}
コード例 #2
0
ファイル: eek-preview.cpp プロジェクト: wdmchaft/DoonSketch
gboolean eek_preview_expose_event( GtkWidget* widget, GdkEventExpose* event )
{
/*     g_message("Exposed!!!   %s", GTK_WIDGET_HAS_FOCUS(widget) ? "XXX" : "---" ); */
    gint insetX = 0;
    gint insetY = 0;

    (void)event;
/*
    gint lower = widget->allocation.width;
    lower = (widget->allocation.height < lower) ? widget->allocation.height : lower;
    if ( lower > 16 ) {
        insetX++;
        if ( lower > 18 ) {
            insetX++;
            if ( lower > 22 ) {
                insetX++;
                if ( lower > 24 ) {
                    insetX++;
                    if ( lower > 32 ) {
                        insetX++;
                    }
                }
            }
        }
        insetY = insetX;
    }
*/

    if ( GTK_WIDGET_DRAWABLE( widget ) ) {
        GtkStyle* style = gtk_widget_get_style( widget );

        if ( insetX > 0 || insetY > 0 ) {
            gtk_paint_flat_box( style,
                                widget->window,
                                (GtkStateType)GTK_WIDGET_STATE(widget),
                                GTK_SHADOW_NONE,
                                NULL,
                                widget,
                                NULL,
                                0, 0,
                                widget->allocation.width, widget->allocation.height);
        }

        GdkGC *gc = gdk_gc_new( widget->window );
        EekPreview* preview = EEK_PREVIEW(widget);
        GdkColor fg = {0, static_cast<guint16>(preview->_r), static_cast<guint16>(preview->_g), static_cast<guint16>(preview->_b)};

        gdk_colormap_alloc_color( gdk_colormap_get_system(), &fg, FALSE, TRUE );

        gdk_gc_set_foreground( gc, &fg );

        gdk_draw_rectangle( widget->window,
                            gc,
                            TRUE,
                            insetX, insetY,
                            widget->allocation.width - (insetX * 2), widget->allocation.height - (insetY * 2) );

        if ( preview->_previewPixbuf ) {
            GtkDrawingArea* da = &(preview->drawing);
            GdkDrawable* drawable = (GdkDrawable*) (((GtkWidget*)da)->window);
            gint w = 0;
            gint h = 0;
            gdk_drawable_get_size(drawable, &w, &h);
            if ((w != preview->_scaledW) || (h != preview->_scaledH)) {
                if (preview->_scaled) {
                    g_object_unref(preview->_scaled);
                }
                preview->_scaled = gdk_pixbuf_scale_simple(preview->_previewPixbuf, w, h, GDK_INTERP_BILINEAR);
                preview->_scaledW = w;
                preview->_scaledH = h;
            }

            GdkPixbuf* pix = (preview->_scaled) ? preview->_scaled : preview->_previewPixbuf;
            gdk_draw_pixbuf( drawable, 0, pix, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0 );
        }


        if ( preview->_linked ) {
            /* Draw arrow */
            GdkRectangle possible = {insetX, insetY, (widget->allocation.width - (insetX * 2)), (widget->allocation.height - (insetY * 2)) };
            GdkRectangle area = {possible.x, possible.y, possible.width / 2, possible.height / 2 };

            /* Make it square */
            if ( area.width > area.height )
                area.width = area.height;
            if ( area.height > area.width )
                area.height = area.width;

            /* Center it horizontally */
            if ( area.width < possible.width ) {
                int diff = (possible.width - area.width) / 2;
                area.x += diff;
            }


            if ( preview->_linked & PREVIEW_LINK_IN ) {
                gtk_paint_arrow( style,
                                 widget->window,
                                 (GtkStateType)widget->state,
                                 GTK_SHADOW_ETCHED_IN,
                                 NULL, /* clip area.  &area, */
                                 widget, /* may be NULL */
                                 NULL, /* detail */
                                 GTK_ARROW_DOWN,
                                 FALSE,
                                 area.x, area.y,
                                 area.width, area.height
                                 );
            }

            if ( preview->_linked & PREVIEW_LINK_OUT ) {
                GdkRectangle otherArea = {area.x, area.y, area.width, area.height};
                if ( otherArea.height < possible.height ) {
                    otherArea.y = possible.y + (possible.height - otherArea.height);
                }

                gtk_paint_arrow( style,
                                 widget->window,
                                 (GtkStateType)widget->state,
                                 GTK_SHADOW_ETCHED_OUT,
                                 NULL, /* clip area.  &area, */
                                 widget, /* may be NULL */
                                 NULL, /* detail */
                                 GTK_ARROW_DOWN,
                                 FALSE,
                                 otherArea.x, otherArea.y,
                                 otherArea.width, otherArea.height
                                 );
            }

            if ( preview->_linked & PREVIEW_LINK_OTHER ) {
                GdkRectangle otherArea = {insetX, area.y, area.width, area.height};
                if ( otherArea.height < possible.height ) {
                    otherArea.y = possible.y + (possible.height - otherArea.height) / 2;
                }

                gtk_paint_arrow( style,
                                 widget->window,
                                 (GtkStateType)widget->state,
                                 GTK_SHADOW_ETCHED_OUT,
                                 NULL, /* clip area.  &area, */
                                 widget, /* may be NULL */
                                 NULL, /* detail */
                                 GTK_ARROW_LEFT,
                                 FALSE,
                                 otherArea.x, otherArea.y,
                                 otherArea.width, otherArea.height
                                 );
            }


            if ( preview->_linked & PREVIEW_FILL ) {
                GdkRectangle otherArea = {possible.x + ((possible.width / 4) - (area.width / 2)),
                                          area.y,
                                          area.width, area.height};
                if ( otherArea.height < possible.height ) {
                    otherArea.y = possible.y + (possible.height - otherArea.height) / 2;
                }
                gtk_paint_check( style,
                                 widget->window,
                                 (GtkStateType)widget->state,
                                 GTK_SHADOW_ETCHED_OUT,
                                 NULL,
                                 widget,
                                 NULL,
                                 otherArea.x, otherArea.y,
                                 otherArea.width, otherArea.height );
            }

            if ( preview->_linked & PREVIEW_STROKE ) {
                GdkRectangle otherArea = {possible.x + (((possible.width * 3) / 4) - (area.width / 2)),
                                          area.y,
                                          area.width, area.height};
                if ( otherArea.height < possible.height ) {
                    otherArea.y = possible.y + (possible.height - otherArea.height) / 2;
                }
                gtk_paint_diamond( style,
                                   widget->window,
                                   (GtkStateType)widget->state,
                                   GTK_SHADOW_ETCHED_OUT,
                                   NULL,
                                   widget,
                                   NULL,
                                   otherArea.x, otherArea.y,
                                   otherArea.width, otherArea.height );
            }
        }


        if ( GTK_WIDGET_HAS_FOCUS(widget) ) {
            gtk_paint_focus( style,
                             widget->window,
                             GTK_STATE_NORMAL,
                             NULL, /* GdkRectangle *area, */
                             widget,
                             NULL,
                             0 + 1, 0 + 1,
                             widget->allocation.width - 2, widget->allocation.height - 2 );
        }
    }


    return FALSE;
}