2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
7 // ---------------------------------------------------------------------------------------------------------------
8 // WX headers inclusion.
9 // For compilers that support precompilation, includes <wx/wx.h>.
10 // ---------------------------------------------------------------------------------------------------------------
16 //----------------------------------------------------------------------------------------------------------------
17 // Class implementation
18 //----------------------------------------------------------------------------------------------------------------
19 /** @file pFigure.cxx */
20 IMPLEMENT_CLASS(pFigure, wxObject)
22 //------------------------------------------------------------------------------------------------------------
23 // Constructors & Destructors
24 //------------------------------------------------------------------------------------------------------------
26 * Create a figure with edges_n edges
27 * @param edges_n The number of edges of the new figure
28 * @param _w The width to set
29 * @param _h The height to set
30 * @param _orientation The orientation to set
32 pFigure :: pFigure(int edges_n, int _w, int _h, int _orientation, bool bar_orientation)
35 orientation = _orientation;
38 setBarOrientation( bar_orientation );
46 //------------------------------------------------------------------------------------------------------------
48 //------------------------------------------------------------------------------------------------------------
51 * Gets the number of edges of the figure
52 * @retval edges Number of edges in the figure
54 int pFigure :: getNumberEdges()
60 * Sets the vertex points of the figure
61 * @param edges Number of edges in the figure to set
63 void pFigure :: setNumberEdges(int n_edges)
69 * Gets the vertex points of the figure
70 * @param wxPoint The vector to get the points
71 * @retval points Vertex points distribution in the figure
73 void pFigure :: getVertexPoints(wxPoint thePoints[])
75 if (edges == TRIANGLE)
79 if ( barOrientation ) // HORIZONTAL
81 halfWidth = (int)(width/2);
82 halfHeigth = (int)(heigth/2);
83 switch ( orientation )
86 thePoints[0].x = halfWidth;
88 thePoints[1].x = width;
89 thePoints[1].y = heigth;
90 thePoints[2].x = -halfWidth;
91 thePoints[2].y = heigth;
95 thePoints[0].x = halfWidth;
96 thePoints[0].y = heigth;
97 thePoints[1].x = width;
99 thePoints[2].x = -halfWidth;
105 thePoints[0].y = halfHeigth;
106 thePoints[1].x = width;
108 thePoints[2].x = width;
109 thePoints[2].y = heigth;
113 thePoints[0].x = width;
114 thePoints[0].y = halfHeigth;
118 thePoints[2].y = heigth;
124 halfWidth = (int)(heigth/2);
125 halfHeigth = (int)(width/2);
126 switch ( orientation )
129 thePoints[0].x = halfWidth;
131 thePoints[1].x = heigth;
132 thePoints[1].y = width;
133 thePoints[2].x = -halfWidth;
134 thePoints[2].y = width;
138 thePoints[0].x = halfWidth;
139 thePoints[0].y = width;
140 thePoints[1].x = heigth;
142 thePoints[2].x = -halfWidth;
148 thePoints[0].y = halfHeigth;
149 thePoints[1].x = heigth;
150 thePoints[1].y = -halfHeigth;
151 thePoints[2].x = heigth;
152 thePoints[2].y = width;
156 thePoints[0].x = heigth;
157 thePoints[0].y = halfHeigth;
159 thePoints[1].y = -halfHeigth;
161 thePoints[2].y = width;
166 else if (edges == RECTANGLE)
168 if ( barOrientation ) // HORIZONTAL
172 thePoints[1].x = width;
174 thePoints[2].x = width;
175 thePoints[2].y = heigth;
177 thePoints[3].y = heigth;
183 thePoints[1].x = heigth;
185 thePoints[2].x = heigth;
186 thePoints[2].y = width;
188 thePoints[3].y = width;
194 * Sets the vertex points of the figure
195 * @param edges Vertex points distribution in the figure to set
197 void pFigure :: setVertexPoints(wxPoint * n_points)
203 * Sets the heigth of the figure
204 * @param _h The heigth to set
206 void pFigure :: setHeigth(int _h)
212 * Gets the heigth of the figure
213 * @retval heigth The heigth of the figure
215 int pFigure :: getHeigth()
221 * Sets the width of the figure
222 * @param _w The width to set
224 void pFigure :: setWidth(int _w)
230 * Gets the width of the figure
231 * @retval width The width of the figure
233 int pFigure :: getWidth()
239 * Indicates if a pixel point is inside the figure
240 * @param xFig_PixelPoint The known reference point inside the figure
241 * @param xPixel The x-pixel coord asking for
242 * @retval Returns true if the point is inside
244 bool pFigure :: isPointInside(int xFig_PixelPoint, int xPixel)
246 bool isInside = false;
248 if (edges == TRIANGLE)
250 int halfWidth = (int)(width/2)+1;
251 int halfHeigth = (int)(heigth/2)+1;
252 if ( orientation == UP || orientation == DOWN )
254 isInside = (xPixel>=xFig_PixelPoint-halfWidth) && (xPixel<=xFig_PixelPoint+halfWidth);
256 else if( orientation == LEFT || orientation == RIGHT )
258 isInside = (xPixel>=xFig_PixelPoint-halfHeigth) && (xPixel<=xFig_PixelPoint+halfHeigth);
261 else if (edges == RECTANGLE)
263 isInside = (xPixel >= xFig_PixelPoint) && (xPixel<=xFig_PixelPoint+width);
269 * Sets the bar orientation
270 * @ bar_orientation The orientation to set (true for horizontal, false for vertical)
272 void pFigure :: setBarOrientation(bool bar_orientation)
274 barOrientation = bar_orientation;
278 * Sets the bar orientation used for triangles
279 * @ bar_orientation The orientation to set (LEFT = -4, RIGHT = -6, UP = -8, DOWN = -2)
281 void pFigure :: setFigureOrientation(int fig_orientation)
283 orientation = fig_orientation;