mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
add background color property to Canvas::Canvas ; rearrange expose handling and include background fill
Conflicts: libs/canvas/canvas.cc libs/canvas/canvas/canvas.h
This commit is contained in:
parent
9cf5b23392
commit
ef56948d4a
2 changed files with 45 additions and 41 deletions
|
|
@ -35,6 +35,7 @@
|
||||||
#include "canvas/debug.h"
|
#include "canvas/debug.h"
|
||||||
#include "canvas/line.h"
|
#include "canvas/line.h"
|
||||||
#include "canvas/scroll_group.h"
|
#include "canvas/scroll_group.h"
|
||||||
|
#include "canvas/utils.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace ArdourCanvas;
|
using namespace ArdourCanvas;
|
||||||
|
|
@ -44,6 +45,7 @@ uint32_t Canvas::tooltip_timeout_msecs = 750;
|
||||||
/** Construct a new Canvas */
|
/** Construct a new Canvas */
|
||||||
Canvas::Canvas ()
|
Canvas::Canvas ()
|
||||||
: _root (this)
|
: _root (this)
|
||||||
|
, _bg_color (rgba_to_color (0, 1.0, 0.0, 1.0))
|
||||||
{
|
{
|
||||||
set_epoch ();
|
set_epoch ();
|
||||||
}
|
}
|
||||||
|
|
@ -340,6 +342,18 @@ Canvas::set_tooltip_timeout (uint32_t msecs)
|
||||||
tooltip_timeout_msecs = msecs;
|
tooltip_timeout_msecs = msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
GtkCanvas::re_enter ()
|
GtkCanvas::re_enter ()
|
||||||
{
|
{
|
||||||
|
|
@ -743,47 +757,35 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
|
||||||
if (!canvas_image) {
|
if (!canvas_image) {
|
||||||
canvas_image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height());
|
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
|
||||||
|
|
||||||
{
|
/* draw background color */
|
||||||
/* scope for image_context */
|
|
||||||
Cairo::RefPtr<Cairo::Context> image_context = Cairo::Context::create (canvas_image);
|
draw_context->save ();
|
||||||
|
draw_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||||
/* clear expose area */
|
draw_context->clip ();
|
||||||
|
draw_context->set_operator (Cairo::OPERATOR_SOURCE);
|
||||||
image_context->save ();
|
set_source_rgba (draw_context, _bg_color);
|
||||||
image_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
draw_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||||
image_context->clip ();
|
draw_context->fill ();
|
||||||
image_context->set_operator (Cairo::OPERATOR_SOURCE);
|
draw_context->restore ();
|
||||||
// TODO get canvas backround see CairoWidget::get_parent_bg
|
|
||||||
// also subscribe to parent's signal_style_changed()
|
/* render canvas */
|
||||||
// ..until new canvas color-theme API is in place, hardcode some values.
|
|
||||||
image_context->set_source_rgba (84./255., 85./255., 93./255., 1.0);
|
render (Rect (ev->area.x, ev->area.y, ev->area.x + ev->area.width, ev->area.y + ev->area.height), draw_context);
|
||||||
image_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
|
||||||
image_context->fill ();
|
|
||||||
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 */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#ifdef USE_CAIRO_IMAGE_SURFACE_FOR_GTK_CANVAS
|
||||||
/* now blit our private surface back to the GDK one */
|
/* now blit our private surface back to the GDK one */
|
||||||
|
|
||||||
Cairo::RefPtr<Cairo::Context> cairo_context = get_window()->create_cairo_context ();
|
window_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||||
|
window_context->clip ();
|
||||||
cairo_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
window_context->set_source (canvas_image, 0, 0);
|
||||||
cairo_context->clip ();
|
window_context->set_operator (Cairo::OPERATOR_SOURCE);
|
||||||
cairo_context->set_source (canvas_image, 0, 0);
|
window_context->paint ();
|
||||||
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);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,9 @@ public:
|
||||||
return &_root;
|
return &_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_background_color (ArdourCanvas::Color);
|
||||||
|
ArdourCanvas::Color background_color() const { return _bg_color; }
|
||||||
|
|
||||||
/** Called when an item is being destroyed */
|
/** Called when an item is being destroyed */
|
||||||
virtual void item_going_away (Item *, boost::optional<Rect>) {}
|
virtual void item_going_away (Item *, boost::optional<Rect>) {}
|
||||||
void item_shown_or_hidden (Item *);
|
void item_shown_or_hidden (Item *);
|
||||||
|
|
@ -152,13 +155,12 @@ public:
|
||||||
static void set_tooltip_timeout (uint32_t msecs);
|
static void set_tooltip_timeout (uint32_t msecs);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void queue_draw_item_area (Item *, Rect);
|
Root _root;
|
||||||
|
Color _bg_color;
|
||||||
/** our root item */
|
|
||||||
Root _root;
|
|
||||||
|
|
||||||
static uint32_t tooltip_timeout_msecs;
|
static uint32_t tooltip_timeout_msecs;
|
||||||
|
|
||||||
|
void queue_draw_item_area (Item *, Rect);
|
||||||
virtual void pick_current_item (int state) = 0;
|
virtual void pick_current_item (int state) = 0;
|
||||||
virtual void pick_current_item (Duple const &, int state) = 0;
|
virtual void pick_current_item (Duple const &, int state) = 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue