1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
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.
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.
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 *****************************************************************************/
28 #include "variable.hpp"
29 #include "observer.hpp"
30 #include "pointer.hpp"
33 /// Interface for rectangular objects
39 /// Get the size of the box
40 virtual int getWidth() const = 0;
41 virtual int getHeight() const = 0;
45 /// Interface for rectangular objects with a position
46 class GenericRect: public Box
49 virtual int getLeft() const = 0;
50 virtual int getTop() const = 0;
54 /// Characterization of a rectangle
55 class SkinsRect: public GenericRect
58 SkinsRect( int left, int top, int right, int bottom );
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; }
75 /// Relative position of a rectangle in a box
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).
82 class Position: public GenericRect
85 /// Type for reference edge/corner
88 /// Coordinates are relative to the upper left corner
90 /// Coordinates are relative to the upper right corner
92 /// Coordinates are relative to the lower left corner
94 /// Coordinates are relative to the lower right corner
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 );
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; }
119 /// Position and reference edge/corner
124 const GenericRect &m_rRect;
126 Ref_t m_refRighBottom;
127 /// "Keep ratio" mode
130 /// Initial width ratio (usually between 0 and 1)
132 /// Initial height ratio (usually between 0 and 1)
136 typedef CountedPtr<Position> PositionPtr;
139 /// Variable implementing the Box interface
140 class VarBox: public Variable, public Box, public Subject<VarBox>
143 VarBox( intf_thread_t *pIntf, int width = 0, int height = 0 );
147 /// Get the variable type
148 virtual const string &getType() const { return m_type; }
150 /// Get the size of the box
151 virtual int getWidth() const;
152 virtual int getHeight() const;
154 /// Change the size of the box
155 void setSize( int width, int height );
159 static const string m_type;
161 int m_width, m_height;