skins2: fix RadialSlider
[vlc/asuraparaju-public.git] / modules / gui / skins2 / src / anchor.cpp
blob24e80516c0c9a35badedc17484955d8d3a619cde
1 /*****************************************************************************
2 * anchor.cpp
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
5 * $Id$
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 *****************************************************************************/
25 #include "anchor.hpp"
28 bool Anchor::isHanging( const Anchor &rOther ) const
30 if( m_priority <= rOther.m_priority )
31 return false;
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();
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);
44 bool Anchor::canHang( const Anchor &rOther, int &xOffset, int &yOffset ) const
46 int deltaX = getXPosAbs() - (rOther.getXPosAbs() + xOffset);
47 int deltaY = getYPosAbs() - (rOther.getYPosAbs() + yOffset);
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) )
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 );
57 xOffset = getXPosAbs() - (rOther.getXPosAbs() + xx);
58 yOffset = getYPosAbs() - (rOther.getYPosAbs() + yy);
59 return true;
61 else if( (rOther.isPoint() &&
62 m_rCurve.getMinDist( -deltaX, -deltaY ) < m_range) )
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 );
69 xOffset = (getXPosAbs() + xx) - rOther.getXPosAbs();
70 yOffset = (getYPosAbs() + yy) - rOther.getYPosAbs();
71 return true;
73 else
75 return false;