1 /*
2  * Copyright © 2009-2018 Siyan Panayotov <contact@siyanpanayotov.com>
3  *
4  * Based on code by (see README for details):
5  * - Björn Lindqvist <bjourne@gmail.com>
6  *
7  * This file is part of Viewnior.
8  *
9  * Viewnior is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Viewnior is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Viewnior.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef __UNI_IMAGE_VIEW_H__
24 #define __UNI_IMAGE_VIEW_H__
25 
26 #include <gdk/gdk.h>
27 #include <gtk/gtk.h>
28 
29 #include "vnr-prefs.h"
30 
31 G_BEGIN_DECLS
32 #define UNI_TYPE_IMAGE_VIEW             (uni_image_view_get_type ())
33 #define UNI_IMAGE_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNI_TYPE_IMAGE_VIEW, UniImageView))
34 #define UNI_IMAGE_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), UNI_TYPE_IMAGE_VIEW, UniImageViewClass))
35 #define UNI_IS_IMAGE_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNI_TYPE_IMAGE_VIEW))
36 #define UNI_IS_IMAGE_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), UNI_TYPE_IMAGE_VIEW))
37 #define UNI_IMAGE_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), UNI_TYPE_IMAGE_VIEW, UniImageViewClass))
38 typedef struct _UniImageView UniImageView;
39 typedef struct _UniImageViewClass UniImageViewClass;
40 
41 typedef enum {
42     UNI_FITTING_NONE, /* Fitting disabled */
43     UNI_FITTING_NORMAL, /* Fitting enabled. Max zoom: 1x */
44     UNI_FITTING_FULL, /* Fitting enabled. Max zoom: UNI_ZOOM_MAX */
45 } UniFittingMode;
46 
47 struct _UniImageView {
48     GtkWidget parent;
49 
50     gboolean is_rendering;
51     GdkInterpType interp;
52     UniFittingMode fitting;
53     GdkPixbuf *pixbuf;
54     gdouble zoom;
55     /* Offset in zoom space coordinates of the image area in the
56      * widget. */
57     gdouble offset_x;
58     gdouble offset_y;
59     gboolean show_cursor;
60     GdkCursor *void_cursor;
61     GtkAdjustment *hadj;
62     GtkAdjustment *vadj;
63 
64     GObject *tool;
65 };
66 
67 struct _UniImageViewClass {
68     GtkWidgetClass parent_class;
69 
70     /* Keybinding signals. */
71     void (*set_zoom)    (UniImageView * view, gdouble zoom);
72     void (*zoom_in)     (UniImageView * view);
73     void (*zoom_out)    (UniImageView * view);
74 
75     void (*set_fitting) (UniImageView * view, UniFittingMode fitting);
76     void (*scroll)      (UniImageView * view,
77                          GtkScrollType xscroll, GtkScrollType yscroll);
78 
79     /* Non-keybinding signals. */
80     void (*set_scroll_adjustments) (UniImageView * view,
81                                     GtkAdjustment * hadj,
82                                     GtkAdjustment * vadj);
83 
84     void (*pixbuf_changed)          (UniImageView * view);
85 };
86 
87 GType   uni_image_view_get_type (void) G_GNUC_CONST;
88 
89 /* Constructors */
90 GtkWidget*  uni_image_view_new  (void);
91 
92 /* Read-only properties */
93 gboolean    uni_image_view_get_viewport     (UniImageView * view,
94                                              GdkRectangle * rect);
95 
96 gboolean    uni_image_view_get_draw_rect    (UniImageView * view,
97                                              GdkRectangle * rect);
98 
99 /* Write-only properties */
100 void        uni_image_view_set_offset       (UniImageView * view,
101                                              gdouble x, gdouble y,
102                                              gboolean invalidate);
103 
104 /* Read-write properties */
105 void        uni_image_view_set_fitting  (UniImageView * view,
106                                          UniFittingMode fitting);
107 
108 GdkPixbuf*  uni_image_view_get_pixbuf   (UniImageView * view);
109 void        uni_image_view_set_pixbuf   (UniImageView * view,
110                                          GdkPixbuf * pixbuf,
111                                          gboolean reset_fit);
112 
113 void        uni_image_view_set_zoom      (UniImageView * view, gdouble zoom);
114 void        uni_image_view_set_zoom_mode (UniImageView * view, VnrPrefsZoom mode);
115 
116 /* Actions */
117 void        uni_image_view_zoom_in      (UniImageView * view);
118 void        uni_image_view_zoom_out     (UniImageView * view);
119 void        uni_image_view_damage_pixels(UniImageView * view,
120                                          GdkRectangle * rect);
121 
122 G_END_DECLS
123 #endif /* __UNI_IMAGE_VIEW_H__ */
124