]> git.sesse.net Git - vlc/blob - plugins/beos/MediaControlView.cpp
Some heavy changes today:
[vlc] / plugins / beos / MediaControlView.cpp
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 $
6  *
7  * Authors: Tony Castley <tony@castley.net>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /* System headers */
25 #include <InterfaceKit.h>
26 #include <AppKit.h>
27 #include <string.h>
28
29 /* VLC headers */
30 extern "C"
31 {
32 #include <videolan/vlc.h>
33
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
36
37 #include "interface.h"
38 #include "intf_playlist.h"
39 }
40
41 /* BeOS interface headers */
42 #include "MsgVals.h"
43 #include "Bitmaps.h"
44 #include "TransportButton.h"
45 #include "MediaControlView.h"
46
47
48 MediaControlView::MediaControlView( BRect frame )
49     : BBox( frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER )
50 {
51         float xStart = HORZ_SPACE;
52         float yStart = VERT_SPACE;
53         fScrubSem = B_ERROR;
54         
55         BRect controlRect = BRect(xStart,yStart, 
56                                   frame.Width() - (HORZ_SPACE * 2), 15);
57         
58     /* Seek Status */
59     rgb_color fill_color = {0,255,0};
60     p_seek = new SeekSlider(controlRect, this, 0, 100, B_TRIANGLE_THUMB);
61     p_seek->SetValue(0);
62     p_seek->UseFillColor(true, &fill_color);
63     AddChild( p_seek );
64     yStart += 15 + VERT_SPACE;
65
66
67     /* Buttons */
68     /* Slow play */
69     controlRect.SetLeftTop(BPoint(xStart, yStart));
70     controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
71     xStart += kRewindBitmapWidth;
72     p_slow = new TransportButton(controlRect, B_EMPTY_STRING,
73                                             kSkipBackBitmapBits,
74                                             kPressedSkipBackBitmapBits,
75                                             kDisabledSkipBackBitmapBits,
76                                             new BMessage(SLOWER_PLAY));
77     AddChild( p_slow );
78
79     /* Play Pause */
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));
92
93     AddChild( p_play );
94
95     /* Fast Foward */
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));
104     AddChild( p_fast );
105
106     /* Stop */
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));
115     AddChild( p_stop );
116
117     controlRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
118     controlRect.SetRightBottom(controlRect.LeftTop() + kSpeakerButtonSize);
119     xStart += kSpeakerIconBitmapWidth;
120
121     p_mute = new TransportButton(controlRect, B_EMPTY_STRING,
122                                             kSpeakerIconBits,
123                                             kPressedSpeakerIconBits,
124                                             kSpeakerIconBits,
125                                             new BMessage(VOLUME_MUTE));
126
127     AddChild( p_mute );
128
129     /* Volume Slider */
130     p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
131                             0, VOLUME_MAX);
132     p_vol->SetValue(VOLUME_DEFAULT);
133     p_vol->UseFillColor(true, &fill_color);
134     AddChild( p_vol );
135
136 }
137
138 MediaControlView::~MediaControlView()
139 {
140 }
141
142 void MediaControlView::MessageReceived(BMessage *message)
143 {
144 }
145
146 void MediaControlView::SetProgress(uint64 seek, uint64 size)
147 {
148         p_seek->SetPosition((float)seek/size);
149 }
150
151 void MediaControlView::SetStatus(int status, int rate)
152 {
153     switch( status )
154     {
155         case PLAYING_S:
156         case FORWARD_S:
157         case BACKWARD_S:
158         case START_S:
159             p_play->SetPlaying();
160             break;
161         case PAUSE_S:
162             p_play->SetPaused();
163             break;
164         case UNDEF_S:
165         case NOT_STARTED_S:
166         default:
167             p_play->SetStopped();
168             break;
169     }
170     if ( rate < DEFAULT_RATE )
171     {
172     }
173 }
174
175 void MediaControlView::SetEnabled(bool enabled)
176 {
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);
184 }
185
186 uint32 MediaControlView::GetSeekTo()
187 {
188         return p_seek->seekTo;
189 }
190
191 uint32 MediaControlView::GetVolume()
192 {
193         return p_vol->Value();
194 }
195
196
197 /*****************************************************************************
198  * MediaSlider
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 )
203 {
204
205 }
206
207 MediaSlider::~MediaSlider()
208 {
209
210 }
211
212 void MediaSlider::DrawThumb(void)
213 {
214     BRect r;
215     BView *v;
216
217     rgb_color black = {0,0,0};
218     r = ThumbFrame();
219     v = OffscreenView();
220
221     if(IsEnabled())
222     {
223         v->SetHighColor(black);
224     }
225     else
226     {
227         v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
228     }
229
230     r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
231     v->StrokeEllipse(r);
232
233     if(IsEnabled())
234     {
235         v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
236     }
237     else
238     {
239         v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
240     }
241
242     r.InsetBy(1,1);
243     v->FillEllipse(r);
244 }
245
246 /*****************************************************************************
247  * SeekSlider
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 )
252 {
253     fOwner = p_owner;
254     fMouseDown = false;
255 }
256
257 SeekSlider::~SeekSlider()
258 {
259 }
260
261 /*****************************************************************************
262  * SeekSlider::MouseDown
263  *****************************************************************************/
264 void SeekSlider::MouseDown(BPoint where)
265 {
266     BSlider::MouseDown(where);
267     seekTo = ValueForPoint(where);
268     fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
269     release_sem(fOwner->fScrubSem);
270     fMouseDown = true;
271 }
272
273 /*****************************************************************************
274  * SeekSlider::MouseUp
275  *****************************************************************************/
276 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
277 {
278     BSlider::MouseMoved(where, code, message);
279     if (!fMouseDown)
280         return;
281     seekTo = ValueForPoint(where);
282     release_sem(fOwner->fScrubSem);
283 }
284
285 /*****************************************************************************
286  * SeekSlider::MouseUp
287  *****************************************************************************/
288 void SeekSlider::MouseUp(BPoint where)
289 {
290     BSlider::MouseUp(where);
291     seekTo = ValueForPoint(where);
292     delete_sem(fOwner->fScrubSem);
293     fOwner->fScrubSem = B_ERROR;
294     fMouseDown = false;
295 }