mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-12 09:36:33 +01:00
a variety of fixes for the cairocanvas, but it still buggy as hell handling events and lots of other stuff
This commit is contained in:
parent
1267b1d61c
commit
053eaf77fd
9 changed files with 100 additions and 33 deletions
|
|
@ -282,15 +282,19 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
|
||||||
|
|
||||||
editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
|
editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
|
||||||
|
|
||||||
group->set_data ("marker", this);
|
/* events will be handled by both the group and the mark itself, so
|
||||||
|
* make sure they can both be used to lookup this object.
|
||||||
|
*/
|
||||||
|
|
||||||
|
group->set_data ("marker", this);
|
||||||
|
mark->set_data ("marker", this);
|
||||||
|
|
||||||
if (handle_events) {
|
if (handle_events) {
|
||||||
group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
|
group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Marker::~Marker ()
|
Marker::~Marker ()
|
||||||
{
|
{
|
||||||
CatchDeletion (this); /* EMIT SIGNAL */
|
CatchDeletion (this); /* EMIT SIGNAL */
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,6 @@ class Marker : public sigc::trackable
|
||||||
ArdourCanvas::Text *_name_item;
|
ArdourCanvas::Text *_name_item;
|
||||||
ArdourCanvas::Points *points;
|
ArdourCanvas::Points *points;
|
||||||
ArdourCanvas::Line* _line;
|
ArdourCanvas::Line* _line;
|
||||||
ArdourCanvas::Points *line_points;
|
|
||||||
ArdourCanvas::Rectangle* _name_background;
|
ArdourCanvas::Rectangle* _name_background;
|
||||||
|
|
||||||
std::string _name;
|
std::string _name;
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,13 @@ Canvas::Canvas (XMLTree const * tree)
|
||||||
void
|
void
|
||||||
Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context) const
|
Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context) const
|
||||||
{
|
{
|
||||||
cerr << "CANVAS @ " << this << endl;
|
#ifdef CANVAS_DEBUG
|
||||||
dump (cerr);
|
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
||||||
cerr << "-------------------------\n";
|
cerr << "CANVAS @ " << this << endl;
|
||||||
|
dump (cerr);
|
||||||
|
cerr << "-------------------------\n";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
checkpoint ("render", "-> render");
|
checkpoint ("render", "-> render");
|
||||||
render_count = 0;
|
render_count = 0;
|
||||||
|
|
@ -136,6 +140,18 @@ Canvas::indent() const
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Canvas::render_indent() const
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
|
||||||
|
for (int n = 0; n < ArdourCanvas::render_depth; ++n) {
|
||||||
|
s += ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Canvas::dump (ostream& o) const
|
Canvas::dump (ostream& o) const
|
||||||
{
|
{
|
||||||
|
|
@ -334,6 +350,10 @@ GtkCanvas::deliver_event (Duple point, GdkEvent* event)
|
||||||
while (i != items.rend()) {
|
while (i != items.rend()) {
|
||||||
|
|
||||||
if ((*i)->ignore_events ()) {
|
if ((*i)->ignore_events ()) {
|
||||||
|
DEBUG_TRACE (
|
||||||
|
PBD::DEBUG::CanvasEvents,
|
||||||
|
string_compose ("canvas event ignored by %1 %2\n", (*i)->whatami(), (*i)->name.empty() ? "[unknown]" : (*i)->name)
|
||||||
|
);
|
||||||
++i;
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -342,7 +362,7 @@ GtkCanvas::deliver_event (Duple point, GdkEvent* event)
|
||||||
/* this item has just handled the event */
|
/* this item has just handled the event */
|
||||||
DEBUG_TRACE (
|
DEBUG_TRACE (
|
||||||
PBD::DEBUG::CanvasEvents,
|
PBD::DEBUG::CanvasEvents,
|
||||||
string_compose ("canvas event handled by %1\n", (*i)->name.empty() ? "[unknown]" : (*i)->name)
|
string_compose ("canvas event handled by %1 %2\n", (*i)->whatami(), (*i)->name.empty() ? "[unknown]" : (*i)->name)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -350,7 +370,7 @@ GtkCanvas::deliver_event (Duple point, GdkEvent* event)
|
||||||
|
|
||||||
DEBUG_TRACE (
|
DEBUG_TRACE (
|
||||||
PBD::DEBUG::CanvasEvents,
|
PBD::DEBUG::CanvasEvents,
|
||||||
string_compose ("canvas event ignored by %1\n", (*i)->name.empty() ? "[unknown]" : (*i)->name)
|
string_compose ("canvas event left unhandled by %1 %2\n", (*i)->whatami(), (*i)->name.empty() ? "[unknown]" : (*i)->name)
|
||||||
);
|
);
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string indent() const;
|
std::string indent() const;
|
||||||
|
std::string render_indent() const;
|
||||||
void dump (std::ostream&) const;
|
void dump (std::ostream&) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ namespace PBD {
|
||||||
extern uint64_t CanvasItems;
|
extern uint64_t CanvasItems;
|
||||||
extern uint64_t CanvasItemsDirtied;
|
extern uint64_t CanvasItemsDirtied;
|
||||||
extern uint64_t CanvasEvents;
|
extern uint64_t CanvasEvents;
|
||||||
|
extern uint64_t CanvasRender;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ namespace ArdourCanvas {
|
||||||
extern void checkpoint (std::string, std::string);
|
extern void checkpoint (std::string, std::string);
|
||||||
extern void set_epoch ();
|
extern void set_epoch ();
|
||||||
extern int render_count;
|
extern int render_count;
|
||||||
|
extern int render_depth;
|
||||||
extern int dump_depth;
|
extern int dump_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ using namespace std;
|
||||||
uint64_t PBD::DEBUG::CanvasItems = PBD::new_debug_bit ("canvasitems");
|
uint64_t PBD::DEBUG::CanvasItems = PBD::new_debug_bit ("canvasitems");
|
||||||
uint64_t PBD::DEBUG::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitemsdirtied");
|
uint64_t PBD::DEBUG::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitemsdirtied");
|
||||||
uint64_t PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
|
uint64_t PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
|
||||||
|
uint64_t PBD::DEBUG::CanvasRender = PBD::new_debug_bit ("canvasrender");
|
||||||
|
|
||||||
struct timeval ArdourCanvas::epoch;
|
struct timeval ArdourCanvas::epoch;
|
||||||
map<string, struct timeval> ArdourCanvas::last_time;
|
map<string, struct timeval> ArdourCanvas::last_time;
|
||||||
int ArdourCanvas::render_count;
|
int ArdourCanvas::render_count;
|
||||||
|
int ArdourCanvas::render_depth;
|
||||||
int ArdourCanvas::dump_depth;
|
int ArdourCanvas::dump_depth;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cairomm/context.h>
|
#include <cairomm/context.h>
|
||||||
|
|
||||||
#include "pbd/stacktrace.h"
|
#include "pbd/stacktrace.h"
|
||||||
|
#include "pbd/compose.h"
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
|
|
||||||
#include "canvas/group.h"
|
#include "canvas/group.h"
|
||||||
|
|
@ -55,15 +57,34 @@ Group::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
||||||
ensure_lut ();
|
ensure_lut ();
|
||||||
vector<Item*> items = _lut->get (area);
|
vector<Item*> items = _lut->get (area);
|
||||||
|
|
||||||
|
++render_depth;
|
||||||
|
|
||||||
|
#ifdef CANVAS_DEBUG
|
||||||
|
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
||||||
|
cerr << string_compose ("%1GROUP %2 render %3 items out of %4\n",
|
||||||
|
_canvas->render_indent(), (name.empty() ? string ("[unnamed]") : name), items.size(), _items.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
for (vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
|
for (vector<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
|
||||||
|
|
||||||
if (!(*i)->visible ()) {
|
if (!(*i)->visible ()) {
|
||||||
|
#ifdef CANVAS_DEBUG
|
||||||
|
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
||||||
|
cerr << _canvas->render_indent() << "Item " << (*i)->whatami() << ' ' << (*i)->name << " invisible - skipped\n";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
|
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
|
||||||
|
|
||||||
if (!item_bbox) {
|
if (!item_bbox) {
|
||||||
|
#ifdef CANVAS_DEBUG
|
||||||
|
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
||||||
|
cerr << _canvas->render_indent() << "Item " << (*i)->whatami() << ' ' << (*i)->name << " empty - skipped\n";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,11 +98,26 @@ Group::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
||||||
/* render the intersection */
|
/* render the intersection */
|
||||||
context->save ();
|
context->save ();
|
||||||
context->translate ((*i)->position().x, (*i)->position().y);
|
context->translate ((*i)->position().x, (*i)->position().y);
|
||||||
|
#ifdef CANVAS_DEBUG
|
||||||
|
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
||||||
|
cerr << string_compose ("%1render %2 %3\n", _canvas->render_indent(), (*i)->whatami(),
|
||||||
|
(*i)->name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
(*i)->render (r.get(), context);
|
(*i)->render (r.get(), context);
|
||||||
context->restore ();
|
|
||||||
++render_count;
|
++render_count;
|
||||||
|
context->restore ();
|
||||||
|
} else {
|
||||||
|
#ifdef CANVAS_DEBUG
|
||||||
|
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
||||||
|
cerr << string_compose ("%1skip render of %2 %3, no intersection\n", _canvas->render_indent(), (*i)->whatami(),
|
||||||
|
(*i)->name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--render_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -22,21 +22,17 @@ Item::Item (Canvas* canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Item (Group* parent)
|
Item::Item (Group* parent)
|
||||||
: _parent (parent)
|
: _canvas (parent->canvas ())
|
||||||
|
, _parent (parent)
|
||||||
{
|
{
|
||||||
assert (parent);
|
|
||||||
_canvas = _parent->canvas ();
|
|
||||||
|
|
||||||
init ();
|
init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Item (Group* parent, Duple position)
|
Item::Item (Group* parent, Duple position)
|
||||||
: _parent (parent)
|
: _canvas (parent->canvas())
|
||||||
|
, _parent (parent)
|
||||||
, _position (position)
|
, _position (position)
|
||||||
{
|
{
|
||||||
assert (parent);
|
|
||||||
_canvas = _parent->canvas ();
|
|
||||||
|
|
||||||
init ();
|
init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +52,9 @@ Item::init ()
|
||||||
|
|
||||||
Item::~Item ()
|
Item::~Item ()
|
||||||
{
|
{
|
||||||
_canvas->item_going_away (this, _bounding_box);
|
if (_canvas) {
|
||||||
|
_canvas->item_going_away (this, _bounding_box);
|
||||||
|
}
|
||||||
|
|
||||||
if (_parent) {
|
if (_parent) {
|
||||||
_parent->remove (this);
|
_parent->remove (this);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
|
#include <gdk/gdk.h>
|
||||||
|
|
||||||
#include <cairomm/cairomm.h>
|
#include <cairomm/cairomm.h>
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
|
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
|
#include "pbd/stacktrace.h"
|
||||||
|
|
||||||
#include "canvas/text.h"
|
#include "canvas/text.h"
|
||||||
#include "canvas/canvas.h"
|
#include "canvas/canvas.h"
|
||||||
|
|
@ -68,13 +71,6 @@ Text::redraw (Cairo::RefPtr<Cairo::Context> context) const
|
||||||
/* and draw, in the appropriate color of course */
|
/* and draw, in the appropriate color of course */
|
||||||
|
|
||||||
set_source_rgba (img_context, _color);
|
set_source_rgba (img_context, _color);
|
||||||
|
|
||||||
std::cerr << "render " << _text << " as "
|
|
||||||
<< ((_color >> 24) & 0xff) / 255.0
|
|
||||||
<< ((_color >> 16) & 0xff) / 255.0
|
|
||||||
<< ((_color >> 8) & 0xff) / 255.0
|
|
||||||
<< ((_color >> 0) & 0xff) / 255.
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
layout->show_in_cairo_context (img_context);
|
layout->show_in_cairo_context (img_context);
|
||||||
|
|
||||||
|
|
@ -88,18 +84,29 @@ Text::redraw (Cairo::RefPtr<Cairo::Context> context) const
|
||||||
void
|
void
|
||||||
Text::compute_bounding_box () const
|
Text::compute_bounding_box () const
|
||||||
{
|
{
|
||||||
if (!_canvas || !_canvas->context () || _text.empty()) {
|
if (!_canvas || _text.empty()) {
|
||||||
_bounding_box = boost::optional<Rect> ();
|
_bounding_box = boost::optional<Rect> ();
|
||||||
_bounding_box_dirty = false;
|
_bounding_box_dirty = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw (_canvas->context());
|
PangoContext* _pc = gdk_pango_context_get ();
|
||||||
|
Glib::RefPtr<Pango::Context> context = Glib::wrap (_pc); // context now owns _pc and will free it
|
||||||
_bounding_box = Rect (_origin.x, _origin.y, _width - _origin.x, _height - _origin.y);
|
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
|
||||||
|
|
||||||
|
layout->set_text (_text);
|
||||||
|
layout->set_font_description (*_font_description);
|
||||||
|
layout->set_alignment (_alignment);
|
||||||
|
Pango::Rectangle const r = layout->get_ink_extents ();
|
||||||
|
|
||||||
|
_bounding_box = Rect (
|
||||||
|
r.get_x() / Pango::SCALE,
|
||||||
|
r.get_y() / Pango::SCALE,
|
||||||
|
(r.get_x() + r.get_width()) / Pango::SCALE,
|
||||||
|
(r.get_y() + r.get_height()) / Pango::SCALE
|
||||||
|
);
|
||||||
|
|
||||||
_bounding_box_dirty = false;
|
_bounding_box_dirty = false;
|
||||||
|
|
||||||
cerr << "bbox for " << _text << " = " << _bounding_box << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -113,8 +120,6 @@ Text::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) cons
|
||||||
redraw (context);
|
redraw (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << " with " << _origin << " and " << _width << " x " << _height << " render " << _text << endl;
|
|
||||||
|
|
||||||
context->set_source (_image, 0, 0);
|
context->set_source (_image, 0, 0);
|
||||||
context->rectangle (0, 0, _width, _height);
|
context->rectangle (0, 0, _width, _height);
|
||||||
context->fill ();
|
context->fill ();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue