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