aboutsummaryrefslogtreecommitdiff
path: root/src/viewport.h
blob: 5e5bc24187ddced16851d1d7e3c3176a8f55d4f4 (plain)
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
#ifndef IMV_VIEWPORT_H
#define IMV_VIEWPORT_H

#include <stdbool.h>
#include "image.h"

struct imv_viewport;

enum scaling_mode {
  SCALING_NONE,
  SCALING_DOWN,
  SCALING_FULL,
  SCALING_CROP,
  SCALING_MODE_COUNT
};

/* Used to signify how a a user requested a zoom */
enum imv_zoom_source {
  IMV_ZOOM_MOUSE,
  IMV_ZOOM_KEYBOARD
};

/* Creates an instance of imv_viewport */
struct imv_viewport *imv_viewport_create(int window_width, int window_height,
                                         int buffer_width, int buffer_height);

/* Cleans up an imv_viewport instance */
void imv_viewport_free(struct imv_viewport *view);

/* Set playback of animated gifs */
void imv_viewport_set_playing(struct imv_viewport *view, bool playing);

/* Get playback status of animated gifs */
bool imv_viewport_is_playing(struct imv_viewport *view);

/* Toggle playback of animated gifs */
void imv_viewport_toggle_playing(struct imv_viewport *view);

/* Fetch viewport offset/position */
void imv_viewport_get_offset(struct imv_viewport *view, int *x, int *y);

/* Fetch viewport scale */
void imv_viewport_get_scale(struct imv_viewport *view, double *scale);

/* Set the default pan_factor factor for the x and y position */
void imv_viewport_set_default_pan_factor(struct imv_viewport *view, double pan_factor_x, double pan_factor_y);

/* Pan the view by the given amounts without letting the image get too far
 * off-screen */
void imv_viewport_move(struct imv_viewport *view, int x, int y,
    const struct imv_image *image);

/* Zoom the view by the given amount. imv_image* is used to get the image
 * dimensions */
void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *image,
                       enum imv_zoom_source, int mouse_x, int mouse_y, int amount);

/* Recenter the view to be in the middle of the image */
void imv_viewport_center(struct imv_viewport *view,
                         const struct imv_image *image);

/* Scale the view so that the image appears at its actual resolution */
void imv_viewport_scale_to_actual(struct imv_viewport *view,
                                  const struct imv_image *image);

/* Scale the view so that the image fits in the window */
void imv_viewport_scale_to_window(struct imv_viewport *view,
                                  const struct imv_image *image);

/* Scale the view so that the image fills the window */
void imv_viewport_crop_to_window(struct imv_viewport *view,
                                  const struct imv_image *image);

/* Rescale the view with the chosen scaling method */
void imv_viewport_rescale(struct imv_viewport *view, const struct imv_image *image,
                          enum scaling_mode);

/* Tell the viewport that it needs to be redrawn */
void imv_viewport_set_redraw(struct imv_viewport *view);

/* Tell the viewport the window or image has changed */
void imv_viewport_update(struct imv_viewport *view,
                         int window_width, int window_height,
                         int buffer_width, int buffer_height,
                         struct imv_image *image, enum scaling_mode);

/* Poll whether we need to redraw */
int imv_viewport_needs_redraw(struct imv_viewport *view);

#endif

/* vim:set ts=2 sts=2 sw=2 et: */