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