]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_checkbox.hpp
* all: use command objects in FSM instead of C-style callbacks
[vlc] / modules / gui / skins2 / controls / ctrl_checkbox.hpp
1 /*****************************************************************************
2  * ctrl_checkbox.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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #ifndef CTRL_CHECKBOX_HPP
26 #define CTRL_CHECKBOX_HPP
27
28 #include "ctrl_generic.hpp"
29 #include "../utils/fsm.hpp"
30 #include "../utils/observer.hpp"
31
32 class GenericBitmap;
33 class OSGraphics;
34 class CmdGeneric;
35
36
37 /// Base class for checkbox controls
38 class CtrlCheckbox: public CtrlGeneric
39 {
40     public:
41         /// Create a checkbox with 6 images
42         CtrlCheckbox( intf_thread_t *pIntf,
43                       const GenericBitmap &rBmpUp1,
44                       const GenericBitmap &rBmpOver1,
45                       const GenericBitmap &rBmpDown1,
46                       const GenericBitmap &rBmpUp2,
47                       const GenericBitmap &rBmpOver2,
48                       const GenericBitmap &rBmpDown2,
49                       CmdGeneric &rCommand1, CmdGeneric &rCommand2,
50                       const UString &rTooltip1, const UString &rTooltip2,
51                       VarBool &rVariable, const UString &rHelp,
52                       VarBool *pVisible);
53
54         virtual ~CtrlCheckbox();
55
56         /// Handle an event
57         virtual void handleEvent( EvtGeneric &rEvent );
58
59         /// Check whether coordinates are inside the control
60         virtual bool mouseOver( int x, int y ) const;
61
62         /// Draw the control on the given graphics
63         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
64
65         /// Get the text of the tooltip XXX
66         virtual UString getTooltipText() const { return *m_pTooltip; }
67
68         /// Get the type of control (custom RTTI)
69         virtual string getType() const { return "checkbox"; }
70
71     private:
72         /// Finite state machine of the control
73         FSM m_fsm;
74         /// Observed variable
75         VarBool &m_rVariable;
76         /// Commands for the 2 states
77         CmdGeneric &m_rCommand1, &m_rCommand2;
78         /// Current command
79         CmdGeneric *m_pCommand;
80         /// Tooltip texts for the 2 states
81         const UString m_tooltip1, m_tooltip2;
82         /// Current tooltip
83         const UString *m_pTooltip;
84          /// Images of the checkbox in the different states
85         OSGraphics *m_pImgUp1, *m_pImgOver1, *m_pImgDown1;
86         OSGraphics *m_pImgUp2, *m_pImgOver2, *m_pImgDown2;
87         /// Current set of images (pointing to 1 or 2)
88         /// In fact, we consider here that a checkbox acts like 2 buttons, in a
89         /// symetric way; this is a small trick to avoid multiplicating the
90         /// callbacks (and it could be extended easily to support 3 buttons or
91         /// more...)
92         OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
93         /// Current image
94         OSGraphics *m_pImgCurrent;
95
96         /// Callback objects
97         DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver )
98         DEFINE_CALLBACK( CtrlCheckbox, DownOverUpOver )
99         DEFINE_CALLBACK( CtrlCheckbox, DownOverDown )
100         DEFINE_CALLBACK( CtrlCheckbox, DownDownOver )
101         DEFINE_CALLBACK( CtrlCheckbox, UpOverUp )
102         DEFINE_CALLBACK( CtrlCheckbox, UpUpOver )
103         DEFINE_CALLBACK( CtrlCheckbox, DownUp )
104         DEFINE_CALLBACK( CtrlCheckbox, UpHidden )
105         DEFINE_CALLBACK( CtrlCheckbox, HiddenUp )
106
107         /// Method called when the observed variable is modified
108         virtual void onVarBoolUpdate( VarBool &rVariable );
109
110         /// Helper function to update the current state of images
111         void changeButton();
112 };
113
114
115 #endif