]> git.donarmstrong.com Git - lilypond.git/blob - lily/g-staff-side.cc
release: 1.1.38
[lilypond.git] / lily / g-staff-side.cc
1 /*   
2   g-staff-side.cc --  implement G_staff_side_item
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 "g-staff-side.hh"
11 #include "staff-symbol.hh"
12 #include "debug.hh"
13
14 G_staff_side_item::G_staff_side_item ()
15 {
16   dir_ = CENTER;
17   to_position_l_ = 0;
18   set_elt_property (transparent_scm_sym, SCM_BOOL_T);
19   staff_support_b_ = true;
20   axis_ = Y_AXIS;
21 }
22
23
24
25 void
26 G_staff_side_item::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 G_staff_side_item::get_default_direction () const
37 {
38   return DOWN;
39 }
40
41
42 void
43 G_staff_side_item::set_victim (Score_element *e)
44 {
45   add_dependency (e);
46   to_position_l_ = e;
47   to_position_l_->dim_cache_[axis_].parent_l_ = &dim_cache_[axis_];
48 }
49
50 void
51 G_staff_side_item::add_support (Score_element*e)
52 {
53   add_dependency (e);
54   support_l_arr_.push (e);
55 }
56
57
58 void
59 G_staff_side_item::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 G_staff_side_item::position_self ()
70 {
71
72   Interval dim;
73   Dimension_cache *common = 0;
74   if (support_l_arr_.size ())
75     {
76       common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
77                              axis_);
78
79       for (int i=0; i < support_l_arr_.size (); i++)
80         {
81           Score_element * e = support_l_arr_ [i];
82           Real coord = e->relative_coordinate (common, axis_);
83           dim.unite (coord + e->extent (axis_));
84         }
85     }
86   else
87     {
88       dim = Interval(0,0);
89       common = dim_cache_[axis_].parent_l_;
90     }
91
92   
93   Interval sym_dim
94     = to_position_l_
95     ? to_position_l_->extent (axis_)
96     : Interval(0,0);
97
98   Real off = dim_cache_[axis_].relative_coordinate (common);
99
100   SCM pad = remove_elt_property (padding_scm_sym);
101   if (pad != SCM_BOOL_F)
102     {
103       off += gh_scm2double (SCM_CDR(pad)) * dir_;
104     }
105   dim_cache_[axis_].set_offset (dim[dir_] - sym_dim[-dir_] + off);
106 }
107
108 void
109 G_staff_side_item::do_post_processing ()
110 {
111   if (axis_ == Y_AXIS)
112     position_self ();
113 }
114
115
116 void
117 G_staff_side_item::do_add_processing ()
118 {
119   if (staff_support_b_
120       && axis_ == Y_AXIS && staff_symbol_l ())
121     {
122       add_support (staff_symbol_l ());
123     }
124 }
125
126 Interval
127 G_staff_side_item::do_height () const
128 {
129   Interval i;
130   if (to_position_l_)
131     return to_position_l_->extent (Y_AXIS);
132   return i;
133 }
134
135 Interval
136 G_staff_side_item::do_width () const
137 {
138   Interval i;
139   if (to_position_l_)
140     return to_position_l_->extent (X_AXIS);
141   return i;
142 }
143 void
144 G_staff_side_item::do_print () const
145 {
146 #ifndef NPRINT
147   if (to_position_l_)
148     DOUT << "positioning " << to_position_l_->name();
149
150   DOUT << "axis == " << axis_name_str (axis_)
151        << ", dir == " << to_str (dir_ );
152 #endif
153 }