2 graphical-element.cc -- implement Graphical_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "graphical-element.hh"
10 #include "axis-group-element.hh"
14 Graphical_element::empty_b () const
19 Graphical_element::Graphical_element ()
24 Graphical_element::Graphical_element (Graphical_element
const &s
)
27 empty_b_
= s
.empty_b_
;
28 axis_group_l_a_
[0] = axis_group_l_a_
[1] =0;
29 offset_
= Offset (0,0);
32 Graphical_element::~Graphical_element ()
38 Graphical_element::init ()
41 axis_group_l_a_
[X_AXIS
] = axis_group_l_a_
[Y_AXIS
] =0;
42 offset_
= Offset (0,0);
43 cached_valid_b_a_
[X_AXIS
] = cached_valid_b_a_
[Y_AXIS
] = false;
47 Graphical_element::invalidate_cache (Axis a
)
49 Graphical_element
* g
= this;
50 while (g
&& g
->cached_valid_b_a_
[a
])
52 g
->cached_valid_b_a_
[a
] = false;
53 g
= g
->axis_group_l_a_
[a
];
58 Graphical_element::absolute_coordinate (Axis a
) const
61 for (Axis_group_element
* axis_group_l
= axis_group_l_a_
[a
];
62 axis_group_l
; axis_group_l
= axis_group_l
->axis_group_l_a_
[a
])
64 r
+= axis_group_l
->offset_
[a
];
70 Graphical_element::absolute_offset() const
72 return Offset (absolute_coordinate (X_AXIS
), absolute_coordinate (Y_AXIS
));
76 Graphical_element::translate_axis (Real y
, Axis a
)
78 if (axis_group_l_a_
[a
])
79 axis_group_l_a_
[a
]->invalidate_cache (a
);
84 Graphical_element::relative_coordinate (Axis_group_element
*e
, Axis a
) const
87 for (Axis_group_element
* axis_group_l
= axis_group_l_a_
[a
];
89 axis_group_l
= axis_group_l
->axis_group_l_a_
[a
])
90 r
+= axis_group_l
->offset_
[a
];
96 Graphical_element::common_group (Graphical_element
const* s
, Axis a
) const
98 Link_array
<Axis_group_element
> my_groups
;
99 for (Axis_group_element
* axis_group_l
= axis_group_l_a_
[a
];
101 axis_group_l
= axis_group_l
->axis_group_l_a_
[a
])
102 my_groups
.push (axis_group_l
);
104 Axis_group_element
* common_l
=0;
105 for (Axis_group_element
* axis_group_l
= s
->axis_group_l_a_
[a
];
106 !common_l
&& axis_group_l
;
107 axis_group_l
= axis_group_l
->axis_group_l_a_
[a
])
108 common_l
= my_groups
.find_l (axis_group_l
);
116 Graphical_element::translate (Offset offset
)
118 translate_axis (offset
[Y_AXIS
], Y_AXIS
);
119 translate_axis (offset
[X_AXIS
], X_AXIS
);
123 Graphical_element::width() const
125 return extent (X_AXIS
);
129 Graphical_element::set_empty (bool b
)
136 invalidate_cache (X_AXIS
);
137 invalidate_cache (Y_AXIS
);
144 Graphical_element::extent (Axis a
) const
149 if (!cached_valid_b_a_
[a
])
151 Graphical_element
*self
= (Graphical_element
*)this;
152 self
->cached_dimension_a_
[a
] = (a
== X_AXIS
)? do_width(): do_height ();
153 self
->cached_valid_b_a_
[a
] = true;
156 Interval
r(cached_dimension_a_
[a
]);
157 if (!r
.empty_b()) // float exception on DEC Alpha
164 Graphical_element::height() const
166 return extent (Y_AXIS
);
170 Graphical_element::unlink ()
172 for (int j
=0; j
< 2; j
++)
173 if (axis_group_l_a_
[j
])
174 axis_group_l_a_
[j
]->remove_element (this);
178 Graphical_element::junk_links ()
180 axis_group_l_a_
[X_AXIS
] = axis_group_l_a_
[Y_AXIS
] =0;
184 Graphical_element::print () const
187 if (offset_
.x() || offset_
.y ())
188 DOUT
<< "offset: " << offset_
.str() ;
193 IMPLEMENT_IS_TYPE_B(Graphical_element
);