diff --git a/gui/action.c b/gui/action.c index 705c6035..b0f29c42 100644 --- a/gui/action.c +++ b/gui/action.c @@ -28,8 +28,13 @@ #include "action.h" #include "gtk_builder.h" #include "jack.h" +#include "zoom.h" GtkAction * g_clear_xruns_and_max_dsp_action; +GtkAction * g_zoom_100_action; +GtkAction * g_zoom_fit_action; +GtkAction * g_zoom_in_action; +GtkAction * g_zoom_out_action; void init_actions_and_accelerators(void) { @@ -39,6 +44,18 @@ void init_actions_and_accelerators(void) g_clear_xruns_and_max_dsp_action = GTK_ACTION(get_gtk_builder_object("clear_xruns_and_max_dsp_load_action")); g_signal_connect(G_OBJECT(g_clear_xruns_and_max_dsp_action), "activate", G_CALLBACK(clear_xruns_and_max_dsp), NULL); + g_zoom_100_action = GTK_ACTION(get_gtk_builder_object("zoom_100_action")); + g_signal_connect(G_OBJECT(g_zoom_100_action), "activate", G_CALLBACK(zoom_100), NULL); + + g_zoom_fit_action = GTK_ACTION(get_gtk_builder_object("zoom_fit_action")); + g_signal_connect(G_OBJECT(g_zoom_fit_action), "activate", G_CALLBACK(zoom_fit), NULL); + + g_zoom_in_action = GTK_ACTION(get_gtk_builder_object("zoom_in_action")); + g_signal_connect(G_OBJECT(g_zoom_in_action), "activate", G_CALLBACK(zoom_in), NULL); + + g_zoom_out_action = GTK_ACTION(get_gtk_builder_object("zoom_out_action")); + g_signal_connect(G_OBJECT(g_zoom_out_action), "activate", G_CALLBACK(zoom_out), NULL); + struct { GtkAction * action_ptr; @@ -46,6 +63,10 @@ void init_actions_and_accelerators(void) } * descriptor_ptr, descriptors [] = { {g_clear_xruns_and_max_dsp_action, "c"}, + {g_zoom_in_action, "plus"}, + {g_zoom_out_action, "minus"}, + {g_zoom_100_action, "0"}, + {g_zoom_fit_action, "equal"}, {NULL, NULL} }; diff --git a/gui/canvas.cpp b/gui/canvas.cpp index 398d66b8..73624438 100644 --- a/gui/canvas.cpp +++ b/gui/canvas.cpp @@ -249,6 +249,13 @@ canvas_scroll_to_center( } } +double +canvas_get_zoom( + canvas_handle canvas) +{ + return canvas_ptr->get()->get_zoom(); +} + void canvas_set_zoom( canvas_handle canvas, @@ -257,6 +264,13 @@ canvas_set_zoom( canvas_ptr->get()->set_zoom(pix_per_unit); } +void +canvas_set_zoom_fit( + canvas_handle canvas) +{ + canvas_ptr->get()->zoom_full(); +} + void canvas_arrange( canvas_handle canvas) diff --git a/gui/canvas.h b/gui/canvas.h index 9d7b7a49..84014568 100644 --- a/gui/canvas.h +++ b/gui/canvas.h @@ -78,11 +78,19 @@ void canvas_scroll_to_center( canvas_handle canvas); +double +canvas_get_zoom( + canvas_handle canvas); + void canvas_set_zoom( canvas_handle canvas, double pix_per_unit); +void +canvas_set_zoom_fit( + canvas_handle canvas); + void canvas_arrange( canvas_handle canvas); diff --git a/gui/gladish.ui b/gui/gladish.ui index 91a5011c..f437e95d 100644 --- a/gui/gladish.ui +++ b/gui/gladish.ui @@ -283,6 +283,38 @@ + + + True + zoom_in_action + True + True + + + + + True + zoom_out_action + True + True + + + + + True + zoom_100_action + True + True + + + + + True + zoom_fit_action + True + True + + True @@ -486,10 +518,9 @@ - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-zoom-100 + + zoom_in_action + True False @@ -497,10 +528,30 @@ - + + zoom_out_action + True + + + False + True + + + + + zoom_100_action + True + + + False + True + + + + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-zoom-fit + zoom_fit_action + True False @@ -1315,6 +1366,30 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, gtk-clear True + + Zoom 100% + zoom_100 + gtk-zoom-100 + True + + + Zoom to fit + zoom_fit + gtk-zoom-fit + True + + + Zoom in + zoom_in + gtk-zoom-in + True + + + Zoom out + zoom_out + gtk-zoom-out + True + True gtk-preferences diff --git a/gui/zoom.c b/gui/zoom.c new file mode 100644 index 00000000..41a85563 --- /dev/null +++ b/gui/zoom.c @@ -0,0 +1,83 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains the canvas zoom related code + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "zoom.h" +#include "canvas.h" +#include "graph_view.h" + +#define ZOOM_CHANGE 1.1 + +void zoom_100(void) +{ + canvas_handle canvas; + + log_info("zoom 100%% request"); + + canvas = get_current_canvas(); + if (canvas != NULL) + { + canvas_set_zoom(canvas, 1.0); + } +} + +void zoom_fit(void) +{ + canvas_handle canvas; + + log_info("zoom fit request"); + + canvas = get_current_canvas(); + if (canvas != NULL) + { + canvas_set_zoom_fit(canvas); + } +} + +void zoom_in(void) +{ + canvas_handle canvas; + + log_info("zoom in request"); + + canvas = get_current_canvas(); + if (canvas != NULL) + { + canvas_set_zoom(canvas, canvas_get_zoom(canvas) * ZOOM_CHANGE); + } +} + +void zoom_out(void) +{ + canvas_handle canvas; + + log_info("zoom out request"); + + canvas = get_current_canvas(); + if (canvas != NULL) + { + canvas_set_zoom(canvas, canvas_get_zoom(canvas) / ZOOM_CHANGE); + } +} diff --git a/gui/zoom.h b/gui/zoom.h new file mode 100644 index 00000000..a23eaf8c --- /dev/null +++ b/gui/zoom.h @@ -0,0 +1,35 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains interface to the canvas zoom related code + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef ZOOM_H__3D2297C9_5286_47AF_A7A3_0C15FDA40F93__INCLUDED +#define ZOOM_H__3D2297C9_5286_47AF_A7A3_0C15FDA40F93__INCLUDED + +void zoom_100(void); +void zoom_fit(void); +void zoom_in(void); +void zoom_out(void); + +#endif /* #ifndef ZOOM_H__3D2297C9_5286_47AF_A7A3_0C15FDA40F93__INCLUDED */ diff --git a/wscript b/wscript index 8b47a6a7..95571bc9 100644 --- a/wscript +++ b/wscript @@ -450,6 +450,7 @@ def build(bld): 'statusbar.c', 'action.c', 'settings.c', + 'zoom.c', ]: gladish.source.append(os.path.join("gui", source))