2 dimension-cache.cc -- implement Dimension_cache
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "dimension-cache.hh"
11 #include "graphical-element.hh"
13 Dimension_cache::Dimension_cache (Dimension_cache const &d)
16 callback_l_ = d.callback_l_;
17 empty_b_ = d.empty_b_;
18 basic_offset_ = d.basic_offset_;
19 extra_offset_ = d.extra_offset_;
20 off_valid_b_ = d.off_valid_b_;
21 off_callback_l_ = d.off_callback_l_;
24 Dimension_cache::Dimension_cache ()
30 Dimension_cache::init()
48 Dimension_cache::invalidate ()
56 Dimension_cache::set_offset (Real x)
69 Dimension_cache::translate (Real x)
75 Dimension_cache::relative_coordinate (Dimension_cache *refp) const
81 We catch PARENT_L_ == nil case with this, but we crash if we did
82 not ask for the absolute coordinate (ie. REFP == nil.)
85 if (refp == parent_l_)
88 return get_offset () + parent_l_->relative_coordinate (refp);
92 Dimension_cache::axis () const
94 if (elt_l_-> dim_cache_[X_AXIS] == this)
101 Dimension_cache::get_offset () const
103 if (!off_valid_b_ && off_callback_l_ )
105 Dimension_cache *d = (Dimension_cache*) this;
106 d->off_valid_b_ = true;
107 d->basic_offset_ = (*off_callback_l_) (d);
110 return basic_offset_ + extra_offset_;
114 Dimension_cache::common_refpoint (Dimension_cache const* s) const
116 Link_array<Dimension_cache> my_groups;
117 for (Dimension_cache const *c = this; c ; c = c->parent_l_)
118 my_groups.push ((Dimension_cache*)c);
120 Dimension_cache const *common=0;
122 for (Dimension_cache const * d = s; !common && d; d = d->parent_l_)
123 common = (Dimension_cache const*)my_groups.find_l (d);
125 return (Dimension_cache*) common;
131 Dimension_cache::set_empty (bool b)
142 Dimension_cache::get_dim () const
153 Dimension_cache *nc = ((Dimension_cache*)this);
154 nc->dim_= (*callback_l_ ) (nc);
164 Dimension_cache::set_callback (Dim_cache_callback c)
170 Dimension_cache::set_offset_callback (Offset_cache_callback c)