lilypond-1.3.122
[lilypond.git] / lily / graphical-element.cc
blob21a256bc3f1c2f22b9cabb27684249b6dd2f648f
1 /*
2 graphical-element.cc -- implement Graphical_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "dimension-cache.hh"
10 #include "graphical-element.hh"
11 #include "graphical-axis-group.hh"
12 #include "debug.hh"
14 Graphical_element::Graphical_element ()
16 dim_cache_[X_AXIS] = new Dimension_cache;
17 dim_cache_[Y_AXIS] = new Dimension_cache;
18 used_b_ = false;
19 init ();
22 Graphical_element::Graphical_element (Graphical_element const &s)
24 dim_cache_[X_AXIS] = new Dimension_cache (*s.dim_cache_[X_AXIS]);
25 dim_cache_[Y_AXIS] = new Dimension_cache (*s.dim_cache_[Y_AXIS]);
27 used_b_ = true;
28 init ();
31 void
32 Graphical_element::init ()
34 dim_cache_[X_AXIS]->elt_l_ = dim_cache_[Y_AXIS]->elt_l_ = this;
38 void
39 Graphical_element::translate_axis (Real y, Axis a)
41 dim_cache_[a]->translate (y);
44 Real
45 Graphical_element::relative_coordinate (Graphical_element const*e, Axis a) const
47 return dim_cache_[a]->relative_coordinate (e ? e->dim_cache_[a] : 0);
50 Graphical_element *
51 Graphical_element::common_refpoint (Graphical_element const* s, Axis a) const
53 Dimension_cache *dim = dim_cache_[a]->common_refpoint (s->dim_cache_[a]);
54 if (!dim)
55 programming_error ("No common reference point");
56 return dim ? dim->element_l () : 0;
59 void
60 Graphical_element::translate (Offset offset)
62 translate_axis (offset[Y_AXIS], Y_AXIS);
63 translate_axis (offset[X_AXIS], X_AXIS);
67 void
68 Graphical_element::set_empty (bool b, Axis a1, Axis a2)
70 if (a1 != NO_AXES)
71 dim_cache_[a1]->set_empty (b);
72 if (a2 != NO_AXES)
73 dim_cache_[a2]->set_empty (b);
76 /**
77 Return true if empty in both A1 direction and A2 dir.
79 bool
80 Graphical_element::empty_b (Axis a)
82 return dim_cache_[a]->empty_b ();
85 Interval
86 Graphical_element::extent (Axis a) const
88 Dimension_cache const * d = dim_cache_[a];
90 if (d->empty_b ())
91 return Interval ();
93 return d->get_dim ();
97 void
98 Graphical_element::do_print () const
100 #ifndef NPRINT
101 DEBUG_OUT << '\n';
102 #endif
105 void
106 Graphical_element::invalidate_cache (Axis a)
108 dim_cache_[a]->invalidate ();
111 Graphical_element*
112 Graphical_element::parent_l (Axis a) const
114 Dimension_cache*d= dim_cache_[a]->parent_l_;
115 return d ? d->elt_l_ : 0;
118 Graphical_element::~Graphical_element ()
120 delete dim_cache_[X_AXIS];
121 delete dim_cache_[Y_AXIS];
124 Graphical_element *
125 Graphical_element::common_refpoint (Link_array<Graphical_element> gs, Axis a) const
127 Dimension_cache * common = dim_cache_[a];
128 for (int i=0; i < gs.size (); i++)
130 common = common->common_refpoint (gs[i]->dim_cache_[a]);
133 return common->element_l ();
136 char const *
137 Graphical_element::name () const
139 return classname (this);
142 void
143 Graphical_element::print () const
145 #ifndef NPRINT
146 DEBUG_OUT << classname (this) << "{\n";
147 do_print ();
148 DEBUG_OUT << "}\n";
149 #endif
152 void
153 Graphical_element::set_parent (Graphical_element *g, Axis a)
155 dim_cache_[a]->parent_l_ = g ? g->dim_cache_[a]: 0;