Exemplo n.º 1
0
static void
uni_nav_update_pixbuf (UniNav * nav)
{
    if (nav->pixbuf)
    {
        g_object_unref (nav->pixbuf);
        nav->pixbuf = NULL;
    }
    GdkPixbuf *pixbuf = uni_image_view_get_pixbuf (nav->view);
    if (!pixbuf)
        return;

    Size pw = uni_nav_get_preview_size (nav);

    nav->pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
                                  gdk_pixbuf_get_has_alpha (pixbuf),
                                  8, pw.width, pw.height);
    uni_pixbuf_scale_blend (pixbuf, nav->pixbuf,
                            0, 0, pw.width, pw.height,
                            0, 0,
                            uni_nav_get_zoom (nav),
                            GDK_INTERP_BILINEAR, 0, 0);
    // Lower the flag so the pixbuf isn't recreated more than
    // necessarily.
    nav->update_when_shown = FALSE;
}
Exemplo n.º 2
0
void
vnr_properties_dialog_update_image(VnrPropertiesDialog *dialog)
{
    gchar *width_str, *height_str;

    set_new_pixbuf(dialog, uni_image_view_get_pixbuf(UNI_IMAGE_VIEW(dialog->vnr_win->view)));
    gtk_image_set_from_pixbuf (GTK_IMAGE(dialog->image) , dialog->thumbnail);

    width_str = g_strdup_printf("%i px", dialog->vnr_win->current_image_width);
    height_str = g_strdup_printf("%i px", dialog->vnr_win->current_image_height);

    gtk_label_set_text(GTK_LABEL(dialog->width_label), width_str);
    gtk_label_set_text(GTK_LABEL(dialog->height_label), height_str);

    g_free(width_str);
    g_free(height_str);
}
Exemplo n.º 3
0
static Size
uni_nav_get_preview_size (UniNav * nav)
{
    GdkPixbuf *pixbuf = uni_image_view_get_pixbuf (nav->view);
    if (!pixbuf)
        return (Size)
    {
    UNI_NAV_MAX_WIDTH, UNI_NAV_MAX_HEIGHT};
    int img_width = gdk_pixbuf_get_width (pixbuf);
    int img_height = gdk_pixbuf_get_height (pixbuf);

    gdouble zoom = uni_nav_get_zoom (nav);

    Size s;
    s.width = (int) (img_width * zoom + 0.5);
    s.height = (int) (img_height * zoom + 0.5);
    return s;
}
Exemplo n.º 4
0
static gdouble
uni_nav_get_zoom (UniNav * nav)
{
    GdkPixbuf *pixbuf = uni_image_view_get_pixbuf (nav->view);

    /* If there is no image, we can't get it's width and height */
    if (!pixbuf)
    {
        return 0.0;
    }

    int img_width = gdk_pixbuf_get_width (pixbuf);
    int img_height = gdk_pixbuf_get_height (pixbuf);

    gdouble width_zoom = (gdouble) UNI_NAV_MAX_WIDTH / (gdouble) img_width;
    gdouble height_zoom = (gdouble) UNI_NAV_MAX_HEIGHT / (gdouble) img_height;
    return MIN (width_zoom, height_zoom);
}
Exemplo n.º 5
0
static GtkWidget *
vnr_crop_build_dialog (VnrCrop *crop)
{
    GtkBuilder *builder;
    GtkWidget *window;
    GdkPixbuf *original;
    GdkPixbuf *preview;
    GError *error = NULL;

    builder = gtk_builder_new ();
    gtk_builder_add_from_file (builder, CROP_UI_PATH, &error);

    if (error != NULL)
    {
        g_warning ("%s\n", error->message);
        g_object_unref(builder);
        return NULL;
    }

    window = GTK_WIDGET (gtk_builder_get_object (builder, "crop-dialog"));
    gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(crop->vnr_win));

    original = uni_image_view_get_pixbuf(UNI_IMAGE_VIEW(crop->vnr_win->view));

    gdouble width, height;

    width = crop->vnr_win->current_image_width;
    height = crop->vnr_win->current_image_height;

    vnr_tools_fit_to_size_double(&height, &width, 400,400);
    crop->width = width;
    crop->height = height;
    crop->zoom = ( width/crop->vnr_win->current_image_width
                   + height/crop->vnr_win->current_image_height )/2;

    preview = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (original),
                             gdk_pixbuf_get_has_alpha (original),
                             gdk_pixbuf_get_bits_per_sample (original),
                             width, height);

    uni_pixbuf_scale_blend(original, preview, 0, 0, width, height, 0, 0,
                           crop->zoom, GDK_INTERP_BILINEAR, 0, 0);
    crop->preview_pixbuf = preview;

    crop->image = GTK_WIDGET (gtk_builder_get_object (builder, "main-image"));
    gtk_widget_set_size_request(crop->image, width, height);

    crop->spin_x = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "spin-x"));
    gtk_spin_button_set_range (crop->spin_x, 0, crop->vnr_win->current_image_width - 1);
    gtk_spin_button_set_increments (crop->spin_x, 1, 10);

    crop->spin_y = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "spin-y"));
    gtk_spin_button_set_range (crop->spin_y, 0, crop->vnr_win->current_image_height - 1);
    gtk_spin_button_set_increments (crop->spin_y, 1, 10);

    crop->spin_width = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "spin-width"));
    gtk_spin_button_set_range (crop->spin_width, 1, crop->vnr_win->current_image_width);
    gtk_spin_button_set_increments (crop->spin_width, 1, 10);
    gtk_spin_button_set_value (crop->spin_width, crop->vnr_win->current_image_width);

    crop->spin_height = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "spin-height"));
    gtk_spin_button_set_range (crop->spin_height, 1, crop->vnr_win->current_image_height);
    gtk_spin_button_set_increments (crop->spin_height, 1, 10);
    gtk_spin_button_set_value (crop->spin_height, crop->vnr_win->current_image_height);

    gtk_widget_set_events (crop->image, GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_MOTION_MASK);

    g_signal_connect (crop->image, "expose-event",
                      G_CALLBACK (drawable_expose_cb), crop);
    g_signal_connect (crop->image, "button-press-event",
                      G_CALLBACK (drawable_button_press_cb), crop);
    g_signal_connect (crop->image, "button-release-event",
                      G_CALLBACK (drawable_button_release_cb), crop);
    g_signal_connect (crop->image, "motion-notify-event",
                      G_CALLBACK (drawable_motion_cb), crop);

    g_signal_connect (crop->spin_width, "value-changed",
                      G_CALLBACK (spin_width_cb), crop);
    g_signal_connect (crop->spin_x, "value-changed",
                      G_CALLBACK (spin_x_cb), crop);
    g_signal_connect (crop->spin_height, "value-changed",
                      G_CALLBACK (spin_height_cb), crop);
    g_signal_connect (crop->spin_y, "value-changed",
                      G_CALLBACK (spin_y_cb), crop);

    g_object_unref(builder);

    return window;
}