]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/anchor.hpp
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / modules / gui / skins2 / src / anchor.hpp
1 /*****************************************************************************
2  * anchor.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 ANCHOR_HPP
26 #define ANCHOR_HPP
27
28 #include "skin_common.hpp"
29 #include "generic_layout.hpp"
30 #include "../utils/bezier.hpp"
31 #include "../utils/position.hpp"
32
33
34 /// Class for the windows anchors
35 class Anchor: public SkinObject
36 {
37     public:
38         Anchor( intf_thread_t *pIntf, const Position &rPosition, int range,
39                 int priority, const Bezier &rCurve, GenericLayout &rLayout ):
40             SkinObject( pIntf ), m_position( rPosition ),
41             m_rCurve( rCurve ), m_range( range ), m_priority( priority ),
42             m_rLayout( rLayout ) {}
43         virtual ~Anchor() {}
44
45         /**
46          * Return true if the given anchor is hanged by this one
47          * Two conditions are required:
48          *  - the other anchor must be in position of anchoring (as defined
49          *    by canHang())
50          *  - the priority of the other anchor must be lower than this one's
51          */
52         bool isHanging( const Anchor &rOther ) const;
53
54         /**
55          * Return true if the other anchor, moved by the (xOffset, yOffset)
56          * vector, is "hangable" by this one (i.e. if it is in its range of
57          * action), else return false.
58          * When the function returns true, the xOffset and yOffset parameters
59          * are modified to indicate the position that the other anchor would
60          * take if hanged by this one (this position is calculated to minimize
61          * the difference with the old xOffset and yOffset, so that the window
62          * doesn't "jump" in a strange way).
63          */
64         bool canHang( const Anchor &rOther, int &xOffset, int &yOffset ) const;
65
66         // Indicate whether this anchor is reduced to a single point
67         bool isPoint() const { return m_rCurve.getNbCtrlPoints() == 1; }
68
69         // Getters
70         const Position & getPosition() const { return m_position; }
71
72         int getXPosAbs() const
73         {
74             return (m_position.getLeft() + m_rLayout.getLeft());
75         }
76
77         int getYPosAbs() const
78         {
79             return (m_position.getTop() + m_rLayout.getTop());
80         }
81
82     private:
83         /// Position in the layout
84         Position m_position;
85
86         /// Curve of the anchor
87         const Bezier &m_rCurve;
88
89         /// Range of action
90         int m_range;
91
92         /// Priority
93         int m_priority;
94
95         /// Parent layout
96         GenericLayout &m_rLayout;
97 };
98
99
100 #endif