]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-interface.cc
release: 1.3.36
[lilypond.git] / lily / axis-group-interface.cc
1 /*   
2   axis-group-interface.cc --  implement Axis_group_interface
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "axis-group-interface.hh"
11 #include "score-element.hh"
12 #include "dimension-cache.hh"
13
14 Axis_group_interface::Axis_group_interface (Score_element*s)
15   : Group_interface (s)
16 {
17   elt_l_ = s;
18 }
19
20 Axis_group_interface
21 axis_group (Score_element*s)
22 {
23   return Axis_group_interface (s);
24 }
25
26 void
27 Axis_group_interface::add_element (Score_element *e)
28 {
29   elt_l_->used_b_ = true;
30   e->used_b_ = true;
31
32   for (SCM ax = elt_l_->get_elt_property ("axes"); ax != SCM_EOL ; ax = gh_cdr (ax))
33     {
34       Axis a = (Axis) gh_scm2int (gh_car (ax));
35       
36       if (!e->parent_l (a))
37         e->set_parent (elt_l_, a);
38     }
39
40   Group_interface::add_element (e);
41
42   elt_l_->add_dependency (e);
43 }
44
45
46 bool
47 Axis_group_interface::axis_b (Axis a )const
48 {
49   return elt_l_->dim_cache_[a]->extent_callback_l_ == group_extent_callback;
50 }
51
52 Interval
53 Axis_group_interface::group_extent_callback (Dimension_cache const *c) 
54 {
55   Axis a = c->axis ();
56   Score_element * me = c->element_l ();
57
58   Interval r;
59   for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
60     {
61       SCM e=gh_car (s); 
62       Score_element * se = SMOB_TO_TYPE (Score_element, e);
63
64       Interval dims = se->extent (a);
65       if (!dims.empty_b ())
66         r.unite (dims + se->relative_coordinate (me, a));
67     }
68
69   return r;
70 }
71
72
73 void
74 Axis_group_interface::set_interface ()
75 {
76   if (!has_interface_b ())
77     {
78       elt_l_->set_elt_property ("elements", SCM_EOL);
79       elt_l_->set_elt_property ("transparent", SCM_BOOL_T);
80       elt_l_->set_elt_property ("axes" , SCM_EOL);
81       group (elt_l_, "interfaces").add_thing (ly_symbol2scm ("Axis_group"));
82     }
83 }
84
85 void
86 Axis_group_interface::set_axes (Axis a1, Axis a2)
87 {
88   // set_interface () ? 
89
90   SCM ax = gh_cons (gh_int2scm (a1), SCM_EOL);
91   if (a1 != a2)
92     ax= gh_cons (gh_int2scm (a2), ax);
93
94   
95   elt_l_->set_elt_property ("axes", ax);
96
97   if (a1 != X_AXIS && a2 != X_AXIS)
98     elt_l_->set_empty (X_AXIS);
99   if (a1 != Y_AXIS && a2 != Y_AXIS)
100     elt_l_->set_empty (Y_AXIS);
101   
102   elt_l_->dim_cache_[a1]->set_callback (Axis_group_interface::group_extent_callback);
103   elt_l_->dim_cache_[a2]->set_callback (Axis_group_interface::group_extent_callback);
104 }
105
106 Link_array<Score_element> 
107 Axis_group_interface::get_children ()
108 {
109   Link_array<Score_element> childs;
110   childs.push (elt_l_) ;
111
112   if (!has_interface_b ())
113     return childs;
114   
115   for (SCM ep = elt_l_->get_elt_property ("elements"); gh_pair_p (ep); ep = gh_cdr (ep))
116     {
117       Score_element* e = unsmob_element (gh_car (ep));
118       if (e)
119         childs.concat (axis_group (e).get_children ());
120     }
121   
122   return childs;
123 }
124
125 bool
126 Axis_group_interface::has_interface_b ()
127 {
128   SCM memq = scm_memq (ly_symbol2scm ("Axis_group"),
129               elt_l_->get_elt_property ("interfaces"));
130   
131   return (memq != SCM_BOOL_F);
132 }
133
134