]> git.sesse.net Git - vlc/blob - modules/gui/beos/MediaControlView.cpp
Updated to use the new AOUT_VOLUME_* constants.
[vlc] / modules / gui / beos / MediaControlView.cpp
1 /*****************************************************************************
2  * MediaControlView.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: MediaControlView.cpp,v 1.2 2002/09/18 11:50:47 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
24 /* System headers */
25 #include <InterfaceKit.h>
26 #include <AppKit.h>
27 #include <string.h>
28
29 /* VLC headers */
30 #include <vlc/vlc.h>
31 #include <vlc/intf.h>
32
33 /* BeOS interface headers */
34 #include "MsgVals.h"
35 #include "Bitmaps.h"
36 #include "TransportButton.h"
37 #include "MediaControlView.h"
38
39
40 MediaControlView::MediaControlView( BRect frame )
41     : BBox( frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER )
42 {
43         float xStart = HORZ_SPACE;
44         float yStart = VERT_SPACE;
45         fScrubSem = B_ERROR;
46         
47         BRect controlRect = BRect(xStart,yStart, 
48                                   frame.Width() - (HORZ_SPACE * 2), 15);
49         
50     /* Seek Status */
51     rgb_color fill_color = {0,255,0};
52     p_seek = new SeekSlider(controlRect, this, 0, 100, B_TRIANGLE_THUMB);
53     p_seek->SetValue(0);
54     p_seek->UseFillColor(true, &fill_color);
55     AddChild( p_seek );
56     yStart += 15 + VERT_SPACE;
57
58
59     /* Buttons */
60     /* Slow play */
61     controlRect.SetLeftTop(BPoint(xStart, yStart));
62     controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
63     xStart += kRewindBitmapWidth;
64     p_slow = new TransportButton(controlRect, B_EMPTY_STRING,
65                                             kSkipBackBitmapBits,
66                                             kPressedSkipBackBitmapBits,
67                                             kDisabledSkipBackBitmapBits,
68                                             new BMessage(SLOWER_PLAY));
69     AddChild( p_slow );
70
71     /* Play Pause */
72     controlRect.SetLeftTop(BPoint(xStart, yStart));
73     controlRect.SetRightBottom(controlRect.LeftTop() + kPlayButtonSize);
74     xStart += kPlayPauseBitmapWidth + 1.0;
75     p_play = new PlayPauseButton(controlRect, B_EMPTY_STRING,
76                                             kPlayButtonBitmapBits,
77                                             kPressedPlayButtonBitmapBits,
78                                             kDisabledPlayButtonBitmapBits,
79                                             kPlayingPlayButtonBitmapBits,
80                                             kPressedPlayingPlayButtonBitmapBits,
81                                             kPausedPlayButtonBitmapBits,
82                                             kPressedPausedPlayButtonBitmapBits,
83                                             new BMessage(START_PLAYBACK));
84
85     AddChild( p_play );
86
87     /* Fast Foward */
88     controlRect.SetLeftTop(BPoint(xStart, yStart));
89     controlRect.SetRightBottom(controlRect.LeftTop() + kSkipButtonSize);
90     xStart += kRewindBitmapWidth;
91     p_fast = new TransportButton(controlRect, B_EMPTY_STRING,
92                                             kSkipForwardBitmapBits,
93                                             kPressedSkipForwardBitmapBits,
94                                             kDisabledSkipForwardBitmapBits,
95                                             new BMessage(FASTER_PLAY));
96     AddChild( p_fast );
97
98     /* Stop */
99     controlRect.SetLeftTop(BPoint(xStart, yStart));
100     controlRect.SetRightBottom(controlRect.LeftTop() + kStopButtonSize);
101     xStart += kStopBitmapWidth;
102     p_stop = new TransportButton(controlRect, B_EMPTY_STRING,
103                                             kStopButtonBitmapBits,
104                                             kPressedStopButtonBitmapBits,
105                                             kDisabledStopButtonBitmapBits,
106                                             new BMessage(STOP_PLAYBACK));
107     AddChild( p_stop );
108
109     controlRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
110     controlRect.SetRightBottom(controlRect.LeftTop() + kSpeakerButtonSize);
111     xStart += kSpeakerIconBitmapWidth;
112
113     p_mute = new TransportButton(controlRect, B_EMPTY_STRING,
114                                             kSpeakerIconBits,
115                                             kPressedSpeakerIconBits,
116                                             kSpeakerIconBits,
117                                             new BMessage(VOLUME_MUTE));
118
119     AddChild( p_mute );
120
121     /* Volume Slider */
122     p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
123                             AOUT_VOLUME_MIN, AOUT_VOLUME_MAX);
124     p_vol->SetValue(AOUT_VOLUME_DEFAULT);
125     p_vol->UseFillColor(true, &fill_color);
126     AddChild( p_vol );
127
128 }
129
130 MediaControlView::~MediaControlView()
131 {
132 }
133
134 void MediaControlView::MessageReceived(BMessage *message)
135 {
136 }
137
138 void MediaControlView::SetProgress(uint64 seek, uint64 size)
139 {
140         p_seek->SetPosition((float)seek/size);
141 }
142
143 void MediaControlView::SetStatus(int status, int rate)
144 {
145     switch( status )
146     {
147         case PLAYING_S:
148         case FORWARD_S:
149         case BACKWARD_S:
150         case START_S:
151             p_play->SetPlaying();
152             break;
153         case PAUSE_S:
154             p_play->SetPaused();
155             break;
156         case UNDEF_S:
157         case NOT_STARTED_S:
158         default:
159             p_play->SetStopped();
160             break;
161     }
162     if ( rate < DEFAULT_RATE )
163     {
164     }
165 }
166
167 void MediaControlView::SetEnabled(bool enabled)
168 {
169         p_slow->SetEnabled(enabled);
170         p_play->SetEnabled(enabled);
171         p_fast->SetEnabled(enabled);
172         p_stop->SetEnabled(enabled);
173         p_mute->SetEnabled(enabled);
174         p_vol->SetEnabled(enabled);
175         p_seek->SetEnabled(enabled);
176 }
177
178 uint32 MediaControlView::GetSeekTo()
179 {
180         return p_seek->seekTo;
181 }
182
183 uint32 MediaControlView::GetVolume()
184 {
185         return p_vol->Value();
186 }
187
188
189 /*****************************************************************************
190  * MediaSlider
191  *****************************************************************************/
192 MediaSlider::MediaSlider( BRect frame, BMessage *p_message,
193                           int32 i_min, int32 i_max )
194             :BSlider(frame, NULL, NULL, p_message, i_min, i_max )
195 {
196
197 }
198
199 MediaSlider::~MediaSlider()
200 {
201
202 }
203
204 void MediaSlider::DrawThumb(void)
205 {
206     BRect r;
207     BView *v;
208
209     rgb_color black = {0,0,0};
210     r = ThumbFrame();
211     v = OffscreenView();
212
213     if(IsEnabled())
214     {
215         v->SetHighColor(black);
216     }
217     else
218     {
219         v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
220     }
221
222     r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
223     v->StrokeEllipse(r);
224
225     if(IsEnabled())
226     {
227         v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
228     }
229     else
230     {
231         v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
232     }
233
234     r.InsetBy(1,1);
235     v->FillEllipse(r);
236 }
237
238 /*****************************************************************************
239  * SeekSlider
240  *****************************************************************************/
241 SeekSlider::SeekSlider( BRect frame, MediaControlView *p_owner, int32 i_min,
242                         int32 i_max, thumb_style thumbType = B_TRIANGLE_THUMB )
243            :MediaSlider( frame, NULL, i_min, i_max )
244 {
245     fOwner = p_owner;
246     fMouseDown = false;
247 }
248
249 SeekSlider::~SeekSlider()
250 {
251 }
252
253 /*****************************************************************************
254  * SeekSlider::MouseDown
255  *****************************************************************************/
256 void SeekSlider::MouseDown(BPoint where)
257 {
258     BSlider::MouseDown(where);
259     seekTo = ValueForPoint(where);
260     fOwner->fScrubSem = create_sem(0, "Vlc::fScrubSem");
261     release_sem(fOwner->fScrubSem);
262     fMouseDown = true;
263 }
264
265 /*****************************************************************************
266  * SeekSlider::MouseUp
267  *****************************************************************************/
268 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
269 {
270     BSlider::MouseMoved(where, code, message);
271     if (!fMouseDown)
272         return;
273     seekTo = ValueForPoint(where);
274     release_sem(fOwner->fScrubSem);
275 }
276
277 /*****************************************************************************
278  * SeekSlider::MouseUp
279  *****************************************************************************/
280 void SeekSlider::MouseUp(BPoint where)
281 {
282     BSlider::MouseUp(where);
283     seekTo = ValueForPoint(where);
284     delete_sem(fOwner->fScrubSem);
285     fOwner->fScrubSem = B_ERROR;
286     fMouseDown = false;
287 }