]> git.donarmstrong.com Git - lilypond.git/blob - lily/g-staff-side.cc
865eb478add7cf4f13774e5ce48b8752f2d08d96
[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 #include "warn.hh"
14 #include "dimensions.hh"
15
16 G_staff_side_item::G_staff_side_item ()
17 {
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;
23 }
24
25
26
27 void
28 G_staff_side_item::do_pre_processing ()
29 {
30   if (!dir_)
31     dir_ = get_default_direction ();
32
33   if (axis_ == X_AXIS)
34     position_self ();
35 }
36
37 Direction
38 G_staff_side_item::get_default_direction () const
39 {
40   return DOWN;
41 }
42
43
44 void
45 G_staff_side_item::set_victim (Score_element *e)
46 {
47   add_dependency (e);
48   to_position_l_ = e;
49   to_position_l_->dim_cache_[axis_].parent_l_ = &dim_cache_[axis_];
50 }
51
52 void
53 G_staff_side_item::add_support (Score_element*e)
54 {
55   add_dependency (e);
56   support_l_arr_.push (e);
57 }
58
59
60 void
61 G_staff_side_item::do_substitute_element_pointer (Score_element*o, Score_element*n)
62 {
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);
68 }
69
70 void
71 G_staff_side_item::position_self ()
72 {
73   if (to_position_l_ &&
74       to_position_l_->get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
75     return;
76
77   Interval dim;
78   Dimension_cache *common = 0;
79   if (support_l_arr_.size ())
80     {
81       common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
82                              axis_);
83
84       for (int i=0; i < support_l_arr_.size (); i++)
85         {
86           Score_element * e = support_l_arr_ [i];
87           Real coord = e->relative_coordinate (common, axis_);
88           dim.unite (coord + e->extent (axis_));
89         }
90     }
91   else
92      common = dim_cache_[axis_].parent_l_;
93
94   if (dim.empty_b ())
95     {
96       dim = Interval(0,0);
97     }
98
99   
100   Interval sym_dim
101     = to_position_l_
102     ? to_position_l_->extent (axis_)
103     : Interval(0,0);
104
105   Real off = dim_cache_[axis_].relative_coordinate (common);
106
107   SCM pad = remove_elt_property (padding_scm_sym);
108   if (pad != SCM_BOOL_F)
109     {
110       off += gh_scm2double (SCM_CDR(pad)) * dir_;
111     }
112   Real total_off = dim[dir_] - sym_dim[-dir_] + off;
113   dim_cache_[axis_].set_offset (total_off);
114   if (fabs (total_off) > 100 CM)
115     programming_error ("Huh ? Improbable staff side dim.");
116 }
117
118 void
119 G_staff_side_item::do_post_processing ()
120 {
121   if (axis_ == Y_AXIS)
122     position_self ();
123 }
124
125
126 void
127 G_staff_side_item::do_add_processing ()
128 {
129   if (staff_support_b_
130       && axis_ == Y_AXIS && staff_symbol_l ())
131     {
132       add_support (staff_symbol_l ());
133     }
134 }
135
136 Interval
137 G_staff_side_item::do_height () const
138 {
139   Interval i;
140   if (to_position_l_)
141     return to_position_l_->extent (Y_AXIS);
142   return i;
143 }
144
145 Interval
146 G_staff_side_item::do_width () const
147 {
148   Interval i;
149   if (to_position_l_)
150     return to_position_l_->extent (X_AXIS);
151   return i;
152 }
153 void
154 G_staff_side_item::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 }