mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-16 11:46:25 +01:00
add new TimeRectangle to ArdourCanvas
This commit is contained in:
parent
90825340c9
commit
56994e785e
2 changed files with 66 additions and 7 deletions
|
|
@ -79,7 +79,11 @@ public:
|
||||||
ArdourCanvas::Rectangle::BOTTOM));
|
ArdourCanvas::Rectangle::BOTTOM));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
void render_self (Rect const &, Cairo::RefPtr<Cairo::Context>, Rect) const;
|
||||||
|
Rect get_self_for_render () const;
|
||||||
|
|
||||||
|
private:
|
||||||
/** Our rectangle; note that x0 may not always be less than x1
|
/** Our rectangle; note that x0 may not always be less than x1
|
||||||
* and likewise with y0 and y1.
|
* and likewise with y0 and y1.
|
||||||
*/
|
*/
|
||||||
|
|
@ -87,6 +91,18 @@ private:
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -56,15 +56,21 @@ Rectangle::Rectangle (Item* parent, Rect const & rect)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
Rect
|
||||||
Rectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
Rectangle::get_self_for_render () const
|
||||||
{
|
{
|
||||||
/* In general, a Rectangle will have a _position of (0,0) within its
|
/* In general, a Rectangle will have a _position of (0,0) within its
|
||||||
parent, and its extent is actually defined by _rect. But in the
|
parent, and its extent is actually defined by _rect. But in the
|
||||||
unusual case that _position is set to something other than (0,0),
|
unusual case that _position is set to something other than (0,0),
|
||||||
we should take that into account when rendering.
|
we should take that into account when rendering.
|
||||||
*/
|
*/
|
||||||
Rect self = item_to_window (_rect.translate (_position));
|
|
||||||
|
return item_to_window (_rect.translate (_position));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Rectangle::render_self (Rect const & area, Cairo::RefPtr<Cairo::Context> context, Rect self) const
|
||||||
|
{
|
||||||
boost::optional<Rect> r = self.intersection (area);
|
boost::optional<Rect> r = self.intersection (area);
|
||||||
|
|
||||||
if (!r) {
|
if (!r) {
|
||||||
|
|
@ -105,10 +111,8 @@ Rectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) con
|
||||||
* the 0.5 pixel additions.
|
* the 0.5 pixel additions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
self = self.translate (Duple (-0.5, -0.5));
|
self = self.translate (Duple (0.5, 0.5));
|
||||||
|
|
||||||
std::cerr << "Outline using " << self << " from " << _rect << std::endl;
|
|
||||||
|
|
||||||
if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
|
if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
|
||||||
|
|
||||||
context->rectangle (self.x0, self.y0, self.width(), self.height());
|
context->rectangle (self.x0, self.y0, self.width(), self.height());
|
||||||
|
|
@ -140,6 +144,12 @@ Rectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Rectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
||||||
|
{
|
||||||
|
render_self (area, context, get_self_for_render ());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Rectangle::compute_bounding_box () const
|
Rectangle::compute_bounding_box () const
|
||||||
{
|
{
|
||||||
|
|
@ -238,3 +248,36 @@ Rectangle::set_outline_what (What what)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------*/
|
||||||
|
|
||||||
|
void
|
||||||
|
TimeRectangle::compute_bounding_box () const
|
||||||
|
{
|
||||||
|
Rectangle::compute_bounding_box ();
|
||||||
|
assert (_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