ctrl_slider.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * ctrl_slider.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: ac31b9944fb3a225b1b80f5df34827be1587788b $
00006  *
00007  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
00008  *          Olivier Teulière <ipkiss@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef CTRL_SLIDER_HPP
00026 #define CTRL_SLIDER_HPP
00027 
00028 #include "ctrl_generic.hpp"
00029 #include "../utils/bezier.hpp"
00030 #include "../utils/fsm.hpp"
00031 #include "../utils/observer.hpp"
00032 
00033 
00034 class GenericBitmap;
00035 class OSGraphics;
00036 class VarPercent;
00037 
00038 
00039 /// Cursor of a slider
00040 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
00041 {
00042 public:
00043     /// Create a cursor with 3 images (which are NOT copied, be careful)
00044     /// If pVisible is NULL, the control is always visible
00045     CtrlSliderCursor( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
00046                       const GenericBitmap &rBmpOver,
00047                       const GenericBitmap &rBmpDown,
00048                       const Bezier &rCurve, VarPercent &rVariable,
00049                       VarBool *pVisible, const UString &rTooltip,
00050                       const UString &rHelp );
00051 
00052     virtual ~CtrlSliderCursor();
00053 
00054     /// Handle an event
00055     virtual void handleEvent( EvtGeneric &rEvent );
00056 
00057     /// Check whether coordinates are inside the control
00058     virtual bool mouseOver( int x, int y ) const;
00059 
00060     /// Draw the control on the given graphics
00061     virtual void draw( OSGraphics &rImage, int xDest, int yDest );
00062 
00063     /// Get the text of the tooltip
00064     virtual UString getTooltipText() const { return m_tooltip; }
00065 
00066     /// Get the type of control (custom RTTI)
00067     virtual string getType() const { return "slider_cursor"; }
00068 
00069 private:
00070     /// Finite state machine of the control
00071     FSM m_fsm;
00072     /// Variable associated to the cursor
00073     VarPercent &m_rVariable;
00074     /// Tooltip text
00075     const UString m_tooltip;
00076     /// Initial size of the control
00077     int m_width, m_height;
00078     /// Position of the cursor
00079     int m_xPosition, m_yPosition;
00080     /// Callback objects
00081     DEFINE_CALLBACK( CtrlSliderCursor, OverDown )
00082     DEFINE_CALLBACK( CtrlSliderCursor, DownOver )
00083     DEFINE_CALLBACK( CtrlSliderCursor, OverUp )
00084     DEFINE_CALLBACK( CtrlSliderCursor, UpOver )
00085     DEFINE_CALLBACK( CtrlSliderCursor, Move )
00086     DEFINE_CALLBACK( CtrlSliderCursor, Scroll )
00087     /// Last saved position of the cursor (stored as a percentage)
00088     float m_lastPercentage;
00089     /// Offset between the mouse pointer and the center of the cursor
00090     int m_xOffset, m_yOffset;
00091     /// The last received event
00092     EvtGeneric *m_pEvt;
00093     /// Images of the cursor in the differents states
00094     OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
00095     /// Current image
00096     OSGraphics *m_pImg;
00097     /// Bezier curve of the slider
00098     const Bezier &m_rCurve;
00099 
00100     /// Method called when the position variable is modified
00101     virtual void onUpdate( Subject<VarPercent> &rVariable, void * );
00102 
00103     /// Method to compute the resize factors
00104     void getResizeFactors( float &rFactorX, float &rFactorY ) const;
00105 
00106     /// Call notifyLayout
00107     void refreshLayout();
00108 };
00109 
00110 
00111 /// Slider background
00112 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
00113 {
00114 public:
00115     CtrlSliderBg( intf_thread_t *pIntf,
00116                   const Bezier &rCurve, VarPercent &rVariable,
00117                   int thickness, GenericBitmap *pBackground, int nbHoriz,
00118                   int nbVert, int padHoriz, int padVert, VarBool *pVisible,
00119                   const UString &rHelp );
00120     virtual ~CtrlSliderBg();
00121 
00122     /// Tell whether the mouse is over the control
00123     virtual bool mouseOver( int x, int y ) const;
00124 
00125     /// Draw the control on the given graphics
00126     virtual void draw( OSGraphics &rImage, int xDest, int yDest );
00127 
00128     /// Handle an event
00129     virtual void handleEvent( EvtGeneric &rEvent );
00130 
00131     /// Method called when the control is resized
00132     virtual void onResize();
00133 
00134     /// Get the type of control (custom RTTI)
00135     virtual string getType() const { return "slider_bg"; }
00136 
00137     /// Associate a cursor to this background
00138     void associateCursor( CtrlSliderCursor &rCursor );
00139 
00140 private:
00141     /// Cursor of the slider
00142     CtrlSliderCursor *m_pCursor;
00143     /// Variable associated to the slider
00144     VarPercent &m_rVariable;
00145     /// Thickness of the curve
00146     int m_thickness;
00147     /// Bezier curve of the slider
00148     const Bezier &m_rCurve;
00149     /// Initial size of the control
00150     int m_width, m_height;
00151     /// Background image sequence (optional)
00152     GenericBitmap *m_pImgSeq;
00153     /// Number of images in the background bitmap
00154     int m_nbHoriz, m_nbVert;
00155     /// Number of pixels between two images
00156     int m_padHoriz, m_padVert;
00157     /// Size of a background image
00158     int m_bgWidth, m_bgHeight;
00159     /// Index of the current background image
00160     int m_position;
00161 
00162     /// Method called when the observed variable is modified
00163     virtual void onUpdate( Subject<VarPercent> &rVariable, void* );
00164 
00165     /// Method to compute the resize factors
00166     void getResizeFactors( float &rFactorX, float &rFactorY ) const;
00167 };
00168 
00169 
00170 #endif

Generated on Tue May 25 08:04:58 2010 for VLC by  doxygen 1.5.6