00001
00002
00003
00004
00005
00006 #include "xyarca.h"
00007
00008 const char* xy_id_xyarca_cpp="$Id: xyarca.cpp,v 1.4 2002/06/04 20:01:32 clinio Exp $";
00009
00010 XYCartesianArea::XYCartesianArea(
00011 const XYAxis* axis1, const XYAxis* axis2,
00012 double begin1, double end1,
00013 double begin2, double end2, xybool visible) :
00014 XYArea(axis1, axis2, begin1, end1, begin2, end2, visible)
00015 {
00016 }
00017
00018 XYCartesianArea::~XYCartesianArea (void)
00019 {
00020 }
00021
00022 xybool XYCartesianArea::pick (int px, int py)
00023 {
00024 if (visible() == xyfalse) return xyfalse;
00025
00026
00027 int x1, y1, x2, y2;
00028 boundingBox(x1, y1, x2, y2);
00029
00030 return mtPointInRect(px, py, x1, y1, x2, y2);
00031 }
00032
00033 xybool XYCartesianArea::fence (int x2, int y2, int x3, int y3)
00034 {
00035 if (visible() == xyfalse) return xyfalse;
00036
00037
00038 int x0, y0, x1, y1;
00039 boundingBox (x0, y0, x1, y1);
00040
00041 return mtInclude (x0, y0, x1, y1, x2, y2, x3, y3);
00042 }
00043
00044 void XYCartesianArea::draw (void)
00045 {
00046 int xmin, ymin, xmax, ymax;
00047
00048
00049 getViewport (xmin, xmax, ymin, ymax);
00050 draw(xmin, ymin, xmax, ymax);
00051 }
00052
00053 void XYCartesianArea::draw (int xmin, int ymin, int xmax, int ymax) const
00054 {
00055 if (visible() == xyfalse) return;
00056
00057 int vpxmin, vpxmax, vpymin, vpymax;
00058 getViewport(vpxmin, vpxmax, vpymin, vpymax);
00059
00060 int mode = cdClip(CD_CLIPON);
00061
00062
00063 int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00064 cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00065
00066
00067 int clipxmin, clipymin, clipxmax, clipymax;
00068 getClip(clipxmin, clipymin, clipxmax, clipymax);
00069 cdClipArea(clipxmin, clipxmax, clipymin, clipymax);
00070
00071
00072 cdForeground (backgroundColor());
00073 cdInteriorStyle(CD_SOLID);
00074
00075 int x1, y1, x2, y2;
00076 boundingBox(x1, y1, x2, y2);
00077
00078
00079
00080 x1 = x1 < clipxmin ? clipxmin-10 : x1;
00081 x2 = x2 < clipxmin ? clipxmin-10 : x2;
00082 x1 = x1 > clipxmax ? clipxmax+10 : x1;
00083 x2 = x2 > clipxmax ? clipxmax+10 : x2;
00084
00085 y1 = y1 < clipymin ? clipymin-10 : y1;
00086 y2 = y2 < clipymin ? clipymin-10 : y2;
00087 y1 = y1 > clipymax ? clipymax+10 : y1;
00088 y2 = y2 > clipymax ? clipymax+10 : y2;
00089
00090 cdBox(x1, x2, y1, y2);
00091
00092 cdLineStyle(style());
00093 cdLineWidth(width());
00094 cdForeground(color());
00095 cdRect(x1, x2, y1, y2);
00096
00097 int old_alg = cdTextAlignment( CD_CENTER );
00098 double old_or = cdTextOrientation( 0.0 );
00099 int tw, th;
00100 cdTextSize( _text, &tw, &th );
00101
00102 if ( fabs(x2-x1) < fabs(y2-y1) ) {
00103 cdTextOrientation( 90.0 );
00104 int trash = th;
00105 th = tw;
00106 tw = trash;
00107 }
00108 cdForeground(_textColor);
00109 cdFont(CD_HELVETICA, CD_BOLD, _textSize);
00110
00111 if ( ( tw < fabs(x2-x1) && th < fabs(y2-y1) ) || _forced_text ) {
00112 cdText( (x1+x2)/2, (y1+y2)/2, _text );
00113 }
00114
00115 cdTextOrientation(old_or);
00116 cdTextAlignment(old_alg);
00117 cdClip(mode);
00118
00119 cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00120 }
00121
00122 void XYCartesianArea::getClip(int &xmin, int &ymin,
00123 int &xmax, int &ymax) const
00124 {
00125 if (visible() == xyfalse) return;
00126
00127 int trash;
00128 int lxmin, lxmax, lymin, lymax;
00129 pixelAt( _axis1, _axis1->min(), lxmin, trash );
00130 pixelAt( _axis1, _axis1->max(), lxmax, trash );
00131 pixelAt( _axis2, _axis2->min(), trash, lymin );
00132 pixelAt( _axis2, _axis2->max(), trash, lymax );
00133
00134 int x1, x2, x3, x4;
00135 int y1, y2, y3, y4;
00136 pixelAt( _axis1, _begin1, x1, y1 );
00137 pixelAt( _axis1, _end1, x2, y2 );
00138 pixelAt( _axis2, _begin2, x3, y3 );
00139 pixelAt( _axis2, _end2, x4, y4 );
00140
00141 xmin = MAX( x1, lxmin )-_width;
00142 ymin = MAX( y3, lymin )-_width;
00143 xmax = MIN( x2, lxmax )+_width;
00144 ymax = MIN( y4, lymax )+_width;
00145 }
00146
00147 void XYCartesianArea::boundingBox(int &xmin, int &ymin,
00148 int &xmax, int &ymax) const
00149 {
00150 if (visible() == xyfalse) return;
00151
00152 int trash;
00153 int lxmin, lxmax, lymin, lymax;
00154 pixelAt( _axis1, _axis1->min(), lxmin, trash );
00155 pixelAt( _axis1, _axis1->max(), lxmax, trash );
00156 pixelAt( _axis2, _axis2->min(), trash, lymin );
00157 pixelAt( _axis2, _axis2->max(), trash, lymax );
00158
00159 int x1, x2, x3, x4;
00160 int y1, y2, y3, y4;
00161 pixelAt( _axis1, _begin1, x1, y1 );
00162 pixelAt( _axis1, _end1, x2, y2 );
00163 pixelAt( _axis2, _begin2, x3, y3 );
00164 pixelAt( _axis2, _end2, x4, y4 );
00165
00166 xmin = x1;
00167 ymin = y3;
00168 xmax = x2;
00169 ymax = y4;
00170 }
00171
00172 void XYCartesianArea::pixelAt( const XYAxis* acont,
00173 double value, int& px, int& py ) const
00174 {
00175 if (acont)
00176 {
00177 acont->pointInValue( value, px, py );
00178 }
00179 }
00180