]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/generic_layout.hpp
* skins/utils/bezier.cpp: Fixed a bug in the computation of the size of a
[vlc] / modules / gui / skins2 / src / generic_layout.hpp
1 /*****************************************************************************
2  * generic_layout.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
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 GENERIC_LAYOUT_HPP
26 #define GENERIC_LAYOUT_HPP
27
28 #include "skin_common.hpp"
29 #include "top_window.hpp"
30 #include "../utils/pointer.hpp"
31 #include "../utils/position.hpp"
32
33 #include <list>
34
35 class Anchor;
36 class OSGraphics;
37 class CtrlGeneric;
38
39
40 /// Control and its associated layer
41 struct LayeredControl
42 {
43     LayeredControl( CtrlGeneric *pControl, int layer ):
44         m_pControl( pControl ), m_layer( layer ) {}
45
46     /// Pointer on the control
47     CtrlGeneric *m_pControl;
48     /// Layer number
49     int m_layer;
50 };
51
52
53 /// Base class for layouts
54 class GenericLayout: public SkinObject, public Box
55 {
56     public:
57         GenericLayout( intf_thread_t *pIntf, int width, int height,
58                        int minWidth, int maxWidth, int minHeight,
59                        int maxHeight );
60
61         virtual ~GenericLayout();
62
63         /// Attach the layout to a window
64         virtual void setWindow( TopWindow *pWindow );
65
66         /// Get the associated window, if any
67         virtual TopWindow *getWindow() const { return m_pWindow; }
68
69         /// Called by a control which wants to capture the mouse
70         virtual void onControlCapture( const CtrlGeneric &rCtrl );
71
72         /// Called by a control which wants to release the mouse
73         virtual void onControlRelease( const CtrlGeneric &rCtrl );
74
75         /// Refresh the window
76         virtual void refreshAll();
77
78         /// Get the image of the layout
79         virtual OSGraphics *getImage() const { return m_pImage; }
80
81         /// Get the position of the layout (relative to the screen)
82         virtual int getLeft() const { return m_pWindow->getLeft(); }
83         virtual int getTop() const { return m_pWindow->getTop(); }
84
85         /// Get the size of the layout
86         virtual int getWidth() const { return m_width; }
87         virtual int getHeight() const { return m_height; }
88
89         /// Get the minimum and maximum size of the layout
90         virtual int getMinWidth() const { return m_minWidth; }
91         virtual int getMaxWidth() const { return m_maxWidth; }
92         virtual int getMinHeight() const { return m_minHeight; }
93         virtual int getMaxHeight() const { return m_maxHeight; }
94
95         /// Resize the layout
96         virtual void resize( int width, int height );
97
98         /// Add a control in the layout at the given position, and
99         /// the optional given layer
100         virtual void addControl( CtrlGeneric *pControl,
101                                  const Position &rPosition,
102                                  int layer );
103
104         /// Get the list of the controls in this layout, by layer order
105         virtual const list<LayeredControl> &getControlList() const;
106
107         /// Called by a control when its image has changed
108         /// The arguments indicate the size of the rectangle to refresh,
109         /// and the offset (from the control position) of this rectangle.
110         /// Use a negative width or height to refresh the layout completely
111         virtual void onControlUpdate( const CtrlGeneric &rCtrl,
112                                       int width, int height,
113                                       int xOffSet, int yOffSet );
114
115         /// Get the list of the anchors of this layout
116         virtual const list<Anchor*>& getAnchorList() const;
117
118         /// Add an anchor to this layout
119         virtual void addAnchor( Anchor *pAnchor );
120
121     private:
122         /// Refresh a rectangular portion of the window
123         void GenericLayout::refreshRect( int x, int y, int width, int height );
124
125         /// Parent window of the layout
126         TopWindow *m_pWindow;
127         /// Layout size
128         int m_width, m_height;
129         int m_minWidth, m_maxWidth;
130         int m_minHeight, m_maxHeight;
131         /// Image of the layout
132         OSGraphics *m_pImage;
133         /// List of the controls in the layout
134         list<LayeredControl> m_controlList;
135         /// List of the anchors in the layout
136         list<Anchor*> m_anchorList;
137 };
138
139
140 typedef CountedPtr<GenericLayout> GenericLayoutPtr;
141
142
143 #endif