コード例 #1
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static void
uni_image_view_unrealize (GtkWidget * widget)
{
    UniImageView *view = UNI_IMAGE_VIEW (widget);
    gdk_cursor_unref (view->void_cursor);
    GTK_WIDGET_CLASS (uni_image_view_parent_class)->unrealize (widget);
}
コード例 #2
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static void
uni_image_view_finalize (GObject * object)
{
    UniImageView *view = UNI_IMAGE_VIEW (object);
    if (view->hadj)
    {
        g_signal_handlers_disconnect_by_data (G_OBJECT (view->hadj), view);
        g_object_unref (view->hadj);
        view->hadj = NULL;
    }
    if (view->vadj)
    {
        g_signal_handlers_disconnect_by_data (G_OBJECT (view->vadj), view);
        g_object_unref (view->vadj);
        view->vadj = NULL;
    }
    if (view->pixbuf)
    {
        g_object_unref (view->pixbuf);
        view->pixbuf = NULL;
    }
    g_object_unref (view->tool);
    /* Chain up. */
    G_OBJECT_CLASS (uni_image_view_parent_class)->finalize (object);
}
コード例 #3
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static void
uni_image_view_realize (GtkWidget * widget)
{
    UniImageView *view = UNI_IMAGE_VIEW (widget);
    gtk_widget_set_realized(widget, TRUE);

    GdkWindowAttr attrs;
    attrs.window_type = GDK_WINDOW_CHILD;
    attrs.x = widget->allocation.x;
    attrs.y = widget->allocation.y;
    attrs.width = widget->allocation.width;
    attrs.height = widget->allocation.height;
    attrs.wclass = GDK_INPUT_OUTPUT;
    attrs.visual = gtk_widget_get_visual (widget);
    attrs.colormap = gtk_widget_get_colormap (widget);
    attrs.event_mask = (gtk_widget_get_events (widget)
                        | GDK_EXPOSURE_MASK
                        | GDK_BUTTON_MOTION_MASK
                        | GDK_BUTTON_PRESS_MASK
                        | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK);

    int attr_mask = (GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP);
    GdkWindow *parent = gtk_widget_get_parent_window (widget);
    widget->window = gdk_window_new (parent, &attrs, attr_mask);
    gdk_window_set_user_data (widget->window, view);

    widget->style = gtk_style_attach (widget->style, widget->window);
    gtk_style_set_background (widget->style, widget->window,
                              GTK_STATE_NORMAL);

    view->void_cursor = gdk_cursor_new (GDK_ARROW);
}
コード例 #4
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static int
uni_image_view_motion_notify (GtkWidget * widget, GdkEventMotion * ev)
{
    UniImageView *view = UNI_IMAGE_VIEW (widget);
    if (view->is_rendering)
        return FALSE;
    return uni_dragger_motion_notify (UNI_DRAGGER(view->tool), ev);
}
コード例 #5
0
ファイル: uni-image-view.c プロジェクト: dlueke/Viewnior
static int
uni_image_view_button_press (GtkWidget * widget, GdkEventButton * ev)
{
    gtk_widget_grab_focus(widget);
    UniImageView *view = UNI_IMAGE_VIEW (widget);
    VnrWindow *vnr_win = VNR_WINDOW(gtk_widget_get_toplevel(widget));
    g_assert(gtk_widget_is_toplevel(GTK_WIDGET(vnr_win)));

    if(ev->type == GDK_2BUTTON_PRESS && ev->button == 1 && vnr_win->prefs->behavior_click == VNR_PREFS_CLICK_FULLSCREEN)
    {
        vnr_window_toggle_fullscreen(vnr_win);
        return 1;
    }
    else if(ev->type == GDK_2BUTTON_PRESS && ev->button == 1 && vnr_win->prefs->behavior_click == VNR_PREFS_CLICK_NEXT)
    {

        int width;
        gdk_drawable_get_size(GDK_DRAWABLE(widget->window), &width, NULL);

        if(ev->x/width < 0.5)
            vnr_window_prev(vnr_win);
        else
            vnr_window_next(vnr_win, TRUE);

        return 1;
    }
    else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1)
    {
        return uni_dragger_button_press (UNI_DRAGGER(view->tool), ev);
    }
    else if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1)
    {
        if (view->fitting == UNI_FITTING_FULL ||
            (view->fitting == UNI_FITTING_NORMAL && view->zoom != 1.0))
            uni_image_view_set_zoom_with_center (view, 1., ev->x, ev->y,
                                                 FALSE);
        else
            uni_image_view_set_fitting (view, UNI_FITTING_FULL);
        return 1;
    }
    else if(ev->type == GDK_BUTTON_PRESS && ev->button == 3)
    {
        gtk_menu_popup(GTK_MENU(VNR_WINDOW(gtk_widget_get_toplevel (widget))->popup_menu),
                NULL, NULL, NULL, NULL, ev->button,
                gtk_get_current_event_time());

    }
    else if(ev->type == GDK_BUTTON_PRESS && ev->button == 8)
    {
        vnr_window_prev(vnr_win);
    }
    else if(ev->type == GDK_BUTTON_PRESS && ev->button == 9)
    {
        vnr_window_next(vnr_win, TRUE);
    }
    return 0;
}
コード例 #6
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static int
uni_image_view_scroll_event (GtkWidget * widget, GdkEventScroll * ev)
{
    gdouble zoom;
    UniImageView *view = UNI_IMAGE_VIEW (widget);
    VnrWindow *vnr_win = VNR_WINDOW(gtk_widget_get_toplevel(widget));
    g_assert(gtk_widget_is_toplevel(GTK_WIDGET(vnr_win)));

    /* Horizontal scroll left is equivalent to scroll up and right is
     * like scroll down. No idea if that is correct -- I have no input
     * device that can do horizontal scrolls. */

    if (vnr_win->prefs->behavior_wheel == VNR_PREFS_WHEEL_ZOOM || (ev->state & GDK_CONTROL_MASK) != 0)
    {
        if ( ev->direction == GDK_SCROLL_UP || ev->direction == GDK_SCROLL_LEFT )
            zoom = CLAMP (view->zoom * UNI_ZOOM_STEP, UNI_ZOOM_MIN, UNI_ZOOM_MAX);
        else
            zoom = CLAMP (view->zoom / UNI_ZOOM_STEP, UNI_ZOOM_MIN, UNI_ZOOM_MAX);

        uni_image_view_set_zoom_with_center (view, zoom, ev->x, ev->y, FALSE);
    }
    else if(vnr_win->prefs->behavior_wheel == VNR_PREFS_WHEEL_NAVIGATE)
    {
        if (ev->direction == GDK_SCROLL_UP || ev->direction == GDK_SCROLL_LEFT)
            vnr_window_prev(vnr_win);
        else
            vnr_window_next(vnr_win, TRUE);
    }
    else
    {
        switch (ev->direction)
        {
        case GDK_SCROLL_UP:
            uni_image_view_scroll (view, GTK_SCROLL_NONE, GTK_SCROLL_PAGE_UP);
            break;
        case GDK_SCROLL_LEFT:
            uni_image_view_scroll (view, GTK_SCROLL_PAGE_LEFT, GTK_SCROLL_NONE);
            break;
        case GDK_SCROLL_RIGHT:
            uni_image_view_scroll (view, GTK_SCROLL_PAGE_RIGHT, GTK_SCROLL_NONE);
            break;
        default:
            uni_image_view_scroll (view, GTK_SCROLL_NONE, GTK_SCROLL_PAGE_DOWN);
            break;
        }
    }

    return TRUE;
}
コード例 #7
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);
}
コード例 #8
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static void
uni_image_view_size_allocate (GtkWidget * widget, GtkAllocation * alloc)
{
    UniImageView *view = UNI_IMAGE_VIEW (widget);
    widget->allocation = *alloc;

    if (view->pixbuf && view->fitting != UNI_FITTING_NONE)
        uni_image_view_zoom_to_fit (view, TRUE);

    uni_image_view_clamp_offset (view, &view->offset_x, &view->offset_y);

    uni_image_view_update_adjustments (view);

    if (gtk_widget_get_realized (widget))
        gdk_window_move_resize (widget->window,
                                alloc->x, alloc->y,
                                alloc->width, alloc->height);
}
コード例 #9
0
ファイル: uni-dragger.c プロジェクト: mcsf/Viewnior
gboolean
uni_dragger_motion_notify (UniDragger * tool, GdkEventMotion * ev)
{
    if (tool->pressed)
        tool->dragging = TRUE;
    else
    	return FALSE;

    tool->drag_ofs_x = ev->x;
    tool->drag_ofs_y = ev->y;

    int dx, dy;
    uni_dragger_get_drag_delta (tool, &dx, &dy);
    if (abs (dx) < 1 && abs (dy) < 1)
        return FALSE;
        
    if ( pow(dx, 2) + pow(dy, 2) > 7 && UNI_IMAGE_VIEW(tool->view)->pixbuf != NULL && 
    		UNI_IMAGE_VIEW(tool->view)->vadj->upper <= UNI_IMAGE_VIEW(tool->view)->vadj->page_size && 
    		UNI_IMAGE_VIEW(tool->view)->hadj->upper <= UNI_IMAGE_VIEW(tool->view)->hadj->page_size ) 
    {
		uni_dragger_button_release (tool, (GdkEventButton*)ev);
    	gtk_drag_begin (GTK_WIDGET(tool->view),
                gtk_target_list_new(target_table, G_N_ELEMENTS(target_table)),
                GDK_ACTION_COPY,
                1,
                (GdkEvent*)ev);
		return TRUE;
    }

    GdkRectangle viewport;
    uni_image_view_get_viewport (UNI_IMAGE_VIEW (tool->view), &viewport);

    int offset_x = viewport.x + dx;
    int offset_y = viewport.y + dy;

    uni_image_view_set_offset (UNI_IMAGE_VIEW (tool->view), offset_x,
                               offset_y, FALSE);

    tool->drag_base_x = tool->drag_ofs_x;
    tool->drag_base_y = tool->drag_ofs_y;

    return TRUE;
}
コード例 #10
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static int
uni_image_view_button_release (GtkWidget * widget, GdkEventButton * ev)
{
    UniImageView *view = UNI_IMAGE_VIEW (widget);
    return uni_dragger_button_release (UNI_DRAGGER(view->tool), ev);
}
コード例 #11
0
ファイル: uni-image-view.c プロジェクト: medicalwei/Viewnior
static int
uni_image_view_expose (GtkWidget * widget, GdkEventExpose * ev)
{
    return uni_image_view_repaint_area (UNI_IMAGE_VIEW (widget), &ev->area);
}
コード例 #12
0
ファイル: vnr-crop.c プロジェクト: sjoblomj/Viewnior
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;
}