1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001 the VideoLAN team
7 * Authors: Tony Castley <tcastley@mail.powerup.com.au>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef __MEDIA_BUTTON__
25 #define __MEDIA_BUTTON__
31 class PeriodicMessageSender;
34 // TransportButton must be installed into a window with B_ASYNCHRONOUS_CONTROLS on
35 // currently no button focus drawing
37 class TransportButton : public BControl {
40 TransportButton(BRect frame, const char *name,
41 const unsigned char *normalBits,
42 const unsigned char *pressedBits,
43 const unsigned char *disabledBits,
44 BMessage *invokeMessage, // done pressing over button
45 BMessage *startPressingMessage = 0, // just clicked button
46 BMessage *pressingMessage = 0, // periodical still pressing
47 BMessage *donePressing = 0, // tracked out of button/didn't invoke
48 bigtime_t period = 0, // pressing message period
49 uint32 key = 0, // optional shortcut key
50 uint32 modifiers = 0, // optional shortcut key modifier
51 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP);
53 virtual ~TransportButton();
55 void SetStartPressingMessage(BMessage *);
56 void SetPressingMessage(BMessage *);
57 void SetDonePressingMessage(BMessage *);
58 void SetPressingPeriod(bigtime_t);
60 virtual void SetEnabled(bool);
69 virtual void AttachedToWindow();
70 virtual void DetachedFromWindow();
71 virtual void Draw(BRect);
72 virtual void MouseDown(BPoint);
73 virtual void MouseMoved(BPoint, uint32 code, const BMessage *);
74 virtual void MouseUp(BPoint);
75 virtual void WindowActivated(bool);
77 virtual BBitmap *MakeBitmap(uint32);
78 // lazy bitmap builder
80 virtual uint32 ModeMask() const;
81 // mode mask corresponding to the current button state
82 // - determines which bitmap will be used
83 virtual const unsigned char *BitsForMask(uint32) const;
84 // pick the right bits based on a mode mask
86 // overriding class can add swapping between two pairs of bitmaps, etc.
87 virtual void StartPressing();
88 virtual void MouseCancelPressing();
89 virtual void DonePressing();
92 void ShortcutKeyDown();
95 void MouseStartPressing();
96 void MouseDonePressing();
99 // using BitmapStash * here instead of a direct member so that the class can be private in
102 // bitmap bits used to build bitmaps for the different states
103 const unsigned char *normalBits;
104 const unsigned char *pressedBits;
105 const unsigned char *disabledBits;
107 BMessage *startPressingMessage;
108 BMessage *pressingMessage;
109 BMessage *donePressingMessage;
110 bigtime_t pressingPeriod;
114 PeriodicMessageSender *messageSender;
115 BMessageFilter *keyPressFilter;
117 typedef BControl _inherited;
119 friend class SkipButtonKeypressFilter;
120 friend class BitmapStash;
123 class PlayPauseButton : public TransportButton {
124 // Knows about playing and paused states, blinks
125 // the pause LED during paused state
127 PlayPauseButton(BRect frame, const char *name,
128 const unsigned char *normalBits,
129 const unsigned char *pressedBits,
130 const unsigned char *disabledBits,
131 const unsigned char *normalPlayingBits,
132 const unsigned char *pressedPlayingBits,
133 const unsigned char *normalPausedBits,
134 const unsigned char *pressedPausedBits,
135 BMessage *invokeMessage, // done pressing over button
136 uint32 key = 0, // optional shortcut key
137 uint32 modifiers = 0, // optional shortcut key modifier
138 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP);
140 // These need get called periodically to update the button state
141 // OK to call them over and over - once the state is correct, the call
142 // is very low overhead
149 virtual uint32 ModeMask() const;
150 virtual const unsigned char *BitsForMask(uint32) const;
152 virtual void StartPressing();
153 virtual void MouseCancelPressing();
154 virtual void DonePressing();
157 const unsigned char *normalPlayingBits;
158 const unsigned char *pressedPlayingBits;
159 const unsigned char *normalPausedBits;
160 const unsigned char *pressedPausedBits;
177 bigtime_t lastPauseBlinkTime;
180 typedef TransportButton _inherited;
183 #endif // __MEDIA_BUTTON__