]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-element.cc
release: 1.1.18
[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--1998 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 bool
14 Graphical_element::empty_b () const
15 {
16   return dim_cache_[X_AXIS].empty_b () && dim_cache_[Y_AXIS].empty_b ();
17 }
18
19 Graphical_element::Graphical_element ()
20 {
21   init ();
22 }
23
24 Graphical_element::Graphical_element (Graphical_element const &s)
25   : dim_cache_ (s.dim_cache_)
26 {
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
43 Offset
44 Graphical_element::absolute_offset() const
45 {
46   return Offset (absolute_coordinate (X_AXIS), absolute_coordinate (Y_AXIS));
47 }
48
49
50
51 void
52 Graphical_element::translate_axis (Real y, Axis a)
53 {
54   dim_cache_[a].translate (y);
55 }  
56
57 Real
58 Graphical_element::relative_coordinate (Dimension_cache*e, Axis a) const
59 {
60   return dim_cache_[a].relative_coordinate (e);
61 }
62
63 Dimension_cache * 
64 Graphical_element::common_group (Graphical_element const* s, Axis a) const
65 {
66   return dim_cache_[a].common_group (&s->dim_cache_[a]);
67 }
68
69 void
70 Graphical_element::translate (Offset offset)
71 {
72   translate_axis (offset[Y_AXIS], Y_AXIS);
73   translate_axis (offset[X_AXIS], X_AXIS);
74 }
75
76
77 void
78 Graphical_element::set_empty (bool b)
79 {
80   dim_cache_[X_AXIS].set_empty (b);
81   dim_cache_[Y_AXIS].set_empty (b);
82 }
83
84 Interval
85 Graphical_element::extent (Axis a) const
86 {
87   Dimension_cache const * d = //(Dimension_cache*)
88     &dim_cache_[a];
89
90   if (d->empty_b ())
91     return Interval ();
92   
93   if (!d->valid_b ())
94     ((Dimension_cache*)d)->set_dim  ((a == X_AXIS)? do_width(): do_height ());
95   
96
97   return d->get_dim ();
98 }
99
100 void
101 Graphical_element::unlink ()
102 {
103   for (int a=X_AXIS; a < NO_AXES; a++)
104     if (Dimension_cache * d = dim_cache_[a].parent_l_)
105       {
106         if (Graphical_axis_group * eg
107             = dynamic_cast<Graphical_axis_group*> (d->elt_l_))
108           eg->remove_element (this);
109       }
110 }
111
112 void
113 Graphical_element::junk_links ()
114 {
115 }
116
117 void
118 Graphical_element::do_print () const
119 {
120 #ifndef NPRINT
121   DOUT << '\n';
122 #endif
123 }
124
125
126
127 void
128 Graphical_element::invalidate_cache (Axis a)
129 {
130   dim_cache_[a].invalidate ();
131 }
132
133 Graphical_element*
134 Graphical_element::parent_l (Axis a) const
135 {
136   Dimension_cache*d= dim_cache_[a].parent_l_;
137   return d ? d->elt_l_ : 0;
138 }
139
140 Graphical_element::~Graphical_element ()
141 {
142 }
143
144 Dimension_cache *
145 Graphical_element::common_group (Link_array<Graphical_element> gs, Axis a) const
146 {
147   Dimension_cache * common = &dim_cache_[a];
148   for (int i=0; i < gs.size (); i++)
149     {
150       common = common->common_group (&gs[i]->dim_cache_[a]);
151     }
152
153   return common;
154 }
155
156 char const *
157 Graphical_element::name () const
158 {
159   return classname (this);
160 }