X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Faxis-group-interface.cc;h=b13eecd868d33c684e74cca529a3732aa8f650f0;hb=58a112d5df3f1a8313ee721cea5cd9ce479e2f48;hp=a08865c19cd9207144b9ba53854acab1115da6ee;hpb=e4f07a592ebde9621dede5a47430a51b9c232eb3;p=lilypond.git diff --git a/lily/axis-group-interface.cc b/lily/axis-group-interface.cc index a08865c19c..b13eecd868 100644 --- a/lily/axis-group-interface.cc +++ b/lily/axis-group-interface.cc @@ -1,145 +1,112 @@ -/* - axis-group-interface.cc -- implement Axis_group_interface - +/* + axis-group-interface.cc -- implement Axis_group_interface + source file of the GNU LilyPond music typesetter - - (c) 2000 Han-Wen Nienhuys - - */ -#include "axis-group-interface.hh" -#include "score-element.hh" -#include "dimension-cache.hh" + (c) 2000--2006 Han-Wen Nienhuys +*/ -Axis_group_interface::Axis_group_interface (Score_element*s) -{ - elt_l_ = s; -} +#include "axis-group-interface.hh" -Axis_group_interface -Axis_group_interface (Score_element*s) -{ - return Axis_group_interface (s); -} +#include "pointer-group-interface.hh" +#include "grob.hh" +#include "hara-kiri-group-spanner.hh" +#include "warn.hh" void -Axis_group_interface::add_element (Score_element *e) +Axis_group_interface::add_element (Grob *me, Grob *e) { + SCM axes = me->get_property ("axes"); + if (!scm_is_pair (axes)) + programming_error ("axes should be nonempty"); - // ugh. used_b_ should be junked. - elt_l_->used_b_ = true; - e->used_b_ = true; - - for (SCM ax = elt_l_->get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax)) + for (SCM ax = axes; ax != SCM_EOL; ax = scm_cdr (ax)) { - Axis a = (Axis) gh_scm2int (gh_car (ax)); - - if (!e->parent_l (a)) - e->set_parent (elt_l_, a); + Axis a = (Axis) scm_to_int (scm_car (ax)); + + if (!e->get_parent (a)) + e->set_parent (me, a); + + e->internal_set_object ((a == X_AXIS) + ? ly_symbol2scm ("axis-group-parent-X") + : ly_symbol2scm ("axis-group-parent-Y"), + me->self_scm ()); } - Pointer_group_interface (elt_l_).add_element (e); - elt_l_->add_dependency (e); + Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e); } - bool -Axis_group_interface::axis_b (Axis a )const +Axis_group_interface::has_axis (Grob *me, Axis a) { - return elt_l_->has_extent_callback_b (group_extent_callback, a); + SCM axes = me->get_property ("axes"); + + return (SCM_BOOL_F != scm_memq (scm_from_int (a), axes)); } Interval -Axis_group_interface::relative_group_extent (Axis a, Score_element *common, SCM elts) +Axis_group_interface::relative_group_extent (vector const &elts, + Grob *common, Axis a) { Interval r; - for (SCM s = elts; gh_pair_p (s); s = gh_cdr (s)) + for (vsize i = 0; i < elts.size (); i++) { - Score_element * se = unsmob_element (gh_car (s)); - Interval dims = se->extent (a); - if (!dims.empty_b ()) - r.unite (dims + se->relative_coordinate (common, a)); + Grob *se = elts[i]; + Interval dims = se->extent (common, a); + if (!dims.is_empty ()) + r.unite (dims); } return r; } -Interval -Axis_group_interface::group_extent_callback (Score_element const*me, Axis a) +MAKE_SCHEME_CALLBACK (Axis_group_interface, width, 1); +SCM +Axis_group_interface::width (SCM smob) { - Score_element * common =(Score_element*) me; - - for (SCM s = me->get_elt_pointer ("elements"); gh_pair_p (s); s = gh_cdr (s)) - { - Score_element * se = unsmob_element (gh_car (s)); - common = se->common_refpoint (common, a); - } - - Real my_coord = me->relative_coordinate (common, a); - Interval r (relative_group_extent (a, common, me->get_elt_pointer ("elements"))); - - return r - my_coord; + Grob *me = unsmob_grob (smob); + return generic_group_extent (me, X_AXIS); } -void -Axis_group_interface::set_interface () +MAKE_SCHEME_CALLBACK (Axis_group_interface, height, 1); +SCM +Axis_group_interface::height (SCM smob) { - if (!has_interface_b ()) - { - elt_l_->set_elt_pointer ("elements", SCM_EOL); - elt_l_->set_elt_property ("transparent", SCM_BOOL_T); // junk this? - elt_l_->set_elt_property ("axes" , SCM_EOL); - Group_interface (elt_l_, "interfaces").add_thing (ly_symbol2scm ("Axis_group")); - } + Grob *me = unsmob_grob (smob); + return generic_group_extent (me, Y_AXIS); } - -void -Axis_group_interface::set_axes (Axis a1, Axis a2) + +SCM +Axis_group_interface::generic_group_extent (Grob *me, Axis a) { - // set_interface () ? + extract_grob_set (me, "elements", elts); + Grob *common = common_refpoint_of_array (elts, me, a); - SCM ax = gh_cons (gh_int2scm (a1), SCM_EOL); - if (a1 != a2) - ax= gh_cons (gh_int2scm (a2), ax); - - - elt_l_->set_elt_property ("axes", ax); + Real my_coord = me->relative_coordinate (common, a); + Interval r (relative_group_extent (elts, common, a)); - if (a1 != X_AXIS && a2 != X_AXIS) - elt_l_->set_extent_callback (0, X_AXIS); - if (a1 != Y_AXIS && a2 != Y_AXIS) - elt_l_->set_extent_callback (0, Y_AXIS); - - elt_l_->set_extent_callback (Axis_group_interface::group_extent_callback,a1); - elt_l_->set_extent_callback (Axis_group_interface::group_extent_callback,a2); + return ly_interval2scm (r - my_coord); } -Link_array -Axis_group_interface::get_children () +void +Axis_group_interface::get_children (Grob *me, vector *found) { - Link_array childs; - childs.push (elt_l_) ; + found->push_back (me); - if (!has_interface_b ()) - return childs; - - for (SCM ep = elt_l_->get_elt_pointer ("elements"); gh_pair_p (ep); ep = gh_cdr (ep)) + if (!has_interface (me)) + return; + + extract_grob_set (me, "elements", elements); + for (vsize i = 0; i < elements.size (); i++) { - Score_element* e = unsmob_element (gh_car (ep)); - if (e) - childs.concat (Axis_group_interface (e).get_children ()); + Grob *e = elements[i]; + Axis_group_interface::get_children (e, found); } - - return childs; } -bool -Axis_group_interface::has_interface_b () -{ - SCM ifs = elt_l_->get_elt_property ("interfaces"); - - if (!gh_pair_p (ifs )) - return false; - return scm_memq (ly_symbol2scm ("Axis_group"),ifs) != SCM_BOOL_F; -} +ADD_INTERFACE (Axis_group_interface, "axis-group-interface", + "An object that groups other layout objects.", + /* properties */ + "axes " + "elements ");