2 Copyright (C) 2016 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.
19 #include <cairomm/context.h>
20 #include <cairomm/surface.h>
21 #include <pangomm/layout.h>
26 using namespace ARDOUR;
30 using namespace ArdourSurface;
35 Push2Menu::Push2Menu (Cairo::RefPtr<Cairo::Context> context)
38 Pango::FontDescription fd2 ("Sans 10");
41 Glib::RefPtr<Pango::Layout> throwaway = Pango::Layout::create (context);
42 throwaway->set_font_description (fd2);
43 throwaway->set_text (X_("Hg")); /* ascender + descender) */
45 throwaway->get_pixel_size (w, h);
47 nrows = Push2::rows / baseline;
50 for (int n = 0; n < 8; ++n) {
51 columns[n].layout = Pango::Layout::create (context);
52 columns[n].layout->set_font_description (fd2);
54 columns[n].active = -1;
59 Push2Menu::fill_column (int col, vector<string> v)
61 if (col < 0 || col > 7) {
65 columns[col].text = v;
68 columns[col].active = -1;
70 columns[col].active = 0;
79 Push2Menu::set_text (int col, int top_row)
81 if (top_row > (int) columns[col].text.size() - nrows || top_row < 0) {
85 if (top_row == columns[col].top) {
89 vector<string>::iterator s = columns[col].text.begin();
97 if (s != columns[col].text.end()) {
104 columns[col].layout->set_text (rows);
105 columns[col].top = top_row;
111 Push2Menu::scroll (int col, int dir)
114 set_text (col, columns[col].top + 1);
116 set_text (col, columns[col].top - 1);
121 Push2Menu::set_active (int col, int index)
123 if (col < 0 || col > 7) {
127 if (index < 0 || index > (int) columns[col].text.size()) {
131 columns[col].active = index;
133 ActiveChanged (); /* emit signal */
139 Push2Menu::step_active (int col, int dir)
141 if (col < 0 || col > 7) {
145 if (columns[col].text.empty()) {
151 if (columns[col].active == -1) {
152 columns[col].active = 0;
154 columns[col].active = columns[col].active - 1;
155 if (columns[col].active < 0) {
156 columns[col].active = columns[col].text.size() - 1;
160 if (columns[col].active == -1) {
161 columns[col].active = 0;
163 columns[col].active = columns[col].active + 1;
164 if (columns[col].active >= (int) columns[col].text.size()) {
165 columns[col].active = 0;
170 if (columns[col].active < nrows/2) {
173 set_text (col, columns[col].active - (nrows/2) + 1);
180 Push2Menu::get_active (int col)
182 if (col < 0 || col > 7) {
186 return columns[col].active;
190 Push2Menu::redraw (Cairo::RefPtr<Cairo::Context> context, bool force) const
192 for (int n = 0; n < 8; ++n) {
194 /* Active: move to column/now, draw background indicator
198 const double x = 10.0 + (n * 120.0);
199 const double y = 2.0;
201 if (columns[n].active >= 0) {
202 int effective_row = columns[n].active - columns[n].top;
203 context->rectangle (x, y + (effective_row * baseline), 120.0, baseline);
204 context->set_source_rgb (1.0, 1.0, 1.0);
208 /* now draw all the text, in one go */
210 context->move_to (x, y);
211 context->set_source_rgb (0.23, 0.0, 0.349);
212 columns[n].layout->update_from_cairo_context (context);
213 columns[n].layout->show_in_cairo_context (context);