00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdlib.h>
00012 #include <math.h>
00013 #include <stdio.h>
00014
00015 #include "xyrgrid.h"
00016
00017 const char* xy_id_xyrgrid_cpp="$Id: xyrgrid.cpp,v 1.5 1999/12/09 21:47:46 rborges Exp $";
00018
00019 XYRadialGrid::XYRadialGrid (double mn,
00020 double mx,
00021 double p,
00022 long color,
00023 double step,
00024 xybool visible)
00025 : XYAxis(mn, mx, .5, .5, color, 1., 0., step,
00026 xyfalse, visible),
00027 _first(p),
00028 _style(continuous)
00029 {
00030 }
00031
00032 void XYRadialGrid::first (double f)
00033 {
00034 _first = f;
00035 }
00036
00037 double XYRadialGrid::first (void) const
00038 {
00039 return _first;
00040 }
00041
00042 void XYRadialGrid::style (int s)
00043 {
00044 _style = s;
00045 }
00046
00047 int XYRadialGrid::style (void) const
00048 {
00049 return _style;
00050 }
00051
00052 xybool XYRadialGrid::pick (int px, int py)
00053 {
00054 if (visible() == xyfalse)
00055 return xyfalse;
00056
00057
00058 double s = _step * _size / (_mx - _mn);
00059
00060
00061 double x0, y0;
00062 position (&x0, &y0);
00063
00064 int px0, py0, px1, py1;
00065 double x1, y1;
00066
00067 double dx = 0.;
00068
00069 for (double p = _first; p <= _mx; p += _step)
00070 {
00071 x1 = x0 + dx * 2.;
00072 y1 = y0 + dx * 2.;
00073
00074
00075 wdWorld2Canvas (x0, y0, &px0, &py0);
00076 wdWorld2Canvas (x1, y1, &px1, &py1);
00077
00078
00079 if (mtPointInCircle(px, py, px0, py0, px1, py1))
00080 return xytrue;
00081
00082 dx += s;
00083 }
00084
00085 return xyfalse;
00086 }
00087
00088 void XYRadialGrid::draw (void)
00089 {
00090 draw (_xmin, _ymin, _xmax, _ymax);
00091 }
00092
00093 void XYRadialGrid::draw (int xmin, int ymin, int xmax, int ymax) const
00094 {
00095 if (visible() == xyfalse)
00096 return;
00097
00098
00099 double s = _step * _size / (_mx - _mn);
00100
00101
00102 if (s <= 0.01)
00103 return;
00104
00105 int mode = cdClip(CD_CLIPON);
00106
00107
00108 int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00109 cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00110
00111 cdClipArea(xmin, xmax, ymin, ymax);
00112
00113
00114 double x0, y0;
00115 position (&x0, &y0);
00116
00117
00118
00119 cdLineWidth (1);
00120 cdLineStyle (continuous);
00121 cdForeground (_color);
00122
00123 double dx = 0.;
00124
00125 for (double p = _first; p <= _mx; p += _step)
00126 {
00127
00128 wdArc(x0, y0, dx * 2., dx * 2., 0., 360.);
00129
00130 dx += s;
00131 }
00132
00133 cdClip(mode);
00134
00135 cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00136 }
00137
00138 void XYRadialGrid::boundingBox (int& xmin, int& ymin, int& xmax, int& ymax)
00139 const
00140 {
00141 if (visible() == xyfalse)
00142 return;
00143
00144
00145 double s = _step * _size / (_mx - _mn);
00146
00147
00148 if (s <= 0.01)
00149 return;
00150
00151
00152 double x0, y0;
00153 position (&x0, &y0);
00154
00155 int bx1, by1;
00156 wdWorld2Canvas (x0, y0, &bx1, &by1);
00157
00158
00159 xmin = bx1;
00160 ymin = by1;
00161 xmax = bx1;
00162 ymax = by1;
00163
00164
00165 double dx = 0.;
00166
00167 for (double p = _first; p <= _mx; p += _step)
00168 {
00169
00170 xmin = MIN(bx1, xmin);
00171 ymin = MIN(by1, ymin);
00172 xmax = MAX(bx1, xmax);
00173 ymax = MAX(by1, ymax);
00174
00175 dx += s;
00176 }
00177 }
00178