]> git.sesse.net Git - vlc/blob - modules/gui/skins2/utils/position.hpp
Fix MRL generation for open dialog in order to stream. (#1575)
[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 #include "pointer.hpp"
31
32
33 /// Interface for rectangular objects
34 class Box
35 {
36     public:
37         virtual ~Box() {}
38
39         /// Get the size of the box
40         virtual int getWidth() const = 0;
41         virtual int getHeight() const = 0;
42 };
43
44
45 /// Interface for rectangular objects with a position
46 class GenericRect: public Box
47 {
48     public:
49         virtual int getLeft() const = 0;
50         virtual int getTop() const = 0;
51 };
52
53
54 /// Characterization of a rectangle
55 class SkinsRect: public GenericRect
56 {
57     public:
58         SkinsRect( int left, int top, int right, int bottom );
59
60         virtual int getLeft() const { return m_left; }
61         virtual int getTop() const { return m_top; }
62         virtual int getRight() const { return m_right; }
63         virtual int getBottom() const { return m_bottom; }
64         virtual int getWidth() const { return m_right - m_left; }
65         virtual int getHeight() const { return m_bottom - m_top; }
66
67     private:
68         int m_left;
69         int m_top;
70         int m_right;
71         int m_bottom;
72 };
73
74
75 /// Relative position of a rectangle in a box
76 /**
77  * Note: Even if the object is tied to its direct container rectangle, the
78  * coordinates returned by getLeft(), getTop(), getRight() and getBottom() are
79  * not relative to the direct container (which is usually a panel or the layout)
80  * but to the root container (i.e. the layout).
81  */
82 class Position: public GenericRect
83 {
84     public:
85         /// Type for reference edge/corner
86         enum Ref_t
87         {
88             /// Coordinates are relative to the upper left corner
89             kLeftTop,
90             /// Coordinates are relative to the upper right corner
91             kRightTop,
92             /// Coordinates are relative to the lower left corner
93             kLeftBottom,
94             /// Coordinates are relative to the lower right corner
95             kRightBottom
96         };
97
98         /// Create a new position relative to the given box
99         Position( int left, int top, int right, int bottom,
100                   const GenericRect &rRect,
101                   Ref_t refLeftTop, Ref_t refRightBottom,
102                   bool xKeepRatio, bool yKeepRatio );
103
104         ~Position() {}
105
106         /// Get the position relative to the left top corner of the box
107         virtual int getLeft() const;
108         virtual int getTop() const;
109         int getRight() const;
110         int getBottom() const;
111         /// Get the size of the rectangle
112         virtual int getWidth() const;
113         virtual int getHeight() const;
114         /// Get the reference corners
115         Ref_t getRefLeftTop() const { return m_refLeftTop; }
116         Ref_t getRefRightBottom() const { return m_refRighBottom; }
117
118     private:
119         /// Position and reference edge/corner
120         int m_left;
121         int m_top;
122         int m_right;
123         int m_bottom;
124         const GenericRect &m_rRect;
125         Ref_t m_refLeftTop;
126         Ref_t m_refRighBottom;
127         /// "Keep ratio" mode
128         bool m_xKeepRatio;
129         bool m_yKeepRatio;
130         /// Initial width ratio (usually between 0 and 1)
131         double m_xRatio;
132         /// Initial height ratio (usually between 0 and 1)
133         double m_yRatio;
134 };
135
136 typedef CountedPtr<Position> PositionPtr;
137
138
139 /// Variable implementing the Box interface
140 class VarBox: public Variable, public Box, public Subject<VarBox>
141 {
142     public:
143         VarBox( intf_thread_t *pIntf, int width = 0, int height = 0 );
144
145         virtual ~VarBox() {}
146
147         /// Get the variable type
148         virtual const string &getType() const { return m_type; }
149
150         /// Get the size of the box
151         virtual int getWidth() const;
152         virtual int getHeight() const;
153
154         /// Change the size of the box
155         void setSize( int width, int height );
156
157     private:
158         /// Variable type
159         static const string m_type;
160         /// Size
161         int m_width, m_height;
162 };
163
164
165 #endif