]> git.sesse.net Git - vlc/blob - plugins/beos/MediaControlView.cpp
801b8ee25f8ef7e08b033288d2a62310f2282c34
[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.2 2001/09/12 01:31:37 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
29 /* VLC headers */
30 extern "C"
31 {
32 #include "config.h"
33 #include "common.h"
34 #include "threads.h"
35 #include "mtime.h"
36 #include "main.h"
37 #include "tests.h"
38 #include "stream_control.h"
39 #include "input_ext-intf.h"
40 #include "interface.h"
41 #include "intf_msg.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        intf_Msg("Fastler Rate: %d", rate);
177     }
178 }
179
180 void MediaControlView::SetEnabled(bool enabled)
181 {
182         p_slow->SetEnabled(enabled);
183         p_play->SetEnabled(enabled);
184         p_fast->SetEnabled(enabled);
185         p_stop->SetEnabled(enabled);
186         p_mute->SetEnabled(enabled);
187         p_vol->SetEnabled(enabled);
188         p_seek->SetEnabled(enabled);
189 }
190
191 uint32 MediaControlView::GetSeekTo()
192 {
193         return p_seek->seekTo;
194 }
195
196 uint32 MediaControlView::GetVolume()
197 {
198         return p_vol->Value();
199 }
200
201
202 /*****************************************************************************
203  * MediaSlider
204  *****************************************************************************/
205 MediaSlider::MediaSlider( BRect frame, BMessage *p_message,
206                           int32 i_min, int32 i_max )
207             :BSlider(frame, NULL, NULL, p_message, i_min, i_max )
208 {
209
210 }
211
212 MediaSlider::~MediaSlider()
213 {
214
215 }
216
217 void MediaSlider::DrawThumb(void)
218 {
219     BRect r;
220     BView *v;
221
222     rgb_color black = {0,0,0};
223     r = ThumbFrame();
224     v = OffscreenView();
225
226     if(IsEnabled())
227     {
228         v->SetHighColor(black);
229     }
230     else
231     {
232         v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
233     }
234
235     r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
236     v->StrokeEllipse(r);
237
238     if(IsEnabled())
239     {
240         v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
241     }
242     else
243     {
244         v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
245     }
246
247     r.InsetBy(1,1);
248     v->FillEllipse(r);
249 }
250
251 /*****************************************************************************
252  * SeekSlider
253  *****************************************************************************/
254 SeekSlider::SeekSlider( BRect frame, MediaControlView *p_owner, int32 i_min,
255                         int32 i_max, thumb_style thumbType = B_TRIANGLE_THUMB )
256            :MediaSlider( frame, NULL, i_min, i_max )
257 {
258     fOwner = p_owner;
259     fMouseDown = false;
260 }
261
262 SeekSlider::~SeekSlider()
263 {
264 }
265
266 /*****************************************************************************
267  * SeekSlider::MouseDown
268  *****************************************************************************/
269 void SeekSlider::MouseDown(BPoint where)
270 {
271     BSlider::MouseDown(where);
272     seekTo = ValueForPoint(where);
273     fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
274     release_sem(fOwner->fScrubSem);
275     fMouseDown = true;
276 }
277
278 /*****************************************************************************
279  * SeekSlider::MouseUp
280  *****************************************************************************/
281 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
282 {
283     BSlider::MouseMoved(where, code, message);
284     if (!fMouseDown)
285         return;
286     seekTo = ValueForPoint(where);
287     release_sem(fOwner->fScrubSem);
288 }
289
290 /*****************************************************************************
291  * SeekSlider::MouseUp
292  *****************************************************************************/
293 void SeekSlider::MouseUp(BPoint where)
294 {
295     BSlider::MouseUp(where);
296     seekTo = ValueForPoint(where);
297     delete_sem(fOwner->fScrubSem);
298     fOwner->fScrubSem = B_ERROR;
299     fMouseDown = false;
300 }