00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "a2dprec.h"
00013
00014 #ifdef __BORLANDC__
00015 #pragma hdrstop
00016 #endif
00017
00018 #ifndef WX_PRECOMP
00019 #include "wx/wx.h"
00020 #endif
00021
00022 #include <float.h>
00023 #include <wx/artbase/drawer2d.h>
00024 #include <wx/canvas/hittest.h>
00025
00026 a2dHit HitTestRectangle( double xtest, double ytest, double xmin, double ymin, double xmax, double ymax, double margin )
00027 {
00028 if ( xmin > xmax )
00029 {
00030 double x = xmax;
00031 xmax = xmin;
00032 xmin = x;
00033 }
00034 if ( ymin > ymax )
00035 {
00036 double y = ymax;
00037 ymax = ymin;
00038 ymin = y;
00039 }
00040 wxASSERT( margin >= 0 );
00041
00042 static a2dHit hittypes [16] = {
00043
00044 a2dHit( a2dHit::hit_fill, a2dHit::stroke1_none, a2dHit::stroke2_none, 0, 0 ),
00045
00046 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_edgevert, 0, 0 ),
00047
00048 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_edgevert, 1, 0 ),
00049
00050 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_edgevert, 1, 0 ),
00051
00052
00053 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_edgehor, 2, 0 ),
00054
00055 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 0, 0 ),
00056
00057 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 1, 0 ),
00058
00059 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 1, 0 ),
00060
00061
00062 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_edgehor, 3, 0 ),
00063
00064 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 2, 0 ),
00065
00066 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 3, 0 ),
00067
00068 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 3, 0 ),
00069
00070
00071 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_edgehor, 2, 0 ),
00072
00073 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 0, 0 ),
00074
00075 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 1, 0 ),
00076
00077 a2dHit( a2dHit::hit_stroke, a2dHit::stroke1_none, a2dHit::stroke2_vertex, 1, 0 )
00078 };
00079
00080 a2dHit result;
00081
00082
00083 if (
00084 xtest < xmax + margin &&
00085 ytest < ymax + margin &&
00086 xtest > xmin - margin &&
00087 ytest > ymin - margin
00088 )
00089 {
00090
00091 int hittype = 0;
00092 if ( xtest < xmin + margin ) hittype +=1;
00093 if ( xtest > xmax - margin ) hittype +=2;
00094 if ( ytest < ymin + margin ) hittype +=4;
00095 if ( ytest > ymax - margin ) hittype +=8;
00096
00097 result = hittypes[hittype];
00098 if( result.m_hit == a2dHit::hit_stroke )
00099 {
00100
00101 if (
00102 xtest < xmax &&
00103 ytest < ymax &&
00104 xtest > xmin &&
00105 ytest > ymin
00106 )
00107 result.m_stroke1 = a2dHit::stroke1_inside;
00108 else
00109 result.m_stroke1 = a2dHit::stroke1_outside;
00110 }
00111 }
00112
00113 return result;
00114 }