aboutsummaryrefslogtreecommitdiff
path: root/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'image.c')
-rw-r--r--image.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/image.c b/image.c
index 034dd62..5489259 100644
--- a/image.c
+++ b/image.c
@@ -1,7 +1,7 @@
#include "image.h"
#include <gtk-3.0/gtk/gtk.h>
-GtkWidget* new_image()
+GtkWidget *new_image()
{
image = gtk_image_new();
return image;
@@ -16,8 +16,9 @@ int load_image(char *file_name, int win_width, int win_height)
pixbuf = gdk_pixbuf_new_from_file(file_name, &error);
if (error)
return -1;
- pixbuf_width = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf));
- pixbuf_height = gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf));
+ curr_pixbuf_width = pixbuf_width = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf));
+ curr_pixbuf_height = pixbuf_height =
+ gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf));
aspect_ratio = (double)pixbuf_width / (double)pixbuf_height;
curr_zoom = 1.0;
fit_image(win_width, win_height);
@@ -30,8 +31,9 @@ void update_pixbuf()
g_object_unref(curr_pixbuf);
if (pixbuf == NULL)
return;
- curr_pixbuf = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), pixbuf_width,
- pixbuf_height, GDK_INTERP_BILINEAR);
+ curr_pixbuf =
+ gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), curr_pixbuf_width,
+ curr_pixbuf_height, GDK_INTERP_BILINEAR);
gtk_image_set_from_pixbuf(GTK_IMAGE(image), GDK_PIXBUF(curr_pixbuf));
}
@@ -40,26 +42,26 @@ void fit_image(int win_width, int win_height)
if (pixbuf == NULL || win_width < 1 || win_height < 1)
return;
if (win_width < pixbuf_width && win_height > pixbuf_height) {
- pixbuf_width = win_width;
- pixbuf_height = (double)pixbuf_width / aspect_ratio;
+ curr_pixbuf_width = win_width;
+ curr_pixbuf_height = (double)curr_pixbuf_width / aspect_ratio;
} else if (win_width > pixbuf_width && win_height < pixbuf_height) {
- pixbuf_height = win_height;
- pixbuf_width = (double)pixbuf_height * aspect_ratio;
+ curr_pixbuf_height = win_height;
+ curr_pixbuf_width = (double)curr_pixbuf_height * aspect_ratio;
} else if (win_width < pixbuf_width && win_height < pixbuf_height) {
if (((double)win_width / (double)win_height) > aspect_ratio) {
- pixbuf_height = win_height;
- pixbuf_width = ((double)pixbuf_height * aspect_ratio);
+ curr_pixbuf_height = win_height;
+ curr_pixbuf_width = ((double)curr_pixbuf_height * aspect_ratio);
} else {
- pixbuf_width = win_width;
- pixbuf_height = (double)pixbuf_width / aspect_ratio;
+ curr_pixbuf_width = win_width;
+ curr_pixbuf_height = (double)curr_pixbuf_width / aspect_ratio;
}
} else {
- pixbuf_width = pixbuf_width;
- pixbuf_height = pixbuf_height;
+ curr_pixbuf_width = pixbuf_width;
+ curr_pixbuf_height = pixbuf_height;
}
- curr_zoom = (double)pixbuf_width / (double)pixbuf_width;
- if (pixbuf_width < 1 || pixbuf_height < 1)
+ curr_zoom = (double)curr_pixbuf_width / (double)pixbuf_width;
+ if (curr_pixbuf_width < 1 || curr_pixbuf_height < 1)
return;
update_pixbuf();
@@ -72,18 +74,19 @@ void zoom(int type)
if (type == 0) {
if (curr_zoom == 1.0)
return;
- curr_zoom = (double)1.0;
+ curr_zoom = 1.0;
} else if (type < 0) {
if (curr_zoom < 0.2)
return;
- curr_zoom -= (double)ZOOM_FACTOR;
+ curr_zoom -= 0.1;
} else if (type > 0) {
if (curr_zoom > 2)
return;
- curr_zoom += (double)ZOOM_FACTOR;
+ curr_zoom += 0.1;
}
- pixbuf_width *= curr_zoom;
- pixbuf_height += curr_zoom;
+
+ curr_pixbuf_width = curr_zoom * (double)pixbuf_width;
+ curr_pixbuf_height = curr_zoom * (double)pixbuf_height;
update_pixbuf();
}