]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/MediaControlView.cpp
A bit of headers cleanup
[vlc] / modules / gui / beos / MediaControlView.cpp
index e5cbf842512f1aa8178622f7f3757ea10d93aef8..02825b18569407fb56bf276c868339f9861a134d 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * MediaControlView.cpp: beos interface
  *****************************************************************************
- * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: MediaControlView.cpp,v 1.16 2003/04/22 16:36:16 titer Exp $
+ * Copyright (C) 1999, 2000, 2001 the VideoLAN team
+ * $Id$
  *
  * Authors: Tony Castley <tony@castley.net>
  *          Stephan Aßmus <stippi@yellowbites.com>
@@ -19,7 +19,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /* System headers */
 
 /* VLC headers */
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <vlc_interface.h>
+extern "C"
+{
+  #include <audio_output.h>
+}
 
 /* BeOS interface headers */
-#include "VlcWrapper.h"
 #include "Bitmaps.h"
 #include "DrawingTidbits.h"
 #include "InterfaceWindow.h"
@@ -61,7 +64,8 @@ const rgb_color kSeekRed = (rgb_color){ 255, 0, 0, 255 };
 const rgb_color kSeekRedLight = (rgb_color){ 255, 152, 152, 255 };
 const rgb_color kSeekRedShadow = (rgb_color){ 178, 0, 0, 255 };
 
-const char* kDisabledSeekMessage = _("Drop files to play");
+#define DISABLED_SEEK_MESSAGE _("Drop files to play")
+#define SEEKSLIDER_RANGE 2048
 
 enum
 {
@@ -72,22 +76,19 @@ enum
 };
 
 // constructor
-MediaControlView::MediaControlView(BRect frame, intf_thread_t *p_interface)
+MediaControlView::MediaControlView( intf_thread_t * _p_intf, BRect frame)
        : BBox(frame, NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED,
                   B_PLAIN_BORDER),
-      fScrubSem(B_ERROR),
-      fCurrentRate(DEFAULT_RATE),
-      fCurrentStatus(UNDEF_S),
+      p_intf( _p_intf ),
+      fCurrentRate(INPUT_RATE_DEFAULT),
+      fCurrentStatus(-1),
       fBottomControlHeight(0.0),
       fIsEnabled( true )
 {
-    p_intf = p_interface;
-
        BRect frame(0.0, 0.0, 10.0, 10.0);
        
     // Seek Slider
-    fSeekSlider = new SeekSlider(frame, "seek slider", this,
-                                 0, SEEKSLIDER_RANGE - 1);
+    fSeekSlider = new SeekSlider( p_intf, frame, "seek slider", this );
     fSeekSlider->SetValue(0);
     fSeekSlider->ResizeToPreferred();
     AddChild( fSeekSlider );
@@ -172,7 +173,7 @@ MediaControlView::MediaControlView(BRect frame, intf_thread_t *p_interface)
                                                                                   kVolumeSliderBitmapHeight - 1.0),
                                                                         "volume slider", 1, AOUT_VOLUME_MAX,
                                                                         new BMessage(VOLUME_CHG));
-       fVolumeSlider->SetValue(AOUT_VOLUME_DEFAULT);
+       fVolumeSlider->SetValue( config_GetInt( p_intf, "volume" ) );
        AddChild( fVolumeSlider );
        
        // Position Info View
@@ -199,8 +200,17 @@ MediaControlView::AttachedToWindow()
        fVolumeSlider->SetTarget(Window());
 
        BRect r(_MinFrame());
-       if (BMenuBar* menuBar = Window()->KeyMenuBar())
-               r.bottom += menuBar->Bounds().Height();
+       if (BMenuBar* menuBar = Window()->KeyMenuBar()) {
+               float width, height;
+               menuBar->GetPreferredSize(&width, &height);
+//             r.bottom += menuBar->Bounds().Height();
+               r.bottom += height;
+               // see that our calculated minimal width is not smaller than what
+               // the menubar can be
+               width -= r.Width();
+               if (width > 0.0)
+                       r.right += width;
+       }
 
        Window()->SetSizeLimits(r.Width(), r.Width() * 1.8, r.Height(), r.Height() * 1.3);
        if (!Window()->Bounds().Contains(r))
@@ -279,6 +289,10 @@ MediaControlView::Pulse()
        InterfaceWindow* window = dynamic_cast<InterfaceWindow*>(Window());
        if (window && window->IsStopped())
                        fPlayPause->SetStopped();
+
+    unsigned short i_volume;
+    aout_VolumeGet( p_intf, (audio_volume_t*)&i_volume );
+    fVolumeSlider->SetValue( i_volume );
 }
 
 // SetProgress
@@ -298,16 +312,13 @@ MediaControlView::SetStatus(int status, int rate)
     switch( status )
     {
         case PLAYING_S:
-        case FORWARD_S:
-        case BACKWARD_S:
-        case START_S:
+        case OPENNING_S:
+        case BUFFERING_S:
             fPlayPause->SetPlaying();
             break;
         case PAUSE_S:
             fPlayPause->SetPaused();
             break;
-        case UNDEF_S:
-        case NOT_STARTED_S:
         default:
             fPlayPause->SetStopped();
             break;
@@ -315,7 +326,7 @@ MediaControlView::SetStatus(int status, int rate)
        if (rate != fCurrentRate)
        {
                fCurrentRate = rate;
-           if ( rate < DEFAULT_RATE )
+           if ( rate < INPUT_RATE_DEFAULT )
            {
                // TODO: ...
            }
@@ -357,13 +368,6 @@ MediaControlView::SetAudioEnabled(bool enabled)
        fVolumeSlider->SetEnabled(enabled);
 }
 
-// GetSeekTo
-uint32
-MediaControlView::GetSeekTo() const
-{
-       return fSeekSlider->Value();
-}
-
 // GetVolume
 uint32
 MediaControlView::GetVolume() const
@@ -518,14 +522,13 @@ MediaControlView::_LayoutControl(BView* view, BRect frame,
 /*****************************************************************************
  * SeekSlider
  *****************************************************************************/
-SeekSlider::SeekSlider(BRect frame, const char* name, MediaControlView *owner,
-                                          int32 minValue, int32 maxValue)
+SeekSlider::SeekSlider( intf_thread_t * _p_intf,
+                        BRect frame, const char* name, MediaControlView *owner )
        : BControl(frame, name, NULL, NULL, B_FOLLOW_NONE,
                           B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
+         p_intf(_p_intf),
          fOwner(owner),
-         fTracking(false),
-         fMinValue(minValue),
-         fMaxValue(maxValue)
+         fTracking(false)
 {
        BFont font(be_plain_font);
        font.SetSize(9.0);
@@ -534,7 +537,6 @@ SeekSlider::SeekSlider(BRect frame, const char* name, MediaControlView *owner,
 
 SeekSlider::~SeekSlider()
 {
-       _EndSeek();
 }
 
 /*****************************************************************************
@@ -558,8 +560,8 @@ SeekSlider::Draw(BRect updateRect)
        float sliderStart = (r.left + knobWidth2);
        float sliderEnd = (r.right - knobWidth2);
        float knobPos = sliderStart
-                                       + floorf((sliderEnd - sliderStart - 1.0) * (Value() - fMinValue)
-                                       / (fMaxValue - fMinValue) + 0.5);
+                                       + floorf((sliderEnd - sliderStart - 1.0) * Value()
+                                       / SEEKSLIDER_RANGE);
        // draw both sides (the original from Be doesn't seem
        // to make a difference for enabled/disabled state)
 //     DrawBitmapAsync(fLeftSideBits, r.LeftTop());
@@ -695,7 +697,7 @@ SeekSlider::Draw(BRect updateRect)
                SetHighColor(darkShadow);
                SetLowColor(shadow);
                // stripes
-               float width = floorf(StringWidth(kDisabledSeekMessage));
+               float width = floorf(StringWidth(DISABLED_SEEK_MESSAGE));
                float textPos = r.left + r.Width() / 2.0 - width / 2.0;
                pattern stripes = {{ 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, 0xf8, 0xf1, 0xe3 }};
                BRect stripesRect(r);
@@ -712,7 +714,7 @@ SeekSlider::Draw(BRect updateRect)
                SetLowColor(darkShadow);
                font_height fh;
                GetFontHeight(&fh);
-               DrawString(kDisabledSeekMessage, BPoint(textPos, r.top + ceilf(fh.ascent) - 1.0));
+               DrawString(DISABLED_SEEK_MESSAGE, BPoint(textPos, r.top + ceilf(fh.ascent) - 1.0));
        }
 }
 
@@ -727,7 +729,6 @@ SeekSlider::MouseDown(BPoint where)
                SetValue(_ValueFor(where.x));
                fTracking = true;
                SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
-               _BeginSeek();
        }
 }
 
@@ -740,7 +741,6 @@ SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
        if (fTracking)
        {
                SetValue(_ValueFor(where.x));
-               _Seek();
        }
 }
 
@@ -753,7 +753,16 @@ SeekSlider::MouseUp(BPoint where)
        if (fTracking)
        {
                fTracking = false;
-               _EndSeek();
+               input_thread_t * p_input;
+               p_input = (input_thread_t *)
+            vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
+
+        if( p_input )
+        {
+                   var_SetFloat( p_input, "position",
+                                 (float) Value() / SEEKSLIDER_RANGE );
+                   vlc_object_release( p_input );
+               }
        }
 }
 
@@ -763,7 +772,7 @@ SeekSlider::MouseUp(BPoint where)
 void
 SeekSlider::ResizeToPreferred()
 {
-       float width = 15.0 + StringWidth(kDisabledSeekMessage) + 15.0;
+       float width = 15.0 + StringWidth(DISABLED_SEEK_MESSAGE) + 15.0;
        ResizeTo(width, 17.0);
 }
 
@@ -775,7 +784,10 @@ SeekSlider::SetPosition(float position)
 {
        if ( LockLooper() )
        {
-               SetValue(fMinValue + (int32)floorf((fMaxValue - fMinValue) * position + 0.5));
+           if( !fTracking )
+           {
+                   SetValue( SEEKSLIDER_RANGE * position );
+               }
                UnlockLooper();
        }
 }
@@ -790,12 +802,12 @@ SeekSlider::_ValueFor(float xPos) const
        float knobWidth2 = SEEK_SLIDER_KNOB_WIDTH / 2.0;
        float sliderStart = (r.left + knobWidth2);
        float sliderEnd = (r.right - knobWidth2);
-       int32 value =  fMinValue + (int32)(((xPos - sliderStart) * (fMaxValue - fMinValue))
+       int32 value =  (int32)(((xPos - sliderStart) * SEEKSLIDER_RANGE)
                                  / (sliderEnd - sliderStart - 1.0));
-       if (value < fMinValue)
-               value = fMinValue;
-       if (value > fMaxValue)
-               value = fMaxValue;
+       if (value < 0)
+               value = 0;
+       if (value > SEEKSLIDER_RANGE)
+               value = SEEKSLIDER_RANGE;
        return value;
 }
 
@@ -814,42 +826,6 @@ SeekSlider::_StrokeFrame(BRect r, rgb_color left, rgb_color top,
        EndLineArray();
 }
 
-/*****************************************************************************
- * SeekSlider::_BeginSeek
- *****************************************************************************/
-void
-SeekSlider::_BeginSeek()
-{
-       fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
-       if (fOwner->fScrubSem >= B_OK)
-               release_sem(fOwner->fScrubSem);
-}
-
-/*****************************************************************************
- * SeekSlider::_Seek
- *****************************************************************************/
-void
-SeekSlider::_Seek()
-{
-       if (fOwner->fScrubSem >= B_OK)
-               delete_sem(fOwner->fScrubSem);
-       fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
-       if (fOwner->fScrubSem >= B_OK)
-               release_sem(fOwner->fScrubSem);
-}
-
-/*****************************************************************************
- * SeekSlider::_EndSeek
- *****************************************************************************/
-void
-SeekSlider::_EndSeek()
-{
-       if (fOwner->fScrubSem >= B_OK)
-               delete_sem(fOwner->fScrubSem);
-       fOwner->fScrubSem = B_ERROR;
-}
-
-
 /*****************************************************************************
  * VolumeSlider
  *****************************************************************************/
@@ -1321,6 +1297,7 @@ PositionInfoView::Pulse()
        bigtime_t now = system_time();
        if ( now - fLastPulseUpdate > 900000 )
        {
+#if 0
                int32 index, size;
                p_intf->p_sys->p_wrapper->GetPlaylistInfo( index, size );
                SetFile( index + 1, size );
@@ -1330,6 +1307,7 @@ PositionInfoView::Pulse()
                SetChapter( index, size );
                SetTime( p_intf->p_sys->p_wrapper->GetTimeAsString() );
                fLastPulseUpdate = now;
+#endif
        }
 }