1 /*****************************************************************************
2 * MediaControlView.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: MediaControlView.cpp,v 1.1 2002/08/04 17:23:43 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>
33 /* BeOS interface headers */
36 #include "TransportButton.h"
37 #include "MediaControlView.h"
40 MediaControlView::MediaControlView( BRect frame )
41 : BBox( frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER )
43 float xStart = HORZ_SPACE;
44 float yStart = VERT_SPACE;
47 BRect controlRect = BRect(xStart,yStart,
48 frame.Width() - (HORZ_SPACE * 2), 15);
51 rgb_color fill_color = {0,255,0};
52 p_seek = new SeekSlider(controlRect, this, 0, 100, B_TRIANGLE_THUMB);
54 p_seek->UseFillColor(true, &fill_color);
56 yStart += 15 + VERT_SPACE;
61 controlRect.SetLeftTop(BPoint(xStart, yStart));
62 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
63 xStart += kRewindBitmapWidth;
64 p_slow = new TransportButton(controlRect, B_EMPTY_STRING,
66 kPressedSkipBackBitmapBits,
67 kDisabledSkipBackBitmapBits,
68 new BMessage(SLOWER_PLAY));
72 controlRect.SetLeftTop(BPoint(xStart, yStart));
73 controlRect.SetRightBottom(controlRect.LeftTop() + kPlayButtonSize);
74 xStart += kPlayPauseBitmapWidth + 1.0;
75 p_play = new PlayPauseButton(controlRect, B_EMPTY_STRING,
76 kPlayButtonBitmapBits,
77 kPressedPlayButtonBitmapBits,
78 kDisabledPlayButtonBitmapBits,
79 kPlayingPlayButtonBitmapBits,
80 kPressedPlayingPlayButtonBitmapBits,
81 kPausedPlayButtonBitmapBits,
82 kPressedPausedPlayButtonBitmapBits,
83 new BMessage(START_PLAYBACK));
88 controlRect.SetLeftTop(BPoint(xStart, yStart));
89 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
90 xStart += kRewindBitmapWidth;
91 p_fast = new TransportButton(controlRect, B_EMPTY_STRING,
92 kSkipForwardBitmapBits,
93 kPressedSkipForwardBitmapBits,
94 kDisabledSkipForwardBitmapBits,
95 new BMessage(FASTER_PLAY));
99 controlRect.SetLeftTop(BPoint(xStart, yStart));
100 controlRect.SetRightBottom(controlRect.LeftTop() + kStopButtonSize);
101 xStart += kStopBitmapWidth;
102 p_stop = new TransportButton(controlRect, B_EMPTY_STRING,
103 kStopButtonBitmapBits,
104 kPressedStopButtonBitmapBits,
105 kDisabledStopButtonBitmapBits,
106 new BMessage(STOP_PLAYBACK));
109 controlRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
110 controlRect.SetRightBottom(controlRect.LeftTop() + kSpeakerButtonSize);
111 xStart += kSpeakerIconBitmapWidth;
113 p_mute = new TransportButton(controlRect, B_EMPTY_STRING,
115 kPressedSpeakerIconBits,
117 new BMessage(VOLUME_MUTE));
122 p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
124 p_vol->SetValue(VOLUME_DEFAULT);
125 p_vol->UseFillColor(true, &fill_color);
130 MediaControlView::~MediaControlView()
134 void MediaControlView::MessageReceived(BMessage *message)
138 void MediaControlView::SetProgress(uint64 seek, uint64 size)
140 p_seek->SetPosition((float)seek/size);
143 void MediaControlView::SetStatus(int status, int rate)
151 p_play->SetPlaying();
159 p_play->SetStopped();
162 if ( rate < DEFAULT_RATE )
167 void MediaControlView::SetEnabled(bool enabled)
169 p_slow->SetEnabled(enabled);
170 p_play->SetEnabled(enabled);
171 p_fast->SetEnabled(enabled);
172 p_stop->SetEnabled(enabled);
173 p_mute->SetEnabled(enabled);
174 p_vol->SetEnabled(enabled);
175 p_seek->SetEnabled(enabled);
178 uint32 MediaControlView::GetSeekTo()
180 return p_seek->seekTo;
183 uint32 MediaControlView::GetVolume()
185 return p_vol->Value();
189 /*****************************************************************************
191 *****************************************************************************/
192 MediaSlider::MediaSlider( BRect frame, BMessage *p_message,
193 int32 i_min, int32 i_max )
194 :BSlider(frame, NULL, NULL, p_message, i_min, i_max )
199 MediaSlider::~MediaSlider()
204 void MediaSlider::DrawThumb(void)
209 rgb_color black = {0,0,0};
215 v->SetHighColor(black);
219 v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
222 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
227 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
231 v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
238 /*****************************************************************************
240 *****************************************************************************/
241 SeekSlider::SeekSlider( BRect frame, MediaControlView *p_owner, int32 i_min,
242 int32 i_max, thumb_style thumbType = B_TRIANGLE_THUMB )
243 :MediaSlider( frame, NULL, i_min, i_max )
249 SeekSlider::~SeekSlider()
253 /*****************************************************************************
254 * SeekSlider::MouseDown
255 *****************************************************************************/
256 void SeekSlider::MouseDown(BPoint where)
258 BSlider::MouseDown(where);
259 seekTo = ValueForPoint(where);
260 fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
261 release_sem(fOwner->fScrubSem);
265 /*****************************************************************************
266 * SeekSlider::MouseUp
267 *****************************************************************************/
268 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
270 BSlider::MouseMoved(where, code, message);
273 seekTo = ValueForPoint(where);
274 release_sem(fOwner->fScrubSem);
277 /*****************************************************************************
278 * SeekSlider::MouseUp
279 *****************************************************************************/
280 void SeekSlider::MouseUp(BPoint where)
282 BSlider::MouseUp(where);
283 seekTo = ValueForPoint(where);
284 delete_sem(fOwner->fScrubSem);
285 fOwner->fScrubSem = B_ERROR;