1 /*****************************************************************************
2 * MediaControlView.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: MediaControlView.cpp,v 1.2 2001/09/12 01:31:37 tcastley 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 *****************************************************************************/
26 #include <InterfaceKit.h>
38 #include "stream_control.h"
39 #include "input_ext-intf.h"
40 #include "interface.h"
42 #include "intf_playlist.h"
45 /* BeOS interface headers */
48 #include "TransportButton.h"
49 #include "MediaControlView.h"
52 MediaControlView::MediaControlView( BRect frame )
53 : BBox( frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER )
55 float xStart = HORZ_SPACE;
56 float yStart = VERT_SPACE;
59 BRect controlRect = BRect(xStart,yStart,
60 frame.Width() - (HORZ_SPACE * 2), 15);
63 rgb_color fill_color = {0,255,0};
64 p_seek = new SeekSlider(controlRect, this, 0, 100, B_TRIANGLE_THUMB);
66 p_seek->UseFillColor(true, &fill_color);
68 yStart += 15 + VERT_SPACE;
73 controlRect.SetLeftTop(BPoint(xStart, yStart));
74 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
75 xStart += kRewindBitmapWidth;
76 p_slow = new TransportButton(controlRect, B_EMPTY_STRING,
78 kPressedSkipBackBitmapBits,
79 kDisabledSkipBackBitmapBits,
80 new BMessage(SLOWER_PLAY));
84 controlRect.SetLeftTop(BPoint(xStart, yStart));
85 controlRect.SetRightBottom(controlRect.LeftTop() + kPlayButtonSize);
86 xStart += kPlayPauseBitmapWidth + 1.0;
87 p_play = new PlayPauseButton(controlRect, B_EMPTY_STRING,
88 kPlayButtonBitmapBits,
89 kPressedPlayButtonBitmapBits,
90 kDisabledPlayButtonBitmapBits,
91 kPlayingPlayButtonBitmapBits,
92 kPressedPlayingPlayButtonBitmapBits,
93 kPausedPlayButtonBitmapBits,
94 kPressedPausedPlayButtonBitmapBits,
95 new BMessage(START_PLAYBACK));
100 controlRect.SetLeftTop(BPoint(xStart, yStart));
101 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
102 xStart += kRewindBitmapWidth;
103 p_fast = new TransportButton(controlRect, B_EMPTY_STRING,
104 kSkipForwardBitmapBits,
105 kPressedSkipForwardBitmapBits,
106 kDisabledSkipForwardBitmapBits,
107 new BMessage(FASTER_PLAY));
111 controlRect.SetLeftTop(BPoint(xStart, yStart));
112 controlRect.SetRightBottom(controlRect.LeftTop() + kStopButtonSize);
113 xStart += kStopBitmapWidth;
114 p_stop = new TransportButton(controlRect, B_EMPTY_STRING,
115 kStopButtonBitmapBits,
116 kPressedStopButtonBitmapBits,
117 kDisabledStopButtonBitmapBits,
118 new BMessage(STOP_PLAYBACK));
121 controlRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
122 controlRect.SetRightBottom(controlRect.LeftTop() + kSpeakerButtonSize);
123 xStart += kSpeakerIconBitmapWidth;
125 p_mute = new TransportButton(controlRect, B_EMPTY_STRING,
127 kPressedSpeakerIconBits,
129 new BMessage(VOLUME_MUTE));
134 p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
136 p_vol->SetValue(VOLUME_DEFAULT);
137 p_vol->UseFillColor(true, &fill_color);
142 MediaControlView::~MediaControlView()
146 void MediaControlView::MessageReceived(BMessage *message)
150 void MediaControlView::SetProgress(uint64 seek, uint64 size)
152 p_seek->SetPosition((float)seek/size);
155 void MediaControlView::SetStatus(int status, int rate)
163 p_play->SetPlaying();
171 p_play->SetStopped();
174 if ( rate < DEFAULT_RATE )
176 intf_Msg("Fastler Rate: %d", rate);
180 void MediaControlView::SetEnabled(bool enabled)
182 p_slow->SetEnabled(enabled);
183 p_play->SetEnabled(enabled);
184 p_fast->SetEnabled(enabled);
185 p_stop->SetEnabled(enabled);
186 p_mute->SetEnabled(enabled);
187 p_vol->SetEnabled(enabled);
188 p_seek->SetEnabled(enabled);
191 uint32 MediaControlView::GetSeekTo()
193 return p_seek->seekTo;
196 uint32 MediaControlView::GetVolume()
198 return p_vol->Value();
202 /*****************************************************************************
204 *****************************************************************************/
205 MediaSlider::MediaSlider( BRect frame, BMessage *p_message,
206 int32 i_min, int32 i_max )
207 :BSlider(frame, NULL, NULL, p_message, i_min, i_max )
212 MediaSlider::~MediaSlider()
217 void MediaSlider::DrawThumb(void)
222 rgb_color black = {0,0,0};
228 v->SetHighColor(black);
232 v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
235 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
240 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
244 v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
251 /*****************************************************************************
253 *****************************************************************************/
254 SeekSlider::SeekSlider( BRect frame, MediaControlView *p_owner, int32 i_min,
255 int32 i_max, thumb_style thumbType = B_TRIANGLE_THUMB )
256 :MediaSlider( frame, NULL, i_min, i_max )
262 SeekSlider::~SeekSlider()
266 /*****************************************************************************
267 * SeekSlider::MouseDown
268 *****************************************************************************/
269 void SeekSlider::MouseDown(BPoint where)
271 BSlider::MouseDown(where);
272 seekTo = ValueForPoint(where);
273 fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
274 release_sem(fOwner->fScrubSem);
278 /*****************************************************************************
279 * SeekSlider::MouseUp
280 *****************************************************************************/
281 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
283 BSlider::MouseMoved(where, code, message);
286 seekTo = ValueForPoint(where);
287 release_sem(fOwner->fScrubSem);
290 /*****************************************************************************
291 * SeekSlider::MouseUp
292 *****************************************************************************/
293 void SeekSlider::MouseUp(BPoint where)
295 BSlider::MouseUp(where);
296 seekTo = ValueForPoint(where);
297 delete_sem(fOwner->fScrubSem);
298 fOwner->fScrubSem = B_ERROR;