]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_text.hpp
skins2: improve refresh of layouts
[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 along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 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>
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         // Only manual scrolling is allowed (with the mouse)
58         kManual,
59         // No scrolling of the text is allowed
60         kNone
61     };
62
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,
67               Align_t alignment);
68     virtual ~CtrlText();
69
70     /// Handle an event
71     virtual void handleEvent( EvtGeneric &rEvent );
72
73     /// Check whether coordinates are inside the control
74     virtual bool mouseOver( int x, int y ) const;
75
76     /// Draw the control on the given graphics
77     virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
78
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 );
82
83     /// Get the type of control (custom RTTI)
84     virtual string getType() const { return "text"; }
85
86 private:
87     /// Finite state machine of the control
88     FSM m_fsm;
89     /// Variable associated to the control
90     VarText &m_rVariable;
91     /// Callback objects
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
97     EvtGeneric *m_pEvt;
98     /// Font used to render the text
99     const GenericFont &m_rFont;
100     /// Color of the text
101     uint32_t m_color;
102     /// Scrolling mode
103     Scrolling_t m_scrollMode;
104     /// Type of alignment
105     Align_t m_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)
114     int m_xPos;
115     /// Offset between the mouse pointer and the left side of the
116     /// moving text
117     int m_xOffset;
118      /// Timer to move the text
119     OSTimer *m_pTimer;
120
121     /// Callback for the timer
122     DEFINE_CALLBACK( CtrlText, UpdateText );
123
124     /// Method called when the observed variable is modified
125     virtual void onUpdate( Subject<VarText> &rVariable, void* );
126
127     /// Method called when visibility is updated
128     virtual void onUpdate( Subject<VarBool> &rVariable , void* );
129
130     /// Display the text on the control
131     void displayText( const UString &rText );
132
133     /// Helper function to set the position in the correct interval
134     void adjust( int &position );
135
136     /// Update the behaviour of the text whenever the control size changes
137     virtual void onPositionChange();
138     /// Update the behaviour of the text whenever the control size changes
139     virtual void onResize();
140 };
141
142
143 #endif