lilypond-1.5.10
[lilypond.git] / lily / axis-group-element.cc
blobd3235510d484fc27b4b6afae7b614c1006c89a9a
1 /*
2 axis-group-element.cc -- implement Axis_group_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "axis-group-element.hh"
10 #include "dimension-cache.hh"
11 #include "group-interface.hh"
13 Link_array<Score_element>
14 Axis_group_element::elem_l_arr () const
16 return
17 Group_interface__extract_elements (this, (Score_element*)0, "elements");
20 Link_array<Score_element>
21 Axis_group_element::get_children ()
23 Link_array<Score_element> childs;
24 Link_array<Score_element> elems = elem_l_arr ();
26 for (int i=0; i < elems.size (); i++)
28 Score_element* e = elems[i];
29 childs.push (e) ;
30 Axis_group_element * axis_group= dynamic_cast <Axis_group_element *> (e);
31 if (axis_group)
32 childs.concat (axis_group->get_children ());
35 return childs;
38 Axis_group_element::Axis_group_element()
40 set_elt_property ("elements", SCM_EOL);
41 set_elt_property ("transparent", SCM_BOOL_T);
44 void
45 Axis_group_element::set_axes (Axis a1, Axis a2)
47 SCM ax = gh_cons (gh_int2scm (a1), SCM_EOL);
48 if (a1 != a2)
49 ax= gh_cons (gh_int2scm (a2), ax);
52 set_elt_property ("axes", ax);
54 if (a1 != X_AXIS && a2 != X_AXIS)
55 set_empty (X_AXIS);
56 if (a1 != Y_AXIS && a2 != Y_AXIS)
57 set_empty (Y_AXIS);
59 dim_cache_[a1]->set_callback(extent_callback);
60 dim_cache_[a2]->set_callback (extent_callback);
63 Interval
64 Axis_group_element::extent_callback (Dimension_cache const *c)
66 Axis a = c->axis ();
67 Axis_group_element * me
68 = dynamic_cast<Axis_group_element*> (c->element_l ());
70 Interval r;
71 for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
73 SCM e=gh_car (s);
74 Score_element * se = SMOB_TO_TYPE (Score_element, e);
76 Interval dims = se->extent (a);
77 if (!dims.empty_b ())
78 r.unite (dims + se->relative_coordinate (me, a));
81 return r;
85 bool
86 Axis_group_element::axis_b (Axis a )const
88 return dim_cache_[a]->extent_callback_l_ == extent_callback;
92 void
93 Axis_group_element::add_element (Score_element *e)
95 used_b_ =true;
96 e->used_b_ = true;
98 for (SCM ax = get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
100 Axis a = (Axis) gh_scm2int (gh_car (ax));
102 if (!e->parent_l (a))
103 e->set_parent (this, a);
105 Group_interface gi (this);
106 gi.add_element (e);
108 add_dependency (e);