Tooltips for audio matrix.
authorCarl Hetherington <cth@carlh.net>
Mon, 6 Jan 2014 22:30:35 +0000 (22:30 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 6 Jan 2014 22:30:35 +0000 (22:30 +0000)
src/wx/audio_mapping_view.cc
src/wx/audio_mapping_view.h

index 54749845d6977146313c74d94d265df43a10a72d..9fa57a1b10b2f21dc0aa54674d1ea543e6284289 100644 (file)
@@ -104,6 +104,8 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
        : wxPanel (parent, wxID_ANY)
        , _menu_row (0)
        , _menu_column (1)
+       , _last_tooltip_row (0)
+       , _last_tooltip_column (0)
 {
        _grid = new wxGrid (this, wxID_ANY);
 
@@ -123,6 +125,7 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
 
        Bind (wxEVT_GRID_CELL_LEFT_CLICK, boost::bind (&AudioMappingView::left_click, this, _1));
        Bind (wxEVT_GRID_CELL_RIGHT_CLICK, boost::bind (&AudioMappingView::right_click, this, _1));
+       _grid->GetGridWindow()->Bind (wxEVT_MOTION, boost::bind (&AudioMappingView::mouse_moved, this, _1));
 
        _menu = new wxMenu;
        _menu->Append (ID_off, _("Off"));
@@ -136,6 +139,14 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
        Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&AudioMappingView::edit, this), ID_edit);
 }
 
+void
+AudioMappingView::map_changed ()
+{
+       update_cells ();
+       Changed (_map);
+       _last_tooltip_column = -1;
+}      
+
 void
 AudioMappingView::left_click (wxGridEvent& ev)
 {
@@ -151,8 +162,7 @@ AudioMappingView::left_click (wxGridEvent& ev)
                _map.set (ev.GetRow(), d, 1);
        }
 
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
@@ -171,24 +181,21 @@ void
 AudioMappingView::off ()
 {
        _map.set (_menu_row, static_cast<libdcp::Channel> (_menu_column - 1), 0);
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
 AudioMappingView::full ()
 {
        _map.set (_menu_row, static_cast<libdcp::Channel> (_menu_column - 1), 1);
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
 AudioMappingView::minus3dB ()
 {
        _map.set (_menu_row, static_cast<libdcp::Channel> (_menu_column - 1), 1 / sqrt (2));
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
@@ -199,8 +206,7 @@ AudioMappingView::edit ()
        AudioGainDialog* dialog = new AudioGainDialog (this, _menu_row, _menu_column - 1, _map.get (_menu_row, d));
        if (dialog->ShowModal () == wxID_OK) {
                _map.set (_menu_row, d, dialog->value ());
-               update_cells ();
-               Changed (_map);
+               map_changed ();
        }
        
        dialog->Destroy ();
@@ -288,3 +294,40 @@ AudioMappingView::set_column_labels ()
 
        _grid->AutoSize ();
 }
+
+void
+AudioMappingView::mouse_moved (wxMouseEvent& ev)
+{
+       int xx;
+       int yy;
+       _grid->CalcUnscrolledPosition (ev.GetX(), ev.GetY(), &xx, &yy);
+
+       int const row = _grid->YToRow (yy);
+       int const column = _grid->XToCol (xx);
+
+       if (row < 0 || column < 1) {
+               _grid->GetGridWindow()->SetToolTip ("");
+               _last_tooltip_row = row;
+               _last_tooltip_column = column;
+       }
+
+       if (row != _last_tooltip_row || column != _last_tooltip_column) {
+
+               wxString s;
+               float const gain = _map.get (row, static_cast<libdcp::Channel> (column - 1));
+               if (gain == 0) {
+                       s = wxString::Format (_("No audio will be passed from content channel %d to DCP channel %d."), row + 1, column);
+               } else if (gain == 1) {
+                       s = wxString::Format (_("Audio will be passed from content channel %d to DCP channel %d unaltered."), row + 1, column);
+               } else {
+                       float const dB = 20 * log10 (gain);
+                       s = wxString::Format (_("Audio will be passed from content channel %d to DCP channel %d with gain %.1fdB."), row + 1, column, dB);
+               }
+               
+               _grid->GetGridWindow()->SetToolTip (s + " " + _("Right click to change gain."));
+               _last_tooltip_row = row;
+               _last_tooltip_column = column;
+       }
+
+        ev.Skip ();
+}
index 31b6e6e3cbaf4cba30eb489feb058d75c72e1b0f..26f1746e09bbeb9c73d86a6c1ce761bc36efa81c 100644 (file)
@@ -35,8 +35,10 @@ public:
 private:
        void left_click (wxGridEvent &);
        void right_click (wxGridEvent &);
+       void mouse_moved (wxMouseEvent &);
        void set_column_labels ();
        void update_cells ();
+       void map_changed ();
 
        void off ();
        void full ();
@@ -50,4 +52,7 @@ private:
        wxMenu* _menu;
        int _menu_row;
        int _menu_column;
+
+       int _last_tooltip_row;
+       int _last_tooltip_column;
 };