Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

sxy_task_mvlegend.cpp

Go to the documentation of this file.
00001 // =======================================================================
00002 
00003 char *task_mvlegend_cpp = "$Id: sxy_task_mvlegend.cpp,v 1.1 2002/11/25 19:52:05 clinio Exp $";
00004 
00005 // =======================================================================
00006 
00007 #include <assert.h>
00008 #include <cd.h>
00009 #include <xy.h>
00010 
00011 #include "sxy_chart.h"
00012 #include "sxy_graph.h"
00013 #include "sxy_task.h"
00014 #include "sxy_task_mvlegend.h"
00015 
00016 // =======================================================================
00017 
00018 SXYTaskReturn SXYTaskMoveLegend::mouseClick(SXYGraph* graph, int b, int x, int y, 
00019 int sft, int ctr) {
00020    if ( b != 1 ) return CALLBACK_NOT_TREATED;
00021    int cht = graph->getChartOfEvent(x, y);
00022    if (cht < 0) return CALLBACK_NOT_TREATED;
00023 
00024    SXYChart* chart = graph->getChart(cht);
00025    XYLegend* leg = chart->getXyLegend();
00026    if ( leg == NULL ) return CALLBACK_NOT_TREATED;
00027    if ( !leg->pick(x, y) ) return CALLBACK_NOT_TREATED;
00028 
00029    legend = leg;
00030    is_moving = 1;
00031    ref_x = x; ref_y = y;
00032    shift_x = 0; shift_y = 0;
00033    drawFence();
00034 
00035    return CALLBACK_TREATED;
00036 }
00037 
00038 // ......................................................................
00039 //
00040 SXYTaskReturn SXYTaskMoveLegend::mouseUnclick(SXYGraph* graph, int b, int x, int y, 
00041 int sft, int ctr) {
00042    if ( !is_moving ) return CALLBACK_NOT_TREATED;
00043 
00044    if ( b != 1 ) return CALLBACK_NOT_TREATED;
00045    int cht = graph->getChartOfEvent(x, y);
00046    if (cht < 0) return CALLBACK_NOT_TREATED;
00047 
00048    drawFence();
00049    translateLegend();
00050    shift_x = 0; shift_y = 0;
00051    ref_x = x; ref_y = y;
00052    is_moving = 0;
00053    legend = NULL;
00054    graph->redrawGraph();
00055 
00056    return CALLBACK_TREATED;
00057 }
00058 
00059 // ......................................................................
00060 
00061 SXYTaskReturn SXYTaskMoveLegend::mouseMotion(SXYGraph* graph, int x, int y, 
00062 int sft, int ctr) {
00063    if ( !is_moving ) return CALLBACK_NOT_TREATED;
00064    int cht = graph->getChartOfEvent(x, y);
00065    if (cht < 0) return CALLBACK_NOT_TREATED;
00066 
00067    drawFence();
00068    shift_x = x - ref_x;
00069    shift_y = y - ref_y;
00070    drawFence();
00071 
00072    return CALLBACK_TREATED;
00073 }
00074 
00075 // ......................................................................
00076 
00077 SXYTaskReturn SXYTaskMoveLegend::mouseEnter(SXYGraph* graph) {
00078    is_moving = 0;
00079    graph->redrawGraph();
00080    return CALLBACK_NOT_TREATED;
00081 }
00082 
00083 // ......................................................................
00084 
00085 SXYTaskReturn SXYTaskMoveLegend::mouseLeave(SXYGraph* graph) {
00086    is_moving = 0;
00087    graph->redrawGraph();
00088    return CALLBACK_NOT_TREATED;
00089 }
00090 
00091 // ......................................................................
00092 
00093 void SXYTaskMoveLegend::drawFence(void) {
00094    int bxmin, bymin, bxmax, bymax;
00095    legend->boundingBox(bxmin, bymin, bxmax, bymax);
00096    int old_write_mode = cdWriteMode( CD_NOT_XOR );
00097    long int old_color = cdForeground( getXorColor() );
00098 
00099    bxmin += shift_x; bymin += shift_y;
00100    bxmax += shift_x; bymax += shift_y;
00101    cdRect( bxmin, bxmax, bymin, bymax );
00102 
00103    cdWriteMode( old_write_mode );
00104    cdForeground( old_color );
00105 }
00106 
00107 // ......................................................................
00108 
00109 void SXYTaskMoveLegend::translateLegend(void) {
00110    int xp, yp;
00111    assert(legend);
00112    legend->position(&xp, &yp);
00113    xp += shift_x; yp += shift_y;
00114    legend->position(xp, yp);
00115 }
00116 
00117 // ......................................................................
00118 
00119 SXYTaskMoveLegend::SXYTaskMoveLegend(void) {
00120    is_moving = 0;
00121    shift_x = 0; shift_y = 0;
00122    ref_x = 0;   ref_y = 0;
00123    legend = NULL;
00124 }
00125 
00126 // ......................................................................
00127 
00128 SXYTaskMoveLegend::~SXYTaskMoveLegend() {
00129    legend = NULL;
00130 };
00131 

SXY
Tecgraf / PUC-Rio - Computer Graphics Technology Group