remove use of boost::optional to define "undefined" Canvas::Rect, and use Rect::empty instead.

This commit includes Rect::operator bool() which might be a candidate for removal in a future commit, in an attempt
to make the meaning clearer
This commit is contained in:
Paul Davis 2017-01-19 20:54:24 +01:00
parent 758f183b99
commit 4fa4b9a135
27 changed files with 159 additions and 160 deletions

View file

@ -73,7 +73,7 @@ Box::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
void
Box::compute_bounding_box () const
{
_bounding_box = boost::none;
_bounding_box = Rect();
if (_items.empty()) {
_bounding_box_dirty = false;
@ -83,7 +83,7 @@ Box::compute_bounding_box () const
add_child_bounding_boxes (!collapse_on_hide);
if (_bounding_box) {
Rect r = _bounding_box.get();
Rect r = _bounding_box;
_bounding_box = r.expand (top_padding + outline_width() + top_margin,
right_padding + outline_width() + right_margin,
@ -152,7 +152,7 @@ Box::reset_self ()
return;
}
Rect r (_bounding_box.get());
Rect r (_bounding_box);
/* XXX need to shrink by margin */
@ -169,10 +169,10 @@ Box::reposition_children ()
if (homogenous) {
for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) {
boost::optional<Rect> bb = (*i)->bounding_box();
Rect bb = (*i)->bounding_box();
if (bb) {
largest_height = std::max (largest_height, bb.get().height());
largest_width = std::max (largest_width, bb.get().width());
largest_height = std::max (largest_height, bb.height());
largest_width = std::max (largest_width, bb.width());
}
}
}
@ -188,19 +188,19 @@ Box::reposition_children ()
if (homogenous) {
shift = largest_height;
} else {
boost::optional<Rect> bb = (*i)->bounding_box();
Rect bb = (*i)->bounding_box();
if (!(*i)->visible()) {
/* invisible child */
if (!collapse_on_hide) {
/* still add in its size */
if (bb) {
shift += bb.get().height();
shift += bb.height();
}
}
} else {
if (bb) {
shift += bb.get().height();
shift += bb.height();
}
}
}
@ -214,17 +214,17 @@ Box::reposition_children ()
if (homogenous) {
shift = largest_width;
} else {
boost::optional<Rect> bb = (*i)->bounding_box();
Rect bb = (*i)->bounding_box();
if (!(*i)->visible()) {
if (!collapse_on_hide) {
if (bb) {
shift += bb.get().width();
shift += bb.width();
}
}
} else {
if (bb) {
shift += bb.get().width();
shift += bb.width();
}
}
}

View file

@ -107,20 +107,20 @@ Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context
render_count = 0;
boost::optional<Rect> root_bbox = _root.bounding_box();
Rect root_bbox = _root.bounding_box();
if (!root_bbox) {
/* the root has no bounding box, so there's nothing to render */
return;
}
boost::optional<Rect> draw = root_bbox->intersection (area);
Rect draw = root_bbox.intersection (area);
if (draw) {
/* there's a common area between the root and the requested
area, so render it.
*/
_root.render (*draw, context);
_root.render (draw, context);
#if defined CANVAS_DEBUG && !PLATFORM_WINDOWS
if (getenv ("CANVAS_HARLEQUIN_DEBUGGING")) {
@ -128,7 +128,7 @@ Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context
double r = (random() % 65536) /65536.0;
double g = (random() % 65536) /65536.0;
double b = (random() % 65536) /65536.0;
context->rectangle (draw->x0, draw->y0, draw->x1 - draw->x0, draw->y1 - draw->y0);
context->rectangle (draw.x0, draw.y0, draw.x1 - draw.x0, draw.y1 - draw.y0);
context->set_source_rgba (r, g, b, 0.25);
context->fill ();
}
@ -181,10 +181,10 @@ Canvas::dump (ostream& o) const
void
Canvas::item_shown_or_hidden (Item* item)
{
boost::optional<Rect> bbox = item->bounding_box ();
Rect bbox = item->bounding_box ();
if (bbox) {
if (item->item_to_window (*bbox).intersection (visible_area ())) {
queue_draw_item_area (item, bbox.get ());
if (item->item_to_window (bbox.intersection (visible_area ()))) {
queue_draw_item_area (item, bbox);
}
}
}
@ -196,10 +196,10 @@ Canvas::item_shown_or_hidden (Item* item)
void
Canvas::item_visual_property_changed (Item* item)
{
boost::optional<Rect> bbox = item->bounding_box ();
Rect bbox = item->bounding_box ();
if (bbox) {
if (item->item_to_window (*bbox).intersection (visible_area ())) {
queue_draw_item_area (item, bbox.get ());
if (item->item_to_window (bbox.intersection (visible_area ()))) {
queue_draw_item_area (item, bbox);
}
}
}
@ -210,25 +210,23 @@ Canvas::item_visual_property_changed (Item* item)
* in the item's coordinates.
*/
void
Canvas::item_changed (Item* item, boost::optional<Rect> pre_change_bounding_box)
Canvas::item_changed (Item* item, Rect pre_change_bounding_box)
{
Rect window_bbox = visible_area ();
if (pre_change_bounding_box) {
if (item->item_to_window (*pre_change_bounding_box).intersection (window_bbox)) {
if (item->item_to_window (pre_change_bounding_box).intersection (window_bbox)) {
/* request a redraw of the item's old bounding box */
queue_draw_item_area (item, pre_change_bounding_box.get ());
queue_draw_item_area (item, pre_change_bounding_box);
}
}
boost::optional<Rect> post_change_bounding_box = item->bounding_box ();
if (post_change_bounding_box) {
Rect post_change_bounding_box = item->bounding_box ();
if (item->item_to_window (*post_change_bounding_box).intersection (window_bbox)) {
if (post_change_bounding_box) {
if (item->item_to_window (post_change_bounding_box).intersection (window_bbox)) {
/* request a redraw of the item's new bounding box */
queue_draw_item_area (item, post_change_bounding_box.get ());
queue_draw_item_area (item, post_change_bounding_box);
}
}
}
@ -324,7 +322,7 @@ Canvas::canvas_to_window (Duple const & d, bool rounded) const
* the move, in its parent's coordinates.
*/
void
Canvas::item_moved (Item* item, boost::optional<Rect> pre_change_parent_bounding_box)
Canvas::item_moved (Item* item, Rect pre_change_parent_bounding_box)
{
if (pre_change_parent_bounding_box) {
/* request a redraw of where the item used to be. The box has
@ -336,13 +334,13 @@ Canvas::item_moved (Item* item, boost::optional<Rect> pre_change_parent_bounding
* invalidation area. If we use the parent (which has not
* moved, then this will work.
*/
queue_draw_item_area (item->parent(), pre_change_parent_bounding_box.get ());
queue_draw_item_area (item->parent(), pre_change_parent_bounding_box);
}
boost::optional<Rect> post_change_bounding_box = item->bounding_box ();
Rect post_change_bounding_box = item->bounding_box ();
if (post_change_bounding_box) {
/* request a redraw of where the item now is */
queue_draw_item_area (item, post_change_bounding_box.get ());
queue_draw_item_area (item, post_change_bounding_box);
}
}
@ -367,10 +365,10 @@ Canvas::set_background_color (Color c)
{
_bg_color = c;
boost::optional<Rect> r = _root.bounding_box();
Rect r = _root.bounding_box();
if (r) {
request_redraw (_root.item_to_window (r.get()));
request_redraw (_root.item_to_window (r));
}
}
@ -720,10 +718,10 @@ GtkCanvas::deliver_event (GdkEvent* event)
* @param bounding_box Last known bounding box of the item.
*/
void
GtkCanvas::item_going_away (Item* item, boost::optional<Rect> bounding_box)
GtkCanvas::item_going_away (Item* item, Rect bounding_box)
{
if (bounding_box) {
queue_draw_item_area (item, bounding_box.get ());
queue_draw_item_area (item, bounding_box);
}
if (_new_current_item == item) {

View file

@ -95,11 +95,11 @@ public:
ArdourCanvas::Color background_color() const { return _bg_color; }
/** Called when an item is being destroyed */
virtual void item_going_away (Item *, boost::optional<Rect>) {}
virtual void item_going_away (Item *, Rect) {}
void item_shown_or_hidden (Item *);
void item_visual_property_changed (Item*);
void item_changed (Item *, boost::optional<Rect>);
void item_moved (Item *, boost::optional<Rect>);
void item_changed (Item *, Rect);
void item_moved (Item *, Rect);
Duple canvas_to_window (Duple const&, bool rounded = true) const;
Duple window_to_canvas (Duple const&) const;
@ -224,7 +224,7 @@ public:
void pick_current_item (Duple const &, int state);
private:
void item_going_away (Item *, boost::optional<Rect>);
void item_going_away (Item *, Rect);
bool send_leave_event (Item const *, double, double) const;
Cairo::RefPtr<Cairo::Surface> canvas_image;

View file

@ -136,7 +136,7 @@ public:
ScrollGroup* scroll_parent() const { return _scroll_parent; }
boost::optional<Rect> bounding_box () const;
Rect bounding_box () const;
Coord height() const;
Coord width() const;
@ -275,10 +275,10 @@ protected:
/** true if this item is visible (ie to be drawn), otherwise false */
bool _visible;
/** our bounding box before any change that is currently in progress */
boost::optional<Rect> _pre_change_bounding_box;
Rect _pre_change_bounding_box;
/** our bounding box; may be out of date if _bounding_box_dirty is true */
mutable boost::optional<Rect> _bounding_box;
mutable Rect _bounding_box;
/** true if _bounding_box might be out of date, false if its definitely not */
mutable bool _bounding_box_dirty;

View file

@ -117,15 +117,15 @@ struct LIBCANVAS_API Rect
Coord x1;
Coord y1;
boost::optional<Rect> intersection (Rect const & o) const throw () {
Rect intersection (Rect const & o) const throw () {
Rect i (std::max (x0, o.x0), std::max (y0, o.y0),
std::min (x1, o.x1), std::min (y1, o.y1));
if (i.x0 > i.x1 || i.y0 > i.y1) {
return boost::optional<Rect> ();
return Rect();
}
return boost::optional<Rect> (i);
return i;
}
Rect extend (Rect const & o) const throw () {
@ -165,6 +165,7 @@ struct LIBCANVAS_API Rect
}
bool empty() const throw () { return (x0 == x1 && y0 == y1); }
operator bool() const throw () { return !empty(); }
Distance width () const throw () {
return x1 - x0;

View file

@ -46,7 +46,7 @@ Container::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) con
void
Container::compute_bounding_box () const
{
_bounding_box = boost::none;
_bounding_box = Rect ();
add_child_bounding_boxes ();
_bounding_box_dirty = false;
}

View file

@ -90,10 +90,10 @@ Curve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
return;
}
Rect self = item_to_window (_bounding_box.get());
boost::optional<Rect> d = self.intersection (area);
Rect self = item_to_window (_bounding_box);
Rect d = self.intersection (area);
assert (d);
Rect draw = d.get ();
Rect draw = d;
/* Our approach is to always draw n_segments across our total size.
*

View file

@ -80,10 +80,10 @@ Flag::set_text (string const & text)
_text->set (text);
}
boost::optional<Rect> bbox = _text->bounding_box ();
Rect bbox = _text->bounding_box ();
assert (bbox);
Duple flag_size (bbox.get().width() + 10, bbox.get().height() + 4);
Duple flag_size (bbox.width() + 10, bbox.height() + 4);
if (_invert) {
const Distance h = fabs(_line->y1() - _line->y0());
@ -101,9 +101,9 @@ Flag::set_height (Distance h)
_line->set (Duple (0, 0), Duple (0, h));
if (_invert) {
boost::optional<Rect> bbox = _text->bounding_box ();
Rect bbox = _text->bounding_box ();
if (bbox) {
Duple flag_size (bbox.get().width() + 10, bbox.get().height() + 4);
Duple flag_size (bbox.width() + 10, bbox.height() + 4);
_rectangle->set (Rect (0, h - flag_size.y, flag_size.x, h));
_text->set_position (Duple (5, h - flag_size.y + 2));
}
@ -123,8 +123,8 @@ Flag::covers (Duple const & point) const
double
Flag::width () const
{
boost::optional<Rect> bbox = _text->bounding_box ();
Rect bbox = _text->bounding_box ();
assert (bbox);
return bbox.get().width() + 10;
return bbox.width() + 10;
}

View file

@ -102,10 +102,10 @@ FramedCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) c
return;
}
Rect self = item_to_window (_bounding_box.get());
boost::optional<Rect> d = self.intersection (area);
Rect self = item_to_window (_bounding_box);
Rect d = self.intersection (area);
assert (d);
Rect draw = d.get ();
Rect draw = d;
/* Our approach is to always draw n_segments across our total size.
*

View file

@ -73,7 +73,7 @@ Grid::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
void
Grid::compute_bounding_box () const
{
_bounding_box = boost::none;
_bounding_box = Rect();
if (_items.empty()) {
_bounding_box_dirty = false;
@ -83,7 +83,7 @@ Grid::compute_bounding_box () const
add_child_bounding_boxes (!collapse_on_hide);
if (_bounding_box) {
Rect r = _bounding_box.get();
Rect r = _bounding_box;
_bounding_box = r.expand (outline_width() + top_margin,
outline_width() + right_margin,
@ -152,7 +152,7 @@ Grid::reset_self ()
return;
}
Rect r (_bounding_box.get());
Rect r (_bounding_box);
/* XXX need to shrink by margin */
@ -195,7 +195,7 @@ Grid::reposition_children ()
continue;
}
boost::optional<Rect> bb = (*i)->bounding_box();
Rect bb = (*i)->bounding_box();
if (!bb) {
continue;
@ -203,8 +203,8 @@ Grid::reposition_children ()
CoordsByItem::const_iterator c = coords_by_item.find (*i);
row_dimens[c->second.y] = max (row_dimens[c->second.y], bb.get().height());
col_dimens[c->second.x] = max (col_dimens[c->second.x] , bb.get().width());
row_dimens[c->second.y] = max (row_dimens[c->second.y], bb.height());
col_dimens[c->second.x] = max (col_dimens[c->second.x] , bb.width());
}
/* now sum the row and column widths, so that row_dimens is transformed

View file

@ -55,11 +55,11 @@ Image::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
}
Rect self = item_to_window (Rect (0, 0, _width, _height));
boost::optional<Rect> draw = self.intersection (area);
Rect draw = self.intersection (area);
if (_surface && draw) {
context->set_source (_surface, self.x0, self.y0);
context->rectangle (draw->x0, draw->y0, draw->width(), draw->height());
context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
context->fill ();
}
}
@ -67,7 +67,7 @@ Image::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
void
Image::compute_bounding_box () const
{
_bounding_box = boost::optional<Rect> (Rect (0, 0, _width, _height));
_bounding_box = Rect (0, 0, _width, _height);
_bounding_box_dirty = false;
}

View file

@ -259,14 +259,14 @@ Item::set_position (Duple p)
return;
}
boost::optional<ArdourCanvas::Rect> bbox = bounding_box ();
boost::optional<ArdourCanvas::Rect> pre_change_parent_bounding_box;
ArdourCanvas::Rect bbox = bounding_box ();
ArdourCanvas::Rect pre_change_parent_bounding_box;
if (bbox) {
/* see the comment in Canvas::item_moved() to understand
* why we use the parent's bounding box here.
*/
pre_change_parent_bounding_box = item_to_parent (bbox.get());
pre_change_parent_bounding_box = item_to_parent (bbox);
}
_position = p;
@ -572,7 +572,7 @@ Item::grab_focus ()
}
/** @return Bounding box in this item's coordinates */
boost::optional<ArdourCanvas::Rect>
ArdourCanvas::Rect
Item::bounding_box () const
{
if (_bounding_box_dirty) {
@ -587,10 +587,10 @@ Item::bounding_box () const
Coord
Item::height () const
{
boost::optional<ArdourCanvas::Rect> bb = bounding_box();
ArdourCanvas::Rect bb = bounding_box();
if (bb) {
return bb->height ();
return bb.height ();
}
return 0;
}
@ -598,10 +598,10 @@ Item::height () const
Coord
Item::width () const
{
boost::optional<ArdourCanvas::Rect> bb = bounding_box();
ArdourCanvas::Rect bb = bounding_box();
if (bb) {
return bb->width ();
return bb.width ();
}
return 0;
@ -611,7 +611,7 @@ void
Item::redraw () const
{
if (visible() && _bounding_box && _canvas) {
_canvas->request_redraw (item_to_window (_bounding_box.get()));
_canvas->request_redraw (item_to_window (_bounding_box));
}
}
@ -717,13 +717,13 @@ Item::covers (Duple const & point) const
compute_bounding_box ();
}
boost::optional<Rect> r = bounding_box();
Rect r = bounding_box();
if (!r) {
return false;
}
return r.get().contains (p);
return r.contains (p);
}
/* nesting/grouping API */
@ -759,7 +759,7 @@ Item::render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context)
continue;
}
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
Rect item_bbox = (*i)->bounding_box ();
if (!item_bbox) {
#ifdef CANVAS_DEBUG
@ -770,11 +770,11 @@ Item::render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context)
continue;
}
Rect item = (*i)->item_to_window (item_bbox.get(), false);
boost::optional<Rect> d = item.intersection (area);
Rect item = (*i)->item_to_window (item_bbox, false);
Rect d = item.intersection (area);
if (d) {
Rect draw = d.get();
Rect draw = d;
if (draw.width() && draw.height()) {
#ifdef CANVAS_DEBUG
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
@ -787,7 +787,7 @@ Item::render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context)
<< ' '
<< (*i)->name
<< " item "
<< item_bbox.get()
<< item_bbox
<< " window = "
<< item
<< " intersect = "
@ -821,12 +821,12 @@ Item::render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context)
void
Item::add_child_bounding_boxes (bool include_hidden) const
{
boost::optional<Rect> self;
Rect self;
Rect bbox;
bool have_one = false;
if (_bounding_box) {
bbox = _bounding_box.get();
bbox = _bounding_box;
have_one = true;
}
@ -836,13 +836,13 @@ Item::add_child_bounding_boxes (bool include_hidden) const
continue;
}
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
Rect item_bbox = (*i)->bounding_box ();
if (!item_bbox) {
continue;
}
Rect group_bbox = (*i)->item_to_parent (item_bbox.get ());
Rect group_bbox = (*i)->item_to_parent (item_bbox);
if (have_one) {
bbox = bbox.extend (group_bbox);
} else {
@ -852,7 +852,7 @@ Item::add_child_bounding_boxes (bool include_hidden) const
}
if (!have_one) {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
} else {
_bounding_box = bbox;
}
@ -1025,11 +1025,11 @@ Item::child_changed ()
void
Item::add_items_at_point (Duple const point, vector<Item const *>& items) const
{
boost::optional<Rect> const bbox = bounding_box ();
Rect const bbox = bounding_box ();
/* Point is in window coordinate system */
if (!bbox || !item_to_window (bbox.get()).contains (point)) {
if (!bbox || !item_to_window (bbox).contains (point)) {
return;
}
@ -1078,7 +1078,7 @@ Item::stop_tooltip_timeout ()
void
Item::dump (ostream& o) const
{
boost::optional<ArdourCanvas::Rect> bb = bounding_box();
ArdourCanvas::Rect bb = bounding_box();
o << _canvas->indent() << whatami() << ' ' << this << " self-Visible ? " << self_visible() << " visible ? " << visible();
o << " @ " << position();
@ -1090,8 +1090,8 @@ Item::dump (ostream& o) const
#endif
if (bb) {
o << endl << _canvas->indent() << "\tbbox: " << bb.get();
o << endl << _canvas->indent() << "\tCANVAS bbox: " << item_to_canvas (bb.get());
o << endl << _canvas->indent() << "\tbbox: " << bb;
o << endl << _canvas->indent() << "\tCANVAS bbox: " << item_to_canvas (bb);
} else {
o << " bbox unset";
}
@ -1107,11 +1107,11 @@ Item::dump (ostream& o) const
o << " Self-Visible ? " << self_visible();
o << " Visible ? " << visible();
boost::optional<Rect> bb = bounding_box();
Rect bb = bounding_box();
if (bb) {
o << endl << _canvas->indent() << " bbox: " << bb.get();
o << endl << _canvas->indent() << " CANVAS bbox: " << item_to_canvas (bb.get());
o << endl << _canvas->indent() << " bbox: " << bb;
o << endl << _canvas->indent() << " CANVAS bbox: " << item_to_canvas (bb);
} else {
o << " bbox unset";
}

View file

@ -50,7 +50,7 @@ void
LineSet::compute_bounding_box () const
{
if (_lines.empty ()) {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
} else {
if (_orientation == Horizontal) {
@ -100,13 +100,13 @@ LineSet::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
self = item_to_window (Rect (i->pos - (i->width/2.0), 0, i->pos + (i->width/2.0), _extent));
}
boost::optional<Rect> isect = self.intersection (area);
Rect isect = self.intersection (area);
if (!isect) {
continue;
}
Rect intersection (isect.get());
Rect intersection (isect);
set_source_rgba (context, i->color);
context->set_line_width (i->width);

View file

@ -47,9 +47,9 @@ DumbLookupTable::get (Rect const &area)
vector<Item *> vitems;
#if 1
for (list<Item *>::const_iterator i = items.begin(); i != items.end(); ++i) {
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
Rect item_bbox = (*i)->bounding_box ();
if (!item_bbox) continue;
Rect item = (*i)->item_to_window (item_bbox.get());
Rect item = (*i)->item_to_window (item_bbox);
if (item.intersection (area)) {
vitems.push_back (*i);
}
@ -121,28 +121,28 @@ OptimizingLookupTable::OptimizingLookupTable (Item const & item, int items_per_c
}
/* our item's bounding box in its coordinates */
boost::optional<Rect> bbox = _item.bounding_box ();
Rect bbox = _item.bounding_box ();
if (!bbox) {
return;
}
_cell_size.x = bbox.get().width() / _dimension;
_cell_size.y = bbox.get().height() / _dimension;
_offset.x = bbox.get().x0;
_offset.y = bbox.get().y0;
_cell_size.x = bbox.width() / _dimension;
_cell_size.y = bbox.height() / _dimension;
_offset.x = bbox.x0;
_offset.y = bbox.y0;
// cout << "BUILD bbox=" << bbox.get() << ", cellsize=" << _cell_size << ", offset=" << _offset << ", dimension=" << _dimension << "\n";
// cout << "BUILD bbox=" << bbox << ", cellsize=" << _cell_size << ", offset=" << _offset << ", dimension=" << _dimension << "\n";
for (list<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
/* item bbox in its own coordinates */
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
Rect item_bbox = (*i)->bounding_box ();
if (!item_bbox) {
continue;
}
/* and in the item's coordinates */
Rect const item_bbox_in_item = (*i)->item_to_parent (item_bbox.get ());
Rect const item_bbox_in_item = (*i)->item_to_parent (item_bbox);
int x0, y0, x1, y1;
area_to_indices (item_bbox_in_item, x0, y0, x1, y1);
@ -158,19 +158,19 @@ OptimizingLookupTable::OptimizingLookupTable (Item const & item, int items_per_c
//assert (y1 <= _dimension);
if (x0 > _dimension) {
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x0 - bbox.get().x0) << "\n";
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x0 - bbox.x0) << "\n";
x0 = _dimension;
}
if (x1 > _dimension) {
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x1 - bbox.get().x1) << "\n";
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x1 - bbox.x1) << "\n";
x1 = _dimension;
}
if (y0 > _dimension) {
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y0 - bbox.get().y0) << "\n";
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y0 - bbox.y0) << "\n";
y0 = _dimension;
}
if (y1 > _dimension) {
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y1 - bbox.get().y1) << "\n";
cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y1 - bbox.y1) << "\n";
y1 = _dimension;
}
@ -246,9 +246,9 @@ OptimizingLookupTable::items_at_point (Duple const & point) const
Cell const & cell = _cells[x][y];
vector<Item*> items;
for (Cell::const_iterator i = cell.begin(); i != cell.end(); ++i) {
boost::optional<Rect> const item_bbox = (*i)->bounding_box ();
Rect const item_bbox = (*i)->bounding_box ();
if (item_bbox) {
Rect parent_bbox = (*i)->item_to_parent (item_bbox.get ());
Rect parent_bbox = (*i)->item_to_parent (item_bbox);
if (parent_bbox.contains (point)) {
items.push_back (*i);
}
@ -283,9 +283,9 @@ OptimizingLookupTable::has_item_at_point (Duple const & point) const
Cell const & cell = _cells[x][y];
vector<Item*> items;
for (Cell::const_iterator i = cell.begin(); i != cell.end(); ++i) {
boost::optional<Rect> const item_bbox = (*i)->bounding_box ();
Rect const item_bbox = (*i)->bounding_box ();
if (item_bbox) {
Rect parent_bbox = (*i)->item_to_parent (item_bbox.get ());
Rect parent_bbox = (*i)->item_to_parent (item_bbox);
if (parent_bbox.contains (point)) {
return true;
}

View file

@ -172,7 +172,7 @@ void
Meter::compute_bounding_box () const
{
if (!_canvas) {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
_bounding_box_dirty = false;
return;
}

View file

@ -46,9 +46,9 @@ void
Pixbuf::compute_bounding_box () const
{
if (_pixbuf) {
_bounding_box = boost::optional<Rect> (Rect (0, 0, _pixbuf->get_width(), _pixbuf->get_height()));
_bounding_box = Rect (Rect (0, 0, _pixbuf->get_width(), _pixbuf->get_height()));
} else {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
}
_bounding_box_dirty = false;

View file

@ -63,7 +63,7 @@ PolyItem::compute_bounding_box () const
} else {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
}
_bounding_box_dirty = false;

View file

@ -44,10 +44,10 @@ PolyLine::compute_bounding_box () const
{
PolyItem::compute_bounding_box ();
if (_y1 > 0 && _bounding_box) {
_bounding_box.get().x0 = 0;
_bounding_box.get().x1 = COORD_MAX;
if (_y1 > _bounding_box.get().y1) {
_bounding_box.get().y1 = _y1;
_bounding_box.x0 = 0;
_bounding_box.x1 = COORD_MAX;
if (_y1 > _bounding_box.y1) {
_bounding_box.y1 = _y1;
}
}
}

View file

@ -71,13 +71,13 @@ Rectangle::get_self_for_render () const
void
Rectangle::render_self (Rect const & area, Cairo::RefPtr<Cairo::Context> context, Rect self) const
{
boost::optional<Rect> r = self.intersection (area);
Rect r = self.intersection (area);
if (!r) {
return;
}
Rect draw = r.get ();
Rect draw = r;
if (_fill && !_transparent) {
if (_stops.empty()) {
@ -273,12 +273,12 @@ Rectangle::vertical_fraction (double y) const
/* y is in canvas coordinates */
Duple i (canvas_to_item (Duple (0, y)));
boost::optional<Rect> r = bounding_box();
Rect r = bounding_box();
if (!r) {
return 0; /* not really correct, but what else can we do? */
}
Rect bbox (r.get());
Rect bbox (r);
if (i.y < bbox.y0 || i.y >= bbox.y1) {
return 0;

View file

@ -37,7 +37,7 @@ Root::compute_bounding_box () const
Container::compute_bounding_box ();
if (_bounding_box) {
Rect r (_bounding_box.get());
Rect r (_bounding_box);
_canvas->request_size (Duple (r.width (), r.height ()));
}
}

View file

@ -103,13 +103,13 @@ Ruler::render (Rect const & area, Cairo::RefPtr<Cairo::Context> cr) const
}
Rect self (item_to_window (get()));
boost::optional<Rect> i = self.intersection (area);
Rect i = self.intersection (area);
if (!i) {
return;
}
Rect intersection (i.get());
Rect intersection (i);
Distance height = self.height();

View file

@ -46,16 +46,16 @@ ScrollGroup::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) c
* WITHOUT scroll offsets in effect
*/
boost::optional<Rect> r = bounding_box();
Rect r = bounding_box();
if (!r) {
return;
}
Rect self (_position.x + r.get().x0,
_position.y + r.get().y0,
_position.x + r.get().x1,
_position.y + r.get().y1);
Rect self (_position.x + r.x0,
_position.y + r.y0,
_position.x + r.x1,
_position.y + r.y1);
self.x1 = min (_position.x + _canvas->width(), self.x1);
self.y1 = min (_position.y + _canvas->height(), self.y1);
@ -84,7 +84,7 @@ ScrollGroup::scroll_to (Duple const& d)
bool
ScrollGroup::covers_canvas (Duple const& d) const
{
boost::optional<Rect> r = bounding_box ();
Rect r = bounding_box ();
if (!r) {
return false;
@ -95,13 +95,13 @@ ScrollGroup::covers_canvas (Duple const& d) const
within the canvas.
*/
return r->translate (position()).contains (d);
return r.translate (position()).contains (d);
}
bool
ScrollGroup::covers_window (Duple const& d) const
{
boost::optional<Rect> r = bounding_box ();
Rect r = bounding_box ();
if (!r) {
return false;
@ -112,5 +112,5 @@ ScrollGroup::covers_window (Duple const& d) const
within the canvas.
*/
return r->translate (position()).contains (d);
return r.translate (position()).contains (d);
}

View file

@ -45,7 +45,7 @@ StatefulImage::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context)
ImageHandle image = _states[_state].image;
Rect self = item_to_window (Rect (0, 0, image->get_width(), image->get_height()));
boost::optional<Rect> draw = self.intersection (area);
Rect draw = self.intersection (area);
if (!draw) {
return;
@ -55,7 +55,7 @@ StatefulImage::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context)
("window" coordinates) and render it.
*/
context->set_source (image, self.x0, self.y0);
context->rectangle (draw->x0, draw->y0, draw->width(), draw->height());
context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
context->fill ();
if (!_text.empty()) {

View file

@ -195,7 +195,7 @@ Text::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
}
Rect self = item_to_window (Rect (0, 0, min (_clamped_width, (double)_image->get_width ()), _image->get_height ()));
boost::optional<Rect> i = self.intersection (area);
Rect i = self.intersection (area);
if (!i) {
return;
@ -205,7 +205,7 @@ Text::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
_redraw ();
}
Rect intersection (i.get());
Rect intersection (i);
context->rectangle (intersection.x0, intersection.y0, intersection.width(), intersection.height());
#ifdef __APPLE__
@ -238,7 +238,7 @@ void
Text::compute_bounding_box () const
{
if (!_canvas || _text.empty()) {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
_bounding_box_dirty = false;
return;
}

View file

@ -1101,13 +1101,13 @@ WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) cons
/* Now lets get the intersection with the area we've been asked to draw */
boost::optional<Rect> d = self.intersection (area);
Rect d = self.intersection (area);
if (!d) {
return;
}
Rect draw = d.get();
Rect draw = d;
/* "draw" is now a rectangle that defines the rectangle we need to
* update/render the waveview into, in window coordinate space.
@ -1276,7 +1276,7 @@ WaveView::compute_bounding_box () const
if (_region) {
_bounding_box = Rect (0.0, 0.0, region_length() / _samples_per_pixel, _height);
} else {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
}
_bounding_box_dirty = false;

View file

@ -82,15 +82,15 @@ Widget::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
return;
}
Rect self = item_to_window (_bounding_box.get());
boost::optional<Rect> r = self.intersection (area);
Rect self = item_to_window (_bounding_box);
Rect r = self.intersection (area);
if (!r) {
std::cerr << "no intersection\n";
return;
}
Rect draw = r.get ();
Rect draw = r;
cairo_rectangle_t crect;
crect.x = draw.x0;
crect.y = draw.y0;

View file

@ -118,7 +118,7 @@ XFadeCurve::compute_bounding_box () const
_bounding_box = bbox.expand (1.0);
} else {
_bounding_box = boost::optional<Rect> ();
_bounding_box = Rect ();
}
_bounding_box_dirty = false;
@ -233,10 +233,10 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
if (_in.points.size() < 2) { return; }
if (_out.points.size() < 2) { return; }
Rect self = item_to_window (_bounding_box.get());
boost::optional<Rect> d = self.intersection (area);
Rect self = item_to_window (_bounding_box);
Rect d = self.intersection (area);
assert (d);
Rect draw = d.get ();
Rect draw = d;
context->save ();
context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());