position.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * position.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id$
00006  *
00007  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
00008  *          Olivier Teulière <ipkiss@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef POSITION_HPP
00026 #define POSITION_HPP
00027 
00028 #include "variable.hpp"
00029 #include "observer.hpp"
00030 #include "pointer.hpp"
00031 
00032 
00033 /// Interface for rectangular objects
00034 class Box
00035 {
00036     public:
00037         virtual ~Box() {}
00038 
00039         /// Get the size of the box
00040         virtual int getWidth() const = 0;
00041         virtual int getHeight() const = 0;
00042 };
00043 
00044 
00045 /// Interface for rectangular objects with a position
00046 class GenericRect: public Box
00047 {
00048     public:
00049         virtual int getLeft() const = 0;
00050         virtual int getTop() const = 0;
00051 };
00052 
00053 
00054 /// Characterization of a rectangle
00055 class SkinsRect: public GenericRect
00056 {
00057     public:
00058         SkinsRect( int left, int top, int right, int bottom );
00059 
00060         virtual int getLeft() const { return m_left; }
00061         virtual int getTop() const { return m_top; }
00062         virtual int getRight() const { return m_right; }
00063         virtual int getBottom() const { return m_bottom; }
00064         virtual int getWidth() const { return m_right - m_left; }
00065         virtual int getHeight() const { return m_bottom - m_top; }
00066 
00067     private:
00068         int m_left;
00069         int m_top;
00070         int m_right;
00071         int m_bottom;
00072 };
00073 
00074 
00075 /// Relative position of a rectangle in a box
00076 /**
00077  * Note: Even if the object is tied to its direct container rectangle, the
00078  * coordinates returned by getLeft(), getTop(), getRight() and getBottom() are
00079  * not relative to the direct container (which is usually a panel or the layout)
00080  * but to the root container (i.e. the layout).
00081  */
00082 class Position: public GenericRect
00083 {
00084     public:
00085         /// Type for reference edge/corner
00086         enum Ref_t
00087         {
00088             /// Coordinates are relative to the upper left corner
00089             kLeftTop,
00090             /// Coordinates are relative to the upper right corner
00091             kRightTop,
00092             /// Coordinates are relative to the lower left corner
00093             kLeftBottom,
00094             /// Coordinates are relative to the lower right corner
00095             kRightBottom
00096         };
00097 
00098         /// Create a new position relative to the given box
00099         Position( int left, int top, int right, int bottom,
00100                   const GenericRect &rRect,
00101                   Ref_t refLeftTop, Ref_t refRightBottom,
00102                   bool xKeepRatio, bool yKeepRatio );
00103 
00104         ~Position() {}
00105 
00106         /// Get the position relative to the left top corner of the box
00107         virtual int getLeft() const;
00108         virtual int getTop() const;
00109         int getRight() const;
00110         int getBottom() const;
00111         /// Get the size of the rectangle
00112         virtual int getWidth() const;
00113         virtual int getHeight() const;
00114         /// Get the reference corners
00115         Ref_t getRefLeftTop() const { return m_refLeftTop; }
00116         Ref_t getRefRightBottom() const { return m_refRighBottom; }
00117 
00118     private:
00119         /// Position and reference edge/corner
00120         int m_left;
00121         int m_top;
00122         int m_right;
00123         int m_bottom;
00124         const GenericRect &m_rRect;
00125         Ref_t m_refLeftTop;
00126         Ref_t m_refRighBottom;
00127         /// "Keep ratio" mode
00128         bool m_xKeepRatio;
00129         bool m_yKeepRatio;
00130         /// Initial width ratio (usually between 0 and 1)
00131         double m_xRatio;
00132         /// Initial height ratio (usually between 0 and 1)
00133         double m_yRatio;
00134 };
00135 
00136 typedef CountedPtr<Position> PositionPtr;
00137 
00138 
00139 /// Variable implementing the Box interface
00140 class VarBox: public Variable, public Box, public Subject<VarBox>
00141 {
00142     public:
00143         VarBox( intf_thread_t *pIntf, int width = 0, int height = 0 );
00144 
00145         virtual ~VarBox() {}
00146 
00147         /// Get the variable type
00148         virtual const string &getType() const { return m_type; }
00149 
00150         /// Get the size of the box
00151         virtual int getWidth() const;
00152         virtual int getHeight() const;
00153 
00154         /// Change the size of the box
00155         void setSize( int width, int height );
00156 
00157     private:
00158         /// Variable type
00159         static const string m_type;
00160         /// Size
00161         int m_width, m_height;
00162 };
00163 
00164 
00165 #endif

Generated on Wed Aug 13 08:02:38 2008 for VLC by  doxygen 1.5.1