]> git.donarmstrong.com Git - lilypond.git/blob - lily/g-staff-side.cc
release: 1.1.37
[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
13 G_staff_side_item::G_staff_side_item ()
14 {
15   dir_ = CENTER;
16   to_position_l_ = 0;
17   set_elt_property (transparent_scm_sym, SCM_BOOL_T);
18
19   axis_ = Y_AXIS;
20 }
21
22
23 void
24 G_staff_side_item::do_pre_processing ()
25 {
26   if (!dir_)
27     set_default_direction ();
28
29   if (axis_ == X_AXIS)
30     position_self ();
31 }
32
33 void
34 G_staff_side_item::set_default_direction ()
35 {
36   dir_ = DOWN;
37 }
38
39
40 void
41 G_staff_side_item::set_victim (Score_element *e)
42 {
43   add_dependency (e);
44   to_position_l_ = e;
45   to_position_l_->dim_cache_[axis_].parent_l_ = &dim_cache_[axis_];
46 }
47
48 void
49 G_staff_side_item::add_support (Score_element*e)
50 {
51   add_dependency (e);
52   support_l_arr_.push (e);
53 }
54
55
56 void
57 G_staff_side_item::do_substitute_element_pointer (Score_element*o, Score_element*n)
58 {
59   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
60   if (o == to_position_l_)
61     to_position_l_ = n;
62   else
63     support_l_arr_.unordered_substitute (o,n);
64 }
65
66 void
67 G_staff_side_item::position_self ()
68 {
69   Interval dim;
70   Dimension_cache *common = 0;
71   if (support_l_arr_.size ())
72     {
73       common = common_group (typecast_array (support_l_arr_, (Graphical_element*)0),
74                              axis_);
75
76       for (int i=0; i < support_l_arr_.size (); i++)
77         {
78           Score_element * e = support_l_arr_ [i];
79           Real coord = e->relative_coordinate (common, axis_);
80           dim.unite (coord + e->extent (axis_));
81         }
82     }
83   else
84     {
85       dim = Interval(0,0);
86       common = dim_cache_[axis_].parent_l_;
87     }
88   Interval sym_dim = to_position_l_->extent (axis_);
89   Real off = dim_cache_[axis_].relative_coordinate (common);
90
91   SCM pad =   remove_elt_property (padding_scm_sym);
92   if (pad != SCM_BOOL_F)
93     {
94       off -= gh_scm2double (SCM_CDR(pad)) * dir_;
95     }
96   dim_cache_[axis_].set_offset (dim[dir_] - sym_dim[-dir_] - off);
97 }
98
99 void
100 G_staff_side_item::do_post_processing ()
101 {
102   if (axis_ == Y_AXIS)
103     position_self ();
104 }
105
106
107 void
108 G_staff_side_item::do_add_processing ()
109 {
110   if (axis_ == Y_AXIS && staff_symbol_l ())
111     {
112       add_support (staff_symbol_l ());
113     }
114 }