diff -r 7cc35bc348cc src/DLD-FUNCTIONS/fltk_backend.cc --- a/src/DLD-FUNCTIONS/fltk_backend.cc Sun Jun 28 08:51:41 2009 +0100 +++ b/src/DLD-FUNCTIONS/fltk_backend.cc Sun Jul 19 15:53:18 2009 +0200 @@ -442,63 +442,52 @@ pixel2status (px0, py0, Fl::event_x (), Fl::event_y ()); if (Fl::event_button () == 1) { - canvas->zoom (true); - Matrix zoom_box (1,4,0); - zoom_box (0) = px0; - zoom_box (1) = py0; - zoom_box (2) = Fl::event_x (); - zoom_box (3) = Fl::event_y (); - canvas->set_zoom_box (zoom_box); - canvas->redraw_overlay (); + graphics_object ax = gh_manager::get_object (fp.get_currentaxes ()); + if (ax && ax.isa ("axes")) + { + axes::properties& ap = dynamic_cast (ax.get_properties ()); + + double x0, y0, x1, y1; + pixel2pos (px0, py0, x0, y0); + pixel2pos (Fl::event_x (), Fl::event_y (), x1, y1); + px0 = Fl::event_x (); + py0 = Fl::event_y (); + + ap.translate_view (x0 - x1, y0 - y1); + mark_modified (); + } return 1; } break; + case FL_MOUSEWHEEL: + { + // Parameter controlling how fast we zoom. FIXME: Should this be user tweakable? + const double zoom_speed = 0.05; + + graphics_object ax = gh_manager::get_object (fp.get_currentaxes ()); + if (ax && ax.isa ("axes")) + { + axes::properties& ap = dynamic_cast (ax.get_properties ()); + + // Determine if we're zooming in or out + const double factor = (Fl::event_dy () > 0) ? 1.0 + zoom_speed : 1.0 - zoom_speed; + + // Get the point we're zooming about + double x1, y1; + pixel2pos (Fl::event_x (), Fl::event_y (), x1, y1); + + ap.zoom_about_point (x1, y1, factor, false); + mark_modified (); + } + } + return 1; + case FL_RELEASE: if (Fl::event_button () == 1) { - // end of drag -- zoom - if (canvas->zoom ()) - { - canvas->zoom (false); - double x0,y0,x1,y1; - graphics_object ax = - gh_manager::get_object (fp.get_currentaxes ()); - if (ax && ax.isa ("axes")) - { - axes::properties& ap = - dynamic_cast (ax.get_properties ()); - pixel2pos (px0, py0, x0, y0); - pixel2pos (Fl::event_x (), Fl::event_y (), x1, y1); - Matrix xl (1,2,0); - Matrix yl (1,2,0); - if (x0 < x1) - { - xl(0) = x0; - xl(1) = x1; - } - else - { - xl(0) = x1; - xl(1) = x0; - } - - if (y0 < y1) - { - yl(0) = y0; - yl(1) = y1; - } - else - { - yl(0) = y1; - yl(1) = y0; - } - ap.zoom (xl, yl); - mark_modified (); - } - } // one click -- select axes - else if ( Fl::event_clicks () == 0) + if ( Fl::event_clicks () == 0) { std::cout << "ca="<< h0.value ()<<"\n"; if (h0.ok ()) diff -r 7cc35bc348cc src/graphics.cc --- a/src/graphics.cc Sun Jun 28 08:51:41 2009 +0100 +++ b/src/graphics.cc Sun Jul 19 15:53:18 2009 +0200 @@ -3458,7 +3458,7 @@ labels = c; } -static void +void get_children_limits (double& min_val, double& max_val, double& min_pos, const Matrix& kids, char limit_type) { @@ -3696,14 +3696,63 @@ unwind_protect::run (); } -void -axes::properties::zoom (const Matrix& xl, const Matrix& yl) -{ - zoom_stack.push_front (xlimmode.get ()); - zoom_stack.push_front (xlim.get ()); - zoom_stack.push_front (ylimmode.get ()); - zoom_stack.push_front (ylim.get ()); - +inline +double force_in_range (const double x, const double lower, const double upper) +{ + if (x < lower) + { return lower; } + else if (x > upper) + { return upper; } + else + { return x; } +} + +void +axes::properties::zoom_about_point (double x, double y, double factor, + bool push_to_zoom_stack) +{ + // FIXME: Do we need error checking here? + Matrix xlims = get_xlim ().matrix_value (); + Matrix ylims = get_ylim ().matrix_value (); + + // Get children axes limits + Matrix kids = get_children (); + double minx = octave_Inf; + double maxx = -octave_Inf; + double min_pos_x = octave_Inf; + get_children_limits (minx, maxx, min_pos_x, kids, 'x'); + + double miny = octave_Inf; + double maxy = -octave_Inf; + double min_pos_y = octave_Inf; + get_children_limits (miny, maxy, min_pos_y, kids, 'y'); + + // Perform the zooming + xlims (0) = x + factor * (xlims (0) - x); + xlims (1) = x + factor * (xlims (1) - x); + ylims (0) = y + factor * (ylims (0) - y); + ylims (1) = y + factor * (ylims (1) - y); + + // Make sure we stay within the range og the plot + xlims (0) = force_in_range (xlims (0), minx, maxx); + xlims (1) = force_in_range (xlims (1), minx, maxx); + ylims (0) = force_in_range (ylims (0), miny, maxy); + ylims (1) = force_in_range (ylims (1), miny, maxy); + + zoom (xlims, ylims, push_to_zoom_stack); +} + +void +axes::properties::zoom (const Matrix& xl, const Matrix& yl, bool push_to_zoom_stack) +{ + if (push_to_zoom_stack) + { + zoom_stack.push_front (xlimmode.get ()); + zoom_stack.push_front (xlim.get ()); + zoom_stack.push_front (ylimmode.get ()); + zoom_stack.push_front (ylim.get ()); + } + xlim = xl; xlimmode = "manual"; ylim = yl; @@ -3715,6 +3764,43 @@ } void +axes::properties::translate_view (double delta_x, double delta_y) +{ + // FIXME: Do we need error checking here? + Matrix xlims = get_xlim ().matrix_value (); + Matrix ylims = get_ylim ().matrix_value (); + + // Get children axes limits + Matrix kids = get_children (); + double minx = octave_Inf; + double maxx = -octave_Inf; + double min_pos_x = octave_Inf; + get_children_limits (minx, maxx, min_pos_x, kids, 'x'); + + double miny = octave_Inf; + double maxy = -octave_Inf; + double min_pos_y = octave_Inf; + get_children_limits (miny, maxy, min_pos_y, kids, 'y'); + + // Make sure we don't exceed the borders + if (delta_x > 0) + delta_x = std::min (xlims (1) + delta_x, maxx) - xlims (1); + else + delta_x = std::max (xlims (0) + delta_x, minx) - xlims (0); + xlims (0) = xlims (0) + delta_x; + xlims (1) = xlims (1) + delta_x; + + if (delta_y > 0) + delta_y = std::min (ylims (1) + delta_y, maxy) - ylims (1); + else + delta_y = std::max (ylims (0) + delta_y, miny) - ylims (0); + ylims (0) = ylims (0) + delta_y; + ylims (1) = ylims (1) + delta_y; + + zoom (xlims, ylims, false); +} + +void axes::properties::unzoom (void) { if (zoom_stack.size () >= 4) diff -r 7cc35bc348cc src/graphics.h.in --- a/src/graphics.h.in Sun Jun 28 08:51:41 2009 +0100 +++ b/src/graphics.h.in Sun Jul 19 15:53:18 2009 +0200 @@ -2610,7 +2610,10 @@ ColumnVector coord2pixel (double x, double y, double z) const { return get_transform ().transform (x, y, z); } - void zoom (const Matrix& xl, const Matrix& yl); + void zoom_about_point (double x, double y, double factor, + bool push_to_zoom_stack = true); + void zoom (const Matrix& xl, const Matrix& yl, bool push_to_zoom_stack = true); + void translate_view (double delta_x, double delta_y); void unzoom (void); void clear_zoom_stack (void); @@ -3907,6 +3910,8 @@ void do_post_event (const graphics_event& e); }; +void get_children_limits (double& min_val, double& max_val, double& min_pos, + const Matrix& kids, char limit_type); // This function is NOT equivalent to the scripting language function gcf. OCTINTERP_API graphics_handle gcf (void);