lilypond-1.3.11
[lilypond.git] / lily / axis-group-element.cc
blob081b42a22faee300ad1e5c6ac66dc0771df5fe8d
1 /*
2 axis-group-element.cc -- implement Axis_group_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 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::get_extra_dependencies() const
16 Link_array<Score_element> e(elem_l_arr ());
17 return e;
20 Link_array<Score_element>
21 Axis_group_element::elem_l_arr () const
23 return
24 Group_interface__extract_elements (this, (Score_element*)0, "elements");
27 Link_array<Score_element>
28 Axis_group_element::get_children ()
30 Link_array<Score_element> childs;
31 Link_array<Score_element> elems = elem_l_arr ();
33 for (int i=0; i < elems.size (); i++)
35 Score_element* e = elems[i];
36 childs.push (e) ;
37 Axis_group_element * axis_group= dynamic_cast <Axis_group_element *> (e);
38 if (axis_group)
39 childs.concat (axis_group->get_children ());
42 return childs;
45 Axis_group_element::Axis_group_element()
47 axes_[0] = (Axis)-1 ;
48 axes_[1] = (Axis)-1 ;
50 set_elt_property ("elements", SCM_EOL);
51 set_elt_property ("transparent", SCM_BOOL_T);
54 void
55 Axis_group_element::set_axes (Axis a1, Axis a2)
57 axes_[0] = a1 ;
58 axes_[1] = a2 ;
59 if (a1 != X_AXIS && a2 != X_AXIS)
60 set_empty (X_AXIS);
61 if (a1 != Y_AXIS && a2 != Y_AXIS)
62 set_empty (Y_AXIS);
64 dim_cache_[a1]->set_callback(extent_callback);
65 dim_cache_[a2]->set_callback (extent_callback);
68 Interval
69 Axis_group_element::extent_callback (Dimension_cache const *c)
71 Axis a = c->axis ();
72 Axis_group_element * me
73 = dynamic_cast<Axis_group_element*> (c->element_l ());
75 Interval r;
76 for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
78 SCM e=gh_car (s);
79 Score_element * se = SMOB_TO_TYPE (Score_element, e);
81 Interval dims = se->extent (a);
82 if (!dims.empty_b ())
83 r.unite (dims + se->relative_coordinate (me, a));
86 return r;
91 void
92 Axis_group_element::add_element (Score_element *e)
94 used_b_ =true;
95 e->used_b_ = true;
97 for (int i = 0; i < 2; i++)
99 if (!e->parent_l (axes_[i]))
100 e->set_parent (this, axes_[i]);
102 Group_interface gi (this);
103 gi.add_element (e);