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 "../src/skin_common.hpp"
29 #include "pointer.hpp"
32 #define MAX_BEZIER_POINT 1023
35 /// Class for Bezier curves
36 class Bezier: public SkinObject
39 /// Values to indicate which coordinate(s) must be checked to consider
40 /// that two points are distinct
43 kCoordsBoth, // x or y must be different (default)
44 kCoordsX, // only x is different
45 kCoordsY // only y is different
48 Bezier( intf_thread_t *p_intf,
49 const vector<float> &pAbscissas,
50 const vector<float> &pOrdinates,
51 Flag_t flag = kCoordsBoth );
54 /// Get the number of control points used to define the curve
55 int getNbCtrlPoints() const { return m_nbCtrlPt; }
57 /// Return the percentage (between 0 and 1) of the curve point nearest
59 float getNearestPercent( int x, int y ) const;
61 /// Return the distance of (x, y) to the curve, corrected
62 /// by the (optional) given scale factors
63 float getMinDist( int x, int y, float xScale = 1.0f,
64 float yScale = 1.0f ) const;
66 /// Get the coordinates of the point at t percent of
67 /// the curve (t must be between 0 and 1)
68 void getPoint( float t, int &x, int &y ) const;
70 /// Get the width (maximum abscissa) of the curve
73 /// Get the height (maximum ordinate) of the curve
74 int getHeight() const;
77 /// Number of control points
79 /// vectors containing the coordinates of the control points
82 /// Vector containing precalculated factoriels
85 /// Number of points (=pixels) used by the curve
87 /// Vectors with the coordinates of the different points of the curve
88 vector<int> m_leftVect;
89 vector<int> m_topVect;
90 /// Vector with the percentages associated with the points of the curve
91 vector<float> m_percVect;
93 /// Return the index of the curve point that is the nearest from (x, y)
94 int findNearestPoint( int x, int y ) const;
95 /// Compute the coordinates of a point corresponding to a given
97 void computePoint( float t, int &x, int &y ) const;
98 /// Helper function to compute a coefficient of the curve
99 inline float computeCoeff( int i, int n, float t ) const;
101 inline float power( float x, int n ) const;
105 typedef CountedPtr<Bezier> BezierPtr;