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