1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/* See LICENSE file for copyright and license details. */
#ifndef SCROLL_AMOUNT
# define SCROLL_AMOUNT 30
#endif
#ifndef DRAG_ICON_SIZE
# define DRAG_ICON_SIZE 128
#endif
#ifndef PREVIEW_WIDTH
# define PREVIEW_WIDTH 192
#endif
#ifndef PREVIEW_HEIGHT
# define PREVIEW_HEIGHT 256
#endif
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# pragma GCC diagnostic ignored "-Wstrict-prototypes"
#endif
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <libsimple.h>
#include <libsimple-arg.h>
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
#if defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants"
# pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
#endif
#if defined(__GNUC__)
# define PURE __attribute__((__pure__))
#else
# define PURE
#endif
#include "logical-scroll-pane.h"
#define FLOAT_EQ(A, B) ((A) >= (B) && (A) <= (B))
#define COMMA ,
enum toggle_group {
GROUP_NONE,
GROUP_ZOOM
};
enum zoom_mode {
ZOOM_CUSTOM,
ZOOM_NORMAL,
ZOOM_FIT_WIDTH,
ZOOM_FIT_HEIGHT,
ZOOM_FIT_WINDOW,
ZOOM_BEST_FIT
};
enum transformation {
TRANS_NONE, /* 1 */
TRANS_CLOCKWISE, /* r */
TRANS_180_DEGREES, /* r² */
TRANS_ANTICLOCKWISE, /* r³ */
TRANS_TRANSPOSE, /* t */
TRANS_FLOP, /* rt */
TRANS_ANTITRANSPOSE, /* r²t */
TRANS_FLIP, /* r³t */
/*
* t² = r⁴ = 1
* trⁿ = r⁻ⁿt
*/
TRANS_NEGATIVE = 0x08
};
struct file {
char *path;
off_t size;
GdkPixbuf *image;
};
typedef double Zoom; /* TODO */
/* dragging.c */
void set_up_dragging(void);
/* dropping.c */
void set_up_dropping(void);
/* events.c */
void open_action(GtkAction *action, void *user);
void reload_action(GtkAction *action, void *user);
void print_action(GtkAction *action, void *user);
void properties_action(GtkAction *action, void *user);
void close_action(GtkAction *action, void *user);
void fullscreen_action(GtkToggleAction *action, void *user);
void reset_transformations_action(GtkAction *action, void *user);
void rotate_clockwise_action(GtkAction *action, void *user);
void rotate_180_degrees_action(GtkAction *action, void *user);
void rotate_anticlockwise_action(GtkAction *action, void *user);
void flop_action(GtkAction *action, void *user);
void flip_action(GtkAction *action, void *user);
void transpose_action(GtkAction *action, void *user);
void antitranspose_action(GtkAction *action, void *user);
void invert_action(GtkToggleAction *action, void *user);
void zoom_in_action(GtkAction *action, void *user);
void zoom_out_action(GtkAction *action, void *user);
void normal_size_action(GtkToggleAction *action, void *user);
void width_fit_action(GtkToggleAction *action, void *user);
void height_fit_action(GtkToggleAction *action, void *user);
void window_fit_action(GtkToggleAction *action, void *user);
void best_fit_action(GtkToggleAction *action, void *user);
void next_action(GtkAction *action, void *user);
void previous_action(GtkAction *action, void *user);
void first_action(GtkAction *action, void *user);
void last_action(GtkAction *action, void *user);
int key_pressed(GtkWidget *widget, GdkEventKey *event, void *user);
int scroll_event(GtkWidget *widget, GdkEventScroll *event, void *user);
/* files.c */
extern struct file *files;
extern size_t nfiles;
extern size_t current_file;
void free_files(void);
size_t files_from_array(struct file *selected_files, size_t nselected_files);
size_t files_from_list(struct file **files_out, GSList *selected_files);
int set_files_from_argv(int argc, char **argv);
struct file *get_file(void);
int navigate_without_redraw(size_t jump, size_t move);
/* filters.c */
void add_image_filters(GtkFileChooser *chooser);
void free_image_filters(void);
/* image.c */
extern GdkPixbuf *transformed_image;
GdkPixbuf *get_image(void);
GdkPixbuf *get_original_image(void);
/* opening.c */
int load_image(struct file *file, int errors_to_stderr);
GtkFileChooser *construct_chooser(void);
/* printing.c */
void open_print(GdkPixbuf *image);
/* properties.c */
void open_properties(struct file *file);
/* transform.c */
extern enum transformation trans;
GdkPixbuf *apply_transformations(GdkPixbuf *image);
enum transformation reset_transformations_without_redraw(void);
int add_transformation_without_redraw(enum transformation augment);
void transform_point(enum transformation t, double *x, double *y, double *w, double *h);
/* ui.c */
extern GtkWidget *window;
extern GtkWidget *display_area;
extern GtkWidget *scroll;
extern GtkToggleAction *fullscreen;
void set_up_ui(void);
void set_actions_sensitive(void);
void clear_toggles(enum toggle_group group, GtkToggleAction *except);
void set_fullscreen_mode(int active);
int activate_fullscreen(void *user);
int deactivate_fullscreen(void *user);
void set_statusbar_message(const char *message);
void free_ui(void);
/* zoom.c */
extern Zoom zoom;
extern enum zoom_mode zoom_mode;
int zoom_eq(Zoom a, Zoom b);
double get_zoom(Zoom z);
Zoom make_zoom(double s);
Zoom zoom_in(Zoom z);
Zoom zoom_out(Zoom z);
Zoom calculate_fit(GdkPixbuf *image, int xfit, int yfit, double cap);
Zoom calculate_zoom_mode(GdkPixbuf *image, enum zoom_mode mode);
/* gbild.c */
int expose_image(GtkWidget *widget, GdkEventExpose *event, void *user);
void add_images(struct file *new_files, size_t nnew_files);
void set_images_from_array(struct file *selected_files, size_t nselected_files);
void set_images_from_list(GSList *selected_files);
void scroll_by(double horizontally, double vertically);
void set_zoom_around_point(Zoom new_zoom, double x, double y);
void set_zoom_around_centre(Zoom new_zoom);
void set_zoom_and_recentre(Zoom new_zoom);
void reload_redraw(void);
void transform_redraw(enum transformation augment);
void navigate_redraw(void);
int recalculate_zoom_mode(void *user);
|