2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "axis-group-interface.hh"
11 #include "score-element.hh"
12 #include "dimension-cache.hh"
14 Axis_group_interface::Axis_group_interface (Score_element*s)
20 Axis_group_interface (Score_element*s)
22 return Axis_group_interface (s);
26 Axis_group_interface::add_element (Score_element *e)
29 // ugh. used_b_ should be junked.
30 elt_l_->used_b_ = true;
33 for (SCM ax = elt_l_->get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
35 Axis a = (Axis) gh_scm2int (gh_car (ax));
38 e->set_parent (elt_l_, a);
41 Group_interface (elt_l_).add_element (e);
42 elt_l_->add_dependency (e);
47 Axis_group_interface::axis_b (Axis a )const
49 return elt_l_->dim_cache_[a]->extent_callback_l_ == group_extent_callback;
53 Axis_group_interface::relative_group_extent (Axis a, Score_element *common, SCM elts)
56 for (SCM s = elts; gh_pair_p (s); s = gh_cdr (s))
58 Score_element * se = unsmob_element (gh_car (s));
59 Interval dims = se->extent (a);
61 r.unite (dims + se->relative_coordinate (common, a));
67 Axis_group_interface::group_extent_callback (Dimension_cache const *c)
70 Score_element * me = c->element_l ();
71 Score_element * common = me;
73 for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
75 Score_element * se = unsmob_element (gh_car (s));
76 common = se->common_refpoint (common, a);
79 Real my_coord = me->relative_coordinate (common, a);
80 Interval r (relative_group_extent (a, common, me->get_elt_property ("elements")));
86 Axis_group_interface::set_interface ()
88 if (!has_interface_b ())
90 elt_l_->set_elt_property ("elements", SCM_EOL);
91 elt_l_->set_elt_property ("transparent", SCM_BOOL_T); // junk this?
92 elt_l_->set_elt_property ("axes" , SCM_EOL);
93 group (elt_l_, "interfaces").add_thing (ly_symbol2scm ("Axis_group"));
98 Axis_group_interface::set_axes (Axis a1, Axis a2)
100 // set_interface () ?
102 SCM ax = gh_cons (gh_int2scm (a1), SCM_EOL);
104 ax= gh_cons (gh_int2scm (a2), ax);
107 elt_l_->set_elt_property ("axes", ax);
109 if (a1 != X_AXIS && a2 != X_AXIS)
110 elt_l_->set_extent_callback (0, X_AXIS);
111 if (a1 != Y_AXIS && a2 != Y_AXIS)
112 elt_l_->set_extent_callback (0, Y_AXIS);
114 elt_l_->dim_cache_[a1]->set_extent_callback (Axis_group_interface::group_extent_callback);
115 elt_l_->dim_cache_[a2]->set_extent_callback (Axis_group_interface::group_extent_callback);
118 Link_array<Score_element>
119 Axis_group_interface::get_children ()
121 Link_array<Score_element> childs;
122 childs.push (elt_l_) ;
124 if (!has_interface_b ())
127 for (SCM ep = elt_l_->get_elt_property ("elements"); gh_pair_p (ep); ep = gh_cdr (ep))
129 Score_element* e = unsmob_element (gh_car (ep));
131 childs.concat (Axis_group_interface (e).get_children ());
138 Axis_group_interface::has_interface_b ()
140 SCM memq = scm_memq (ly_symbol2scm ("Axis_group"),
141 elt_l_->get_elt_property ("interfaces"));
143 return (memq != SCM_BOOL_F);