mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-21 14:16:31 +01:00
simplify Canvas::Rectangle rendering to avoid unnecessary nonsense, and remove TimeRectangle
This commit is contained in:
parent
2a5921ecf1
commit
a992a2e6e0
2 changed files with 19 additions and 58 deletions
|
|
@ -88,18 +88,6 @@ public:
|
||||||
What _outline_what;
|
What _outline_what;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TimeRectangle : public Rectangle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TimeRectangle (Canvas* c) : Rectangle (c) {}
|
|
||||||
TimeRectangle (Canvas* c, Rect const & r) : Rectangle (c, r) {}
|
|
||||||
TimeRectangle (Item* i) : Rectangle (i) {}
|
|
||||||
TimeRectangle (Item* i, Rect const & r) : Rectangle (i, r) {}
|
|
||||||
|
|
||||||
void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
|
|
||||||
void compute_bounding_box () const;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -99,36 +99,43 @@ Rectangle::render_self (Rect const & area, Cairo::RefPtr<Cairo::Context> context
|
||||||
* coordinates of the rectangle. So if the rectangle
|
* coordinates of the rectangle. So if the rectangle
|
||||||
* has a left edge at 0 and a right edge at 10, then
|
* has a left edge at 0 and a right edge at 10, then
|
||||||
* the left edge must span 0..1, the right edge
|
* the left edge must span 0..1, the right edge
|
||||||
* must span 9..10 because the first and final pixels
|
* must span 10..11 because the first and final pixels
|
||||||
* to be colored are actually "at" 0.5 and 9.5 (midway
|
* to be colored are actually "at" 0.5 and 10.5 (midway
|
||||||
* between the integer coordinates.
|
* between the integer coordinates).
|
||||||
|
*
|
||||||
|
* See the Cairo FAQ on single pixel lines for more
|
||||||
|
* detail.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (fmod (_outline_width, 2.0) != 0.0) {
|
||||||
|
const double shift = _outline_width * 0.5;
|
||||||
|
self = self.translate (Duple (shift, shift));
|
||||||
|
}
|
||||||
|
|
||||||
if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
|
if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
|
||||||
|
|
||||||
self = self.shrink (0.5);
|
|
||||||
context->rectangle (self.x0, self.y0, self.width(), self.height());
|
context->rectangle (self.x0, self.y0, self.width(), self.height());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (_outline_what & LEFT) {
|
if (_outline_what & LEFT) {
|
||||||
context->move_to (self.x0+0.5, self.y0);
|
context->move_to (self.x0, self.y0);
|
||||||
context->line_to (self.x0+0.5, self.y1);
|
context->line_to (self.x0, self.y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_outline_what & TOP) {
|
if (_outline_what & TOP) {
|
||||||
context->move_to (self.x0, self.y0+0.5);
|
context->move_to (self.x0, self.y0);
|
||||||
context->line_to (self.x1, self.y0+0.5);
|
context->line_to (self.x1, self.y0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_outline_what & BOTTOM) {
|
if (_outline_what & BOTTOM) {
|
||||||
context->move_to (self.x0, self.y1-0.5);
|
context->move_to (self.x0, self.y1);
|
||||||
context->line_to (self.x1, self.y1-0.5);
|
context->line_to (self.x1, self.y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_outline_what & RIGHT) {
|
if (_outline_what & RIGHT) {
|
||||||
context->move_to (self.x1-0.5, self.y0);
|
context->move_to (self.x1, self.y0);
|
||||||
context->line_to (self.x1-0.5, self.y1);
|
context->line_to (self.x1, self.y1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,37 +266,3 @@ Rectangle::set_outline_what (What what)
|
||||||
end_visual_change ();
|
end_visual_change ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------*/
|
|
||||||
|
|
||||||
void
|
|
||||||
TimeRectangle::compute_bounding_box () const
|
|
||||||
{
|
|
||||||
Rectangle::compute_bounding_box ();
|
|
||||||
|
|
||||||
if (_bounding_box) {
|
|
||||||
Rect r = _bounding_box.get ();
|
|
||||||
|
|
||||||
/* This is a TimeRectangle, so its right edge is drawn 1 pixel beyond
|
|
||||||
* (larger x-axis coordinates) than a normal Rectangle.
|
|
||||||
*/
|
|
||||||
|
|
||||||
r.x1 += 1.0; /* this should be using safe_add() */
|
|
||||||
|
|
||||||
_bounding_box = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TimeRectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
|
||||||
{
|
|
||||||
Rect self = get_self_for_render ();
|
|
||||||
|
|
||||||
/* This is a TimeRectangle, so its right edge is drawn 1 pixel beyond
|
|
||||||
* (larger x-axis coordinates) than a normal Rectangle.
|
|
||||||
*/
|
|
||||||
|
|
||||||
self.x1 += 1.0; /* this should be using safe_add() */
|
|
||||||
render_self (area, context, self);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue