Mercurial > hg > octave-lojdl
changeset 7828:4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
* * *
Fix figure boundingbox <-> position conversion bug.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Wed, 13 Feb 2008 17:06:22 +0100 |
parents | 3584f37eac69 |
children | 8ca8e97e8c0a |
files | src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 83 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -15,6 +15,19 @@ 2008-06-04 Michael Goffioul <michael.goffioul@gmail.com> + * graphics.h.in (base_properties::update_boundingbox): New method + to handle object resize. + (figure::properties::set_boundingbox): New method to set figure + position from backend. + (figure::properties::update_position): Remove method. + (figure::properties::position): Remove 'u' modifier and add 'S' + modifier. + (axes::properties::update_boundingbox): Overload to recompute + transformation when axes size changed. + * graphics.cc (base_properties::update_boundingbox): New method. + (figure::properties::set_boundingbox, + figure::properties::set_position): Likewise. + * genprops.awk: Add 'U' modifier to support extern updaters. * graphics.h.in (base_graphics_backend::gripe_invalid): New method to simplify error reporting.
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -1301,6 +1301,20 @@ return graphics_backend (); } +void +base_properties::update_boundingbox (void) +{ + Matrix kids = get_children (); + + for (int i = 0; i < kids.numel (); i++) + { + graphics_object go = gh_manager::get_object (kids(i)); + + if (go.valid_object ()) + go.get_properties ().update_boundingbox (); + } +} + // --------------------------------------------------------------------- class gnuplot_backend : public base_graphics_backend @@ -1503,6 +1517,49 @@ return pos; } +void +figure::properties::set_boundingbox (const Matrix& bb) +{ + graphics_backend b = get_backend (); + // FIXME: screen size should be obtained from root object + Matrix screen_size = b.get_screen_size (); + Matrix pos = bb; + + pos(1) = screen_size(1) - pos(1) - pos(3); + pos(1)++; + pos(0)++; + pos = convert_position (pos, "pixels", get_units (), screen_size, b); + + set_position (pos); +} + +void +figure::properties::set_position (const octave_value& v) +{ + if (! error_state) + { + Matrix old_bb, new_bb; + + old_bb = get_boundingbox (); + position = v; + new_bb = get_boundingbox (); + + if (old_bb != new_bb) + { + // FIXME: maybe this should be converted into a more generic + // call like "update_gui (this)" + get_backend ().set_figure_position (__myhandle__, new_bb); + if (old_bb(2) != new_bb(2) || old_bb(3) != new_bb(3)) + { + execute_resizefcn (); + update_boundingbox (); + } + } + + mark_modified (); + } +} + octave_value figure::get_default (const caseless_str& name) const {
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -1421,6 +1421,8 @@ virtual Matrix get_boundingbox (bool /*internal*/ = false) const { return Matrix (1, 4, 0.0); } + virtual void update_boundingbox (void); + void set_tag (const octave_value& val) { tag = val; } void set_parent (const octave_value& val); @@ -2162,8 +2164,7 @@ Matrix get_boundingbox (bool internal = false) const; - void update_position (void) - { backend.set_figure_position (__myhandle__, get_boundingbox ()); } + void set_boundingbox (const Matrix& bb); // See the genprops.awk script for an explanation of the // properties declarations. @@ -2200,7 +2201,7 @@ radio_property pointer , "crosshair|fullcrosshair|{arrow}|ibeam|watch|topl|topr|botl|botr|left|top|right|bottom|circle|cross|fleur|custom|hand" array_property pointershapecdata , Matrix (16, 16, 0) array_property pointershapehotspot , Matrix (1, 2, 0) - array_property position u , default_figure_position () + array_property position S , default_figure_position () radio_property renderer , "{painters}|zbuffer|opengl|none" radio_property renderermode , "{auto}|manual" bool_property resize , "on" @@ -2377,6 +2378,15 @@ Matrix get_boundingbox (bool internal = false) const; + void update_boundingbox (void) + { + if (units_is ("normalized")) + { + update_transform (); + base_properties::update_boundingbox (); + } + } + void update_camera (void); void update_aspectratios (void); void update_transform (void)