# HG changeset patch # User Shai Ayal # Date 1203968711 -7200 # Node ID 1357bcae6e29a95fc1d71d0e623c2352398c77be # Parent c643e5c520f50c738e499e66b7de6ec6089cbcb6 added pixel<->coord transform in axes and use it for display of cursor position and zoom in fltk_backend diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2008-06-04 Shai Ayal + * graphics.h.in (axes::pixel2coord, axes::coord2pixel): New functions. + * graphics.cc (convert_position): No longer static. * graphics.h.in: Provide decl. diff --git a/src/graphics.h.in b/src/graphics.h.in --- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -2492,6 +2492,13 @@ Matrix get_opengl_matrix_2 (void) const { return x_gl_mat2; } Matrix get_transform_zlim (void) const { return x_zlim; } + ColumnVector pixel2coord (double px, double py) const + { return get_transform ().untransform (px, py, 0); } + + ColumnVector coord2pixel (double x, double y, double z) const + { return get_transform ().transform (x, y, z); } + + private: scaler sx, sy, sz; Matrix x_render, x_render_inv; diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,15 @@ +2008-02-25 Shai Ayal + + * fltk_backend/fltk_backend.cc (class plot_window): Many changes + to use figure::properties instead of figure handle to reference + the figure + (class figure_manager): ditto + (__fltk_redraw__): moved most of functionality into the + figure_manager class + (plot_window::pixel2pos): Modified to use axes::pixel2coord + (plot_window::pixel2staus): Modified to use pixel2pos + (plot_window::handle): Added zoom with mouse + 2008-02-24 Shai Ayal * fltk_backend/fltk_backend.cc (OpenGL_fltk::Draw): removed double diff --git a/src/graphics/fltk_backend/fltk_backend.cc b/src/graphics/fltk_backend/fltk_backend.cc --- a/src/graphics/fltk_backend/fltk_backend.cc +++ b/src/graphics/fltk_backend/fltk_backend.cc @@ -219,10 +219,16 @@ Fl_Button* help; Fl_Output* status; - void pixel2pos (int px, int py, double& x, double& y) const { - x = static_cast (px) / w (); - y = 1. - static_cast (py) / (h () - status_h); + graphics_object ax = gh_manager::get_object (fp.get_currentaxes ()); + if (ax && ax.isa ("axes")) + { + axes::properties& ap = + dynamic_cast (ax.get_properties ()); + ColumnVector pp = ap.pixel2coord (px, py); + x = pp(0); + y = pp(1); + } } graphics_handle pixel2axes (int px, int py) { @@ -236,51 +242,31 @@ { axes::properties& ap = dynamic_cast (ax.get_properties ()); - Matrix pixpos = - convert_position (ap.get_position (). matrix_value (), - ap.get_units (), - "pixels" , - fp.get_position ().matrix_value (), - fp.get_backend ()); - std::cout << "\npixpos="<= pixpos(0) && px <= pixpos(0) + pixpos(2) - && - py >= pixpos(1) && py <= pixpos(1) + pixpos(3) ) - return ap.get___myhandle__ (); + +// std::cout << "\npixpos="<= pixpos(0) && px <= pixpos(2) +// && +// py >= pixpos(1) && py <= pixpos(3)) +// return ap.get___myhandle__ (); } } return graphics_handle (); } - void pixel2status (int px, int py) { -// std::stringstream cbuf; -// figure::properties fp = get_figure_props (); -// graphics_object obj = gh_manager::get_object (fp.get_currentaxes ()); -// if (obj && obj.isa ("axes")) -// { -// axes::properties& ap = -// dynamic_cast (obj.get_properties ()); - -// Matrix pos(1,2,0); -// pos(0) = px; -// pos(1) = py; + void pixel2status (int px0, int py0, int px1 = -1, int py1 = -1) { + double x0,y0,x1,y1; + std::stringstream cbuf; -// Matrix axpos = -// convert_position (pos, -// "pixels", -// ap.get_units () , -// fp.get_position ().matrix_value (), -// fp.get_backend ()); + pixel2pos (px0, py0, x0, y0); + cbuf << "[" << x0 << ", " << y0 << "]"; + if (px1 >= 0) + { + pixel2pos (px1, py1, x1, y1); + cbuf << " -> ["<< x1 << ", " << y1 << "]"; + } -// cbuf << "[" << axpos(0) << ", " << axpos(1) << "]"; -// } -// else -// { -// cbuf << "[-, -]"; -// } - -// status->value (cbuf.str ().c_str ()); -// status->redraw (); + status->value (cbuf.str ().c_str ()); + status->redraw (); } void resize (int _x,int _y,int _w,int _h) @@ -305,7 +291,7 @@ } int handle (int event) { - static double x0,y0; + static int px0,py0; static graphics_handle h0 = graphics_handle (); static bool in_drag = false; @@ -325,14 +311,15 @@ case FL_PUSH: if (Fl::event_button () == 1) { - pixel2pos (Fl::event_x (), Fl::event_y (), x0, y0); + px0 = Fl::event_x (); + py0 = Fl::event_y (); h0 = pixel2axes (Fl::event_x (), Fl::event_y ()); return 1; } break; case FL_DRAG: - pixel2status (Fl::event_x (), Fl::event_y ()); + pixel2status (px0, py0, Fl::event_x (), Fl::event_y ()); if (Fl::event_button () == 1) { in_drag = true; @@ -346,6 +333,40 @@ // end of drag -- zoom if (in_drag) { + 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 pp (1,2,0); + if (x0 < x1) + { + pp(0) = x0; + pp(1) = x1; + } + else + { + pp(0) = x1; + pp(1) = x0; + } + ap.set_xlim (pp); + if (y0 < y1) + { + pp(0) = y0; + pp(1) = y1; + } + else + { + pp(0) = y1; + pp(1) = y0; + } + ap.set_ylim (pp); + mark_modified (); + } in_drag = false; } // one click -- select axes @@ -570,6 +591,7 @@ return retval; } + // call this to delete the fltk backend DEFUN_DLD (__remove_fltk__, args, nargout,"") {