goodbye USE_TRACKS_CODE_FEATURES and is_tracks_build
[ardour.git] / libs / canvas / scroll_group.cc
1 /*
2  * Copyright (C) 2014-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015 David Robillard <d@drobilla.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include <iostream>
21
22 #include "pbd/compose.h"
23
24 #include "canvas/canvas.h"
25 #include "canvas/debug.h"
26 #include "canvas/scroll_group.h"
27
28 using namespace std;
29 using namespace ArdourCanvas;
30
31 ScrollGroup::ScrollGroup (Canvas* c, ScrollSensitivity s)
32         : Container (c)
33         , _scroll_sensitivity (s)
34 {
35 }
36
37 ScrollGroup::ScrollGroup (Item* parent, ScrollSensitivity s)
38         : Container (parent)
39         , _scroll_sensitivity (s)
40 {
41 }
42
43 void
44 ScrollGroup::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
45 {
46         /* clip the draw to the area that this scroll group nominally occupies
47          * WITHOUT scroll offsets in effect
48          */
49
50         Rect r = bounding_box();
51
52         if (!r) {
53                 return;
54         }
55
56         Rect self (_position.x + r.x0,
57                    _position.y + r.y0,
58                    _position.x + r.x1,
59                    _position.y + r.y1);
60
61         self.x1 = min (_position.x + _canvas->width(), self.x1);
62         self.y1 = min (_position.y + _canvas->height(), self.y1);
63
64         context->save ();
65         context->rectangle (self.x0, self.y0, self.width(), self.height());
66         context->clip ();
67
68         Container::render (area, context);
69
70         context->restore ();
71 }
72
73 void
74 ScrollGroup::scroll_to (Duple const& d)
75 {
76         if (_scroll_sensitivity & ScrollsHorizontally) {
77                 _scroll_offset.x = d.x;
78         }
79
80         if (_scroll_sensitivity & ScrollsVertically) {
81                 _scroll_offset.y = d.y;
82         }
83 }
84
85 bool
86 ScrollGroup::covers_canvas (Duple const& d) const
87 {
88         Rect r = bounding_box ();
89
90         if (!r) {
91                 return false;
92         }
93
94         /* Bounding box is in item coordinates, but we need
95            to consider the position of the bounding box
96            within the canvas.
97         */
98
99         return r.translate (position()).contains (d);
100 }
101
102 bool
103 ScrollGroup::covers_window (Duple const& d) const
104 {
105         Rect r = bounding_box ();
106
107         if (!r) {
108                 return false;
109         }
110
111         /* Bounding box is in item coordinates, but we need
112            to consider the position of the bounding box
113            within the canvas.
114         */
115
116         return r.translate (position()).contains (d);
117 }