Add tooltip for input groups (#1557).
authorCarl Hetherington <cth@carlh.net>
Tue, 14 May 2019 22:06:53 +0000 (23:06 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 14 May 2019 22:08:58 +0000 (23:08 +0100)
Backported from ca20cd4711c6b56ac238cf2313d2d4d1db92fe1a in v2.15.x.

src/wx/audio_mapping_view.cc
src/wx/audio_mapping_view.h

index 9d776b63d7184a4e5a0f2a8fa5a9759e39f1a721..ccd78bb90f9cce5c4cdb875ef1d14189085b0b1e 100644 (file)
@@ -395,6 +395,24 @@ AudioMappingView::mouse_event_to_channels (wxMouseEvent& ev) const
        return make_pair (input, output);
 }
 
+optional<string>
+AudioMappingView::mouse_event_to_input_group_name (wxMouseEvent& ev) const
+{
+       int const x = ev.GetX() + _horizontal_scroll->GetThumbPosition();
+       if (x < GRID_SPACING || x > (2 * GRID_SPACING)) {
+               return optional<string>();
+       }
+
+       int y = (ev.GetY() + _vertical_scroll->GetThumbPosition() - (GRID_SPACING * 2)) / GRID_SPACING;
+       BOOST_FOREACH (Group i, _input_groups) {
+               if (i.from <= y && y <= i.to) {
+                       return i.name;
+               }
+       }
+
+       return optional<string>();
+}
+
 void
 AudioMappingView::left_down (wxMouseEvent& ev)
 {
@@ -512,28 +530,40 @@ void
 AudioMappingView::motion (wxMouseEvent& ev)
 {
        optional<pair<int, int> > channels = mouse_event_to_channels (ev);
-       if (!channels) {
-               SetToolTip ("");
-               _last_tooltip_channels = channels;
-               return;
-       }
+       if (channels) {
+               if (channels != _last_tooltip_channels) {
+                       wxString s;
+                       float const gain = _map.get(channels->first, channels->second);
+                       if (gain == 0) {
+                               s = wxString::Format (
+                                       _("No audio will be passed from content channel %d to DCP channel %d."),
+                                       channels->first + 1, channels->second + 1
+                                       );
+                       } else if (gain == 1) {
+                               s = wxString::Format (
+                                       _("Audio will be passed from content channel %d to DCP channel %d unaltered."),
+                                       channels->first + 1, channels->second + 1
+                                       );
+                       } 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."),
+                                       channels->first + 1, channels->second + 1, dB
+                                       );
+                       }
 
-       if (channels != _last_tooltip_channels) {
-               wxString s;
-               float const gain = _map.get(channels->first, channels->second);
-               if (gain == 0) {
-                       s = wxString::Format (_("No audio will be passed from content channel %d to DCP channel %d."), channels->first + 1, channels->second + 1);
-               } else if (gain == 1) {
-                       s = wxString::Format (_("Audio will be passed from content channel %d to DCP channel %d unaltered."), channels->first + 1, channels->second + 1);
+                       SetToolTip (s + " " + _("Right click to change gain."));
+               }
+       } else {
+               optional<string> group = mouse_event_to_input_group_name (ev);
+               if (group) {
+                       SetToolTip (std_to_wx(*group));
                } 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."), channels->first + 1, channels->second + 1, dB);
+                       SetToolTip ("");
                }
-
-               SetToolTip (s + " " + _("Right click to change gain."));
-               _last_tooltip_channels = channels;
        }
 
+       _last_tooltip_channels = channels;
         ev.Skip ();
 }
 
index 527510c779117b9ee5a7faa578ac7cd27124c9a0..a96757b5c986c49f049061e6a0734a74c34f08ce 100644 (file)
@@ -88,6 +88,7 @@ private:
        void motion (wxMouseEvent &);
        void mouse_wheel (wxMouseEvent &);
        boost::optional<std::pair<int, int> > mouse_event_to_channels (wxMouseEvent& ev) const;
+       boost::optional<std::string> mouse_event_to_input_group_name (wxMouseEvent& ev) const;
        void setup ();
 
        void off ();