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 // Same as above butt default state is off
59 // Only manual scrolling is allowed (with the mouse)
61 // No scrolling of the text is allowed
65 /// Create a text control with the optional given color
66 CtrlText( intf_thread_t *pIntf, VarText &rVariable,
67 const GenericFont &rFont, const UString &rHelp,
68 uint32_t color, VarBool *pVisible, Scrolling_t scrollMode,
73 virtual void handleEvent( EvtGeneric &rEvent );
75 /// Check whether coordinates are inside the control
76 virtual bool mouseOver( int x, int y ) const;
78 /// Draw the control on the given graphics
79 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
81 /// Set the text of the control, with an optional color
82 /// This takes effect immediatly
83 void setText( const UString &rText, uint32_t color = 0xFFFFFFFF );
85 /// Get the type of control (custom RTTI)
86 virtual string getType() const { return "text"; }
89 /// Finite state machine of the control
91 /// Variable associated to the control
94 DEFINE_CALLBACK( CtrlText, ToManual )
95 DEFINE_CALLBACK( CtrlText, ManualMoving )
96 DEFINE_CALLBACK( CtrlText, ManualStill )
97 DEFINE_CALLBACK( CtrlText, Move )
98 /// The last received event
100 /// Font used to render the text
101 const GenericFont &m_rFont;
102 /// Color of the text
105 Scrolling_t m_scrollMode;
106 /// Type of alignment
108 /// Image of the text
109 GenericBitmap *m_pImg;
110 /// Image of the text, repeated twice and with some blank between;
111 /// useful to display a 'circular' moving text...
112 GenericBitmap *m_pImgDouble;
113 /// Current image (should always be equal to m_pImg or m_pImgDouble)
114 GenericBitmap *m_pCurrImg;
115 /// Position of the left side of the moving text (always <= 0)
117 /// Offset between the mouse pointer and the left side of the
120 /// Timer to move the text
123 /// Callback for the timer
124 DEFINE_CALLBACK( CtrlText, UpdateText );
126 /// Method called when the observed variable is modified
127 virtual void onUpdate( Subject<VarText,void*> &rVariable, void* );
129 /// Display the text on the control
130 void displayText( const UString &rText );
132 /// Helper function to set the position in the correct interval
133 void adjust( int &position );
135 /// Update the behaviour of the text whenever the control size changes
136 virtual void onChangePosition();