00001
00002
00003
00004 char *task_zoomin_cpp = "$Id: sxy_task_zoomin.cpp,v 1.2 2002/11/26 21:00:37 clinio Exp $";
00005
00006
00007
00008 #include <assert.h>
00009 #include <xy.h>
00010
00011 extern "C" {
00012 #include <iup.h>
00013 #include <iupgc.h>
00014 #include <cd.h>
00015 }
00016
00017 #include "sxy_chart.h"
00018 #include "sxy_graph.h"
00019 #include "sxy_task.h"
00020 #include "sxy_task_zoomin.h"
00021
00022
00023
00024 SXYTaskReturn SXYTaskZoomIn::mouseClick(SXYGraph* graph, int b, int x, int y,
00025 int sft, int ctr) {
00026 Ihandle* iup_canvas = graph->getIupCanvas();
00027
00028 if (b != 1 || !sft) {
00029 is_doing = 0;
00030 IupSetAttribute( iup_canvas, IUP_CURSOR, IUP_ARROW );
00031 return CALLBACK_NOT_TREATED;
00032 }
00033
00034 int ncht = graph->getChartOfEvent(x,y);
00035 if ( ncht < 0 ) return CALLBACK_NOT_TREATED;
00036 SXYChart* chart = graph->getChart(ncht);
00037 userchart = chart;
00038 is_doing = 1;
00039 ref_x = x; ref_y = y;
00040 shift_x = 0; shift_y = 0;
00041 drawFence();
00042 IupSetAttribute( iup_canvas, IUP_CURSOR, IUP_CROSS );
00043 return CALLBACK_TREATED;
00044
00045 return CALLBACK_NOT_TREATED;
00046 }
00047
00048
00049
00050 SXYTaskReturn SXYTaskZoomIn::mouseUnclick(SXYGraph* graph, int b, int x, int y,
00051 int sft, int ctr) {
00052 if ( !is_doing ) return CALLBACK_NOT_TREATED;
00053 if ( !userchart ) return CALLBACK_NOT_TREATED;
00054 if ( b != 1 ) return CALLBACK_NOT_TREATED;
00055
00056 int cht = graph->getChartOfEvent(x, y);
00057 if (cht < 0) return CALLBACK_NOT_TREATED;
00058
00059 drawFence();
00060 SXYTaskReturn answer = makeZoom( graph, userchart,
00061 ref_x, shift_x, ref_y, shift_y );
00062
00063 shift_x = 0; shift_y = 0;
00064 ref_x = x; ref_y = y;
00065
00066 Ihandle* iup_canvas = graph->getIupCanvas();
00067 IupSetAttribute( iup_canvas, IUP_CURSOR, IUP_ARROW );
00068 is_doing = 0;
00069
00070 userchart = NULL;
00071 graph->redrawGraph();
00072 return answer;
00073 }
00074
00075
00076
00077 SXYTaskReturn SXYTaskZoomIn::mouseMotion(SXYGraph* graph, int x, int y,
00078 int sft, int ctr) {
00079 if ( !is_doing ) return CALLBACK_NOT_TREATED;
00080 int cht = graph->getChartOfEvent(x, y);
00081 if (cht < 0) return CALLBACK_NOT_TREATED;
00082
00083 drawFence();
00084 shift_x = x - ref_x;
00085 shift_y = y - ref_y;
00086 drawFence();
00087
00088 return CALLBACK_TREATED;
00089 }
00090
00091
00092
00093 SXYTaskReturn SXYTaskZoomIn::mouseEnter(SXYGraph* graph) {
00094 Ihandle* iup_canvas = graph->getIupCanvas();
00095 IupSetAttribute( iup_canvas, IUP_CURSOR, IUP_ARROW );
00096
00097 is_doing = 0;
00098 graph->redrawGraph();
00099 return CALLBACK_NOT_TREATED;
00100 }
00101
00102
00103
00104 SXYTaskReturn SXYTaskZoomIn::mouseLeave(SXYGraph* graph) {
00105 Ihandle* iup_canvas = graph->getIupCanvas();
00106 IupSetAttribute( iup_canvas, IUP_CURSOR, IUP_ARROW );
00107
00108 is_doing = 0;
00109 graph->redrawGraph();
00110 return CALLBACK_NOT_TREATED;
00111 }
00112
00113
00114
00115 void SXYTaskZoomIn::drawFence(void) {
00116 int old_write_mode = cdWriteMode( CD_NOT_XOR );
00117 long int old_color = cdForeground( getXorColor() );
00118
00119 int xmin, xmax, ymin, ymax;
00120 if ( shift_x > 0 ) { xmin = ref_x; xmax = ref_x + shift_x; }
00121 else { xmax = ref_x; xmin = ref_x + shift_x; }
00122
00123 if ( shift_y > 0 ) { ymin = ref_y; ymax = ref_y + shift_y; }
00124 else { ymax = ref_y; ymin = ref_y + shift_y; }
00125
00126 cdRect( xmin, xmax, ymin, ymax );
00127
00128 cdWriteMode( old_write_mode );
00129 cdForeground( old_color );
00130 }
00131
00132
00133
00134 static void zoom(SXYAxis *axis, double min, double max) {
00135 if(min > max)
00136 {
00137 double tmp = max;
00138 max = min;
00139 min = tmp;
00140 }
00141 axis->setScales( min, max );
00142 axis->tryScalesAdjust();
00143 axis->tryStepAdjust();
00144 axis->calcPrecision();
00145 }
00146
00147
00148
00149 SXYTaskReturn SXYTaskZoomIn::makeZoom( SXYGraph* graph, SXYChart* chart,
00150 int x, int dx, int y, int dy ) {
00151 double min, max;
00152 SXYAxis* a;
00153
00154 for (unsigned int nh = 0; nh < chart->getNumAxes(HORIZONTAL_AXIS); nh++ ) {
00155 a = chart->getAxis( HORIZONTAL_AXIS, nh );
00156 if (dx != 0) {
00157 min = a->getPositionValue(x);
00158 max = a->getPositionValue(x+dx);
00159 zoom(a, min, max);
00160 }
00161 }
00162
00163 for (unsigned int nv = 0; nv < chart->getNumAxes(VERTICAL_AXIS); nv++ ) {
00164 a = chart->getAxis(VERTICAL_AXIS, nv );
00165 if (dy != 0) {
00166 min = a->getPositionValue(y);
00167 max = a->getPositionValue(y+dy);
00168 zoom(a, min, max);
00169 }
00170 }
00171
00172 chart->tryGridAdjust();
00173 return CALLBACK_TREATED;
00174 }
00175
00176
00177
00178 SXYTaskZoomIn::SXYTaskZoomIn() {
00179 is_doing = 0;
00180 userchart = NULL;
00181 ref_x = ref_y = 0;
00182 shift_x = shift_y = 0;
00183 }
00184
00185
00186
00187 SXYTaskZoomIn::~SXYTaskZoomIn() {
00188 }
00189