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

xyslca.cpp

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /* Módulo: xyslca.cpp                                                        */
00003 /* Autores: Carlos Henrique Levy e Jaudênia Cavalcante                       */
00004 /* Data: 12 mai 97                                                           */
00005 /* Comentário:                                                               */
00006 /*    Implementação de métodos da classe que evidencia uma área num gráfico  */
00007 /* cartesiano através de traços verticais e cor de fundo entre eles diferen  */
00008 /* te da usada em seus delimitadores.                                        */
00009 /*****************************************************************************/
00010 
00011 #include "xyslca.h"
00012 
00013 const char* xy_id_xyslca_cpp="$Id: xyslca.cpp,v 1.5 1999/12/09 21:47:46 rborges Exp $";
00014                                                                 
00015 XYCartesianSlice::XYCartesianSlice (const XYAxis* axis,
00016                                     double begin,
00017                                     double end,
00018                                     xybool visible)
00019                                                 : XYSlice(axis, begin, end, visible)
00020 {
00021    _beginMarker = new XYCartesianMarker (axis, begin, XY_DARK_GREEN, 2,
00022                                          XYObject::continuous, visible);
00023    _endMarker   = new XYCartesianMarker (axis, end,   XY_DARK_GREEN, 2,
00024                                          XYObject::continuous, visible);
00025 
00026    _backgroundColor = changeColor(XY_DARK_GREEN, 0, 255 - XY_DARK_GREEN, 0);
00027 }
00028 
00029 XYCartesianSlice::~XYCartesianSlice (void)
00030 {
00031    if (_beginMarker)
00032       delete _beginMarker;
00033 
00034    if (_endMarker)
00035       delete _endMarker;
00036 }
00037 
00038 xybool XYCartesianSlice::pick (int px, int py)
00039 {
00040    if (visible() == xyfalse)           // invisível!!!
00041       return xyfalse;
00042 
00043    // limites da menor caixa que contém um "slice"
00044    int x1, y1, x2, y2;
00045    boundingBox (x1, y1, x2, y2);
00046 
00047    return mtPointInRect (px, py, x1, y1, x2, y2);
00048 }
00049 
00050 xybool XYCartesianSlice::fence (int x2, int y2, int x3, int y3)
00051 {
00052    if (visible() == xyfalse)           // invisível!!!
00053       return xyfalse;
00054 
00055    // limites da menor caixa que contém um "slice"
00056    int x0, y0, x1, y1;
00057    boundingBox (x0, y0, x1, y1);
00058 
00059    return mtInclude (x0, y0, x1, y1, x2, y2, x3, y3);
00060 }
00061 
00062 void XYCartesianSlice::draw (void)
00063 {
00064    int xmin, ymin, xmax, ymax;
00065 
00066    // consulta área do gráfico
00067    getViewport (xmin, xmax, ymin, ymax);
00068 
00069    draw(xmin, ymin, xmax, ymax);
00070 }
00071 
00072 void XYCartesianSlice::draw (int xmin, int ymin, int xmax, int ymax) const
00073 {
00074    if (visible() == xyfalse)  // invisível!!!
00075       return;
00076 
00077    int vpxmin, vpxmax, vpymin, vpymax;
00078    getViewport(vpxmin, vpxmax, vpymin, vpymax);
00079 
00080    int mode = cdClip(CD_CLIPON);
00081 
00082    // guarda a região de clip corrente
00083    int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00084    cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00085    // define nova região de clip
00086    cdClipArea(MAX(vpxmin,xmin), MIN(vpxmax,xmax), MAX(vpymin,ymin),
00087               MIN(vpymax,ymax));
00088 
00089    // pinta o fundo da região com a cor dada pelo usuário
00090    cdForeground (backgroundColor());
00091    cdInteriorStyle(CD_SOLID);
00092 
00093    int x1, y1, x2, y2;
00094    boundingBox(x1, y1, x2, y2);
00095 
00096    cdBox(x1, x2, y1, y2);
00097 
00098    // desenha os marcadores de fronteiras
00099    _beginMarker -> draw(xmin, ymin, xmax, ymax);
00100    _endMarker   -> draw(xmin, ymin, xmax, ymax);
00101 
00102    cdClip(mode);
00103    // restaura a região de clip anterior
00104    cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00105 }
00106 
00107 void XYCartesianSlice::boundingBox (int &xmin, int &ymin, int &xmax,
00108                                     int &ymax) const
00109 {
00110    if (visible() == xyfalse)  // invisível!!!
00111       return;
00112 
00113    int x0, y0, x1, y1, x2, y2, x3, y3;
00114    _beginMarker -> boundingBox (x0, y0, x1, y1);
00115    _endMarker   -> boundingBox (x2, y2, x3, y3);
00116 
00117    int bmnx1, bmny1, bmnx2, bmny2;
00118    int bmxx1, bmxy1, bmxx2, bmxy2;
00119 
00120    // valores mínimos                // valores máximos
00121    bmnx1 = MIN(x0, x1);            bmxx1 = MAX(x0, x1);
00122    bmnx2 = MIN(x2, x3);            bmxx2 = MAX(x2, x3);
00123    bmny1 = MIN(y0, y1);            bmxy1 = MAX(y0, y1);
00124    bmny2 = MIN(y2, y3);            bmxy2 = MAX(y2, y3);
00125 
00126    // boundingBox do "slice"
00127    xmin = MIN(bmnx1, bmnx2);
00128    ymin = MIN(bmny1, bmny2);
00129    xmax = MAX(bmxx1, bmxx2);
00130    ymax = MAX(bmxy1, bmxy2);
00131 }
00132 

XY
Tecgraf / PUC-Rio - Computer Graphics Technology Group