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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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, void*>
53 // The text starts scrolling automatically if it is larger than the
54 // width of the control. The user can still stop it or make it
55 // scroll manually with the mouse.
57 // Only manual scrolling is allowed (with the mouse)
59 // No scrolling of the text is allowed
63 /// Create a text control with the optional given color
64 CtrlText( intf_thread_t *pIntf, VarText &rVariable,
65 const GenericFont &rFont, const UString &rHelp,
66 uint32_t color, VarBool *pVisible, Scrolling_t scrollMode,
71 virtual void handleEvent( EvtGeneric &rEvent );
73 /// Check whether coordinates are inside the control
74 virtual bool mouseOver( int x, int y ) const;
76 /// Draw the control on the given graphics
77 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
79 /// Set the text of the control, with an optional color
80 /// This takes effect immediatly
81 void setText( const UString &rText, uint32_t color = 0xFFFFFFFF );
83 /// Get the type of control (custom RTTI)
84 virtual string getType() const { return "text"; }
87 /// Finite state machine of the control
89 /// Variable associated to the control
92 DEFINE_CALLBACK( CtrlText, ToManual )
93 DEFINE_CALLBACK( CtrlText, ManualMoving )
94 DEFINE_CALLBACK( CtrlText, ManualStill )
95 DEFINE_CALLBACK( CtrlText, Move )
96 /// The last received event
98 /// Font used to render the text
99 const GenericFont &m_rFont;
100 /// Color of the text
103 Scrolling_t m_scrollMode;
104 /// Type of alignment
106 /// Image of the text
107 GenericBitmap *m_pImg;
108 /// Image of the text, repeated twice and with some blank between;
109 /// useful to display a 'circular' moving text...
110 GenericBitmap *m_pImgDouble;
111 /// Current image (should always be equal to m_pImg or m_pImgDouble)
112 GenericBitmap *m_pCurrImg;
113 /// Position of the left side of the moving text (always <= 0)
115 /// Offset between the mouse pointer and the left side of the
118 /// Timer to move the text
121 /// Callback for the timer
122 DEFINE_CALLBACK( CtrlText, UpdateText );
124 /// Method called when the observed variable is modified
125 virtual void onUpdate( Subject<VarText,void*> &rVariable, void* );
127 /// Display the text on the control
128 void displayText( const UString &rText );
130 /// Helper function to set the position in the correct interval
131 void adjust( int &position );
133 /// Update the behaviour of the text whenever the control size changes
134 virtual void onChangePosition();