ctrl_text.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * ctrl_text.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: eafdb8e1b9083d1bbda04dc156f90646b3bf3289 $
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_TEXT_HPP
00026 #define CTRL_TEXT_HPP
00027 
00028 #include "ctrl_generic.hpp"
00029 #include "../utils/fsm.hpp"
00030 #include "../utils/observer.hpp"
00031 #include <string>
00032 
00033 class GenericFont;
00034 class GenericBitmap;
00035 class OSTimer;
00036 class UString;
00037 class VarText;
00038 
00039 
00040 /// Class for control text
00041 class CtrlText: public CtrlGeneric, public Observer<VarText>
00042 {
00043 public:
00044     enum Align_t
00045     {
00046         kLeft,
00047         kCenter,
00048         kRight
00049     };
00050 
00051     enum Scrolling_t
00052     {
00053         // The text starts scrolling automatically if it is larger than the
00054         // width of the control. The user can still stop it or make it
00055         // scroll manually with the mouse.
00056         kAutomatic,
00057         // Only manual scrolling is allowed (with the mouse)
00058         kManual,
00059         // No scrolling of the text is allowed
00060         kNone
00061     };
00062 
00063     /// Create a text control with the optional given color
00064     CtrlText( intf_thread_t *pIntf, VarText &rVariable,
00065               const GenericFont &rFont, const UString &rHelp,
00066               uint32_t color, VarBool *pVisible, Scrolling_t scrollMode,
00067               Align_t alignment);
00068     virtual ~CtrlText();
00069 
00070     /// Handle an event
00071     virtual void handleEvent( EvtGeneric &rEvent );
00072 
00073     /// Check whether coordinates are inside the control
00074     virtual bool mouseOver( int x, int y ) const;
00075 
00076     /// Draw the control on the given graphics
00077     virtual void draw( OSGraphics &rImage, int xDest, int yDest );
00078 
00079     /// Set the text of the control, with an optional color
00080     /// This takes effect immediatly
00081     void setText( const UString &rText, uint32_t color = 0xFFFFFFFF );
00082 
00083     /// Get the type of control (custom RTTI)
00084     virtual string getType() const { return "text"; }
00085 
00086 private:
00087     /// Finite state machine of the control
00088     FSM m_fsm;
00089     /// Variable associated to the control
00090     VarText &m_rVariable;
00091     /// Callback objects
00092     DEFINE_CALLBACK( CtrlText, ToManual )
00093     DEFINE_CALLBACK( CtrlText, ManualMoving )
00094     DEFINE_CALLBACK( CtrlText, ManualStill )
00095     DEFINE_CALLBACK( CtrlText, Move )
00096     /// The last received event
00097     EvtGeneric *m_pEvt;
00098     /// Font used to render the text
00099     const GenericFont &m_rFont;
00100     /// Color of the text
00101     uint32_t m_color;
00102     /// Scrolling mode
00103     Scrolling_t m_scrollMode;
00104     /// Type of alignment
00105     Align_t m_alignment;
00106     /// Image of the text
00107     GenericBitmap *m_pImg;
00108     /// Image of the text, repeated twice and with some blank between;
00109     /// useful to display a 'circular' moving text...
00110     GenericBitmap *m_pImgDouble;
00111     /// Current image (should always be equal to m_pImg or m_pImgDouble)
00112     GenericBitmap *m_pCurrImg;
00113     /// Position of the left side of the moving text (always <= 0)
00114     int m_xPos;
00115     /// Offset between the mouse pointer and the left side of the
00116     /// moving text
00117     int m_xOffset;
00118      /// Timer to move the text
00119     OSTimer *m_pTimer;
00120 
00121     /// Callback for the timer
00122     DEFINE_CALLBACK( CtrlText, UpdateText );
00123 
00124     /// Method called when the observed variable is modified
00125     virtual void onUpdate( Subject<VarText> &rVariable, void* );
00126 
00127     /// Method called when visibility is updated
00128     virtual void onUpdate( Subject<VarBool> &rVariable , void* );
00129 
00130     /// Display the text on the control
00131     void displayText( const UString &rText );
00132 
00133     /// Helper function to set the position in the correct interval
00134     void adjust( int &position );
00135 
00136     /// Update the behaviour of the text whenever the control size changes
00137     virtual void onPositionChange();
00138     /// Update the behaviour of the text whenever the control size changes
00139     virtual void onResize();
00140 };
00141 
00142 
00143 #endif

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