2 Copyright (C) 2014 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "pbd/compose.h"
23 #include "canvas/canvas.h"
24 #include "canvas/debug.h"
25 #include "canvas/scroll_group.h"
28 using namespace ArdourCanvas;
30 ScrollGroup::ScrollGroup (Canvas* c, ScrollSensitivity s, bool clip)
32 , _scroll_sensitivity (s)
37 ScrollGroup::ScrollGroup (Item* parent, ScrollSensitivity s, bool clip)
39 , _scroll_sensitivity (s)
45 ScrollGroup::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
47 /* clip the draw to the area that this scroll group nominally occupies
48 * WITHOUT scroll offsets in effect
51 boost::optional<Rect> r = bounding_box();
58 /* kludge: clip disabled, because for some reason the cursor scroll
59 group requires scroll offsets here to clip correctly yet everything
60 else does not. I can't figure this out, so since not clipping a
61 single arrow isn't the end of the world, just don't clip. */
62 Container::render (area, context);
65 Rect self (_position.x + r.get().x0,
66 _position.y + r.get().y0,
67 _position.x + r.get().x1,
68 _position.y + r.get().y1);
70 self.x1 = min (_position.x + _canvas->width(), self.x1);
71 self.y1 = min (_position.y + _canvas->height(), self.y1);
74 context->rectangle (self.x0, self.y0, self.width(), self.height());
77 Container::render (area, context);
83 ScrollGroup::scroll_to (Duple const& d)
85 if (_scroll_sensitivity & ScrollsHorizontally) {
86 _scroll_offset.x = d.x;
89 if (_scroll_sensitivity & ScrollsVertically) {
90 _scroll_offset.y = d.y;
95 ScrollGroup::covers_canvas (Duple const& d) const
97 boost::optional<Rect> r = bounding_box ();
103 return r->contains (d);
107 ScrollGroup::covers_window (Duple const& d) const
109 boost::optional<Rect> r = bounding_box ();
115 Rect w = r->translate (-_scroll_offset);
117 return w.contains (d);