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