]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
bec8df6367415dfd1baf480b1ab54c4155a029e2
[lilypond.git] / lily / staff-side.cc
1 /*
2   staff-side.cc -- implement Staff_side
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "interval.hh"
10 #include "paper-def.hh"
11 #include "staff-side.hh"
12 #include "staff-sym.hh"
13 #include "debug.hh"
14 #include "dimensions.hh"
15
16
17 Staff_side::Staff_side()
18 {
19   coordinate_offset_f_=0;
20   sym_int_ = Interval (0,0);
21   padding_f_ = 0.0;
22   dir_ = CENTER;
23   axis_ = Y_AXIS;
24 }
25
26
27 Interval
28 Staff_side::support_extent() const
29 {
30   Interval y_int;
31   for (int i=0; i < support_l_arr_.size(); i++) 
32     {
33     Graphical_axis_group *common = 
34         common_group (support_l_arr_[i], axis_);
35         
36       Real y = support_l_arr_[i]->relative_coordinate (common, axis_)  
37         -relative_coordinate (common,axis_);
38
39       y_int.unite (y + support_l_arr_[i]->extent(axis_));
40     }
41
42   if (y_int.empty_b())
43     {
44       y_int = Interval (0,0);
45     }
46   return Interval(y_int[LEFT] - padding_f_, y_int[RIGHT] + padding_f_);
47 }
48
49 void
50 Staff_side::add_support (Score_element*i)
51 {
52   support_l_arr_.push (i);
53   add_dependency (i);
54 }
55
56 Real
57 Staff_side::get_position_f () const
58 {
59   if (!dir_)
60     {
61       warning (_ ("Staff_side::get_position_f(): "
62                  "somebody forgot to set my direction, returning -20"));
63       return -20;
64     }
65
66
67   Real y = 0;
68   Real inter_f = paper()-> internote_f ();
69
70   Interval v = support_extent();
71
72   // ugh, dim[y] = PT over here
73   y = v[dir_] + 1 * dir_ * inter_f;
74
75   int coordinate_offset_f_i = (int)rint (y / inter_f);
76   // ugh: 5 -> staff_lines
77   if (axis_ == Y_AXIS && abs (coordinate_offset_f_i) < 5)
78     {
79       if (!(abs (coordinate_offset_f_i) % 2))
80         y += (Real)dir_ * inter_f;
81     }
82 //  else
83 //    y = v[dir_] + 1 * dir_ * inter_f;
84
85   return y;
86 }
87
88 Interval
89 Staff_side::symbol_height() const
90 {
91   return Interval (0,0);
92 }
93
94 Interval
95 Staff_side::symbol_width () const
96 {
97   return Interval (0,0);
98 }
99
100 void
101 Staff_side::do_pre_processing ()
102 {
103   if (axis_== X_AXIS)
104     do_side_processing ();
105 }
106
107 void
108 Staff_side::do_side_processing ()
109 {
110   sym_int_ = symbol_extent();
111   coordinate_offset_f_ = get_position_f();
112   if (dir_)
113     coordinate_offset_f_ += - sym_int_[-dir_];
114
115 }
116
117 /*
118   ugh should use do_width (), do_height (), get_extent ()
119  */
120 Interval
121 Staff_side::symbol_extent () const
122 {
123   if (axis_ == Y_AXIS)
124     return symbol_height ();
125   else
126     return symbol_width ();
127 }
128
129
130 void
131 Staff_side::do_post_processing()
132 {
133   if (axis_ == Y_AXIS)
134     do_side_processing ();
135 }
136
137 void
138 Staff_side::do_substitute_dependency (Score_element*o, Score_element*n)
139 {
140   support_l_arr_.unordered_substitute (o,n);
141 }
142
143
144 IMPLEMENT_IS_TYPE_B1(Staff_side, Score_element);