1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
28 #include "ctrl_generic.hpp"
29 #include "../utils/fsm.hpp"
30 #include "../utils/observer.hpp"
40 /// Class for control text
41 class CtrlText: public CtrlGeneric, public Observer<VarText>
44 /// Create a text control with the optional given color
45 CtrlText( intf_thread_t *pIntf, VarText &rVariable,
46 const GenericFont &rFont, const UString &rHelp,
47 uint32_t color, VarBool *pVisible );
51 virtual void handleEvent( EvtGeneric &rEvent );
53 /// Check whether coordinates are inside the control
54 virtual bool mouseOver( int x, int y ) const;
56 /// Draw the control on the given graphics
57 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
59 /// Set the text of the control, with an optional color
60 /// This takes effect immediatly
61 void setText( const UString &rText, uint32_t color = 0xFFFFFFFF );
63 /// Get the type of control (custom RTTI)
64 virtual string getType() const { return "text"; }
67 /// Finite state machine of the control
69 /// Variable associated to the control
72 Callback m_cmdToManual;
73 Callback m_cmdManualMoving;
74 Callback m_cmdManualStill;
76 /// The last received event
78 /// Font used to render the text
79 const GenericFont &m_rFont;
83 GenericBitmap *m_pImg;
84 /// Image of the text, repeated twice and with some blank between;
85 /// useful to display a 'circular' moving text...
86 GenericBitmap *m_pImgDouble;
87 /// Current image (should always be equal to m_pImg or m_pImgDouble)
88 GenericBitmap *m_pCurrImg;
89 /// Position of the left side of the moving text
91 /// Offset between the mouse pointer and the left side of the
94 /// Timer to move the text
97 /// Callback functions
98 static void transToManual( SkinObject *pCtrl );
99 static void transManualMoving( SkinObject *pCtrl );
100 static void transManualStill( SkinObject *pCtrl );
101 static void transMove( SkinObject *pCtrl );
102 /// Callback for the timer
103 static void updateText( SkinObject *pCtrl );
105 /// Method called when the observed variable is modified
106 virtual void onUpdate( Subject<VarText> &rVariable );
108 /// Display the text on the control
109 void displayText( const UString &rText );
111 /// Helper function to set the position in the correct interval
112 void adjust( int &position );
114 /// Update the behaviour of the text whenever the control size changes
115 virtual void onChangePosition();