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