2016-07-10 08:37:45 -04:00
|
|
|
/*
|
2019-08-03 08:34:29 -04:00
|
|
|
* Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-07-10 08:37:45 -04:00
|
|
|
|
|
|
|
#include <cairomm/context.h>
|
|
|
|
#include <cairomm/surface.h>
|
2016-09-16 09:39:28 -04:00
|
|
|
#include <cairomm/region.h>
|
2016-07-10 08:37:45 -04:00
|
|
|
#include <pangomm/layout.h>
|
|
|
|
|
2016-09-16 09:39:28 -04:00
|
|
|
#include "canvas/text.h"
|
2016-09-28 17:24:14 -04:00
|
|
|
#include "canvas/types.h"
|
2016-09-16 09:39:28 -04:00
|
|
|
#include "canvas/rectangle.h"
|
2017-07-17 12:34:35 -04:00
|
|
|
#include "gtkmm2ext/colors.h"
|
2016-09-16 09:39:28 -04:00
|
|
|
|
|
|
|
#include "canvas.h"
|
2016-07-10 08:37:45 -04:00
|
|
|
#include "gui.h"
|
2016-09-16 09:39:28 -04:00
|
|
|
#include "push2.h"
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-28 17:24:14 -04:00
|
|
|
#include "menu.h"
|
|
|
|
|
2018-09-21 13:05:39 -04:00
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
2016-09-28 17:24:14 -04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#define Rect ArdourCanvas::Rect
|
|
|
|
#endif
|
|
|
|
|
2016-07-10 08:37:45 -04:00
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace Glib;
|
|
|
|
using namespace ArdourSurface;
|
2016-09-16 09:39:28 -04:00
|
|
|
using namespace ArdourCanvas;
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2021-06-18 20:31:35 -04:00
|
|
|
Push2Menu::Push2Menu (Item* parent, std::vector<std::string> s)
|
2016-09-16 09:39:28 -04:00
|
|
|
: Container (parent)
|
2021-06-18 16:33:32 -04:00
|
|
|
, _baseline (-1)
|
|
|
|
, _ncols (0)
|
|
|
|
, _nrows (0)
|
|
|
|
, _wrap (true)
|
|
|
|
, _first (0)
|
|
|
|
, _last (0)
|
2016-09-23 15:34:17 -04:00
|
|
|
, _active (0)
|
2016-07-10 08:37:45 -04:00
|
|
|
{
|
2016-09-21 16:25:01 -04:00
|
|
|
Pango::FontDescription fd ("Sans 10");
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_baseline < 0) {
|
2016-09-16 09:39:28 -04:00
|
|
|
Push2Canvas* p2c = dynamic_cast<Push2Canvas*> (canvas());
|
2021-06-18 20:32:09 -04:00
|
|
|
Glib::RefPtr<Pango::Layout> throwaway = Pango::Layout::create (p2c->get_pango_context());
|
2016-09-21 16:25:01 -04:00
|
|
|
throwaway->set_font_description (fd);
|
2016-07-10 08:37:45 -04:00
|
|
|
throwaway->set_text (X_("Hg")); /* ascender + descender) */
|
|
|
|
int h, w;
|
|
|
|
throwaway->get_pixel_size (w, h);
|
2021-06-18 16:33:32 -04:00
|
|
|
_baseline = h;
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
_active_bg = new ArdourCanvas::Rectangle (this);
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2021-06-18 20:31:35 -04:00
|
|
|
for (std::vector<std::string>::iterator si = s.begin(); si != s.end(); ++si) {
|
2016-09-16 09:39:28 -04:00
|
|
|
Text* t = new Text (this);
|
2016-09-21 16:25:01 -04:00
|
|
|
t->set_font_description (fd);
|
|
|
|
t->set (*si);
|
2021-06-18 16:33:32 -04:00
|
|
|
_displays.push_back (t);
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
void
|
|
|
|
Push2Menu::set_layout (int c, int r)
|
|
|
|
{
|
2021-06-18 16:33:32 -04:00
|
|
|
_ncols = c;
|
|
|
|
_nrows = r;
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
set_active (_active);
|
|
|
|
rearrange (_active);
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-21 16:25:01 -04:00
|
|
|
Push2Menu::rearrange (uint32_t initial_display)
|
2016-07-10 08:37:45 -04:00
|
|
|
{
|
2021-06-18 16:33:32 -04:00
|
|
|
if (initial_display >= _displays.size()) {
|
2016-07-10 08:37:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-18 20:31:35 -04:00
|
|
|
std::vector<Text*>::iterator i = _displays.begin();
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
/* move to first */
|
|
|
|
|
|
|
|
for (uint32_t n = 0; n < initial_display; ++n) {
|
|
|
|
(*i)->hide ();
|
|
|
|
++i;
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
uint32_t index = initial_display;
|
|
|
|
uint32_t col = 0;
|
|
|
|
uint32_t row = 0;
|
|
|
|
bool active_shown = false;
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
while (i != _displays.end()) {
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
Coord x = col * Push2Canvas::inter_button_spacing();
|
2021-06-18 20:32:09 -04:00
|
|
|
Coord y = row * _baseline;
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
(*i)->set_position (Duple (x, y));
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
if (index == _active) {
|
2021-06-18 16:33:32 -04:00
|
|
|
_active_bg->set (Rect (x - 1,
|
|
|
|
y - 1,
|
|
|
|
x - 1 + Push2Canvas::inter_button_spacing (),
|
|
|
|
y - 1 + _baseline));
|
|
|
|
|
|
|
|
_active_bg->show ();
|
2016-09-21 16:25:01 -04:00
|
|
|
active_shown = true;
|
|
|
|
}
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
(*i)->show ();
|
2021-06-18 16:33:32 -04:00
|
|
|
_last = index;
|
2016-09-21 16:25:01 -04:00
|
|
|
++i;
|
|
|
|
++index;
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
if (++row >= _nrows) {
|
2016-09-21 16:25:01 -04:00
|
|
|
row = 0;
|
2021-06-18 16:33:32 -04:00
|
|
|
if (++col >= _ncols) {
|
2016-09-21 16:25:01 -04:00
|
|
|
/* no more to display */
|
|
|
|
break;
|
|
|
|
}
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
2016-09-21 16:25:01 -04:00
|
|
|
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
while (i != _displays.end()) {
|
2016-09-21 16:25:01 -04:00
|
|
|
(*i)->hide ();
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!active_shown) {
|
2021-06-18 16:33:32 -04:00
|
|
|
_active_bg->hide ();
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
_first = initial_display;
|
2016-09-21 16:25:01 -04:00
|
|
|
|
|
|
|
Rearranged (); /* EMIT SIGNAL */
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-21 16:25:01 -04:00
|
|
|
Push2Menu::scroll (Direction dir, bool page)
|
2016-07-10 08:37:45 -04:00
|
|
|
{
|
2016-09-21 16:25:01 -04:00
|
|
|
switch (dir) {
|
|
|
|
case DirectionUp:
|
|
|
|
if (_active == 0) {
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_wrap) {
|
|
|
|
set_active (_displays.size() - 1);
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_active (_active - 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DirectionDown:
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_active == _displays.size() - 1) {
|
|
|
|
if (_wrap) {
|
2016-09-21 16:25:01 -04:00
|
|
|
set_active (0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_active (_active + 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DirectionLeft:
|
|
|
|
if (page) {
|
2021-06-18 20:31:35 -04:00
|
|
|
set_active (std::max (0, (int) (_first - (_nrows * _ncols))));
|
2016-09-21 16:25:01 -04:00
|
|
|
} else {
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_active / _nrows == 0) {
|
2016-09-21 16:25:01 -04:00
|
|
|
/* in the first column, go to last column, same row */
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_wrap) {
|
|
|
|
set_active (_displays.size() - 1 - active_row ());
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* move to same row, previous column */
|
2021-06-18 16:33:32 -04:00
|
|
|
set_active (_active - _nrows);
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DirectionRight:
|
|
|
|
if (page) {
|
2021-06-18 20:31:35 -04:00
|
|
|
set_active (std::min ((uint32_t) _displays.size(), _first + (_nrows * _ncols)));
|
2016-09-21 16:25:01 -04:00
|
|
|
} else {
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_active / _nrows == _ncols) {
|
2016-09-21 16:25:01 -04:00
|
|
|
/* in the last column, go to same row in first column */
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_wrap) {
|
|
|
|
set_active (active_row());
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* move to same row, next column */
|
2021-06-18 16:33:32 -04:00
|
|
|
set_active (_active + _nrows);
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
void
|
|
|
|
Push2Menu::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
|
|
|
|
{
|
|
|
|
render_children (area, context);
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-21 16:25:01 -04:00
|
|
|
Push2Menu::set_active (uint32_t index)
|
2016-07-10 08:37:45 -04:00
|
|
|
{
|
2016-09-23 15:34:17 -04:00
|
|
|
if (!parent() || (index == _active)) {
|
2016-07-10 08:37:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
if (index >= _displays.size()) {
|
|
|
|
_active_bg->hide ();
|
2016-07-10 08:37:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
/* set text color for old active item, and the new one */
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_active < _displays.size()) {
|
|
|
|
_displays[_active]->set_color (_text_color);
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
_displays[index]->set_color (_contrast_color);
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
Duple p = _displays[index]->position ();
|
2016-09-16 09:39:28 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
_active_bg->set (Rect (p.x - 1, p.y - 1, p.x - 1 + Push2Canvas::inter_button_spacing(), p.y - 1 + _baseline ));
|
|
|
|
_active_bg->show ();
|
2016-09-21 16:25:01 -04:00
|
|
|
_active = index;
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_active < _first) {
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
/* we jumped before current visible range : try to put its column first
|
|
|
|
*/
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
rearrange (active_top());
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
} else if (_active > _last) {
|
2016-09-21 16:25:01 -04:00
|
|
|
|
|
|
|
/* we jumped after current visible range : try putting its
|
|
|
|
* column last
|
|
|
|
*/
|
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
rearrange (active_top() - ((_ncols - 1) * _nrows));
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
ActiveChanged (); /* EMIT SIGNAL */
|
|
|
|
}
|
2016-07-10 08:37:45 -04:00
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
void
|
2017-07-17 12:34:35 -04:00
|
|
|
Push2Menu::set_text_color (Gtkmm2ext::Color c)
|
2016-09-21 16:25:01 -04:00
|
|
|
{
|
2021-06-18 16:33:32 -04:00
|
|
|
_text_color = c;
|
2016-09-21 16:25:01 -04:00
|
|
|
|
2021-06-18 20:31:35 -04:00
|
|
|
for (std::vector<Text*>::iterator t = _displays.begin(); t != _displays.end(); ++t) {
|
2016-09-21 16:25:01 -04:00
|
|
|
(*t)->set_color (c);
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-21 16:25:01 -04:00
|
|
|
void
|
2017-07-17 12:34:35 -04:00
|
|
|
Push2Menu::set_active_color (Gtkmm2ext::Color c)
|
2016-07-10 08:37:45 -04:00
|
|
|
{
|
2021-06-18 16:33:32 -04:00
|
|
|
_active_color = c;
|
|
|
|
_contrast_color = Gtkmm2ext::contrasting_text_color (_active_color);
|
|
|
|
if (_active_bg) {
|
|
|
|
_active_bg->set_fill_color (c);
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
2021-06-18 16:33:32 -04:00
|
|
|
if (_active < _displays.size()) {
|
|
|
|
_displays[_active]->set_color (_contrast_color);
|
2016-09-21 16:25:01 -04:00
|
|
|
}
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-21 16:25:01 -04:00
|
|
|
Push2Menu::set_font_description (Pango::FontDescription fd)
|
2016-07-10 08:37:45 -04:00
|
|
|
{
|
2021-06-18 16:33:32 -04:00
|
|
|
_font_description = fd;
|
2016-09-21 16:25:01 -04:00
|
|
|
|
2021-06-18 20:31:35 -04:00
|
|
|
for (std::vector<Text*>::iterator t = _displays.begin(); t != _displays.end(); ++t) {
|
2016-09-21 16:25:01 -04:00
|
|
|
(*t)->set_font_description (fd);
|
|
|
|
}
|
2016-07-10 08:37:45 -04:00
|
|
|
}
|