]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/anchor.cpp
Use pl_Locked and pl_Unlocked
[vlc] / modules / gui / skins2 / src / anchor.cpp
1 /*****************************************************************************
2  * anchor.cpp
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 #include "anchor.hpp"
26
27
28 bool Anchor::isHanging( const Anchor &rOther ) const
29 {
30     if( m_priority <= rOther.m_priority )
31         return false;
32
33     // Compute delta coordinates between anchors, since the Bezier class
34     // uses coordinates relative to (0;0)
35     int deltaX = getXPosAbs() - rOther.getXPosAbs();
36     int deltaY = getYPosAbs() - rOther.getYPosAbs();
37
38     // One of the anchors (at least) must be a point, else it has no meaning
39     return (isPoint() && rOther.m_rCurve.getMinDist( deltaX, deltaY ) == 0) ||
40            (rOther.isPoint() && m_rCurve.getMinDist( -deltaX, -deltaY ) == 0);
41 }
42
43
44 bool Anchor::canHang( const Anchor &rOther, int &xOffset, int &yOffset ) const
45 {
46     int deltaX = getXPosAbs() - (rOther.getXPosAbs() + xOffset);
47     int deltaY = getYPosAbs() - (rOther.getYPosAbs() + yOffset);
48
49     // One of the anchors (at least) must be a point, else it has no meaning
50     if( (isPoint() && rOther.m_rCurve.getMinDist( deltaX, deltaY ) < m_range) )
51     {
52         // Compute the coordinates of the nearest point of the curve
53         int xx, yy;
54         float p = rOther.m_rCurve.getNearestPercent( deltaX, deltaY );
55         rOther.m_rCurve.getPoint( p, xx, yy );
56
57         xOffset = getXPosAbs() - (rOther.getXPosAbs() + xx);
58         yOffset = getYPosAbs() - (rOther.getYPosAbs() + yy);
59         return true;
60     }
61     else if( (rOther.isPoint() &&
62               m_rCurve.getMinDist( -deltaX, -deltaY ) < m_range) )
63     {
64         // Compute the coordinates of the nearest point of the curve
65         int xx, yy;
66         float p = m_rCurve.getNearestPercent( -deltaX, -deltaY );
67         m_rCurve.getPoint( p, xx, yy );
68
69         xOffset = (getXPosAbs() + xx) - rOther.getXPosAbs();
70         yOffset = (getYPosAbs() + yy) - rOther.getYPosAbs();
71         return true;
72     }
73     else
74     {
75         return false;
76     }
77 }