]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 1.2.4
[lilypond.git] / lily / staff-side.cc
1 /*   
2   g-staff-side.cc --  implement Staff_side_element
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "staff-side.hh"
11 #include "staff-symbol.hh"
12 #include "debug.hh"
13 #include "warn.hh"
14 #include "dimensions.hh"
15 #include "dimension-cache.hh"
16
17 Staff_side_element::Staff_side_element ()
18 {
19   dir_ = CENTER;
20   to_position_l_ = 0;
21   set_elt_property (transparent_scm_sym, SCM_BOOL_T);
22   axis_ = Y_AXIS;
23 }
24
25 void
26 Staff_side_element::do_pre_processing ()
27 {
28   if (!dir_)
29     dir_ = get_default_direction ();
30
31   if (axis_ == X_AXIS)
32     position_self ();
33 }
34
35 Direction
36 Staff_side_element::get_default_direction () const
37 {
38   return DOWN;
39 }
40
41
42 void
43 Staff_side_element::set_victim (Score_element *e)
44 {
45   add_dependency (e);
46   to_position_l_ = e;
47   to_position_l_->set_parent (this, axis_);
48 }
49
50 void
51 Staff_side_element::add_support (Score_element*e)
52 {
53   add_dependency (e);
54   support_l_arr_.push (e);
55 }
56
57
58 void
59 Staff_side_element::do_substitute_element_pointer (Score_element*o, Score_element*n)
60 {
61   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
62   if (o == to_position_l_)
63     to_position_l_ = n;
64   else
65     support_l_arr_.unordered_substitute (o,n);
66 }
67
68 void
69 Staff_side_element::position_self ()
70 {
71   if (to_position_l_ &&
72       to_position_l_->get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
73     return;
74
75   Interval dim;
76   Graphical_element *common = 0;
77   if (support_l_arr_.size ())
78     {
79       common = common_refpoint (typecast_array (support_l_arr_, (Graphical_element*)0),
80                                 axis_);
81
82       for (int i=0; i < support_l_arr_.size (); i++)
83         {
84           Score_element * e = support_l_arr_ [i];
85           Real coord = e->relative_coordinate (common, axis_);
86
87           dim.unite (coord + e->extent (axis_));
88         }
89     }
90   else
91      common = parent_l (axis_);
92
93   if (dim.empty_b ())
94     {
95       dim = Interval(0,0);
96     }
97
98   
99   Interval sym_dim
100     = to_position_l_
101     ? to_position_l_->extent (axis_)
102     : Interval(0,0);
103
104   Real off =  relative_coordinate (common, axis_);
105  
106
107
108   SCM pad = remove_elt_property (padding_scm_sym);
109   if (pad != SCM_BOOL_F)
110     {
111       off += gh_scm2double (SCM_CDR(pad)) * dir_;
112     }
113   Real total_off = dim[dir_] + off;
114
115   /*
116     no_staff_support_scm_sym is ugh bugfix to get staccato dots right.
117    */
118   if (to_position_l_ && to_position_l_->get_elt_property (no_staff_support_scm_sym) == SCM_BOOL_F)
119      total_off += - sym_dim[-dir_];
120   
121   dim_cache_[axis_]->set_offset (total_off);
122   if (fabs (total_off) > 100 CM)
123     programming_error ("Huh ? Improbable staff side dim.");
124 }
125
126 void
127 Staff_side_element::do_post_processing ()
128 {
129   if (axis_ == Y_AXIS)
130     position_self ();
131 }
132
133
134 void
135 Staff_side_element::do_add_processing ()
136 {
137   if (get_elt_property (no_staff_support_scm_sym) == SCM_BOOL_F
138       && axis_ == Y_AXIS && staff_symbol_l ())
139     {
140       add_support (staff_symbol_l ());
141     }
142 }
143
144 Interval
145 Staff_side_element::do_height () const
146 {
147   Interval i;
148   if (to_position_l_)
149     return to_position_l_->extent (Y_AXIS);
150   return i;
151 }
152
153 void
154 Staff_side_element::do_print () const
155 {
156 #ifndef NPRINT
157   if (to_position_l_)
158     DOUT << "positioning " << to_position_l_->name();
159
160   DOUT << "axis == " << axis_name_str (axis_)
161        << ", dir == " << to_str (dir_ );
162 #endif
163 }
164
165
166 Interval
167 Staff_side_item::do_width () const
168 {
169   Interval i;
170   if (to_position_l_)
171     return to_position_l_->extent (X_AXIS);
172   return i;
173 }
174
175 void
176 Staff_side_item::do_print () const
177 {
178   Staff_side_element::do_print ();
179 }
180
181 void
182 Staff_side_spanner::do_print () const
183 {
184   Staff_side_element::do_print ();
185 }