pFigure.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005 #include "pFigure.h"
00006
00007
00008
00009
00010
00011
00012 #ifndef WX_PRECOMP
00013 #include <wx/wx.h>
00014 #endif
00015
00016
00017
00018
00020 IMPLEMENT_CLASS(pFigure, wxObject)
00021
00022
00023
00024
00032 pFigure :: pFigure(int edges_n, int _w, int _h, int _orientation, bool bar_orientation)
00033 {
00034 edges = edges_n;
00035 orientation = _orientation;
00036 width = _w;
00037 heigth = _h;
00038 setBarOrientation( bar_orientation );
00039 }
00040
00041 pFigure :: ~pFigure()
00042 {
00043
00044 }
00045
00046
00047
00048
00049
00054 int pFigure :: getNumberEdges()
00055 {
00056 return edges;
00057 }
00058
00063 void pFigure :: setNumberEdges(int n_edges)
00064 {
00065 edges = n_edges;
00066 }
00067
00073 void pFigure :: getVertexPoints(wxPoint thePoints[])
00074 {
00075 if (edges == TRIANGLE)
00076 {
00077 int halfWidth = 0;
00078 int halfHeigth = 0;
00079 if ( barOrientation )
00080 {
00081 halfWidth = (int)(width/2);
00082 halfHeigth = (int)(heigth/2);
00083 switch ( orientation )
00084 {
00085 case UP :
00086 thePoints[0].x = halfWidth;
00087 thePoints[0].y = 0;
00088 thePoints[1].x = width;
00089 thePoints[1].y = heigth;
00090 thePoints[2].x = -halfWidth;
00091 thePoints[2].y = heigth;
00092 break;
00093
00094 case DOWN :
00095 thePoints[0].x = halfWidth;
00096 thePoints[0].y = heigth;
00097 thePoints[1].x = width;
00098 thePoints[1].y = 0;
00099 thePoints[2].x = -halfWidth;
00100 thePoints[2].y = 0;
00101 break;
00102
00103 case LEFT :
00104 thePoints[0].x = 0;
00105 thePoints[0].y = halfHeigth;
00106 thePoints[1].x = width;
00107 thePoints[1].y = 0;
00108 thePoints[2].x = width;
00109 thePoints[2].y = heigth;
00110 break;
00111
00112 case RIGHT :
00113 thePoints[0].x = width;
00114 thePoints[0].y = halfHeigth;
00115 thePoints[1].x = 0;
00116 thePoints[1].y = 0;
00117 thePoints[2].x = 0;
00118 thePoints[2].y = heigth;
00119 break;
00120 }
00121 }
00122 else
00123 {
00124 halfWidth = (int)(heigth/2);
00125 halfHeigth = (int)(width/2);
00126 switch ( orientation )
00127 {
00128 case UP :
00129 thePoints[0].x = halfWidth;
00130 thePoints[0].y = 0;
00131 thePoints[1].x = heigth;
00132 thePoints[1].y = width;
00133 thePoints[2].x = -halfWidth;
00134 thePoints[2].y = width;
00135 break;
00136
00137 case DOWN :
00138 thePoints[0].x = halfWidth;
00139 thePoints[0].y = width;
00140 thePoints[1].x = heigth;
00141 thePoints[1].y = 0;
00142 thePoints[2].x = -halfWidth;
00143 thePoints[2].y = 0;
00144 break;
00145
00146 case LEFT :
00147 thePoints[0].x = 0;
00148 thePoints[0].y = halfHeigth;
00149 thePoints[1].x = heigth;
00150 thePoints[1].y = -halfHeigth;
00151 thePoints[2].x = heigth;
00152 thePoints[2].y = width;
00153 break;
00154
00155 case RIGHT :
00156 thePoints[0].x = heigth;
00157 thePoints[0].y = halfHeigth;
00158 thePoints[1].x = 0;
00159 thePoints[1].y = -halfHeigth;
00160 thePoints[2].x = 0;
00161 thePoints[2].y = width;
00162 break;
00163 }
00164 }
00165 }
00166 else if (edges == RECTANGLE)
00167 {
00168 if ( barOrientation )
00169 {
00170 thePoints[0].x = 0;
00171 thePoints[0].y = 0;
00172 thePoints[1].x = width;
00173 thePoints[1].y = 0;
00174 thePoints[2].x = width;
00175 thePoints[2].y = heigth;
00176 thePoints[3].x = 0;
00177 thePoints[3].y = heigth;
00178 }
00179 else
00180 {
00181 thePoints[0].x = 0;
00182 thePoints[0].y = 0;
00183 thePoints[1].x = heigth;
00184 thePoints[1].y = 0;
00185 thePoints[2].x = heigth;
00186 thePoints[2].y = width;
00187 thePoints[3].x = 0;
00188 thePoints[3].y = width;
00189 }
00190 }
00191 }
00192
00197 void pFigure :: setVertexPoints(wxPoint * n_points)
00198 {
00199 v_points = n_points;
00200 }
00201
00202
00203
00204
00205
00206 void pFigure :: setHeigth(int _h)
00207 {
00208 heigth = _h;
00209 }
00210
00211
00212
00213
00214
00215 int pFigure :: getHeigth()
00216 {
00217 return heigth;
00218 }
00219
00220
00221
00222
00223
00224 void pFigure :: setWidth(int _w)
00225 {
00226 width = _w;
00227 }
00228
00229
00230
00231
00232
00233 int pFigure :: getWidth()
00234 {
00235 return width;
00236 }
00237
00238
00239
00240
00241
00242
00243
00244 bool pFigure :: isPointInside(int xFig_PixelPoint, int xPixel)
00245 {
00246 bool isInside = false;
00247
00248 if (edges == TRIANGLE)
00249 {
00250 int halfWidth = (int)(width/2)+1;
00251 int halfHeigth = (int)(heigth/2)+1;
00252 if ( orientation == UP || orientation == DOWN )
00253 {
00254 isInside = (xPixel>=xFig_PixelPoint-halfWidth) && (xPixel<=xFig_PixelPoint+halfWidth);
00255 }
00256 else if( orientation == LEFT || orientation == RIGHT )
00257 {
00258 isInside = (xPixel>=xFig_PixelPoint-halfHeigth) && (xPixel<=xFig_PixelPoint+halfHeigth);
00259 }
00260 }
00261 else if (edges == RECTANGLE)
00262 {
00263 isInside = (xPixel >= xFig_PixelPoint) && (xPixel<=xFig_PixelPoint+width);
00264 }
00265 return isInside;
00266 }
00267
00268
00269
00270
00271
00272 void pFigure :: setBarOrientation(bool bar_orientation)
00273 {
00274 barOrientation = bar_orientation;
00275 }
00276
00277
00278
00279
00280
00281 void pFigure :: setFigureOrientation(int fig_orientation)
00282 {
00283 orientation = fig_orientation;
00284 }
00285
00286
00287
00288