2 graphical-element.cc -- implement Graphical_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "graphical-element.hh"
10 #include "axis-group-element.hh"
13 Graphical_element::Graphical_element ()
18 Graphical_element::Graphical_element (Graphical_element const &s)
21 empty_b_ = s.empty_b_;
22 axis_group_l_a_[0] = axis_group_l_a_[1] =0;
23 offset_ = Offset (0,0);
26 Graphical_element::~Graphical_element ()
32 Graphical_element::init ()
35 axis_group_l_a_[X_AXIS] = axis_group_l_a_[Y_AXIS] =0;
36 offset_ = Offset (0,0);
37 cached_valid_b_a_ [X_AXIS] = cached_valid_b_a_[Y_AXIS] = false;
41 Graphical_element::invalidate_cache (Axis a)
43 Graphical_element * g = this;
44 while (g && g->cached_valid_b_a_[a])
46 g->cached_valid_b_a_ [a] = false;
47 g = g->axis_group_l_a_[a];
52 Graphical_element::absolute_coordinate (Axis a) const
55 for (Axis_group_element * axis_group_l = axis_group_l_a_[a];
56 axis_group_l; axis_group_l = axis_group_l->axis_group_l_a_[a])
58 r += axis_group_l->offset_[a];
64 Graphical_element::absolute_offset() const
66 return Offset (absolute_coordinate (X_AXIS), absolute_coordinate (Y_AXIS));
70 Graphical_element::translate_axis (Real y, Axis a)
72 if (axis_group_l_a_[a])
73 axis_group_l_a_[a]->invalidate_cache (a);
78 Graphical_element::relative_coordinate (Axis_group_element*e, Axis a) const
81 for (Axis_group_element * axis_group_l = axis_group_l_a_[a];
83 axis_group_l = axis_group_l->axis_group_l_a_[a])
84 r += axis_group_l->offset_[a];
90 Graphical_element::common_group (Graphical_element const* s, Axis a) const
92 Link_array<Axis_group_element> my_groups;
93 for (Axis_group_element * axis_group_l = axis_group_l_a_[a];
95 axis_group_l = axis_group_l->axis_group_l_a_[a])
96 my_groups.push (axis_group_l);
98 Axis_group_element* common_l=0;
99 for (Axis_group_element * axis_group_l = s->axis_group_l_a_[a];
100 !common_l && axis_group_l;
101 axis_group_l = axis_group_l->axis_group_l_a_[a])
102 common_l = my_groups.find_l (axis_group_l);
110 Graphical_element::translate (Offset offset)
112 translate_axis (offset[Y_AXIS], Y_AXIS);
113 translate_axis (offset[X_AXIS], X_AXIS);
117 Graphical_element::width() const
119 return extent (X_AXIS);
123 Graphical_element::set_empty (bool b)
130 invalidate_cache (X_AXIS);
131 invalidate_cache (Y_AXIS);
138 Graphical_element::extent (Axis a) const
143 if (!cached_valid_b_a_[a])
145 Graphical_element *self = (Graphical_element*)this;
146 self->cached_dimension_a_[a] = (a == X_AXIS)? do_width(): do_height ();
147 self->cached_valid_b_a_[a] = true;
150 Interval r(cached_dimension_a_[a]);
151 if (!r.empty_b()) // float exception on DEC Alpha
158 Graphical_element::height() const
160 return extent (Y_AXIS);
164 Graphical_element::unlink ()
166 for (int j=0; j < 2; j++)
167 if (axis_group_l_a_[j])
168 axis_group_l_a_[j]->remove_element (this);
172 Graphical_element::junk_links ()
174 axis_group_l_a_[X_AXIS] = axis_group_l_a_[Y_AXIS] =0;
178 Graphical_element::print () const
181 if (offset_.x() || offset_.y ())
182 DOUT << "offset: " << offset_.str() ;
187 IMPLEMENT_IS_TYPE_B(Graphical_element);