2 graphical-element.cc -- implement Graphical_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "graphical-element.hh"
10 #include "graphical-axis-group.hh"
14 Graphical_element::empty_b () const
19 Graphical_element::Graphical_element ()
24 Graphical_element::Graphical_element (Graphical_element const &s)
27 empty_b_ = s.empty_b_;
28 axis_group_l_a_[0] = axis_group_l_a_[1] =0;
29 offset_ = Offset (0,0); // Hmmmm.... Should copy?
33 Graphical_element::init ()
36 axis_group_l_a_[X_AXIS] = axis_group_l_a_[Y_AXIS] =0;
37 offset_ = Offset (0,0);
38 cached_valid_b_a_ [X_AXIS] = cached_valid_b_a_[Y_AXIS] = false;
42 Graphical_element::invalidate_cache (Axis a)
44 Graphical_element * g = this;
45 while (g && g->cached_valid_b_a_[a])
47 g->cached_valid_b_a_ [a] = false;
48 g = g->axis_group_l_a_[a];
53 Graphical_element::absolute_coordinate (Axis a) const
56 for (Graphical_axis_group * axis_group_l = axis_group_l_a_[a];
57 axis_group_l; axis_group_l = axis_group_l->axis_group_l_a_[a])
59 r += axis_group_l->offset_[a];
65 Graphical_element::absolute_offset() const
67 return Offset (absolute_coordinate (X_AXIS), absolute_coordinate (Y_AXIS));
71 Graphical_element::translate_axis (Real y, Axis a)
73 if (axis_group_l_a_[a])
74 axis_group_l_a_[a]->invalidate_cache (a);
79 Graphical_element::relative_coordinate (Graphical_axis_group*e, Axis a) const
82 for (Graphical_axis_group * axis_group_l = axis_group_l_a_[a];
84 axis_group_l = axis_group_l->axis_group_l_a_[a])
85 r += axis_group_l->offset_[a];
91 Graphical_element::common_group (Graphical_element const* s, Axis a) const
93 Link_array<Graphical_axis_group> my_groups;
94 for (Graphical_axis_group * axis_group_l = axis_group_l_a_[a];
96 axis_group_l = axis_group_l->axis_group_l_a_[a])
97 my_groups.push (axis_group_l);
99 Graphical_axis_group* common_l=0;
100 for (Graphical_axis_group * axis_group_l = s->axis_group_l_a_[a];
101 !common_l && axis_group_l;
102 axis_group_l = axis_group_l->axis_group_l_a_[a])
103 common_l = my_groups.find_l (axis_group_l);
111 Graphical_element::translate (Offset offset)
113 translate_axis (offset[Y_AXIS], Y_AXIS);
114 translate_axis (offset[X_AXIS], X_AXIS);
118 Graphical_element::width() const
120 return extent (X_AXIS);
124 Graphical_element::set_empty (bool b)
131 invalidate_cache (X_AXIS);
132 invalidate_cache (Y_AXIS);
139 Graphical_element::extent (Axis a) const
144 if (!cached_valid_b_a_[a])
146 Graphical_element *self = (Graphical_element*)this;
147 self->cached_dimension_a_[a] = (a == X_AXIS)? do_width(): do_height ();
148 self->cached_valid_b_a_[a] = true;
151 Interval r(cached_dimension_a_[a]);
152 if (!r.empty_b()) // float exception on DEC Alpha
159 Graphical_element::height() const
161 return extent (Y_AXIS);
165 Graphical_element::unlink ()
167 for (int j=0; j < 2; j++)
168 if (axis_group_l_a_[j])
169 axis_group_l_a_[j]->remove_element (this);
173 Graphical_element::junk_links ()
175 axis_group_l_a_[X_AXIS] = axis_group_l_a_[Y_AXIS] =0;
179 Graphical_element::do_print () const
182 if (offset_.x() || offset_.y ())
183 DOUT << "offset: " << offset_.str() ;