]> git.sesse.net Git - vlc/blob - modules/gui/beos/MediaControlView.cpp
* control: use new variables and 'title*', 'chapter*' ones.
[vlc] / modules / gui / beos / MediaControlView.cpp
1 /*****************************************************************************
2  * MediaControlView.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: MediaControlView.cpp,v 1.20 2003/09/07 22:53:09 fenrir Exp $
6  *
7  * Authors: Tony Castley <tony@castley.net>
8  *          Stephan Aßmus <stippi@yellowbites.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /* System headers */
26 #include <InterfaceKit.h>
27 #include <AppKit.h>
28 #include <String.h>
29 #include <string.h>
30
31 /* VLC headers */
32 #include <vlc/vlc.h>
33 #include <vlc/intf.h>
34
35 /* BeOS interface headers */
36 #include "VlcWrapper.h"
37 #include "Bitmaps.h"
38 #include "DrawingTidbits.h"
39 #include "InterfaceWindow.h"
40 #include "MsgVals.h"
41 #include "TransportButton.h"
42 #include "ListViews.h"
43 #include "MediaControlView.h"
44
45 #define BORDER_INSET 6.0
46 #define MIN_SPACE 4.0
47 #define SPEAKER_SLIDER_DIST 6.0
48 #define VOLUME_MIN_WIDTH 70.0
49 #define DIM_LEVEL 0.4
50 #define VOLUME_SLIDER_LAYOUT_WEIGHT 2.0
51 #define SEEK_SLIDER_KNOB_WIDTH 8.0
52
53 // slider colors are hardcoded here, because that's just
54 // what they currently are within those bitmaps
55 const rgb_color kGreen = (rgb_color){ 152, 203, 152, 255 };
56 const rgb_color kGreenShadow = (rgb_color){ 102, 152, 102, 255 };
57 const rgb_color kBackground = (rgb_color){ 216, 216, 216, 255 };
58 const rgb_color kSeekGreen = (rgb_color){ 171, 221, 161, 255 };
59 const rgb_color kSeekGreenShadow = (rgb_color){ 144, 186, 136, 255 };
60 const rgb_color kSeekRed = (rgb_color){ 255, 0, 0, 255 };
61 const rgb_color kSeekRedLight = (rgb_color){ 255, 152, 152, 255 };
62 const rgb_color kSeekRedShadow = (rgb_color){ 178, 0, 0, 255 };
63
64 #define DISABLED_SEEK_MESSAGE _("Drop files to play")
65
66 enum
67 {
68         MSG_REWIND                              = 'rwnd',
69         MSG_FORWARD                             = 'frwd',
70         MSG_SKIP_BACKWARDS              = 'skpb',
71         MSG_SKIP_FORWARD                = 'skpf',
72 };
73
74 // constructor
75 MediaControlView::MediaControlView(BRect frame, intf_thread_t *p_interface)
76         : BBox(frame, NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED,
77                    B_PLAIN_BORDER),
78       fScrubSem(B_ERROR),
79       fCurrentRate(DEFAULT_RATE),
80       fCurrentStatus(UNDEF_S),
81       fBottomControlHeight(0.0),
82       fIsEnabled( true )
83 {
84     p_intf = p_interface;
85
86         BRect frame(0.0, 0.0, 10.0, 10.0);
87         
88     // Seek Slider
89     fSeekSlider = new SeekSlider( frame, "seek slider", this,
90                                   0, SEEKSLIDER_RANGE );
91     fSeekSlider->SetValue(0);
92     fSeekSlider->ResizeToPreferred();
93     AddChild( fSeekSlider );
94
95     // Buttons
96     // Skip Back
97     frame.SetRightBottom(kSkipButtonSize);
98         fBottomControlHeight = kRewindBitmapHeight - 1.0;
99     fSkipBack = new TransportButton(frame, B_EMPTY_STRING,
100                                     kSkipBackBitmapBits,
101                                     kPressedSkipBackBitmapBits,
102                                     kDisabledSkipBackBitmapBits,
103                                     new BMessage(MSG_SKIP_BACKWARDS));
104     AddChild( fSkipBack );
105
106         // Play Pause
107     frame.SetRightBottom(kPlayButtonSize);
108         if (fBottomControlHeight < kPlayPauseBitmapHeight - 1.0)
109                 fBottomControlHeight = kPlayPauseBitmapHeight - 1.0;
110     fPlayPause = new PlayPauseButton(frame, B_EMPTY_STRING,
111                                      kPlayButtonBitmapBits,
112                                      kPressedPlayButtonBitmapBits,
113                                      kDisabledPlayButtonBitmapBits,
114                                      kPlayingPlayButtonBitmapBits,
115                                      kPressedPlayingPlayButtonBitmapBits,
116                                      kPausedPlayButtonBitmapBits,
117                                      kPressedPausedPlayButtonBitmapBits,
118                                      new BMessage(START_PLAYBACK));
119
120     AddChild( fPlayPause );
121
122     // Skip Foward
123     frame.SetRightBottom(kSkipButtonSize);
124     fSkipForward = new TransportButton(frame, B_EMPTY_STRING,
125                                        kSkipForwardBitmapBits,
126                                        kPressedSkipForwardBitmapBits,
127                                        kDisabledSkipForwardBitmapBits,
128                                        new BMessage(MSG_SKIP_FORWARD));
129     AddChild( fSkipForward );
130
131         // Forward
132         fForward = new TransportButton(frame, B_EMPTY_STRING,
133                                                                    kForwardBitmapBits,
134                                                                    kPressedForwardBitmapBits,
135                                                                    kDisabledForwardBitmapBits,
136                                                                    new BMessage(MSG_FORWARD));
137 //      AddChild( fForward );
138
139         // Rewind
140         fRewind = new TransportButton(frame, B_EMPTY_STRING,
141                                                                   kRewindBitmapBits,
142                                                                   kPressedRewindBitmapBits,
143                                                                   kDisabledRewindBitmapBits,
144                                                                   new BMessage(MSG_REWIND));
145 //      AddChild( fRewind );
146
147     // Stop
148     frame.SetRightBottom(kStopButtonSize);
149         if (fBottomControlHeight < kStopBitmapHeight - 1.0)
150                 fBottomControlHeight = kStopBitmapHeight - 1.0;
151     fStop = new TransportButton(frame, B_EMPTY_STRING,
152                                 kStopButtonBitmapBits,
153                                 kPressedStopButtonBitmapBits,
154                                 kDisabledStopButtonBitmapBits,
155                                 new BMessage(STOP_PLAYBACK));
156         AddChild( fStop );
157
158         // Mute
159     frame.SetRightBottom(kSpeakerButtonSize);
160         if (fBottomControlHeight < kSpeakerIconBitmapHeight - 1.0)
161                 fBottomControlHeight = kSpeakerIconBitmapHeight - 1.0;
162     fMute = new TransportButton(frame, B_EMPTY_STRING,
163                                 kSpeakerIconBits,
164                                 kPressedSpeakerIconBits,
165                                 kSpeakerIconBits,
166                                 new BMessage(VOLUME_MUTE));
167
168         AddChild( fMute );
169
170     // Volume Slider
171         fVolumeSlider = new VolumeSlider(BRect(0.0, 0.0, VOLUME_MIN_WIDTH,
172                                                                                    kVolumeSliderBitmapHeight - 1.0),
173                                                                          "volume slider", 1, AOUT_VOLUME_MAX,
174                                                                          new BMessage(VOLUME_CHG));
175         fVolumeSlider->SetValue( config_GetInt( p_intf, "volume" ) );
176         AddChild( fVolumeSlider );
177         
178         // Position Info View
179     fPositionInfo = new PositionInfoView(BRect(0.0, 0.0, 10.0, 10.0), "led",
180                                          p_intf);
181     fPositionInfo->ResizeToPreferred();
182     AddChild( fPositionInfo );
183 }
184
185 // destructor
186 MediaControlView::~MediaControlView()
187 {
188 }
189
190 // AttachedToWindow
191 void
192 MediaControlView::AttachedToWindow()
193 {
194         // we are now a valid BHandler
195         fRewind->SetTarget(this);
196         fForward->SetTarget(this);
197         fSkipBack->SetTarget(this);
198         fSkipForward->SetTarget(this);
199         fVolumeSlider->SetTarget(Window());
200
201         BRect r(_MinFrame());
202         if (BMenuBar* menuBar = Window()->KeyMenuBar())
203                 r.bottom += menuBar->Bounds().Height();
204
205         Window()->SetSizeLimits(r.Width(), r.Width() * 1.8, r.Height(), r.Height() * 1.3);
206         if (!Window()->Bounds().Contains(r))
207                 Window()->ResizeTo(r.Width(), r.Height());
208         else
209                 FrameResized(Bounds().Width(), Bounds().Height());
210
211         // get pulse message every two frames
212         Window()->SetPulseRate(80000);
213 }
214
215 // FrameResized
216 void
217 MediaControlView::FrameResized(float width, float height)
218 {
219         BRect r(Bounds());
220         // make sure we don't leave dirty pixels
221         // (B_FULL_UPDATE_ON_RESIZE == annoying flicker -> this is smarter)
222         if (fOldBounds.Width() < r.Width())
223                 Invalidate(BRect(fOldBounds.right, fOldBounds.top + 1.0,
224                                                  fOldBounds.right, fOldBounds.bottom - 1.0));
225         else
226                 Invalidate(BRect(r.right, r.top + 1.0,
227                                                  r.right, r.bottom - 1.0));
228         if (fOldBounds.Height() < r.Height())
229                 Invalidate(BRect(fOldBounds.left + 1.0, fOldBounds.bottom,
230                                                  fOldBounds.right - 1.0, fOldBounds.bottom));
231         else
232                 Invalidate(BRect(r.left + 1.0, r.bottom,
233                                                  r.right - 1.0, r.bottom));
234         // remember for next time
235         fOldBounds = r;
236         // layout controls
237         r.InsetBy(BORDER_INSET, BORDER_INSET);
238         _LayoutControls(r);
239 }
240
241 // GetPreferredSize
242 void
243 MediaControlView::GetPreferredSize(float* width, float* height)
244 {
245         if (width && height)
246         {
247                 BRect r(_MinFrame());
248                 *width = r.Width();
249                 *height = r.Height();
250         }
251 }
252
253 // MessageReceived
254 void
255 MediaControlView::MessageReceived(BMessage* message)
256 {
257         switch (message->what)
258         {
259                 case MSG_REWIND:
260                         break;
261                 case MSG_FORWARD:
262                         break;
263                 case MSG_SKIP_BACKWARDS:
264                         Window()->PostMessage(NAVIGATE_PREV);
265                         break;
266                 case MSG_SKIP_FORWARD:
267                         Window()->PostMessage(NAVIGATE_NEXT);
268                         break;
269                 default:
270                     BBox::MessageReceived(message);
271                     break;
272         }
273 }
274
275 // Pulse
276 void
277 MediaControlView::Pulse()
278 {
279         InterfaceWindow* window = dynamic_cast<InterfaceWindow*>(Window());
280         if (window && window->IsStopped())
281                         fPlayPause->SetStopped();
282 }
283
284 // SetProgress
285 void
286 MediaControlView::SetProgress( float position )
287 {
288         fSeekSlider->SetPosition( position );
289 }
290
291 // SetStatus
292 void
293 MediaControlView::SetStatus(int status, int rate)
294 {
295         // we need to set the button status periodically
296         // (even if it is the same) to get a blinking button
297         fCurrentStatus = status;
298     switch( status )
299     {
300         case PLAYING_S:
301         case FORWARD_S:
302         case BACKWARD_S:
303             fPlayPause->SetPlaying();
304             break;
305         case PAUSE_S:
306             fPlayPause->SetPaused();
307             break;
308         case UNDEF_S:
309         default:
310             fPlayPause->SetStopped();
311             break;
312     }
313         if (rate != fCurrentRate)
314         {
315                 fCurrentRate = rate;
316             if ( rate < DEFAULT_RATE )
317             {
318                 // TODO: ...
319             }
320         }
321 }
322
323 // SetEnabled
324 void
325 MediaControlView::SetEnabled(bool enabled)
326 {
327     if( ( enabled && fIsEnabled ) ||
328         ( !enabled && !fIsEnabled ) )
329     {
330         /* do not redraw if it is not necessary */
331         return;
332     }
333     
334         if( LockLooper() )
335         {
336                 fSkipBack->SetEnabled( enabled );
337                 fPlayPause->SetEnabled( enabled );
338                 fSkipForward->SetEnabled( enabled );
339                 fStop->SetEnabled( enabled );
340                 fMute->SetEnabled( enabled );
341                 fVolumeSlider->SetEnabled( enabled );
342                 fSeekSlider->SetEnabled( enabled );
343                 fRewind->SetEnabled( enabled );
344                 fForward->SetEnabled( enabled );
345                 UnlockLooper();
346                 fIsEnabled = enabled;
347         }
348 }
349
350 // SetAudioEnabled
351 void
352 MediaControlView::SetAudioEnabled(bool enabled)
353 {
354         fMute->SetEnabled(enabled);
355         fVolumeSlider->SetEnabled(enabled);
356 }
357
358 // GetSeekTo
359 uint32
360 MediaControlView::GetSeekTo() const
361 {
362         return fSeekSlider->Value();
363 }
364
365 // GetVolume
366 uint32
367 MediaControlView::GetVolume() const
368 {
369         return fVolumeSlider->Value();
370 }
371
372 // SetSkippable
373 void
374 MediaControlView::SetSkippable(bool backward, bool forward)
375 {
376         fSkipBack->SetEnabled(backward);
377         fSkipForward->SetEnabled(forward);
378 }
379
380 // SetMuted
381 void
382 MediaControlView::SetMuted(bool mute)
383 {
384         fVolumeSlider->SetMuted(mute);
385 }
386
387 // _LayoutControls
388 void
389 MediaControlView::_LayoutControls(BRect frame) const
390 {
391         // seek slider
392         BRect r(frame);
393         // calculate absolutly minimal width
394         float minWidth = fSkipBack->Bounds().Width();
395 //      minWidth += fRewind->Bounds().Width();
396         minWidth += fStop->Bounds().Width();
397         minWidth += fPlayPause->Bounds().Width();
398 //      minWidth += fForward->Bounds().Width();
399         minWidth += fSkipForward->Bounds().Width();
400         minWidth += fMute->Bounds().Width();
401         minWidth += VOLUME_MIN_WIDTH;
402         
403         // layout time slider and info view
404     float width, height;
405     fPositionInfo->GetBigPreferredSize( &width, &height );
406     float ratio = width / height;
407     width = r.Height() * ratio;
408     if (frame.Width() - minWidth - MIN_SPACE >= width
409               && frame.Height() >= height)
410     {
411         r.right = r.left + width;
412         fPositionInfo->SetMode(PositionInfoView::MODE_BIG);
413         _LayoutControl(fPositionInfo, r, true, true);
414         frame.left = r.right + MIN_SPACE;
415         r.left = frame.left;
416         r.right = frame.right;
417     //    r.bottom = r.top + r.Height() / 2.0 - MIN_SPACE / 2.0;
418         r.bottom = r.top + fSeekSlider->Bounds().Height();
419         _LayoutControl(fSeekSlider, r, true);
420     }
421     else
422     {
423         fPositionInfo->GetPreferredSize( &width, &height );
424         fPositionInfo->SetMode(PositionInfoView::MODE_SMALL);
425         fPositionInfo->ResizeTo(width, height);
426         r.bottom = r.top + r.Height() / 2.0 - MIN_SPACE / 2.0;
427         r.right = r.left + fPositionInfo->Bounds().Width();
428         _LayoutControl(fPositionInfo, r, true );
429         r.left = r.right + MIN_SPACE;
430         r.right = frame.right;
431         _LayoutControl(fSeekSlider, r, true);
432     }
433         float currentWidth = frame.Width();
434         float space = (currentWidth - minWidth) / 6.0;//8.0;
435         // apply weighting
436         space = MIN_SPACE + (space - MIN_SPACE) / VOLUME_SLIDER_LAYOUT_WEIGHT;
437         // layout controls with "space" inbetween
438         r.left = frame.left;
439         r.top = r.bottom + MIN_SPACE + 1.0;
440         r.bottom = frame.bottom;
441         // skip back
442         r.right = r.left + fSkipBack->Bounds().Width();
443         _LayoutControl(fSkipBack, r);
444         // rewind
445 //      r.left = r.right + space;
446 //      r.right = r.left + fRewind->Bounds().Width();
447 //      _LayoutControl(fRewind, r);
448         // stop
449         r.left = r.right + space;
450         r.right = r.left + fStop->Bounds().Width();
451         _LayoutControl(fStop, r);
452         // play/pause
453         r.left = r.right + space;
454         r.right = r.left + fPlayPause->Bounds().Width();
455         _LayoutControl(fPlayPause, r);
456         // forward
457 //      r.left = r.right + space;
458 //      r.right = r.left + fForward->Bounds().Width();
459 //      _LayoutControl(fForward, r);
460         // skip forward
461         r.left = r.right + space;
462         r.right = r.left + fSkipForward->Bounds().Width();
463         _LayoutControl(fSkipForward, r);
464         // speaker icon
465         r.left = r.right + space + space;
466         r.right = r.left + fMute->Bounds().Width();
467         _LayoutControl(fMute, r);
468         // volume slider
469         r.left = r.right + SPEAKER_SLIDER_DIST; // keep speaker icon and volume slider attached
470         r.right = frame.right;
471         _LayoutControl(fVolumeSlider, r, true);
472 }
473
474 // _MinFrame
475 BRect           
476 MediaControlView::_MinFrame() const
477 {
478         // add up width of controls along bottom (seek slider will likely adopt)
479         float minWidth = 2 * BORDER_INSET;
480         minWidth += fSkipBack->Bounds().Width() + MIN_SPACE;
481 //      minWidth += fRewind->Bounds().Width() + MIN_SPACE;
482         minWidth += fStop->Bounds().Width() + MIN_SPACE;
483         minWidth += fPlayPause->Bounds().Width() + MIN_SPACE;
484 //      minWidth += fForward->Bounds().Width() + MIN_SPACE;
485         minWidth += fSkipForward->Bounds().Width() + MIN_SPACE + MIN_SPACE;
486         minWidth += fMute->Bounds().Width() + SPEAKER_SLIDER_DIST;
487         minWidth += VOLUME_MIN_WIDTH;
488
489         // add up height of seek slider and heighest control on bottom
490         float minHeight = 2 * BORDER_INSET;
491         minHeight += fSeekSlider->Bounds().Height() + MIN_SPACE + MIN_SPACE / 2.0;
492         minHeight += fBottomControlHeight;
493         return BRect(0.0, 0.0, minWidth - 1.0, minHeight - 1.0);
494 }
495
496 // _LayoutControl
497 void
498 MediaControlView::_LayoutControl(BView* view, BRect frame,
499                                  bool resizeWidth, bool resizeHeight) const
500 {
501     if (!resizeHeight)
502             // center vertically
503             frame.top = (frame.top + frame.bottom) / 2.0 - view->Bounds().Height() / 2.0;
504         if (!resizeWidth)
505             //center horizontally
506                 frame.left = (frame.left + frame.right) / 2.0 - view->Bounds().Width() / 2.0;
507         view->MoveTo(frame.LeftTop());
508         float width = resizeWidth ? frame.Width() : view->Bounds().Width();
509         float height = resizeHeight ? frame.Height() : view->Bounds().Height();
510     if (resizeWidth || resizeHeight)
511         view->ResizeTo(width, height);
512 }
513
514
515
516 /*****************************************************************************
517  * SeekSlider
518  *****************************************************************************/
519 SeekSlider::SeekSlider(BRect frame, const char* name, MediaControlView *owner,
520                                            int32 minValue, int32 maxValue)
521         : BControl(frame, name, NULL, NULL, B_FOLLOW_NONE,
522                            B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
523           fOwner(owner),
524           fTracking(false),
525           fMinValue(minValue),
526           fMaxValue(maxValue)
527 {
528         BFont font(be_plain_font);
529         font.SetSize(9.0);
530         SetFont(&font);
531 }
532
533 SeekSlider::~SeekSlider()
534 {
535         _EndSeek();
536 }
537
538 /*****************************************************************************
539  * VolumeSlider::AttachedToWindow
540  *****************************************************************************/
541 void
542 SeekSlider::AttachedToWindow()
543 {
544         BControl::AttachedToWindow();
545         SetViewColor(B_TRANSPARENT_32_BIT);
546 }
547
548 /*****************************************************************************
549  * VolumeSlider::Draw
550  *****************************************************************************/
551 void
552 SeekSlider::Draw(BRect updateRect)
553 {
554         BRect r(Bounds());
555         float knobWidth2 = SEEK_SLIDER_KNOB_WIDTH / 2.0;
556         float sliderStart = (r.left + knobWidth2);
557         float sliderEnd = (r.right - knobWidth2);
558         float knobPos = sliderStart
559                                         + floorf((sliderEnd - sliderStart - 1.0) * (Value() - fMinValue)
560                                         / (fMaxValue - fMinValue) + 0.5);
561         // draw both sides (the original from Be doesn't seem
562         // to make a difference for enabled/disabled state)
563 //      DrawBitmapAsync(fLeftSideBits, r.LeftTop());
564 //      DrawBitmapAsync(fRightSideBits, BPoint(sliderEnd + 1.0, r.top));
565         // colors for the slider area between the two bitmaps
566         rgb_color background = kBackground;//ui_color(B_PANEL_BACKGROUND_COLOR);
567         rgb_color shadow = tint_color(background, B_DARKEN_2_TINT);
568         rgb_color softShadow = tint_color(background, B_DARKEN_1_TINT);
569         rgb_color darkShadow = tint_color(background, B_DARKEN_4_TINT);
570         rgb_color midShadow = tint_color(background, B_DARKEN_3_TINT);
571         rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
572         rgb_color softLight = tint_color(background, B_LIGHTEN_1_TINT);
573         rgb_color green = kSeekGreen;
574         rgb_color greenShadow = kSeekGreenShadow;
575         rgb_color black = kBlack;
576         rgb_color dotGrey = midShadow;
577         rgb_color dotGreen = greenShadow;
578         // draw frame
579         _StrokeFrame(r, softShadow, softShadow, softLight, softLight);
580         r.InsetBy(1.0, 1.0);
581         _StrokeFrame(r, black, black, light, light);
582         if (IsEnabled())
583         {
584                 r.InsetBy(1.0, 1.0);
585                 // inner shadow
586                 _StrokeFrame(r, greenShadow, greenShadow, green, green);
587                 r.top++;
588                 r.left++;
589                 _StrokeFrame(r, greenShadow, greenShadow, green, green);
590                 // inside area
591                 r.InsetBy(1.0, 1.0);
592                 SetHighColor(green);
593                 FillRect(r);
594                 // dots
595                 int32 dotCount = (int32)(r.Width() / 6.0);
596                 BPoint dotPos;
597                 dotPos.y = r.top + 2.0;
598                 SetHighColor(dotGreen);
599                 for (int32 i = 0; i < dotCount; i++)
600                 {
601                         dotPos.x = sliderStart + i * 6.0 + 5.0;
602                         StrokeLine(dotPos, BPoint(dotPos.x, dotPos.y + 6.0));
603                 }
604                 // slider handle
605                 r.top -= 4.0;
606                 r.bottom += 3.0;
607                 r.left = knobPos - knobWidth2;
608                 r.right = knobPos + knobWidth2;
609                 // black outline
610                 float handleBottomSize = 2.0;
611                 float handleArrowSize = 6.0;
612                 BeginLineArray(10);
613                         // upper handle
614                         AddLine(BPoint(r.left, r.top + handleBottomSize),
615                                         BPoint(r.left, r.top), black);
616                         AddLine(BPoint(r.left + 1.0, r.top),
617                                         BPoint(r.right, r.top), black);
618                         AddLine(BPoint(r.right, r.top + 1.0),
619                                         BPoint(r.right, r.top + handleBottomSize), black);
620                         AddLine(BPoint(r.right - 1.0, r.top + handleBottomSize + 1.0),
621                                         BPoint(knobPos, r.top + handleArrowSize), black);
622                         AddLine(BPoint(knobPos - 1.0, r.top + handleArrowSize - 1.0),
623                                         BPoint(r.left + 1.0, r.top + handleBottomSize + 1.0), black);
624                         // lower handle
625                         AddLine(BPoint(r.left, r.bottom),
626                                         BPoint(r.left, r.bottom - handleBottomSize), black);
627                         AddLine(BPoint(r.left + 1.0, r.bottom - handleBottomSize - 1.0),
628                                         BPoint(knobPos, r.bottom - handleArrowSize), black);
629                         AddLine(BPoint(knobPos + 1.0, r.bottom - handleArrowSize + 1.0),
630                                         BPoint(r.right, r.bottom - handleBottomSize), black);
631                         AddLine(BPoint(r.right, r.bottom - handleBottomSize + 1.0),
632                                         BPoint(r.right, r.bottom), black);
633                         AddLine(BPoint(r.right - 1.0, r.bottom),
634                                         BPoint(r.left + 1.0, r.bottom), black);
635                 EndLineArray();
636                 // inner red light and shadow lines
637                 r.InsetBy(1.0, 1.0);
638                 handleBottomSize--;
639                 handleArrowSize -= 2.0;
640                 BeginLineArray(10);
641                         // upper handle
642                         AddLine(BPoint(r.left, r.top + handleBottomSize),
643                                         BPoint(r.left, r.top), kSeekRedLight);
644                         AddLine(BPoint(r.left + 1.0, r.top),
645                                         BPoint(r.right, r.top), kSeekRedLight);
646                         AddLine(BPoint(r.right, r.top + 1.0),
647                                         BPoint(r.right, r.top + handleBottomSize), kSeekRedShadow);
648                         AddLine(BPoint(r.right - 1.0, r.top + handleBottomSize + 1.0),
649                                         BPoint(knobPos, r.top + handleArrowSize), kSeekRedShadow);
650                         AddLine(BPoint(knobPos - 1.0, r.top + handleArrowSize - 1.0),
651                                         BPoint(r.left + 1.0, r.top + handleBottomSize + 1.0), kSeekRedLight);
652                         // lower handle
653                         AddLine(BPoint(r.left, r.bottom),
654                                         BPoint(r.left, r.bottom - handleBottomSize), kSeekRedLight);
655                         AddLine(BPoint(r.left + 1.0, r.bottom - handleBottomSize - 1.0),
656                                         BPoint(knobPos, r.bottom - handleArrowSize), kSeekRedLight);
657                         AddLine(BPoint(knobPos + 1.0, r.bottom - handleArrowSize + 1.0),
658                                         BPoint(r.right, r.bottom - handleBottomSize), kSeekRedShadow);
659                         AddLine(BPoint(r.right, r.bottom - handleBottomSize + 1.0),
660                                         BPoint(r.right, r.bottom), kSeekRedShadow);
661                         AddLine(BPoint(r.right - 1.0, r.bottom),
662                                         BPoint(r.left + 1.0, r.bottom), kSeekRedShadow);
663                 EndLineArray();
664                 // fill rest of handles with red
665                 SetHighColor(kSeekRed);
666                 r.InsetBy(1.0, 1.0);
667                 handleArrowSize -= 2.0;
668                 BPoint arrow[3];
669                 // upper handle arrow
670                 arrow[0].x = r.left;
671                 arrow[0].y = r.top;
672                 arrow[1].x = r.right;
673                 arrow[1].y = r.top;
674                 arrow[2].x = knobPos;
675                 arrow[2].y = r.top + handleArrowSize;
676                 FillPolygon(arrow, 3);
677                 // lower handle arrow
678                 arrow[0].x = r.left;
679                 arrow[0].y = r.bottom;
680                 arrow[1].x = r.right;
681                 arrow[1].y = r.bottom;
682                 arrow[2].x = knobPos;
683                 arrow[2].y = r.bottom - handleArrowSize;
684                 FillPolygon(arrow, 3);
685         }
686         else
687         {
688                 r.InsetBy(1.0, 1.0);
689                 _StrokeFrame(r, darkShadow, darkShadow, darkShadow, darkShadow);
690                 r.InsetBy(1.0, 1.0);
691                 _StrokeFrame(r, darkShadow, darkShadow, darkShadow, darkShadow);
692                 r.InsetBy(1.0, 1.0);
693                 SetHighColor(darkShadow);
694                 SetLowColor(shadow);
695                 // stripes
696                 float width = floorf(StringWidth(DISABLED_SEEK_MESSAGE));
697                 float textPos = r.left + r.Width() / 2.0 - width / 2.0;
698                 pattern stripes = {{ 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, 0xf8, 0xf1, 0xe3 }};
699                 BRect stripesRect(r);
700                 stripesRect.right = textPos - 5.0;
701                 FillRect(stripesRect, stripes);
702                 stripesRect.left = textPos + width + 3.0;
703                 stripesRect.right = r.right;
704                 FillRect(stripesRect, stripes);
705                 // info text
706                 r.left = textPos - 4.0;
707                 r.right = textPos + width + 2.0;
708                 FillRect(r);
709                 SetHighColor(shadow);
710                 SetLowColor(darkShadow);
711                 font_height fh;
712                 GetFontHeight(&fh);
713                 DrawString(DISABLED_SEEK_MESSAGE, BPoint(textPos, r.top + ceilf(fh.ascent) - 1.0));
714         }
715 }
716
717 /*****************************************************************************
718  * SeekSlider::MouseDown
719  *****************************************************************************/
720 void
721 SeekSlider::MouseDown(BPoint where)
722 {
723         if (IsEnabled() && Bounds().Contains(where))
724         {
725                 SetValue(_ValueFor(where.x));
726                 fTracking = true;
727                 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
728                 _BeginSeek();
729         }
730 }
731
732 /*****************************************************************************
733  * SeekSlider::MouseMoved
734  *****************************************************************************/
735 void
736 SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
737 {
738         if (fTracking)
739         {
740                 SetValue(_ValueFor(where.x));
741                 _Seek();
742         }
743 }
744
745 /*****************************************************************************
746  * SeekSlider::MouseUp
747  *****************************************************************************/
748 void
749 SeekSlider::MouseUp(BPoint where)
750 {
751         if (fTracking)
752         {
753                 fTracking = false;
754                 _EndSeek();
755         }
756 }
757
758 /*****************************************************************************
759  * SeekSlider::ResizeToPreferred
760  *****************************************************************************/
761 void
762 SeekSlider::ResizeToPreferred()
763 {
764         float width = 15.0 + StringWidth(DISABLED_SEEK_MESSAGE) + 15.0;
765         ResizeTo(width, 17.0);
766 }
767
768 /*****************************************************************************
769  * SeekSlider::SetPosition
770  *****************************************************************************/
771 void
772 SeekSlider::SetPosition(float position)
773 {
774         if ( LockLooper() )
775         {
776                 SetValue(fMinValue + (int32)floorf((fMaxValue - fMinValue) * position + 0.5));
777                 UnlockLooper();
778         }
779 }
780
781 /*****************************************************************************
782  * SeekSlider::_ValueFor
783  *****************************************************************************/
784 int32
785 SeekSlider::_ValueFor(float xPos) const
786 {
787         BRect r(Bounds());
788         float knobWidth2 = SEEK_SLIDER_KNOB_WIDTH / 2.0;
789         float sliderStart = (r.left + knobWidth2);
790         float sliderEnd = (r.right - knobWidth2);
791         int32 value =  fMinValue + (int32)(((xPos - sliderStart) * (fMaxValue - fMinValue))
792                                   / (sliderEnd - sliderStart - 1.0));
793         if (value < fMinValue)
794                 value = fMinValue;
795         if (value > fMaxValue)
796                 value = fMaxValue;
797         return value;
798 }
799
800 /*****************************************************************************
801  * SeekSlider::_StrokeFrame
802  *****************************************************************************/
803 void
804 SeekSlider::_StrokeFrame(BRect r, rgb_color left, rgb_color top,
805                                                  rgb_color right, rgb_color bottom)
806 {
807         BeginLineArray(4);
808                 AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), left);
809                 AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), top);
810                 AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), right);
811                 AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), bottom);
812         EndLineArray();
813 }
814
815 /*****************************************************************************
816  * SeekSlider::_BeginSeek
817  *****************************************************************************/
818 void
819 SeekSlider::_BeginSeek()
820 {
821         fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
822         if (fOwner->fScrubSem >= B_OK)
823                 release_sem(fOwner->fScrubSem);
824 }
825
826 /*****************************************************************************
827  * SeekSlider::_Seek
828  *****************************************************************************/
829 void
830 SeekSlider::_Seek()
831 {
832         if (fOwner->fScrubSem >= B_OK)
833                 delete_sem(fOwner->fScrubSem);
834         fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
835         if (fOwner->fScrubSem >= B_OK)
836                 release_sem(fOwner->fScrubSem);
837 }
838
839 /*****************************************************************************
840  * SeekSlider::_EndSeek
841  *****************************************************************************/
842 void
843 SeekSlider::_EndSeek()
844 {
845         if (fOwner->fScrubSem >= B_OK)
846                 delete_sem(fOwner->fScrubSem);
847         fOwner->fScrubSem = B_ERROR;
848 }
849
850
851 /*****************************************************************************
852  * VolumeSlider
853  *****************************************************************************/
854 VolumeSlider::VolumeSlider(BRect frame, const char* name, int32 minValue, int32 maxValue,
855                                                    BMessage* message, BHandler* target)
856         : BControl(frame, name, NULL, message, B_FOLLOW_NONE,
857                            B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
858           fLeftSideBits(NULL),
859           fRightSideBits(NULL),
860           fKnobBits(NULL),
861           fTracking(false),
862           fMuted(false),
863           fMinValue(minValue),
864           fMaxValue(maxValue)
865 {
866         SetTarget(target);
867
868         // create bitmaps
869         BRect r(BPoint(0.0, 0.0), kVolumeSliderBitmapSize);
870         fLeftSideBits = new BBitmap(r, B_CMAP8);
871         fRightSideBits = new BBitmap(r, B_CMAP8);
872         r.Set(0.0, 0.0, kVolumeSliderKnobBitmapSize.x, kVolumeSliderKnobBitmapSize.y);
873         fKnobBits = new BBitmap(r, B_CMAP8);
874
875         _MakeBitmaps();
876 }
877
878 /*****************************************************************************
879  * VolumeSlider destructor
880  *****************************************************************************/
881 VolumeSlider::~VolumeSlider()
882 {
883         delete fLeftSideBits;
884         delete fRightSideBits;
885         delete fKnobBits;
886 }
887
888 /*****************************************************************************
889  * VolumeSlider::AttachedToWindow
890  *****************************************************************************/
891 void
892 VolumeSlider::AttachedToWindow()
893 {
894         BControl::AttachedToWindow();
895         SetViewColor(B_TRANSPARENT_32_BIT);
896 }
897
898 /*****************************************************************************
899  * VolumeSlider::SetValue
900  *****************************************************************************/
901 void
902 VolumeSlider::SetValue(int32 value)
903 {
904         if (value != Value())
905         {
906                 BControl::SetValue(value);
907                 Invoke();
908         }
909 }
910
911 /*****************************************************************************
912  * VolumeSlider::SetEnabled
913  *****************************************************************************/
914 void
915 VolumeSlider::SetEnabled(bool enable)
916 {
917         if (enable != IsEnabled())
918         {
919                 BControl::SetEnabled(enable);
920                 _MakeBitmaps();
921                 Invalidate();
922         }
923 }
924
925 /*****************************************************************************
926  * VolumeSlider::Draw
927  *****************************************************************************/
928 void
929 VolumeSlider::Draw(BRect updateRect)
930 {
931         if (IsValid())
932         {
933                 BRect r(Bounds());
934                 float sliderSideWidth = kVolumeSliderBitmapWidth;
935                 float sliderStart = (r.left + sliderSideWidth);
936                 float sliderEnd = (r.right - sliderSideWidth);
937                 float knobPos = sliderStart
938                                                 + (sliderEnd - sliderStart - 1.0) * (Value() - fMinValue)
939                                                 / (fMaxValue - fMinValue);
940                 // draw both sides (the original from Be doesn't seem
941                 // to make a difference for enabled/disabled state)
942                 DrawBitmapAsync(fLeftSideBits, r.LeftTop());
943                 DrawBitmapAsync(fRightSideBits, BPoint(sliderEnd + 1.0, r.top));
944                 // colors for the slider area between the two bitmaps
945                 rgb_color background = kBackground;//ui_color(B_PANEL_BACKGROUND_COLOR);
946                 rgb_color shadow = tint_color(background, B_DARKEN_2_TINT);
947                 rgb_color softShadow = tint_color(background, B_DARKEN_1_TINT);
948                 rgb_color darkShadow = tint_color(background, B_DARKEN_4_TINT);
949                 rgb_color midShadow = tint_color(background, B_DARKEN_3_TINT);
950                 rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
951                 rgb_color softLight = tint_color(background, B_LIGHTEN_1_TINT);
952                 rgb_color green = kGreen;
953                 rgb_color greenShadow = kGreenShadow;
954                 rgb_color black = kBlack;
955                 rgb_color dotGrey = midShadow;
956                 rgb_color dotGreen = greenShadow;
957                 // make dimmed version of colors if we're disabled
958                 if (!IsEnabled())
959                 {
960                         shadow = (rgb_color){ 200, 200, 200, 255 };
961                         softShadow = dimmed_color_cmap8(softShadow, background, DIM_LEVEL);
962                         darkShadow = dimmed_color_cmap8(darkShadow, background, DIM_LEVEL);
963                         midShadow = shadow;
964                         light = dimmed_color_cmap8(light, background, DIM_LEVEL);
965                         softLight = dimmed_color_cmap8(softLight, background, DIM_LEVEL);
966                         green = dimmed_color_cmap8(green, background, DIM_LEVEL);
967                         greenShadow = dimmed_color_cmap8(greenShadow, background, DIM_LEVEL);
968                         black = dimmed_color_cmap8(black, background, DIM_LEVEL);
969                         dotGreen = dotGrey;
970                 }
971                 else if (fMuted)
972                 {
973                         green = tint_color(kBackground, B_DARKEN_3_TINT);
974                         greenShadow = tint_color(kBackground, B_DARKEN_4_TINT);
975                         dotGreen = greenShadow;
976                 }
977                 // draw slider edges between bitmaps
978                 BeginLineArray(7);
979                         AddLine(BPoint(sliderStart, r.top),
980                                         BPoint(sliderEnd, r.top), softShadow);
981                         AddLine(BPoint(sliderStart, r.bottom),
982                                         BPoint(sliderEnd, r.bottom), softLight);
983                         r.InsetBy(0.0, 1.0);
984                         AddLine(BPoint(sliderStart, r.top),
985                                         BPoint(sliderEnd, r.top), black);
986                         AddLine(BPoint(sliderStart, r.bottom),
987                                         BPoint(sliderEnd, r.bottom), light);
988                         r.top++;
989                         AddLine(BPoint(sliderStart, r.top),
990                                         BPoint(knobPos, r.top), greenShadow);
991                         AddLine(BPoint(knobPos, r.top),
992                                         BPoint(sliderEnd, r.top), midShadow);
993                         r.top++;
994                         AddLine(BPoint(sliderStart, r.top),
995                                         BPoint(knobPos, r.top), greenShadow);
996                 EndLineArray();
997                 // fill rest inside of slider
998                 r.InsetBy(0.0, 1.0);
999                 r.left = sliderStart;
1000                 r.right = knobPos;
1001                 SetHighColor(green);
1002                 FillRect(r, B_SOLID_HIGH);
1003                 r.left = knobPos + 1.0;
1004                 r.right = sliderEnd;
1005                 r.top -= 1.0;
1006                 SetHighColor(shadow);
1007                 FillRect(r, B_SOLID_HIGH);
1008                 // draw little dots inside
1009                 int32 dotCount = (int32)((sliderEnd - sliderStart) / 5.0);
1010                 BPoint dotPos;
1011                 dotPos.y = r.top + 4.0;
1012                 for (int32 i = 0; i < dotCount; i++)
1013                 {
1014                         dotPos.x = sliderStart + i * 5.0 + 4.0;
1015                         SetHighColor(dotPos.x < knobPos ? dotGreen : dotGrey);
1016                         StrokeLine(dotPos, BPoint(dotPos.x, dotPos.y + 1.0));
1017                 }
1018                 // draw knob
1019                 r.top -= 1.0;
1020                 SetDrawingMode(B_OP_OVER); // part of knob is transparent
1021                 DrawBitmapAsync(fKnobBits, BPoint(knobPos - kVolumeSliderKnobWidth / 2, r.top));
1022         }
1023 }
1024
1025 /*****************************************************************************
1026  * VolumeSlider::MouseDown
1027  *****************************************************************************/
1028 void
1029 VolumeSlider::MouseDown(BPoint where)
1030 {
1031         if (Bounds().Contains(where) && IsEnabled())
1032         {
1033                 fTracking = true;
1034                 SetValue(_ValueFor(where.x));
1035                 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
1036         }
1037 }
1038
1039 /*****************************************************************************
1040  * VolumeSlider::MouseMoved
1041  *****************************************************************************/
1042 void
1043 VolumeSlider::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
1044 {
1045         if (fTracking)
1046                 SetValue(_ValueFor(where.x));
1047 }
1048
1049 /*****************************************************************************
1050  * VolumeSlider::MouseUp
1051  *****************************************************************************/
1052 void
1053 VolumeSlider::MouseUp(BPoint where)
1054 {
1055         fTracking = false;
1056 }
1057
1058
1059 /*****************************************************************************
1060  * VolumeSlider::IsValid
1061  *****************************************************************************/
1062 bool
1063 VolumeSlider::IsValid() const
1064 {
1065         return (fLeftSideBits && fLeftSideBits->IsValid()
1066                         && fRightSideBits && fRightSideBits->IsValid()
1067                         && fKnobBits && fKnobBits->IsValid());
1068 }
1069
1070 /*****************************************************************************
1071  * VolumeSlider::SetMuted
1072  *****************************************************************************/
1073 void
1074 VolumeSlider::SetMuted(bool mute)
1075 {
1076         if (mute != fMuted)
1077         {
1078                 fMuted = mute;
1079                 _MakeBitmaps();
1080                 Invalidate();
1081         }
1082 }
1083
1084 /*****************************************************************************
1085  * VolumeSlider::_MakeBitmaps
1086  *****************************************************************************/
1087 void
1088 VolumeSlider::_MakeBitmaps()
1089 {
1090         if (IsValid())
1091         {
1092                 // left side of slider
1093                 memcpy(fLeftSideBits->Bits(), kVolumeSliderLeftBitmapBits,
1094                            fLeftSideBits->BitsLength());
1095                 // right side of slider
1096                 memcpy(fRightSideBits->Bits(), kVolumeSliderRightBits,
1097                            fRightSideBits->BitsLength());
1098                 // slider knob
1099                 int32 length = fKnobBits->BitsLength();
1100                 memcpy(fKnobBits->Bits(), kVolumeSliderKnobBits, length);
1101                 uint8* bits = (uint8*)fKnobBits->Bits();
1102                 // black was used in the knob to represent transparency
1103                 // use screen to get index for the "transarent" color used in the bitmap
1104                 BScreen screen(B_MAIN_SCREEN_ID);
1105                 uint8 blackIndex = screen.IndexForColor(kBlack);
1106                 // replace black index with transparent index
1107                 for (int32 i = 0; i < length; i++)
1108                         if (bits[i] == blackIndex)
1109                                 bits[i] = B_TRANSPARENT_MAGIC_CMAP8;
1110
1111                 if (!IsEnabled())
1112                 {
1113                         // make ghosted versions of the bitmaps
1114                         dim_bitmap(fLeftSideBits, kBackground, DIM_LEVEL);
1115                         dim_bitmap(fRightSideBits, kBackground, DIM_LEVEL);
1116                         dim_bitmap(fKnobBits, kBackground, DIM_LEVEL);
1117                 }
1118                 else if (fMuted)
1119                 {
1120                         // replace green color (and shadow) in left slider side
1121                         bits = (uint8*)fLeftSideBits->Bits();
1122                         length = fLeftSideBits->BitsLength();
1123                         uint8 greenIndex = screen.IndexForColor(kGreen);
1124                         uint8 greenShadowIndex = screen.IndexForColor(kGreenShadow);
1125                         rgb_color shadow = tint_color(kBackground, B_DARKEN_3_TINT);
1126                         rgb_color midShadow = tint_color(kBackground, B_DARKEN_4_TINT);
1127                         uint8 replaceIndex = screen.IndexForColor(shadow);
1128                         uint8 replaceShadowIndex = screen.IndexForColor(midShadow);
1129                         for (int32 i = 0; i < length; i++)
1130                         {
1131                                 if (bits[i] == greenIndex)
1132                                         bits[i] = replaceIndex;
1133                                 else if (bits[i] == greenShadowIndex)
1134                                         bits[i] = replaceShadowIndex;
1135                         }
1136                 }
1137         }
1138 }
1139
1140 /*****************************************************************************
1141  * VolumeSlider::_ValueFor
1142  *****************************************************************************/
1143 int32
1144 VolumeSlider::_ValueFor(float xPos) const
1145 {
1146         BRect r(Bounds());
1147         float sliderStart = (r.left + kVolumeSliderBitmapWidth);
1148         float sliderEnd = (r.right - kVolumeSliderBitmapWidth);
1149         int32 value =  fMinValue + (int32)(((xPos - sliderStart) * (fMaxValue - fMinValue))
1150                                   / (sliderEnd - sliderStart - 1.0));
1151         if (value < fMinValue)
1152                 value = fMinValue;
1153         if (value > fMaxValue)
1154                 value = fMaxValue;
1155         return value;
1156 }
1157
1158 /*****************************************************************************
1159  * PositionInfoView::PositionInfoView
1160  *****************************************************************************/
1161 PositionInfoView::PositionInfoView( BRect frame, const char* name,
1162                                     intf_thread_t * p_interface )
1163         : BView( frame, name, B_FOLLOW_NONE,
1164                          B_WILL_DRAW | B_PULSE_NEEDED | B_FULL_UPDATE_ON_RESIZE ),
1165           fMode( MODE_SMALL ),
1166           fCurrentFileIndex( -1 ),
1167           fCurrentFileSize( -1 ),
1168           fCurrentTitleIndex( -1 ),
1169           fCurrentTitleSize( -1 ),
1170           fCurrentChapterIndex( -1 ),
1171           fCurrentChapterSize( -1 ),
1172           fSeconds( -1 ),
1173           fTimeString( "-:--:--" ),
1174           fLastPulseUpdate( system_time() ),
1175           fStackedWidthCache( 0.0 ),
1176           fStackedHeightCache( 0.0 )
1177 {
1178     p_intf = p_interface;
1179
1180         SetViewColor( B_TRANSPARENT_32_BIT );
1181         SetLowColor( kBlack );
1182         SetHighColor( 0, 255, 0, 255 );
1183         SetFontSize( 11.0 );
1184 }
1185
1186 /*****************************************************************************
1187  * PositionInfoView::~PositionInfoView
1188  *****************************************************************************/
1189 PositionInfoView::~PositionInfoView()
1190 {
1191 }
1192
1193 /*****************************************************************************
1194  * PositionInfoView::Draw
1195  *****************************************************************************/
1196 void
1197 PositionInfoView::Draw( BRect updateRect )
1198 {
1199         rgb_color background = ui_color( B_PANEL_BACKGROUND_COLOR );
1200         rgb_color shadow = tint_color( background, B_DARKEN_1_TINT );
1201         rgb_color darkShadow = tint_color( background, B_DARKEN_4_TINT );
1202         rgb_color light = tint_color( background, B_LIGHTEN_MAX_TINT );
1203         rgb_color softLight = tint_color( background, B_LIGHTEN_1_TINT );
1204         // frame
1205         BRect r( Bounds() );
1206         BeginLineArray( 8 );
1207                 AddLine( BPoint( r.left, r.bottom ),
1208                                  BPoint( r.left, r.top ), shadow );
1209                 AddLine( BPoint( r.left + 1.0, r.top ),
1210                                  BPoint( r.right, r.top ), shadow );
1211                 AddLine( BPoint( r.right, r.top + 1.0 ),
1212                                  BPoint( r.right, r.bottom ), softLight );
1213                 AddLine( BPoint( r.right - 1.0, r.bottom ),
1214                                  BPoint( r.left + 1.0, r.bottom ), softLight );
1215                 r.InsetBy( 1.0, 1.0 );
1216                 AddLine( BPoint( r.left, r.bottom ),
1217                                  BPoint( r.left, r.top ), darkShadow );
1218                 AddLine( BPoint( r.left + 1.0, r.top ),
1219                                  BPoint( r.right, r.top ), darkShadow );
1220                 AddLine( BPoint( r.right, r.top + 1.0 ),
1221                                  BPoint( r.right, r.bottom ), light );
1222                 AddLine( BPoint( r.right - 1.0, r.bottom ),
1223                                  BPoint( r.left + 1.0, r.bottom ), light );
1224         EndLineArray();
1225         // background
1226         r.InsetBy( 1.0, 1.0 );
1227         FillRect( r, B_SOLID_LOW );
1228         // contents
1229         font_height fh;
1230         GetFontHeight( &fh );
1231         switch ( fMode )
1232         {
1233                 case MODE_SMALL:
1234                 {
1235                         float width = StringWidth( fTimeString.String() );
1236                         DrawString( fTimeString.String(),
1237                                                 BPoint( r.left + r.Width() / 2.0 - width / 2.0,
1238                                                                 r.top + r.Height() / 2.0 + fh.ascent / 2.0 - 1.0 ) );
1239                         break;
1240                 }
1241                 case MODE_BIG:
1242                 {
1243                         BFont font;
1244                         GetFont( &font );
1245                         BFont smallFont = font;
1246                         BFont bigFont = font;
1247                         BFont tinyFont = font;
1248                         smallFont.SetSize( r.Height() / 5.0 );
1249                         bigFont.SetSize( r.Height() / 3.0 );
1250                         tinyFont.SetSize( r.Height() / 7.0 );
1251                         float timeHeight = r.Height() / 2.5;
1252                         float height = ( r.Height() - timeHeight ) / 3.0;
1253                         SetFont( &tinyFont );
1254                         SetHighColor( 0, 180, 0, 255 );
1255                         DrawString( _("File"), BPoint( r.left + 3.0, r.top + height ) );
1256                         DrawString( _("Title"), BPoint( r.left + 3.0, r.top + 2.0 * height ) );
1257                         DrawString( _("Chapter"), BPoint( r.left + 3.0, r.top + 3.0 * height ) );
1258                         SetFont( &smallFont );
1259                         BString helper;
1260                         SetHighColor( 0, 255, 0, 255 );
1261                         // file
1262                         _MakeString( helper, fCurrentFileIndex, fCurrentFileSize );
1263                         float width = StringWidth( helper.String() );
1264                         DrawString( helper.String(), BPoint( r.right - 3.0 - width, r.top + height ) );
1265                         // title
1266                         _MakeString( helper, fCurrentTitleIndex, fCurrentTitleSize );
1267                         width = StringWidth( helper.String() );
1268                         DrawString( helper.String(), BPoint( r.right - 3.0 - width, r.top + 2.0 * height ) );
1269                         // chapter
1270                         _MakeString( helper, fCurrentChapterIndex, fCurrentChapterSize );
1271                         width = StringWidth( helper.String() );
1272                         DrawString( helper.String(), BPoint( r.right - 3.0 - width, r.top + 3.0 * height ) );
1273                         // time
1274                         SetFont( &bigFont );
1275                         width = StringWidth( fTimeString.String() );
1276                         DrawString( fTimeString.String(),
1277                                                 BPoint( r.left + r.Width() / 2.0 - width / 2.0,
1278                                                                 r.bottom - 3.0 ) );
1279                         break;
1280                 }
1281         }
1282 }
1283
1284 /*****************************************************************************
1285  * PositionInfoView::ResizeToPreferred
1286  *****************************************************************************/
1287 void
1288 PositionInfoView::ResizeToPreferred()
1289 {
1290         float width, height;
1291         GetPreferredSize( &width, &height );
1292         ResizeTo( width, height );
1293 }
1294
1295 /*****************************************************************************
1296  * PositionInfoView::GetPreferredSize
1297  *****************************************************************************/
1298 void
1299 PositionInfoView::GetPreferredSize( float* width, float* height )
1300 {
1301         if ( width && height )
1302         {
1303                 *width = 5.0 + ceilf( StringWidth( "0:00:00" ) ) + 5.0;
1304                 font_height fh;
1305                 GetFontHeight( &fh );
1306                 *height = 3.0 + ceilf( fh.ascent ) + 3.0;
1307                 fStackedWidthCache = *width * 1.2;
1308                 fStackedHeightCache = *height * 2.7;
1309         }
1310 }
1311
1312 /*****************************************************************************
1313  * PositionInfoView::Pulse
1314  *****************************************************************************/
1315 void
1316 PositionInfoView::Pulse()
1317 {
1318         // allow for Pulse frequency to be higher, MediaControlView needs it
1319         bigtime_t now = system_time();
1320         if ( now - fLastPulseUpdate > 900000 )
1321         {
1322                 int32 index, size;
1323                 p_intf->p_sys->p_wrapper->GetPlaylistInfo( index, size );
1324                 SetFile( index + 1, size );
1325                 p_intf->p_sys->p_wrapper->TitleInfo( index, size );
1326                 SetTitle( index, size );
1327                 p_intf->p_sys->p_wrapper->ChapterInfo( index, size );
1328                 SetChapter( index, size );
1329                 SetTime( p_intf->p_sys->p_wrapper->GetTimeAsString() );
1330                 fLastPulseUpdate = now;
1331         }
1332 }
1333
1334 /*****************************************************************************
1335  * PositionInfoView::GetBigPreferredSize
1336  *****************************************************************************/
1337 void
1338 PositionInfoView::GetBigPreferredSize( float* width, float* height )
1339 {
1340         if ( width && height )
1341         {
1342                 *width = fStackedWidthCache;
1343                 *height = fStackedHeightCache;
1344         }
1345 }
1346
1347 /*****************************************************************************
1348  * PositionInfoView::SetMode
1349  *****************************************************************************/
1350 void
1351 PositionInfoView::SetMode( uint32 mode )
1352 {
1353         if ( fMode != mode )
1354         {
1355                 fMode = mode;
1356                 _InvalidateContents();
1357         }
1358 }
1359
1360 /*****************************************************************************
1361  * PositionInfoView::SetFile
1362  *****************************************************************************/
1363 void
1364 PositionInfoView::SetFile( int32 index, int32 size )
1365 {
1366         if ( fCurrentFileIndex != index || fCurrentFileSize != size )
1367         {
1368                 fCurrentFileIndex = index;
1369                 fCurrentFileSize = size;
1370                 _InvalidateContents();
1371         }
1372 }
1373
1374 /*****************************************************************************
1375  * PositionInfoView::SetTitle
1376  *****************************************************************************/
1377 void
1378 PositionInfoView::SetTitle( int32 index, int32 size )
1379 {
1380         if ( fCurrentTitleIndex != index || fCurrentFileSize != size )
1381         {
1382                 fCurrentTitleIndex = index;
1383                 fCurrentTitleSize = size;
1384                 _InvalidateContents();
1385         }
1386 }
1387
1388 /*****************************************************************************
1389  * PositionInfoView::SetChapter
1390  *****************************************************************************/
1391 void
1392 PositionInfoView::SetChapter( int32 index, int32 size )
1393 {
1394         if ( fCurrentChapterIndex != index || fCurrentFileSize != size )
1395         {
1396                 fCurrentChapterIndex = index;
1397                 fCurrentChapterSize = size;
1398                 _InvalidateContents();
1399         }
1400 }
1401
1402 /*****************************************************************************
1403  * PositionInfoView::SetTime
1404  *****************************************************************************/
1405 void
1406 PositionInfoView::SetTime( int32 seconds )
1407 {
1408         if ( fSeconds != seconds )
1409         {
1410                 if ( seconds >= 0 )
1411                 {
1412                         int32 minutes = seconds / 60;
1413                         int32 hours = minutes / 60;
1414                         seconds -= minutes * 60 - hours * 60 * 60;
1415                         minutes -= hours * 60;
1416                         fTimeString.SetTo( "" );
1417                         fTimeString << hours << ":" << minutes << ":" << seconds;
1418                 }
1419                 else
1420                         fTimeString.SetTo( "-:--:--" );
1421
1422                 fSeconds = seconds;
1423                 _InvalidateContents();
1424         }
1425 }
1426
1427 /*****************************************************************************
1428  * PositionInfoView::SetTime
1429  *****************************************************************************/
1430 void
1431 PositionInfoView::SetTime( const char* string )
1432 {
1433         fTimeString.SetTo( string );
1434         _InvalidateContents();
1435 }
1436
1437 /*****************************************************************************
1438  * PositionInfoView::_InvalidateContents
1439  *****************************************************************************/
1440 void
1441 PositionInfoView::_InvalidateContents( uint32 which )
1442 {
1443         BRect r( Bounds() );
1444         r.InsetBy( 2.0, 2.0 );
1445         Invalidate( r );
1446 }
1447
1448 /*****************************************************************************
1449  * PositionInfoView::_InvalidateContents
1450  *****************************************************************************/
1451 void
1452 PositionInfoView::_MakeString( BString& into, int32 index, int32 maxIndex ) const
1453 {
1454         into = "";
1455         if ( index >= 0 && maxIndex >= 0 )
1456                 into << index;
1457         else
1458                 into << "-";
1459         into << "/";
1460         if ( maxIndex >= 0 )
1461                 into << maxIndex;
1462         else
1463                 into << "-";
1464 }