2014-06-03 23:57:12 -04:00
|
|
|
/*
|
2019-08-02 22:40:09 -04:00
|
|
|
* Copyright (C) 2014-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2016-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2014-06-03 23:57:12 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cairomm/context.h>
|
2021-05-05 11:57:16 -04:00
|
|
|
|
2014-06-03 23:57:12 -04:00
|
|
|
#include "pbd/compose.h"
|
|
|
|
|
|
|
|
#include "canvas/canvas.h"
|
|
|
|
#include "canvas/widget.h"
|
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
2021-09-07 13:44:34 -04:00
|
|
|
#include "gtkmm2ext/cairo_widget.h"
|
|
|
|
|
2014-06-03 23:57:12 -04:00
|
|
|
using namespace std;
|
|
|
|
using namespace ArdourCanvas;
|
|
|
|
|
2014-06-12 14:53:44 -04:00
|
|
|
Widget::Widget (Canvas* c, CairoWidget& w)
|
|
|
|
: Item (c)
|
|
|
|
, _widget (w)
|
|
|
|
{
|
|
|
|
Event.connect (sigc::mem_fun (*this, &Widget::event_proxy));
|
2016-12-19 07:36:42 -05:00
|
|
|
w.set_canvas_widget ();
|
|
|
|
w.QueueDraw.connect (sigc::mem_fun(*this, &Widget::queue_draw));
|
|
|
|
w.QueueResize.connect (sigc::mem_fun(*this, &Widget::queue_resize));
|
2014-06-12 14:53:44 -04:00
|
|
|
}
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
Widget::Widget (Item* parent, CairoWidget& w)
|
|
|
|
: Item (parent)
|
2014-06-03 23:57:12 -04:00
|
|
|
, _widget (w)
|
|
|
|
{
|
|
|
|
Event.connect (sigc::mem_fun (*this, &Widget::event_proxy));
|
2016-12-19 07:36:42 -05:00
|
|
|
w.set_canvas_widget ();
|
|
|
|
w.QueueDraw.connect (sigc::mem_fun(*this, &Widget::queue_draw));
|
|
|
|
w.QueueResize.connect (sigc::mem_fun(*this, &Widget::queue_resize));
|
2014-06-03 23:57:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Widget::event_proxy (GdkEvent* ev)
|
|
|
|
{
|
2014-06-12 14:53:44 -04:00
|
|
|
/* XXX need to translate coordinate into widget's own coordinate space */
|
2014-06-03 23:57:12 -04:00
|
|
|
return _widget.event (ev);
|
|
|
|
}
|
|
|
|
|
2016-12-19 07:36:42 -05:00
|
|
|
bool
|
|
|
|
Widget::queue_draw ()
|
|
|
|
{
|
|
|
|
begin_visual_change ();
|
|
|
|
end_visual_change ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Widget::queue_resize ()
|
|
|
|
{
|
|
|
|
begin_change ();
|
|
|
|
end_change ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-03 23:57:12 -04:00
|
|
|
void
|
|
|
|
Widget::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
|
|
|
{
|
2017-01-18 18:23:10 -05:00
|
|
|
//std::cerr << "Render widget " << name << " @ " << position() << endl;
|
2014-06-03 23:57:12 -04:00
|
|
|
|
|
|
|
if (!_bounding_box) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect self = item_to_window (_bounding_box);
|
|
|
|
Rect r = self.intersection (area);
|
2014-06-03 23:57:12 -04:00
|
|
|
|
|
|
|
if (!r) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-19 14:54:24 -05:00
|
|
|
Rect draw = r;
|
2014-06-03 23:57:12 -04:00
|
|
|
cairo_rectangle_t crect;
|
|
|
|
crect.x = draw.x0;
|
|
|
|
crect.y = draw.y0;
|
|
|
|
crect.height = draw.height();
|
|
|
|
crect.width = draw.width();
|
|
|
|
|
2017-01-18 18:23:10 -05:00
|
|
|
Duple p = position_offset();
|
|
|
|
|
2014-06-03 23:57:12 -04:00
|
|
|
context->save ();
|
2017-01-18 18:23:10 -05:00
|
|
|
context->translate (p.x, p.y);
|
2014-06-03 23:57:12 -04:00
|
|
|
//context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
|
2017-01-18 18:23:10 -05:00
|
|
|
//context->clip ();
|
2014-06-03 23:57:12 -04:00
|
|
|
|
2017-03-20 12:11:56 -04:00
|
|
|
_widget.render (context, &crect);
|
2014-06-03 23:57:12 -04:00
|
|
|
|
|
|
|
context->restore ();
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:31:35 -05:00
|
|
|
void
|
2021-08-04 01:21:55 -04:00
|
|
|
Widget::_size_allocate (Rect const & r)
|
2017-01-30 10:31:35 -05:00
|
|
|
{
|
2021-08-04 01:21:55 -04:00
|
|
|
Item::_size_allocate (r);
|
2017-01-30 10:31:35 -05:00
|
|
|
Gtk::Allocation alloc;
|
|
|
|
alloc.set_x (0);
|
|
|
|
alloc.set_y (0);
|
|
|
|
alloc.set_width (r.width());
|
|
|
|
alloc.set_height (r.height());
|
|
|
|
_widget.size_allocate (alloc);
|
|
|
|
}
|
|
|
|
|
2014-06-03 23:57:12 -04:00
|
|
|
void
|
|
|
|
Widget::compute_bounding_box () const
|
|
|
|
{
|
2021-09-10 14:59:29 -04:00
|
|
|
if (_allocation) {
|
|
|
|
_bounding_box = Rect (0, 0, _allocation.width(), _allocation.height());
|
|
|
|
} else {
|
2022-01-26 16:00:02 -05:00
|
|
|
GtkRequisition req = _widget.size_request ();
|
2021-09-10 14:59:29 -04:00
|
|
|
_bounding_box = Rect (0., 0., req.width, req.height);
|
|
|
|
}
|
2014-06-03 23:57:12 -04:00
|
|
|
|
2021-07-27 15:13:14 -04:00
|
|
|
bb_clean ();
|
2014-06-03 23:57:12 -04:00
|
|
|
}
|