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