1 /*****************************************************************************
2 * MediaControlView.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: MediaControlView.cpp,v 1.7 2001/12/30 07:09:54 sam Exp $
7 * Authors: Tony Castley <tony@castley.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
25 #include <InterfaceKit.h>
32 #include <videolan/vlc.h>
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
37 #include "interface.h"
38 #include "intf_playlist.h"
41 /* BeOS interface headers */
44 #include "TransportButton.h"
45 #include "MediaControlView.h"
48 MediaControlView::MediaControlView( BRect frame )
49 : BBox( frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER )
51 float xStart = HORZ_SPACE;
52 float yStart = VERT_SPACE;
55 BRect controlRect = BRect(xStart,yStart,
56 frame.Width() - (HORZ_SPACE * 2), 15);
59 rgb_color fill_color = {0,255,0};
60 p_seek = new SeekSlider(controlRect, this, 0, 100, B_TRIANGLE_THUMB);
62 p_seek->UseFillColor(true, &fill_color);
64 yStart += 15 + VERT_SPACE;
69 controlRect.SetLeftTop(BPoint(xStart, yStart));
70 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
71 xStart += kRewindBitmapWidth;
72 p_slow = new TransportButton(controlRect, B_EMPTY_STRING,
74 kPressedSkipBackBitmapBits,
75 kDisabledSkipBackBitmapBits,
76 new BMessage(SLOWER_PLAY));
80 controlRect.SetLeftTop(BPoint(xStart, yStart));
81 controlRect.SetRightBottom(controlRect.LeftTop() + kPlayButtonSize);
82 xStart += kPlayPauseBitmapWidth + 1.0;
83 p_play = new PlayPauseButton(controlRect, B_EMPTY_STRING,
84 kPlayButtonBitmapBits,
85 kPressedPlayButtonBitmapBits,
86 kDisabledPlayButtonBitmapBits,
87 kPlayingPlayButtonBitmapBits,
88 kPressedPlayingPlayButtonBitmapBits,
89 kPausedPlayButtonBitmapBits,
90 kPressedPausedPlayButtonBitmapBits,
91 new BMessage(START_PLAYBACK));
96 controlRect.SetLeftTop(BPoint(xStart, yStart));
97 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
98 xStart += kRewindBitmapWidth;
99 p_fast = new TransportButton(controlRect, B_EMPTY_STRING,
100 kSkipForwardBitmapBits,
101 kPressedSkipForwardBitmapBits,
102 kDisabledSkipForwardBitmapBits,
103 new BMessage(FASTER_PLAY));
107 controlRect.SetLeftTop(BPoint(xStart, yStart));
108 controlRect.SetRightBottom(controlRect.LeftTop() + kStopButtonSize);
109 xStart += kStopBitmapWidth;
110 p_stop = new TransportButton(controlRect, B_EMPTY_STRING,
111 kStopButtonBitmapBits,
112 kPressedStopButtonBitmapBits,
113 kDisabledStopButtonBitmapBits,
114 new BMessage(STOP_PLAYBACK));
117 controlRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
118 controlRect.SetRightBottom(controlRect.LeftTop() + kSpeakerButtonSize);
119 xStart += kSpeakerIconBitmapWidth;
121 p_mute = new TransportButton(controlRect, B_EMPTY_STRING,
123 kPressedSpeakerIconBits,
125 new BMessage(VOLUME_MUTE));
130 p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
132 p_vol->SetValue(VOLUME_DEFAULT);
133 p_vol->UseFillColor(true, &fill_color);
138 MediaControlView::~MediaControlView()
142 void MediaControlView::MessageReceived(BMessage *message)
146 void MediaControlView::SetProgress(uint64 seek, uint64 size)
148 p_seek->SetPosition((float)seek/size);
151 void MediaControlView::SetStatus(int status, int rate)
159 p_play->SetPlaying();
167 p_play->SetStopped();
170 if ( rate < DEFAULT_RATE )
175 void MediaControlView::SetEnabled(bool enabled)
177 p_slow->SetEnabled(enabled);
178 p_play->SetEnabled(enabled);
179 p_fast->SetEnabled(enabled);
180 p_stop->SetEnabled(enabled);
181 p_mute->SetEnabled(enabled);
182 p_vol->SetEnabled(enabled);
183 p_seek->SetEnabled(enabled);
186 uint32 MediaControlView::GetSeekTo()
188 return p_seek->seekTo;
191 uint32 MediaControlView::GetVolume()
193 return p_vol->Value();
197 /*****************************************************************************
199 *****************************************************************************/
200 MediaSlider::MediaSlider( BRect frame, BMessage *p_message,
201 int32 i_min, int32 i_max )
202 :BSlider(frame, NULL, NULL, p_message, i_min, i_max )
207 MediaSlider::~MediaSlider()
212 void MediaSlider::DrawThumb(void)
217 rgb_color black = {0,0,0};
223 v->SetHighColor(black);
227 v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
230 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
235 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
239 v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
246 /*****************************************************************************
248 *****************************************************************************/
249 SeekSlider::SeekSlider( BRect frame, MediaControlView *p_owner, int32 i_min,
250 int32 i_max, thumb_style thumbType = B_TRIANGLE_THUMB )
251 :MediaSlider( frame, NULL, i_min, i_max )
257 SeekSlider::~SeekSlider()
261 /*****************************************************************************
262 * SeekSlider::MouseDown
263 *****************************************************************************/
264 void SeekSlider::MouseDown(BPoint where)
266 BSlider::MouseDown(where);
267 seekTo = ValueForPoint(where);
268 fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
269 release_sem(fOwner->fScrubSem);
273 /*****************************************************************************
274 * SeekSlider::MouseUp
275 *****************************************************************************/
276 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
278 BSlider::MouseMoved(where, code, message);
281 seekTo = ValueForPoint(where);
282 release_sem(fOwner->fScrubSem);
285 /*****************************************************************************
286 * SeekSlider::MouseUp
287 *****************************************************************************/
288 void SeekSlider::MouseUp(BPoint where)
290 BSlider::MouseUp(where);
291 seekTo = ValueForPoint(where);
292 delete_sem(fOwner->fScrubSem);
293 fOwner->fScrubSem = B_ERROR;