don't queue redraws when various canvas item properties are "reset" to the same value, plus supporting functions

This commit is contained in:
Paul Davis 2014-03-11 07:36:09 -04:00
parent 495c0de4ac
commit c2946ee00f
7 changed files with 131 additions and 107 deletions

View file

@ -262,7 +262,7 @@ void
Canvas::queue_draw_item_area (Item* item, Rect area) Canvas::queue_draw_item_area (Item* item, Rect area)
{ {
ArdourCanvas::Rect canvas_area = item->item_to_canvas (area); ArdourCanvas::Rect canvas_area = item->item_to_canvas (area);
// cerr << "CANVAS " << this << " for " << item->whatami() << ' ' << item->name << " invalidate " << area << " TRANSLATE AS " << canvas_area << " window = " << canvas_to_window (canvas_area) << std::endl; // cerr << "CANVAS " << this << " for " << item << ' ' << item->whatami() << ' ' << item->name << " invalidate " << area << " TRANSLATE AS " << canvas_area << " window = " << canvas_to_window (canvas_area) << std::endl;
request_redraw (canvas_area); request_redraw (canvas_area);
} }

View file

@ -72,7 +72,12 @@ public:
}; };
void set_outline_what (What); void set_outline_what (What);
void set_outline_what (int); void set_outline_all () {
set_outline_what (ArdourCanvas::Rectangle::What (ArdourCanvas::Rectangle::TOP|
ArdourCanvas::Rectangle::LEFT|
ArdourCanvas::Rectangle::RIGHT|
ArdourCanvas::Rectangle::BOTTOM));
}
private: 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

View file

@ -64,6 +64,7 @@ struct LIBCANVAS_API Duple
extern LIBCANVAS_API Duple operator- (Duple const &); extern LIBCANVAS_API Duple operator- (Duple const &);
extern LIBCANVAS_API Duple operator+ (Duple const &, Duple const &); extern LIBCANVAS_API Duple operator+ (Duple const &, Duple const &);
extern LIBCANVAS_API bool operator== (Duple const &, Duple const &); extern LIBCANVAS_API bool operator== (Duple const &, Duple const &);
extern LIBCANVAS_API bool operator!= (Duple const &, Duple const &);
extern LIBCANVAS_API Duple operator- (Duple const &, Duple const &); extern LIBCANVAS_API Duple operator- (Duple const &, Duple const &);
extern LIBCANVAS_API Duple operator/ (Duple const &, double); extern LIBCANVAS_API Duple operator/ (Duple const &, double);
extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Duple const &); extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Duple const &);
@ -106,6 +107,8 @@ struct LIBCANVAS_API Rect
} }
}; };
extern LIBCANVAS_API bool operator!= (Rect const &, Rect const &);
extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Rect const &); extern LIBCANVAS_API std::ostream & operator<< (std::ostream &, Rect const &);
typedef std::vector<Duple> Points; typedef std::vector<Duple> Points;

View file

@ -77,53 +77,55 @@ Line::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) cons
void void
Line::set (Duple a, Duple b) Line::set (Duple a, Duple b)
{ {
begin_change (); if (a != _points[0] || b != _points[1]) {
begin_change ();
_points[0] = a;
_points[1] = b; _points[0] = a;
_points[1] = b;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); }
} }
void void
Line::set_x (Coord x0, Coord x1) Line::set_x (Coord x0, Coord x1)
{ {
begin_change (); if (x0 != _points[0].x || x1 != _points[1].x) {
begin_change ();
_points[0].x = x0;
_points[1].x = x1; _points[0].x = x0;
_points[1].x = x1;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); }
} }
void void
Line::set_x0 (Coord x0) Line::set_x0 (Coord x0)
{ {
begin_change (); if (x0 != _points[0].x) {
begin_change ();
_points[0].x = x0;
_points[0].x = x0;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); }
} }
void void
Line::set_y0 (Coord y0) Line::set_y0 (Coord y0)
{ {
begin_change (); if (y0 != _points[0].y) {
begin_change ();
_points[0].y = y0;
_points[0].y = y0;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
}
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n");
} }
@ -131,27 +133,27 @@ Line::set_y0 (Coord y0)
void void
Line::set_x1 (Coord x1) Line::set_x1 (Coord x1)
{ {
begin_change (); if (x1 != _points[1].x) {
begin_change ();
_points[1].x = x1;
_points[1].x = x1;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); }
} }
void void
Line::set_y1 (Coord y1) Line::set_y1 (Coord y1)
{ {
begin_change (); if (y1 != _points[1].y) {
begin_change ();
_points[1].y = y1;
_points[1].y = y1;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: line change\n"); }
} }
bool bool

View file

@ -127,12 +127,15 @@ PolyItem::render_curve (Rect const & area, Cairo::RefPtr<Cairo::Context> context
void void
PolyItem::set (Points const & points) PolyItem::set (Points const & points)
{ {
begin_change (); if (_points != points) {
_points = points; begin_change ();
_bounding_box_dirty = true; _points = points;
end_change ();
_bounding_box_dirty = true;
end_change ();
}
} }
Points const & Points const &

View file

@ -139,82 +139,77 @@ Rectangle::set (Rect const & r)
/* We don't update the bounding box here; it's just /* We don't update the bounding box here; it's just
as cheap to do it when asked. as cheap to do it when asked.
*/ */
begin_change ();
_rect = r;
_bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (set)\n"); if (r != _rect) {
begin_change ();
_rect = r;
_bounding_box_dirty = true;
end_change ();
}
} }
void void
Rectangle::set_x0 (Coord x0) Rectangle::set_x0 (Coord x0)
{ {
begin_change (); if (x0 != _rect.x0) {
begin_change ();
_rect.x0 = x0;
_rect.x0 = x0;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x0)\n"); }
} }
void void
Rectangle::set_y0 (Coord y0) Rectangle::set_y0 (Coord y0)
{ {
begin_change (); if (y0 != _rect.y0) {
begin_change ();
_rect.y0 = y0;
_rect.y0 = y0;
_bounding_box_dirty = true;
end_change(); _bounding_box_dirty = true;
end_change();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y0)\n"); }
} }
void void
Rectangle::set_x1 (Coord x1) Rectangle::set_x1 (Coord x1)
{ {
begin_change (); if (x1 != _rect.x1) {
begin_change ();
_rect.x1 = x1;
_rect.x1 = x1;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (x1)\n"); }
} }
void void
Rectangle::set_y1 (Coord y1) Rectangle::set_y1 (Coord y1)
{ {
begin_change (); if (y1 != _rect.y1) {
begin_change ();
_rect.y1 = y1;
_rect.y1 = y1;
_bounding_box_dirty = true;
end_change (); _bounding_box_dirty = true;
end_change ();
DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: rectangle change (y1)\n"); }
} }
void void
Rectangle::set_outline_what (What what) Rectangle::set_outline_what (What what)
{ {
begin_change (); if (what != _outline_what) {
begin_visual_change ();
_outline_what = what; _outline_what = what;
end_visual_change ();
end_change (); }
}
void
Rectangle::set_outline_what (int what)
{
set_outline_what ((What) what);
} }

View file

@ -121,6 +121,16 @@ Rect::fix () const
return r; return r;
} }
bool
ArdourCanvas::operator!= (Rect const& a, Rect const& b)
{
return a.x0 != b.x0 ||
a.x1 != b.x1 ||
a.y0 != b.y0 ||
a.y1 != b.y1;
}
Duple Duple
ArdourCanvas::operator- (Duple const & o) ArdourCanvas::operator- (Duple const & o)
{ {
@ -139,6 +149,12 @@ ArdourCanvas::operator== (Duple const & a, Duple const & b)
return a.x == b.x && a.y == b.y; return a.x == b.x && a.y == b.y;
} }
bool
ArdourCanvas::operator!= (Duple const & a, Duple const & b)
{
return a.x != b.x || a.y != b.y;
}
Duple Duple
ArdourCanvas::operator- (Duple const & a, Duple const & b) ArdourCanvas::operator- (Duple const & a, Duple const & b)
{ {