1 /*****************************************************************************
2 * MediaControlView.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: MediaControlView.cpp,v 1.5 2001/11/30 09:49:04 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>
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43 #include "interface.h"
44 #include "intf_playlist.h"
47 /* BeOS interface headers */
50 #include "TransportButton.h"
51 #include "MediaControlView.h"
54 MediaControlView::MediaControlView( BRect frame )
55 : BBox( frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER )
57 float xStart = HORZ_SPACE;
58 float yStart = VERT_SPACE;
61 BRect controlRect = BRect(xStart,yStart,
62 frame.Width() - (HORZ_SPACE * 2), 15);
65 rgb_color fill_color = {0,255,0};
66 p_seek = new SeekSlider(controlRect, this, 0, 100, B_TRIANGLE_THUMB);
68 p_seek->UseFillColor(true, &fill_color);
70 yStart += 15 + VERT_SPACE;
75 controlRect.SetLeftTop(BPoint(xStart, yStart));
76 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
77 xStart += kRewindBitmapWidth;
78 p_slow = new TransportButton(controlRect, B_EMPTY_STRING,
80 kPressedSkipBackBitmapBits,
81 kDisabledSkipBackBitmapBits,
82 new BMessage(SLOWER_PLAY));
86 controlRect.SetLeftTop(BPoint(xStart, yStart));
87 controlRect.SetRightBottom(controlRect.LeftTop() + kPlayButtonSize);
88 xStart += kPlayPauseBitmapWidth + 1.0;
89 p_play = new PlayPauseButton(controlRect, B_EMPTY_STRING,
90 kPlayButtonBitmapBits,
91 kPressedPlayButtonBitmapBits,
92 kDisabledPlayButtonBitmapBits,
93 kPlayingPlayButtonBitmapBits,
94 kPressedPlayingPlayButtonBitmapBits,
95 kPausedPlayButtonBitmapBits,
96 kPressedPausedPlayButtonBitmapBits,
97 new BMessage(START_PLAYBACK));
102 controlRect.SetLeftTop(BPoint(xStart, yStart));
103 controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
104 xStart += kRewindBitmapWidth;
105 p_fast = new TransportButton(controlRect, B_EMPTY_STRING,
106 kSkipForwardBitmapBits,
107 kPressedSkipForwardBitmapBits,
108 kDisabledSkipForwardBitmapBits,
109 new BMessage(FASTER_PLAY));
113 controlRect.SetLeftTop(BPoint(xStart, yStart));
114 controlRect.SetRightBottom(controlRect.LeftTop() + kStopButtonSize);
115 xStart += kStopBitmapWidth;
116 p_stop = new TransportButton(controlRect, B_EMPTY_STRING,
117 kStopButtonBitmapBits,
118 kPressedStopButtonBitmapBits,
119 kDisabledStopButtonBitmapBits,
120 new BMessage(STOP_PLAYBACK));
123 controlRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
124 controlRect.SetRightBottom(controlRect.LeftTop() + kSpeakerButtonSize);
125 xStart += kSpeakerIconBitmapWidth;
127 p_mute = new TransportButton(controlRect, B_EMPTY_STRING,
129 kPressedSpeakerIconBits,
131 new BMessage(VOLUME_MUTE));
136 p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
138 p_vol->SetValue(VOLUME_DEFAULT);
139 p_vol->UseFillColor(true, &fill_color);
144 MediaControlView::~MediaControlView()
148 void MediaControlView::MessageReceived(BMessage *message)
152 void MediaControlView::SetProgress(uint64 seek, uint64 size)
154 p_seek->SetPosition((float)seek/size);
157 void MediaControlView::SetStatus(int status, int rate)
165 p_play->SetPlaying();
173 p_play->SetStopped();
176 if ( rate < DEFAULT_RATE )
181 void MediaControlView::SetEnabled(bool enabled)
183 p_slow->SetEnabled(enabled);
184 p_play->SetEnabled(enabled);
185 p_fast->SetEnabled(enabled);
186 p_stop->SetEnabled(enabled);
187 p_mute->SetEnabled(enabled);
188 p_vol->SetEnabled(enabled);
189 p_seek->SetEnabled(enabled);
192 uint32 MediaControlView::GetSeekTo()
194 return p_seek->seekTo;
197 uint32 MediaControlView::GetVolume()
199 return p_vol->Value();
203 /*****************************************************************************
205 *****************************************************************************/
206 MediaSlider::MediaSlider( BRect frame, BMessage *p_message,
207 int32 i_min, int32 i_max )
208 :BSlider(frame, NULL, NULL, p_message, i_min, i_max )
213 MediaSlider::~MediaSlider()
218 void MediaSlider::DrawThumb(void)
223 rgb_color black = {0,0,0};
229 v->SetHighColor(black);
233 v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
236 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
241 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
245 v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
252 /*****************************************************************************
254 *****************************************************************************/
255 SeekSlider::SeekSlider( BRect frame, MediaControlView *p_owner, int32 i_min,
256 int32 i_max, thumb_style thumbType = B_TRIANGLE_THUMB )
257 :MediaSlider( frame, NULL, i_min, i_max )
263 SeekSlider::~SeekSlider()
267 /*****************************************************************************
268 * SeekSlider::MouseDown
269 *****************************************************************************/
270 void SeekSlider::MouseDown(BPoint where)
272 BSlider::MouseDown(where);
273 seekTo = ValueForPoint(where);
274 fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
275 release_sem(fOwner->fScrubSem);
279 /*****************************************************************************
280 * SeekSlider::MouseUp
281 *****************************************************************************/
282 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
284 BSlider::MouseMoved(where, code, message);
287 seekTo = ValueForPoint(where);
288 release_sem(fOwner->fScrubSem);
291 /*****************************************************************************
292 * SeekSlider::MouseUp
293 *****************************************************************************/
294 void SeekSlider::MouseUp(BPoint where)
296 BSlider::MouseUp(where);
297 seekTo = ValueForPoint(where);
298 delete_sem(fOwner->fScrubSem);
299 fOwner->fScrubSem = B_ERROR;