]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-element.cc
release: 1.2.4
[lilypond.git] / lily / graphical-element.cc
1 /*
2   graphical-element.cc -- implement Graphical_element
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "dimension-cache.hh"
10 #include "graphical-element.hh"
11 #include "graphical-axis-group.hh"
12 #include "debug.hh"
13
14 Graphical_element::Graphical_element ()
15 {
16   dim_cache_[X_AXIS] = new Dimension_cache;
17   dim_cache_[Y_AXIS] = new Dimension_cache;
18   used_b_ = false;
19   init ();
20 }
21
22 Graphical_element::Graphical_element (Graphical_element const &s)
23 {
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]);
26
27   used_b_ = true;
28   init ();
29
30
31 void
32 Graphical_element::init ()
33 {
34   dim_cache_[X_AXIS]->elt_l_ = dim_cache_[Y_AXIS]->elt_l_ = this;  
35 }
36
37
38 void
39 Graphical_element::translate_axis (Real y, Axis a)
40 {
41   dim_cache_[a]->translate (y);
42 }  
43
44 Real
45 Graphical_element::relative_coordinate (Graphical_element const*e, Axis a) const
46 {
47   return dim_cache_[a]->relative_coordinate (e ? e->dim_cache_[a] : 0);
48 }
49
50 Graphical_element * 
51 Graphical_element::common_refpoint (Graphical_element const* s, Axis a) const
52 {
53   return  (dim_cache_[a]->common_refpoint (s->dim_cache_[a])) ->element_l ();
54 }
55
56 void
57 Graphical_element::translate (Offset offset)
58 {
59   translate_axis (offset[Y_AXIS], Y_AXIS);
60   translate_axis (offset[X_AXIS], X_AXIS);
61 }
62
63
64 void
65 Graphical_element::set_empty (bool b, Axis a1, Axis a2)
66 {
67   if (a1 != NO_AXES)
68     dim_cache_[a1]->set_empty (b);
69   if (a2 != NO_AXES)
70     dim_cache_[a2]->set_empty (b);
71 }
72
73 /**
74    Return true if empty in either direction.
75  */
76 bool
77 Graphical_element::empty_b (Axis a1, Axis a2)
78 {
79   bool b = false;
80   if (a1 != NO_AXES)
81     b = b || dim_cache_[a1]->empty_b ();
82   if (a2 != NO_AXES)
83     b = b || dim_cache_[a2]->empty_b ();
84   return b;
85 }
86
87 Interval
88 Graphical_element::extent (Axis a) const
89 {
90   Dimension_cache const * d = dim_cache_[a];
91
92   if (d->empty_b ())
93     return Interval ();
94   
95   return d->get_dim ();
96 }
97
98
99 void
100 Graphical_element::do_print () const
101 {
102 #ifndef NPRINT
103   DOUT << '\n';
104 #endif
105 }
106
107
108
109 void
110 Graphical_element::invalidate_cache (Axis a)
111 {
112   dim_cache_[a]->invalidate ();
113 }
114
115 Graphical_element*
116 Graphical_element::parent_l (Axis a) const
117 {
118   Dimension_cache*d= dim_cache_[a]->parent_l_;
119   return d ? d->elt_l_ : 0;
120 }
121
122 Graphical_element::~Graphical_element ()
123 {
124   delete dim_cache_[X_AXIS];
125   delete dim_cache_[Y_AXIS];  
126 }
127
128 Graphical_element *
129 Graphical_element::common_refpoint (Link_array<Graphical_element> gs, Axis a) const
130 {
131   Dimension_cache * common = dim_cache_[a];
132   for (int i=0; i < gs.size (); i++)
133     {
134       common = common->common_refpoint (gs[i]->dim_cache_[a]);
135     }
136
137   return common->element_l ();
138 }
139
140 char const *
141 Graphical_element::name () const
142 {
143   return classname (this);
144 }
145
146 void
147 Graphical_element::print () const
148 {
149 #ifndef NPRINT
150   DOUT << classname (this) << "{\n";
151   do_print ();
152   DOUT << "}\n";
153 #endif
154 }  
155
156 void
157 Graphical_element::set_parent (Graphical_element *g, Axis a)
158 {
159   dim_cache_[a]->parent_l_ = g ? g->dim_cache_[a]: 0;
160 }