00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "xymkca.h"
00012
00013 const char* xy_id_xymkca_cpp="$Id: xymkca.cpp,v 1.10 1999/12/09 21:47:46 rborges Exp $";
00014
00015 XYCartesianMarker::XYCartesianMarker (const XYAxis* axis,
00016 double pos,
00017 long color,
00018 int width,
00019 LineStyle style,
00020 xybool visible)
00021 : XYMarker(axis, pos, color, width,
00022 style, visible)
00023 {
00024 }
00025
00026 void XYCartesianMarker::draw (void)
00027 {
00028 int xmin, ymin, xmax, ymax;
00029
00030
00031 getViewport (xmin, xmax, ymin, ymax);
00032
00033 draw(xmin, ymin, xmax, ymax);
00034 }
00035
00036 xybool XYCartesianMarker::pick (int px, int py)
00037 {
00038 if (visible() == xyfalse)
00039 return xyfalse;
00040
00041
00042 int x1, y1, x2, y2;
00043 boundingBox (x1, y1, x2, y2);
00044
00045 return mtPointInRect (px, py, x1, y1, x2, y2);
00046 }
00047
00048 xybool XYCartesianMarker::fence (int x2, int y2, int x3, int y3)
00049 {
00050 if (visible() == xyfalse)
00051 return xyfalse;
00052
00053
00054 int x0, y0, x1, y1;
00055 boundingBox (x0, y0, x1, y1);
00056
00057 return mtInclude (x0, y0, x1, y1, x2, y2, x3, y3);
00058 }
00059
00060 void XYCartesianMarker::draw (int xmin, int ymin, int xmax, int ymax) const
00061 {
00062 if (visible() == xyfalse)
00063 return;
00064
00065 int vpxmin, vpxmax, vpymin, vpymax;
00066 getViewport(vpxmin, vpxmax, vpymin, vpymax);
00067
00068 int mode = cdClip(CD_CLIPON);
00069
00070
00071 int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00072 cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00073
00074 cdClipArea(MAX(vpxmin,xmin), MIN(vpxmax,xmax),
00075 MAX(vpymin,ymin), MIN(vpymax,ymax));
00076
00077 const XYAxis* acont = axis();
00078
00079 if (acont)
00080 {
00081
00082 double rot_rad = acont -> rotation() * XY_PI / 180.0;
00083
00084
00085 double f = (pos() - acont -> min()) * acont -> size()
00086 / (acont -> max() - acont -> min());
00087
00088
00089 double x0, y0;
00090 acont -> position (&x0, &y0);
00091
00092
00093 double x1 = x0 + f * cos (rot_rad);
00094 double y1 = y0 + f * sin (rot_rad);
00095
00096
00097 double x2 = x1 + limit() * sin (rot_rad);
00098 double y2 = y1 + limit() * cos (rot_rad);
00099
00100
00101
00102 cdLineStyle (style());
00103 cdLineWidth (width());
00104 cdForeground (color());
00105
00106
00107 wdLine(x1, y1, x2, y2);
00108 }
00109
00110 cdClip(mode);
00111
00112 cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00113 }
00114
00115 void XYCartesianMarker::boundingBox (int &xmin, int &ymin, int &xmax,
00116 int &ymax) const
00117 {
00118 if (visible() == xyfalse)
00119 return;
00120
00121 const XYAxis* acont = axis();
00122
00123 if (acont)
00124 {
00125
00126 double rot_rad = acont -> rotation() * XY_PI / 180.0;
00127
00128
00129 double f = (pos() - acont -> min()) * acont -> size()
00130 / (acont -> max() - acont -> min());
00131
00132
00133 double x0, y0;
00134 acont -> position (&x0, &y0);
00135
00136
00137 double x1 = x0 + f * cos (rot_rad);
00138 double y1 = y0 + f * sin (rot_rad);
00139
00140
00141 double x2 = x1 + limit() * sin (rot_rad);
00142 double y2 = y1 + limit() * cos (rot_rad);
00143
00144 int bx1, by1, bx2, by2;
00145 wdWorld2Canvas (x1, y1, &bx1, &by1);
00146 wdWorld2Canvas (x2, y2, &bx2, &by2);
00147
00148
00149 xmin = MIN(bx1, bx2);
00150 ymin = MIN(by1, by2);
00151 xmax = MAX(bx1, bx2);
00152 ymax = MAX(by1, by2);
00153 }
00154 }
00155