aboutsummaryrefslogtreecommitdiff
path: root/liblogdiag
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2011-02-04 20:19:01 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2011-02-04 20:19:01 +0100
commit2b0672a2cbb9731cfa79d4f41453c12e77f15360 (patch)
tree827b38b26806833e6b32ff9992c4a05a33bae1aa /liblogdiag
parent6e8839d485050ba5551f8db70d7655cce5a786da (diff)
downloadlogdiag-2b0672a2cbb9731cfa79d4f41453c12e77f15360.tar.gz
logdiag-2b0672a2cbb9731cfa79d4f41453c12e77f15360.tar.xz
logdiag-2b0672a2cbb9731cfa79d4f41453c12e77f15360.zip
Implement zooming in LdWindowMain.
Add convenience methods to LdCanvas.
Diffstat (limited to 'liblogdiag')
-rw-r--r--liblogdiag/ld-canvas.c60
-rw-r--r--liblogdiag/ld-canvas.h4
2 files changed, 60 insertions, 4 deletions
diff --git a/liblogdiag/ld-canvas.c b/liblogdiag/ld-canvas.c
index de24513..60da2e5 100644
--- a/liblogdiag/ld-canvas.c
+++ b/liblogdiag/ld-canvas.c
@@ -33,8 +33,8 @@
#define ZOOM_MIN 0.01
#define ZOOM_MAX 100
#define ZOOM_DEFAULT 1
-/* Multiplication factor for zooming with mouse wheel. */
-#define ZOOM_WHEEL_STEP 1.4
+/* Multiplication factor for zooming. */
+#define ZOOM_STEP 1.4
/* When drawing is requested, extend all sides of
* the rectangle to be drawn by this number of pixels.
@@ -862,6 +862,58 @@ ld_canvas_set_zoom (LdCanvas *self, gdouble zoom)
g_object_notify (G_OBJECT (self), "zoom");
}
+/**
+ * ld_canvas_can_zoom_in:
+ * @self: an #LdCanvas object.
+ *
+ * Return value: %TRUE if the view can be zoomed in.
+ */
+gboolean
+ld_canvas_can_zoom_in (LdCanvas *self)
+{
+ g_return_val_if_fail (LD_IS_CANVAS (self), FALSE);
+ return self->priv->zoom < ZOOM_MAX;
+}
+
+/**
+ * ld_canvas_can_zoom_out:
+ * @self: an #LdCanvas object.
+ *
+ * Return value: %TRUE if the view can be zoomed out.
+ */
+gboolean
+ld_canvas_can_zoom_out (LdCanvas *self)
+{
+ g_return_val_if_fail (LD_IS_CANVAS (self), FALSE);
+ return self->priv->zoom > ZOOM_MIN;
+}
+
+/**
+ * ld_canvas_zoom_in:
+ * @self: an #LdCanvas object.
+ *
+ * Zoom the view in.
+ */
+void
+ld_canvas_zoom_in (LdCanvas *self)
+{
+ g_return_if_fail (LD_IS_CANVAS (self));
+ ld_canvas_set_zoom (self, self->priv->zoom * ZOOM_STEP);
+}
+
+/**
+ * ld_canvas_zoom_out:
+ * @self: an #LdCanvas object.
+ *
+ * Zoom the view out.
+ */
+void
+ld_canvas_zoom_out (LdCanvas *self)
+{
+ g_return_if_fail (LD_IS_CANVAS (self));
+ ld_canvas_set_zoom (self, self->priv->zoom / ZOOM_STEP);
+}
+
/* ===== Operations ======================================================== */
@@ -1288,10 +1340,10 @@ on_scroll (GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
switch (event->direction)
{
case GDK_SCROLL_UP:
- ld_canvas_set_zoom (self, self->priv->zoom * ZOOM_WHEEL_STEP);
+ ld_canvas_zoom_in (self);
break;
case GDK_SCROLL_DOWN:
- ld_canvas_set_zoom (self, self->priv->zoom / ZOOM_WHEEL_STEP);
+ ld_canvas_zoom_out (self);
break;
default:
return FALSE;
diff --git a/liblogdiag/ld-canvas.h b/liblogdiag/ld-canvas.h
index ae42f26..9e2d105 100644
--- a/liblogdiag/ld-canvas.h
+++ b/liblogdiag/ld-canvas.h
@@ -80,6 +80,10 @@ void ld_canvas_diagram_to_widget_coords (LdCanvas *self,
gdouble ld_canvas_get_zoom (LdCanvas *self);
void ld_canvas_set_zoom (LdCanvas *self, gdouble zoom);
+gboolean ld_canvas_can_zoom_in (LdCanvas *self);
+void ld_canvas_zoom_in (LdCanvas *self);
+gboolean ld_canvas_can_zoom_out (LdCanvas *self);
+void ld_canvas_zoom_out (LdCanvas *self);
void ld_canvas_add_object_begin (LdCanvas *self, LdDiagramObject *object);