mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-12 17:46:34 +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));
|
||||
|
||||
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) {
|
||||
group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Marker::~Marker ()
|
||||
{
|
||||
CatchDeletion (this); /* EMIT SIGNAL */
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ class Marker : public sigc::trackable
|
|||
ArdourCanvas::Text *_name_item;
|
||||
ArdourCanvas::Points *points;
|
||||
ArdourCanvas::Line* _line;
|
||||
ArdourCanvas::Points *line_points;
|
||||
ArdourCanvas::Rectangle* _name_background;
|
||||
|
||||
std::string _name;
|
||||
|
|
|
|||
|
|
@ -77,9 +77,13 @@ Canvas::Canvas (XMLTree const * tree)
|
|||
void
|
||||
Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context) const
|
||||
{
|
||||
cerr << "CANVAS @ " << this << endl;
|
||||
dump (cerr);
|
||||
cerr << "-------------------------\n";
|
||||
#ifdef CANVAS_DEBUG
|
||||
if (DEBUG_ENABLED(PBD::DEBUG::CanvasRender)) {
|
||||
cerr << "CANVAS @ " << this << endl;
|
||||
dump (cerr);
|
||||
cerr << "-------------------------\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
checkpoint ("render", "-> render");
|
||||
render_count = 0;
|
||||
|
|
@ -136,6 +140,18 @@ Canvas::indent() const
|
|||
return s;
|
||||
}
|
||||
|
||||
std::string
|
||||
Canvas::render_indent() const
|
||||
{
|
||||
string s;
|
||||
|
||||
for (int n = 0; n < ArdourCanvas::render_depth; ++n) {
|
||||
s += ' ';
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
Canvas::dump (ostream& o) const
|
||||
{
|
||||
|
|
@ -334,6 +350,10 @@ GtkCanvas::deliver_event (Duple point, GdkEvent* event)
|
|||
while (i != items.rend()) {
|
||||
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -342,7 +362,7 @@ GtkCanvas::deliver_event (Duple point, GdkEvent* event)
|
|||
/* this item has just handled the event */
|
||||
DEBUG_TRACE (
|
||||
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;
|
||||
|
|
@ -350,7 +370,7 @@ GtkCanvas::deliver_event (Duple point, GdkEvent* event)
|
|||
|
||||
DEBUG_TRACE (
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ public:
|
|||
}
|
||||
|
||||
std::string indent() const;
|
||||
std::string render_indent() const;
|
||||
void dump (std::ostream&) const;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace PBD {
|
|||
extern uint64_t CanvasItems;
|
||||
extern uint64_t CanvasItemsDirtied;
|
||||
extern uint64_t CanvasEvents;
|
||||
extern uint64_t CanvasRender;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ namespace ArdourCanvas {
|
|||
extern void checkpoint (std::string, std::string);
|
||||
extern void set_epoch ();
|
||||
extern int render_count;
|
||||
extern int render_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::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitemsdirtied");
|
||||
uint64_t PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
|
||||
uint64_t PBD::DEBUG::CanvasRender = PBD::new_debug_bit ("canvasrender");
|
||||
|
||||
struct timeval ArdourCanvas::epoch;
|
||||
map<string, struct timeval> ArdourCanvas::last_time;
|
||||
int ArdourCanvas::render_count;
|
||||
int ArdourCanvas::render_depth;
|
||||
int ArdourCanvas::dump_depth;
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <iostream>
|
||||
#include <cairomm/context.h>
|
||||
|
||||
#include "pbd/stacktrace.h"
|
||||
#include "pbd/compose.h"
|
||||
#include "pbd/xml++.h"
|
||||
|
||||
#include "canvas/group.h"
|
||||
|
|
@ -55,15 +57,34 @@ Group::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
|||
ensure_lut ();
|
||||
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) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
boost::optional<Rect> item_bbox = (*i)->bounding_box ();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +98,26 @@ Group::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
|||
/* render the intersection */
|
||||
context->save ();
|
||||
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);
|
||||
context->restore ();
|
||||
++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
|
||||
|
|
|
|||
|
|
@ -22,21 +22,17 @@ Item::Item (Canvas* canvas)
|
|||
}
|
||||
|
||||
Item::Item (Group* parent)
|
||||
: _parent (parent)
|
||||
: _canvas (parent->canvas ())
|
||||
, _parent (parent)
|
||||
{
|
||||
assert (parent);
|
||||
_canvas = _parent->canvas ();
|
||||
|
||||
init ();
|
||||
}
|
||||
|
||||
Item::Item (Group* parent, Duple position)
|
||||
: _parent (parent)
|
||||
: _canvas (parent->canvas())
|
||||
, _parent (parent)
|
||||
, _position (position)
|
||||
{
|
||||
assert (parent);
|
||||
_canvas = _parent->canvas ();
|
||||
|
||||
init ();
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +52,9 @@ Item::init ()
|
|||
|
||||
Item::~Item ()
|
||||
{
|
||||
_canvas->item_going_away (this, _bounding_box);
|
||||
if (_canvas) {
|
||||
_canvas->item_going_away (this, _bounding_box);
|
||||
}
|
||||
|
||||
if (_parent) {
|
||||
_parent->remove (this);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
#include <gdk/gdk.h>
|
||||
|
||||
#include <cairomm/cairomm.h>
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
#include "pbd/xml++.h"
|
||||
#include "pbd/stacktrace.h"
|
||||
|
||||
#include "canvas/text.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 */
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -88,18 +84,29 @@ Text::redraw (Cairo::RefPtr<Cairo::Context> context) const
|
|||
void
|
||||
Text::compute_bounding_box () const
|
||||
{
|
||||
if (!_canvas || !_canvas->context () || _text.empty()) {
|
||||
if (!_canvas || _text.empty()) {
|
||||
_bounding_box = boost::optional<Rect> ();
|
||||
_bounding_box_dirty = false;
|
||||
return;
|
||||
}
|
||||
|
||||
redraw (_canvas->context());
|
||||
|
||||
_bounding_box = Rect (_origin.x, _origin.y, _width - _origin.x, _height - _origin.y);
|
||||
PangoContext* _pc = gdk_pango_context_get ();
|
||||
Glib::RefPtr<Pango::Context> context = Glib::wrap (_pc); // context now owns _pc and will free it
|
||||
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;
|
||||
|
||||
cerr << "bbox for " << _text << " = " << _bounding_box << endl;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -113,8 +120,6 @@ Text::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) cons
|
|||
redraw (context);
|
||||
}
|
||||
|
||||
cerr << " with " << _origin << " and " << _width << " x " << _height << " render " << _text << endl;
|
||||
|
||||
context->set_source (_image, 0, 0);
|
||||
context->rectangle (0, 0, _width, _height);
|
||||
context->fill ();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue