diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2016-09-16 08:39:28 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2016-09-27 14:59:31 -0500 |
commit | 7c9f3acc60fb29a562d28d1f43a9e22298545bf1 (patch) | |
tree | 7418a4922ff7670d6ffc08dce39432afd1e5669c /libs/surfaces/push2/menu.cc | |
parent | 2810e5619a1926a286c6192143ada4973066efd8 (diff) |
first compiling and theoretically correct version of Push2 canvas display.
Not tested with device at this point
Diffstat (limited to 'libs/surfaces/push2/menu.cc')
-rw-r--r-- | libs/surfaces/push2/menu.cc | 110 |
1 files changed, 59 insertions, 51 deletions
diff --git a/libs/surfaces/push2/menu.cc b/libs/surfaces/push2/menu.cc index cdb5d60e91..da1c98ac04 100644 --- a/libs/surfaces/push2/menu.cc +++ b/libs/surfaces/push2/menu.cc @@ -18,38 +18,59 @@ #include <cairomm/context.h> #include <cairomm/surface.h> +#include <cairomm/region.h> #include <pangomm/layout.h> -#include "push2.h" +#include "canvas/text.h" +#include "canvas/rectangle.h" +#include "canvas/colors.h" + +#include "canvas.h" #include "gui.h" +#include "push2.h" using namespace ARDOUR; using namespace std; using namespace PBD; using namespace Glib; using namespace ArdourSurface; +using namespace ArdourCanvas; #include "pbd/i18n.h" #include "menu.h" -Push2Menu::Push2Menu (Cairo::RefPtr<Cairo::Context> context) - : _dirty (true) +Push2Menu::Push2Menu (Item* parent) + : Container (parent) + , baseline (-1) { Pango::FontDescription fd2 ("Sans 10"); - { - Glib::RefPtr<Pango::Layout> throwaway = Pango::Layout::create (context); + if (baseline < 0) { + Push2Canvas* p2c = dynamic_cast<Push2Canvas*> (canvas()); + Glib::RefPtr<Pango::Layout> throwaway = Pango::Layout::create (p2c->image_context()); throwaway->set_font_description (fd2); throwaway->set_text (X_("Hg")); /* ascender + descender) */ int h, w; throwaway->get_pixel_size (w, h); baseline = h; - nrows = Push2::rows / baseline; + // nrows = Push2::rows / baseline; } + for (int n = 0; n < 8; ++n) { - columns[n].layout = Pango::Layout::create (context); - columns[n].layout->set_font_description (fd2); + Text* t = new Text (this); + t->set_font_description (fd2); + t->set_color (rgba_to_color (0.23, 0.0, 0.349, 1.0)); + + const double x = 10.0 + (n * Push2Canvas::inter_button_spacing()); + const double y = 2.0; + t->set_position (Duple (x, y)); + + Rectangle* r = new Rectangle (this); + r->set (Rect (x, y, x + Push2Canvas::inter_button_spacing(), y + baseline)); + + columns[n].lines = t; + columns[n].active_bg = r; columns[n].top = -1; columns[n].active = -1; } @@ -71,8 +92,6 @@ Push2Menu::fill_column (int col, vector<string> v) } set_text (col, 0); - - _dirty = true; } void @@ -86,6 +105,7 @@ Push2Menu::set_text (int col, int top_row) return; } + vector<string>::iterator s = columns[col].text.begin(); s += top_row; @@ -101,10 +121,10 @@ Push2Menu::set_text (int col, int top_row) } } - columns[col].layout->set_text (rows); + columns[col].lines->set (rows); columns[col].top = top_row; - _dirty = true; + redraw (); } void @@ -115,24 +135,43 @@ Push2Menu::scroll (int col, int dir) } else { set_text (col, columns[col].top - 1); } + + redraw (); } void Push2Menu::set_active (int col, int index) { if (col < 0 || col > 7) { + columns[col].active_bg->hide (); return; } if (index < 0 || index > (int) columns[col].text.size()) { + columns[col].active_bg->hide (); return; } columns[col].active = index; + int effective_row = columns[col].active - columns[col].top; + + /* Move active bg */ + + Duple p (columns[col].active_bg->position()); + + columns[col].active_bg->set (Rect (p.x, p.y + (effective_row * baseline), + p.x + Push2Canvas::inter_button_spacing(), p.y + baseline)); + columns[col].active_bg->show (); + + if (columns[col].active < nrows/2) { + set_text (col, 0); + } else { + set_text (col, columns[col].active - (nrows/2) + 1); + } ActiveChanged (); /* emit signal */ - _dirty = true; + redraw (); } void @@ -149,31 +188,25 @@ Push2Menu::step_active (int col, int dir) if (dir < 0) { if (columns[col].active == -1) { - columns[col].active = 0; + set_active (col, -1); } else { columns[col].active = columns[col].active - 1; if (columns[col].active < 0) { - columns[col].active = columns[col].text.size() - 1; + set_active (col, columns[col].text.size() - 1); } } } else { if (columns[col].active == -1) { - columns[col].active = 0; + set_active (col, 0); } else { columns[col].active = columns[col].active + 1; if (columns[col].active >= (int) columns[col].text.size()) { - columns[col].active = 0; + set_active (col, 0); } } } - if (columns[col].active < nrows/2) { - set_text (col, 0); - } else { - set_text (col, columns[col].active - (nrows/2) + 1); - } - - _dirty = true; + redraw (); } int @@ -187,32 +220,7 @@ Push2Menu::get_active (int col) } void -Push2Menu::redraw (Cairo::RefPtr<Cairo::Context> context, bool force) const +Push2Menu::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const { - for (int n = 0; n < 8; ++n) { - - /* Active: move to column/now, draw background indicator - for active row. - */ - - const double x = 10.0 + (n * 120.0); - const double y = 2.0; - - if (columns[n].active >= 0) { - int effective_row = columns[n].active - columns[n].top; - context->rectangle (x, y + (effective_row * baseline), 120.0, baseline); - context->set_source_rgb (1.0, 1.0, 1.0); - context->fill (); - } - - /* now draw all the text, in one go */ - - context->move_to (x, y); - context->set_source_rgb (0.23, 0.0, 0.349); - columns[n].layout->update_from_cairo_context (context); - columns[n].layout->show_in_cairo_context (context); - - } - - _dirty = false; + render_children (area, context); } |