mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-05 21:25:46 +01:00
add background color property to Canvas::Canvas ; rearrange expose handling and include background fill
This commit is contained in:
parent
82b699a27c
commit
781c525643
2 changed files with 47 additions and 36 deletions
|
|
@ -36,6 +36,7 @@
|
|||
#include "canvas/debug.h"
|
||||
#include "canvas/line.h"
|
||||
#include "canvas/scroll_group.h"
|
||||
#include "canvas/utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ArdourCanvas;
|
||||
|
|
@ -43,6 +44,7 @@ using namespace ArdourCanvas;
|
|||
/** Construct a new Canvas */
|
||||
Canvas::Canvas ()
|
||||
: _root (this)
|
||||
, _bg_color (rgba_to_color (0, 1.0, 0.0, 1.0))
|
||||
{
|
||||
set_epoch ();
|
||||
}
|
||||
|
|
@ -333,6 +335,18 @@ Canvas::queue_draw_item_area (Item* item, Rect area)
|
|||
request_redraw (item->item_to_window (area));
|
||||
}
|
||||
|
||||
void
|
||||
Canvas::set_background_color (Color c)
|
||||
{
|
||||
_bg_color = c;
|
||||
|
||||
boost::optional<Rect> r = _root.bounding_box();
|
||||
|
||||
if (r) {
|
||||
request_redraw (_root.item_to_window (r.get()));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GtkCanvas::re_enter ()
|
||||
{
|
||||
|
|
@ -727,42 +741,37 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
|
|||
if (!canvas_image) {
|
||||
canvas_image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height());
|
||||
}
|
||||
Cairo::RefPtr<Cairo::Context> draw_context = Cairo::Context::create (canvas_image);
|
||||
Cairo::RefPtr<Cairo::Context> window_context = get_window()->create_cairo_context ();
|
||||
#else
|
||||
Cairo::RefPtr<Cairo::Context> draw_context = get_window()->create_cairo_context ();
|
||||
#endif
|
||||
|
||||
{
|
||||
/* scope for image_context */
|
||||
Cairo::RefPtr<Cairo::Context> image_context = Cairo::Context::create (canvas_image);
|
||||
|
||||
/* clear expose area to transparent */
|
||||
|
||||
image_context->save ();
|
||||
image_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
image_context->clip ();
|
||||
image_context->set_operator (Cairo::OPERATOR_CLEAR);
|
||||
image_context->paint ();
|
||||
image_context->restore ();
|
||||
|
||||
/* render into image surface */
|
||||
|
||||
render (Rect (ev->area.x, ev->area.y, ev->area.x + ev->area.width, ev->area.y + ev->area.height), image_context);
|
||||
|
||||
/* image surface is flushed when image_context goes out of scope */
|
||||
}
|
||||
/* draw background color */
|
||||
|
||||
#if 1
|
||||
draw_context->save ();
|
||||
draw_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
draw_context->clip ();
|
||||
draw_context->set_operator (Cairo::OPERATOR_SOURCE);
|
||||
set_source_rgba (draw_context, _bg_color);
|
||||
draw_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
draw_context->fill ();
|
||||
draw_context->restore ();
|
||||
#endif
|
||||
|
||||
/* render canvas */
|
||||
|
||||
render (Rect (ev->area.x, ev->area.y, ev->area.x + ev->area.width, ev->area.y + ev->area.height), draw_context);
|
||||
|
||||
#ifdef USE_CAIRO_IMAGE_SURFACE_FOR_GTK_CANVAS
|
||||
/* now blit our private surface back to the GDK one */
|
||||
|
||||
Cairo::RefPtr<Cairo::Context> cairo_context = get_window()->create_cairo_context ();
|
||||
|
||||
cairo_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
cairo_context->clip ();
|
||||
cairo_context->set_source (canvas_image, 0, 0);
|
||||
cairo_context->set_operator (Cairo::OPERATOR_SOURCE);
|
||||
cairo_context->paint ();
|
||||
|
||||
#else
|
||||
|
||||
Cairo::RefPtr<Cairo::Context> cairo_context = get_window()->create_cairo_context ();
|
||||
render (Rect (ev->area.x, ev->area.y, ev->area.x + ev->area.width, ev->area.y + ev->area.height), cairo_context);
|
||||
|
||||
window_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
window_context->clip ();
|
||||
window_context->set_source (canvas_image, 0, 0);
|
||||
window_context->set_operator (Cairo::OPERATOR_SOURCE);
|
||||
window_context->paint ();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue