lilypond-1.3.69
[lilypond.git] / lily / g-staff-side.cc
blob437f34fe21ce386ec48afb014cc147d664ee0792
1 /*
2 g-staff-side.cc -- implement G_staff_side_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "g-staff-side.hh"
11 #include "staff-symbol.hh"
12 #include "debug.hh"
13 #include "warn.hh"
14 #include "dimensions.hh"
16 G_staff_side_element::G_staff_side_element ()
18 dir_ = CENTER;
19 to_position_l_ = 0;
20 set_elt_property (transparent_scm_sym, SCM_BOOL_T);
21 staff_support_b_ = true;
22 axis_ = Y_AXIS;
27 void
28 G_staff_side_element::do_pre_processing ()
30 if (!dir_)
31 dir_ = get_default_direction ();
33 if (axis_ == X_AXIS)
34 position_self ();
37 Direction
38 G_staff_side_element::get_default_direction () const
40 return DOWN;
44 void
45 G_staff_side_element::set_victim (Score_element *e)
47 add_dependency (e);
48 to_position_l_ = e;
49 to_position_l_->dim_cache_[axis_]->parent_l_ = dim_cache_[axis_];
52 void
53 G_staff_side_element::add_support (Score_element*e)
55 add_dependency (e);
56 support_l_arr_.push (e);
60 void
61 G_staff_side_element::do_substitute_element_pointer (Score_element*o, Score_element*n)
63 Staff_symbol_referencer::do_substitute_element_pointer (o,n);
64 if (o == to_position_l_)
65 to_position_l_ = n;
66 else
67 support_l_arr_.unordered_substitute (o,n);
70 void
71 G_staff_side_element::position_self ()
73 if (to_position_l_ &&
74 to_position_l_->get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
75 return;
77 Interval dim;
78 Dimension_cache *common = 0;
79 if (support_l_arr_.size ())
81 common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
82 axis_);
84 for (int i=0; i < support_l_arr_.size (); i++)
86 Score_element * e = support_l_arr_ [i];
87 Real coord = e->relative_coordinate (common, axis_);
89 dim.unite (coord + e->extent (axis_));
92 else
93 common = dim_cache_[axis_]->parent_l_;
95 if (dim.empty_b ())
97 dim = Interval(0,0);
101 Interval sym_dim
102 = to_position_l_
103 ? to_position_l_->extent (axis_)
104 : Interval(0,0);
106 Real off = dim_cache_[axis_]->relative_coordinate (common);
108 SCM pad = remove_elt_property (padding_scm_sym);
109 if (pad != SCM_BOOL_F)
111 off += gh_scm2double (SCM_CDR(pad)) * dir_;
113 Real total_off = dim[dir_] - sym_dim[-dir_] + off;
114 dim_cache_[axis_]->set_offset (total_off);
115 if (fabs (total_off) > 100 CM)
116 programming_error ("Huh ? Improbable staff side dim.");
119 void
120 G_staff_side_element::do_post_processing ()
122 if (axis_ == Y_AXIS)
123 position_self ();
127 void
128 G_staff_side_element::do_add_processing ()
130 if (staff_support_b_
131 && axis_ == Y_AXIS && staff_symbol_l ())
133 add_support (staff_symbol_l ());
137 Interval
138 G_staff_side_element::do_height () const
140 Interval i;
141 if (to_position_l_)
142 return to_position_l_->extent (Y_AXIS);
143 return i;
146 void
147 G_staff_side_element::do_print () const
149 #ifndef NPRINT
150 if (to_position_l_)
151 DOUT << "positioning " << to_position_l_->name();
153 DOUT << "axis == " << axis_name_str (axis_)
154 << ", dir == " << to_str (dir_ );
155 #endif
159 Interval
160 G_staff_side_item::do_width () const
162 Interval i;
163 if (to_position_l_)
164 return to_position_l_->extent (X_AXIS);
165 return i;
168 void
169 G_staff_side_item::do_print () const
171 G_staff_side_element::do_print ();
174 void
175 G_staff_side_spanner::do_print () const
177 G_staff_side_element::do_print ();