]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_text.hpp
3a6a8ff19efeb60229ef85ab88abe6e3066a7567
[vlc] / modules / gui / skins2 / controls / ctrl_text.hpp
1 /*****************************************************************************
2  * ctrl_text.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifndef CTRL_TEXT_HPP
26 #define CTRL_TEXT_HPP
27
28 #include "ctrl_generic.hpp"
29 #include "../utils/fsm.hpp"
30 #include "../utils/observer.hpp"
31 #include <string>
32
33 class GenericFont;
34 class GenericBitmap;
35 class OSTimer;
36 class UString;
37 class VarText;
38
39
40 /// Class for control text
41 class CtrlText: public CtrlGeneric, public Observer<VarText, void*>
42 {
43     public:
44         enum Align_t
45         {
46             kLeft,
47             kCenter,
48             kRight
49         };
50
51         enum Scrolling_t
52         {
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.
56             kAutomatic,
57             // Same as above butt default state is off
58             kAutomaticOff,
59             // Only manual scrolling is allowed (with the mouse)
60             kManual,
61             // No scrolling of the text is allowed
62             kNone
63         };
64
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,
69                   Align_t alignment);
70         virtual ~CtrlText();
71
72         /// Handle an event
73         virtual void handleEvent( EvtGeneric &rEvent );
74
75         /// Check whether coordinates are inside the control
76         virtual bool mouseOver( int x, int y ) const;
77
78         /// Draw the control on the given graphics
79         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
80
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 );
84
85         /// Get the type of control (custom RTTI)
86         virtual string getType() const { return "text"; }
87
88     private:
89         /// Finite state machine of the control
90         FSM m_fsm;
91         /// Variable associated to the control
92         VarText &m_rVariable;
93         /// Callback objects
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
99         EvtGeneric *m_pEvt;
100         /// Font used to render the text
101         const GenericFont &m_rFont;
102         /// Color of the text
103         uint32_t m_color;
104         /// Scrolling mode
105         Scrolling_t m_scrollMode;
106         /// Type of alignment
107         Align_t m_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)
116         int m_xPos;
117         /// Offset between the mouse pointer and the left side of the
118         /// moving text
119         int m_xOffset;
120          /// Timer to move the text
121         OSTimer *m_pTimer;
122
123         /// Callback for the timer
124         DEFINE_CALLBACK( CtrlText, UpdateText );
125
126         /// Method called when the observed variable is modified
127         virtual void onUpdate( Subject<VarText,void*> &rVariable, void* );
128
129         /// Display the text on the control
130         void displayText( const UString &rText );
131
132         /// Helper function to set the position in the correct interval
133         void adjust( int &position );
134
135         /// Update the behaviour of the text whenever the control size changes
136         virtual void onChangePosition();
137 };
138
139
140 #endif