diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2017-04-01 23:02:49 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2017-06-26 08:40:47 +1000 |
commit | c4e31fc32273a84c0436f32fce742ae21718b03c (patch) | |
tree | 3fac41d0063c4dc43112e1a65b43ede9b03f72aa /libs/canvas/canvas.cc | |
parent | 265f52535a73d996de0e6a61a5b30070c6226cf8 (diff) |
Add an optional ArdourCanvas::Item::prepare_for_render interface
Called when an item has requested a redraw and intersects with visible
canvas area.
Also add Canvas::prepare_for_render that will call Item::prepare_for_render for
items visible on the canvas.
Diffstat (limited to 'libs/canvas/canvas.cc')
-rw-r--r-- | libs/canvas/canvas.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index be61b6cb84..baa10f9cf7 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -144,6 +144,22 @@ Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context } +void +Canvas::prepare_for_render (Rect const & area) const +{ + Rect root_bbox = _root.bounding_box(); + if (!root_bbox) { + /* the root has no bounding box, so there's nothing to render */ + return; + } + + Rect draw = root_bbox.intersection (area); + + if (draw) { + _root.prepare_for_render (draw); + } +} + ostream& operator<< (ostream& o, Canvas& c) { @@ -231,9 +247,17 @@ Canvas::item_changed (Item* item, Rect pre_change_bounding_box) Rect post_change_bounding_box = item->bounding_box (); if (post_change_bounding_box) { - if (item->item_to_window (post_change_bounding_box).intersection (window_bbox)) { + Rect const window_intersection = + item->item_to_window (post_change_bounding_box).intersection (window_bbox); + + if (window_intersection) { /* request a redraw of the item's new bounding box */ queue_draw_item_area (item, post_change_bounding_box); + + // Allow item to do any work necessary to prepare for being rendered. + item->prepare_for_render (window_intersection); + } else { + // No intersection with visible window area } } } @@ -937,6 +961,13 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev) return true; } +void +GtkCanvas::prepare_for_render () const +{ + Rect window_bbox = visible_area (); + Canvas::prepare_for_render (window_bbox); +} + /** Handler for GDK scroll events. * @param ev Event. * @return true if the event was handled. |