-/*****************************************************************************
- * Definition of VolCtrl class.
- *****************************************************************************/
-class wxVolCtrl: public wxGauge
-{
-public:
- /* Constructor */
- wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
- wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
- virtual ~wxVolCtrl() {};
-
- void UpdateVolume();
- int GetVolume();
-
- void OnChange( wxMouseEvent& event );
-
-private:
- intf_thread_t *p_intf;
-
- DECLARE_EVENT_TABLE();
-};
-
-BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
- /* Mouse events */
- EVT_LEFT_DOWN(wxVolCtrl::OnChange)
- EVT_MOTION(wxVolCtrl::OnChange)
-END_EVENT_TABLE()
-
-wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
- wxPoint point, wxSize size )
- : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
-{
- p_intf = _p_intf;
- UpdateVolume();
-}
-
-void wxVolCtrl::OnChange( wxMouseEvent& event )
-{
- if( !event.LeftDown() && !event.LeftIsDown() ) return;
-
- int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
- aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
- UpdateVolume();
-}
-
-void wxVolCtrl::UpdateVolume()
-{
- audio_volume_t i_volume;
- aout_VolumeGet( p_intf, &i_volume );
-
- int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
- if( i_gauge_volume == GetValue() ) return;
-
- SetValue( i_gauge_volume );
- SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
- i_gauge_volume / 2 ) );
-}
-
-#if defined(__WXGTK__)
-#define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
-#else
-#define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
-#endif
-VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
- :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
- wxBORDER_NONE ),
- i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
- b_mute(0), p_intf(_p_intf)
-{
- gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
- wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
-}
-
-void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
-{
- wxPaintDC dc( this );
- wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
- dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
-}
-
-void VLCVolCtrl::OnChange( wxMouseEvent& event )
-{
- if( event.GetX() < TOOLBAR_BMP_WIDTH )
- {
- int i_volume;
- aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
-
- b_mute = !b_mute;
- Refresh();
- }
-}
-
-void VLCVolCtrl::UpdateVolume()
-{
- gauge->UpdateVolume();
-
- int i_volume = gauge->GetValue();
- if( !!i_volume == !b_mute ) return;
- b_mute = !b_mute;
- Refresh();
-}
-