Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

TransportButton.h

00001 /*****************************************************************************
00002  * TransportButton.h
00003  *****************************************************************************
00004  * Copyright (C) 2001 the VideoLAN team
00005  * $Id: TransportButton.h 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Tony Castley <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef __MEDIA_BUTTON__
00025 #define __MEDIA_BUTTON__
00026 
00027 #include <Control.h>
00028 
00029 class BMessage;
00030 class BBitmap;
00031 class PeriodicMessageSender;
00032 class BitmapStash;
00033 
00034 // TransportButton must be installed into a window with B_ASYNCHRONOUS_CONTROLS on
00035 // currently no button focus drawing
00036 
00037 class TransportButton : public BControl {
00038 public:
00039 
00040         TransportButton(BRect frame, const char *name,
00041                 const unsigned char *normalBits,
00042                 const unsigned char *pressedBits,
00043                 const unsigned char *disabledBits,
00044                 BMessage *invokeMessage,                        // done pressing over button
00045                 BMessage *startPressingMessage = 0, // just clicked button
00046                 BMessage *pressingMessage = 0,          // periodical still pressing
00047                 BMessage *donePressing = 0,             // tracked out of button/didn't invoke
00048                 bigtime_t period = 0,                           // pressing message period
00049                 uint32 key = 0,                                         // optional shortcut key
00050                 uint32 modifiers = 0,                           // optional shortcut key modifier
00051                 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP);
00052         
00053         virtual ~TransportButton();
00054 
00055         void SetStartPressingMessage(BMessage *);
00056         void SetPressingMessage(BMessage *);
00057         void SetDonePressingMessage(BMessage *);
00058         void SetPressingPeriod(bigtime_t);
00059 
00060         virtual void SetEnabled(bool);
00061 
00062 protected:              
00063 
00064         enum {
00065                 kDisabledMask = 0x1,
00066                 kPressedMask = 0x2
00067         };
00068         
00069         virtual void AttachedToWindow();
00070         virtual void DetachedFromWindow();
00071         virtual void Draw(BRect);
00072         virtual void MouseDown(BPoint);
00073         virtual void MouseMoved(BPoint, uint32 code, const BMessage *);
00074         virtual void MouseUp(BPoint);
00075         virtual void WindowActivated(bool);
00076 
00077         virtual BBitmap *MakeBitmap(uint32);
00078                 // lazy bitmap builder
00079         
00080         virtual uint32 ModeMask() const;
00081                 // mode mask corresponding to the current button state
00082                 // - determines which bitmap will be used
00083         virtual const unsigned char *BitsForMask(uint32) const;
00084                 // pick the right bits based on a mode mask
00085 
00086                 // overriding class can add swapping between two pairs of bitmaps, etc.
00087         virtual void StartPressing();
00088         virtual void MouseCancelPressing();
00089         virtual void DonePressing();
00090 
00091 private:
00092         void ShortcutKeyDown();
00093         void ShortcutKeyUp();
00094         
00095         void MouseStartPressing();
00096         void MouseDonePressing();
00097 
00098         BitmapStash *bitmaps;
00099                 // using BitmapStash * here instead of a direct member so that the class can be private in
00100                 // the .cpp file
00101 
00102         // bitmap bits used to build bitmaps for the different states
00103         const unsigned char *normalBits;
00104         const unsigned char *pressedBits;
00105         const unsigned char *disabledBits;
00106         
00107         BMessage *startPressingMessage;
00108         BMessage *pressingMessage;
00109         BMessage *donePressingMessage;
00110         bigtime_t pressingPeriod;
00111         
00112         bool mouseDown;
00113         bool keyDown;
00114         PeriodicMessageSender *messageSender;
00115         BMessageFilter *keyPressFilter;
00116 
00117         typedef BControl _inherited;
00118         
00119         friend class SkipButtonKeypressFilter;
00120         friend class BitmapStash;
00121 };
00122 
00123 class PlayPauseButton : public TransportButton {
00124 // Knows about playing and paused states, blinks
00125 // the pause LED during paused state
00126 public:
00127         PlayPauseButton(BRect frame, const char *name,
00128                 const unsigned char *normalBits,
00129                 const unsigned char *pressedBits,
00130                 const unsigned char *disabledBits,
00131                 const unsigned char *normalPlayingBits,
00132                 const unsigned char *pressedPlayingBits,
00133                 const unsigned char *normalPausedBits,
00134                 const unsigned char *pressedPausedBits,
00135                 BMessage *invokeMessage,                        // done pressing over button
00136                 uint32 key = 0,                                         // optional shortcut key
00137                 uint32 modifiers = 0,                           // optional shortcut key modifier
00138                 uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP);
00139         
00140         // These need get called periodically to update the button state
00141         // OK to call them over and over - once the state is correct, the call
00142         // is very low overhead
00143         void SetStopped();
00144         void SetPlaying();
00145         void SetPaused();
00146 
00147 protected:
00148         
00149         virtual uint32 ModeMask() const;
00150         virtual const unsigned char *BitsForMask(uint32) const;
00151 
00152         virtual void StartPressing();
00153         virtual void MouseCancelPressing();
00154         virtual void DonePressing();
00155 
00156 private:
00157         const unsigned char *normalPlayingBits;
00158         const unsigned char *pressedPlayingBits;
00159         const unsigned char *normalPausedBits;
00160         const unsigned char *pressedPausedBits;
00161         
00162         enum PlayState {
00163                 kStopped,
00164                 kAboutToPlay,
00165                 kPlaying,
00166                 kAboutToPause,
00167                 kPausedLedOn,
00168                 kPausedLedOff
00169         };
00170         
00171         enum {
00172                 kPlayingMask = 0x4,
00173                 kPausedMask = 0x8
00174         };
00175         
00176         PlayState state;
00177         bigtime_t lastPauseBlinkTime;
00178         uint32 lastModeMask;
00179         
00180         typedef TransportButton _inherited;
00181 };
00182 
00183 #endif  // __MEDIA_BUTTON__

Generated on Tue Dec 20 10:14:38 2005 for vlc-0.8.4a by  doxygen 1.4.2