]> git.sesse.net Git - vlc/blob - modules/gui/skins2/utils/position.hpp
Uniformize source files encoding
[vlc] / modules / gui / skins2 / utils / position.hpp
1 /*****************************************************************************
2  * position.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 POSITION_HPP
26 #define POSITION_HPP
27
28 #include "variable.hpp"
29 #include "observer.hpp"
30
31
32 /// Interface for rectangular objects
33 class Box
34 {
35     public:
36         virtual ~Box() {}
37
38         /// Get the size of the box
39         virtual int getWidth() const = 0;
40         virtual int getHeight() const = 0;
41 };
42
43
44 /// Characterization of a rectangle
45 class Rect: public Box
46 {
47     public:
48         Rect( int left, int top, int right, int bottom );
49
50         virtual int getLeft() const { return m_left; }
51         virtual int getTop() const { return m_top; }
52         virtual int getRight() const { return m_right; }
53         virtual int getBottom() const { return m_bottom; }
54
55         virtual int getWidth() const { return m_right - m_left; }
56         virtual int getHeight() const { return m_bottom - m_top; }
57
58     private:
59         int m_left;
60         int m_top;
61         int m_right;
62         int m_bottom;
63 };
64
65
66 /// Relative position of a rectangle in a box
67 class Position
68 {
69     public:
70         /// Type for reference edge/corner
71         enum Ref_t
72         {
73             /// Coordinates are relative to the upper left corner
74             kLeftTop,
75             /// Coordinates are relative to the upper right corner
76             kRightTop,
77             /// Coordinates are relative to the lower left corner
78             kLeftBottom,
79             /// Coordinates are relative to the lower right corner
80             kRightBottom
81         };
82
83         /// Create a new position relative to the given box
84         Position( int left, int top, int right, int bottom, const Box &rBox,
85                   Ref_t refLeftTop = kLeftTop,
86                   Ref_t refRightBottom = kLeftTop );
87
88         ~Position() {}
89
90         /// Get the position relative to the left top corner of the box
91         int getLeft() const;
92         int getTop() const;
93         int getRight() const;
94         int getBottom() const;
95         /// Get the size of the rectangle
96         int getWidth() const;
97         int getHeight() const;
98
99     private:
100         /// Position and reference edge/corner
101         int m_left;
102         int m_top;
103         int m_right;
104         int m_bottom;
105         const Box &m_rBox;
106         Ref_t m_refLeftTop;
107         Ref_t m_refRighBottom;
108 };
109
110
111 /// Variable implementing the Box interface
112 class VarBox: public Variable, public Box, public Subject<VarBox, void*>
113 {
114     public:
115         VarBox( intf_thread_t *pIntf, int width = 0, int height = 0 );
116
117         virtual ~VarBox() {}
118
119         /// Get the variable type
120         virtual const string &getType() const { return m_type; }
121
122         /// Get the size of the box
123         virtual int getWidth() const;
124         virtual int getHeight() const;
125
126         /// Change the size of the box
127         void setSize( int width, int height );
128
129     private:
130         /// Variable type
131         static const string m_type;
132         /// Size
133         int m_width, m_height;
134 };
135
136
137 #endif