]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-element.cc
release: 1.1.67
[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 Real
38 Graphical_element::absolute_coordinate (Axis a) const
39 {
40   return dim_cache_[a]->absolute_coordinate ();
41 }
42
43 void
44 Graphical_element::translate_axis (Real y, Axis a)
45 {
46   dim_cache_[a]->translate (y);
47 }  
48
49 Real
50 Graphical_element::relative_coordinate (Dimension_cache*e, Axis a) const
51 {
52   return dim_cache_[a]->relative_coordinate (e);
53 }
54
55 Dimension_cache * 
56 Graphical_element::common_group (Graphical_element const* s, Axis a) const
57 {
58   return dim_cache_[a]->common_group (s->dim_cache_[a]);
59 }
60
61 void
62 Graphical_element::translate (Offset offset)
63 {
64   translate_axis (offset[Y_AXIS], Y_AXIS);
65   translate_axis (offset[X_AXIS], X_AXIS);
66 }
67
68
69 void
70 Graphical_element::set_empty (bool b)
71 {
72   dim_cache_[X_AXIS]->set_empty (b);
73   dim_cache_[Y_AXIS]->set_empty (b);
74 }
75
76 Interval
77 Graphical_element::extent (Axis a) const
78 {
79   Dimension_cache const * d = dim_cache_[a];
80
81   if (d->empty_b ())
82     return Interval ();
83   
84   return d->get_dim ();
85 }
86
87
88 void
89 Graphical_element::do_print () const
90 {
91 #ifndef NPRINT
92   DOUT << '\n';
93 #endif
94 }
95
96
97
98 void
99 Graphical_element::invalidate_cache (Axis a)
100 {
101   dim_cache_[a]->invalidate ();
102 }
103
104 Graphical_element*
105 Graphical_element::parent_l (Axis a) const
106 {
107   Dimension_cache*d= dim_cache_[a]->parent_l_;
108   return d ? d->elt_l_ : 0;
109 }
110
111 Graphical_element::~Graphical_element ()
112 {
113   delete dim_cache_[X_AXIS];
114   delete dim_cache_[Y_AXIS];  
115 }
116
117 Dimension_cache *
118 Graphical_element::common_group (Link_array<Graphical_element> gs, Axis a) const
119 {
120   Dimension_cache * common = dim_cache_[a];
121   for (int i=0; i < gs.size (); i++)
122     {
123       common = common->common_group (gs[i]->dim_cache_[a]);
124     }
125
126   return common;
127 }
128
129 char const *
130 Graphical_element::name () const
131 {
132   return classname (this);
133 }
134
135 void
136 Graphical_element::print () const
137 {
138 #ifndef NPRINT
139   DOUT << classname (this) << "{\n";
140   do_print ();
141   DOUT << "}\n";
142 #endif
143 }