globally change all use of "frame" to refer to audio into "sample".
[ardour.git] / libs / canvas / canvas / grid.h
1 /*
2     Copyright (C) 2018 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #ifndef __CANVAS_GRID_H__
20 #define __CANVAS_GRID_H__
21
22 #include <map>
23
24 #include "canvas/item.h"
25
26 namespace ArdourCanvas
27 {
28
29 class Rectangle;
30
31 /** Canvas container that renders its children in a grid layout
32  */
33 class LIBCANVAS_API Grid : public Item
34 {
35 public:
36         Grid (Canvas *);
37         Grid (Item *);
38         Grid (Item *, Duple const & position);
39
40         void set_row_spacing (double s);
41         void set_col_spacing (double s);
42
43         void set_padding (double top, double right = -1.0, double bottom = -1.0, double left = -1.0);
44         void set_margin (double top, double right = -1.0, double bottom = -1.0, double left = -1.0);
45
46         /* aliases so that CSS box model terms work */
47         void set_border_width (double w) { set_outline_width (w); }
48         void set_border_color (Gtkmm2ext::Color c)  { set_outline_color (c); }
49
50         void place (Item*, double x, double y, double col_span = 1, double row_span = 1);
51
52         void set_collapse_on_hide (bool);
53         void set_homogenous (bool);
54
55         void compute_bounding_box () const;
56         void render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
57
58   protected:
59         double row_spacing;
60         double col_spacing;
61         double top_padding, right_padding, bottom_padding, left_padding;
62         double top_margin, right_margin, bottom_margin, left_margin;
63
64         void child_changed ();
65   private:
66         struct ChildInfo {
67                 Item* item;
68                 double x;
69                 double y;
70                 double col_span;
71                 double row_span;
72         };
73
74         typedef std::map<Item*,ChildInfo> CoordsByItem;
75         CoordsByItem coords_by_item;
76
77         Rectangle *bg;
78         bool collapse_on_hide;
79         bool homogenous;
80
81         void reset_bg ();
82         void reposition_children ();
83 };
84
85 }
86
87 #endif