TWbox.cxx

Go to the documentation of this file.
00001 // @(#)root/graf:$Id: TWbox.cxx 35168 2010-09-06 11:20:08Z couet $
00002 // Author: Rene Brun   12/12/94
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "Riostream.h"
00013 #include "TROOT.h"
00014 #include "Strlen.h"
00015 #include "TWbox.h"
00016 #include "TColor.h"
00017 #include "TVirtualPad.h"
00018 #include "TVirtualX.h"
00019 #include "TPoint.h"
00020 
00021 
00022 ClassImp(TWbox)
00023 
00024 
00025 //______________________________________________________________________________
00026 //
00027 // a TWbox is a TBox with a bordersize and a bordermode.
00028 //
00029 //Begin_Html
00030 /*
00031 <img src="gif/wbox.gif">
00032 */
00033 //End_Html
00034 
00035 
00036 //______________________________________________________________________________
00037 TWbox::TWbox(): TBox()
00038 {
00039    // wbox default constructor.
00040 
00041    fBorderSize  = 0;
00042    fBorderMode  = 0;
00043 }
00044 
00045 
00046 //______________________________________________________________________________
00047 TWbox::TWbox(Double_t x1, Double_t y1,Double_t x2, Double_t  y2,
00048              Color_t color ,Short_t bordersize ,Short_t bordermode)
00049        :TBox(x1,y1,x2,y2)
00050 {
00051    // wbox normal constructor.
00052    //
00053    // a WBOX is a box with a bordersize and a bordermode
00054    // the bordersize is in pixels
00055    // bordermode = -1 box looks as it is behind the screen
00056    // bordermode = 0  no special effects
00057    // bordermode = 1  box looks as it is in front of the screen
00058 
00059    fBorderSize  = bordersize;
00060    fBorderMode  = bordermode;
00061    SetFillColor(color);
00062    SetFillStyle(1001);
00063 }
00064 
00065 
00066 //______________________________________________________________________________
00067 TWbox::~TWbox()
00068 {
00069    // wbox default destructor.
00070 }
00071 
00072 
00073 //______________________________________________________________________________
00074 TWbox::TWbox(const TWbox &wbox) : TBox(wbox)
00075 {
00076    // wbox copy constructor.
00077 
00078    fBorderSize  = 0;
00079    fBorderMode  = 0;
00080    ((TWbox&)wbox).Copy(*this);
00081 }
00082 
00083 
00084 //______________________________________________________________________________
00085 void TWbox::Copy(TObject &obj) const
00086 {
00087    // Copy this wbox to wbox.
00088 
00089    TBox::Copy(obj);
00090    ((TWbox&)obj).fBorderSize  = fBorderSize;
00091    ((TWbox&)obj).fBorderMode  = fBorderMode;
00092 }
00093 
00094 
00095 //______________________________________________________________________________
00096 void TWbox::Draw(Option_t *option)
00097 {
00098    // Draw this wbox with its current attributes.
00099 
00100    AppendPad(option);
00101 }
00102 
00103 
00104 //______________________________________________________________________________
00105 void TWbox::DrawWbox(Double_t x1, Double_t y1,Double_t x2, Double_t  y2,
00106                      Color_t color ,Short_t bordersize ,Short_t bordermode)
00107 {
00108    // Draw this wbox with new coordinates.
00109 
00110    TWbox *newwbox = new TWbox(x1,y1,x2,y2,color,bordersize,bordermode);
00111    newwbox->SetBit(kCanDelete);
00112    newwbox->AppendPad();
00113 }
00114 
00115 
00116 //______________________________________________________________________________
00117 void TWbox::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00118 {
00119    // Execute action corresponding to one event.
00120    //
00121    //  This member function is called when a WBOX object is clicked.
00122 
00123    TBox::ExecuteEvent(event, px, py);
00124 }
00125 
00126 
00127 //______________________________________________________________________________
00128 void TWbox::Paint(Option_t *)
00129 {
00130    // Paint this wbox with its current attributes.
00131 
00132    PaintWbox(fX1, fY1, fX2, fY2, GetFillColor(), fBorderSize, fBorderMode);
00133 }
00134 
00135 
00136 //______________________________________________________________________________
00137 void TWbox::PaintWbox(Double_t x1, Double_t y1, Double_t x2, Double_t  y2,
00138                       Color_t color, Short_t bordersize, Short_t bordermode)
00139 {
00140    // Draw this wbox with new coordinates.
00141 
00142    // Draw first wbox as a normal filled box
00143    TBox::PaintBox(x1, y1, x2, y2);
00144 
00145    // then paint 3d frame (depending on bordermode)
00146    if (!IsTransparent())
00147       PaintFrame(x1, y1, x2, y2, color, bordersize, bordermode, kTRUE);
00148 }
00149 
00150 
00151 //______________________________________________________________________________
00152 void TWbox::PaintFrame(Double_t x1, Double_t y1,Double_t x2, Double_t  y2,
00153                        Color_t color, Short_t bordersize, Short_t bordermode,
00154                        Bool_t tops)
00155 {
00156    // Paint a 3D frame around a box.
00157 
00158    if (bordermode == 0) return;
00159    if (bordersize <= 0) bordersize = 2;
00160 
00161    Short_t pxl,pyl,pxt,pyt,px1,py1,px2,py2;
00162    Double_t xl, xt, yl, yt;
00163 
00164    // Compute real left bottom & top right of the box in pixels
00165    px1 = gPad->XtoPixel(x1);   py1 = gPad->YtoPixel(y1);
00166    px2 = gPad->XtoPixel(x2);   py2 = gPad->YtoPixel(y2);
00167    if (px1 < px2) {pxl = px1; pxt = px2; xl = x1; xt = x2; }
00168    else           {pxl = px2; pxt = px1; xl = x2; xt = x1;}
00169    if (py1 > py2) {pyl = py1; pyt = py2; yl = y1; yt = y2;}
00170    else           {pyl = py2; pyt = py1; yl = y2; yt = y1;}
00171 
00172    if (!gPad->IsBatch()) {
00173       TPoint frame[7];
00174 
00175       // GetDarkColor() and GetLightColor() use GetFillColor()
00176       Color_t oldcolor = GetFillColor();
00177       SetFillColor(color);
00178       TAttFill::Modify();
00179 
00180       // Draw top&left part of the box
00181       frame[0].fX = pxl;                 frame[0].fY = pyl;
00182       frame[1].fX = pxl + bordersize;    frame[1].fY = pyl - bordersize;
00183       frame[2].fX = frame[1].fX;         frame[2].fY = pyt + bordersize;
00184       frame[3].fX = pxt - bordersize;    frame[3].fY = frame[2].fY;
00185       frame[4].fX = pxt;                 frame[4].fY = pyt;
00186       frame[5].fX = pxl;                 frame[5].fY = pyt;
00187       frame[6].fX = pxl;                 frame[6].fY = pyl;
00188 
00189       if (bordermode == -1) gVirtualX->SetFillColor(GetDarkColor());
00190       else                  gVirtualX->SetFillColor(GetLightColor());
00191       gVirtualX->DrawFillArea(7, frame);
00192 
00193       // Draw bottom&right part of the box
00194       frame[0].fX = pxl;                 frame[0].fY = pyl;
00195       frame[1].fX = pxl + bordersize;    frame[1].fY = pyl - bordersize;
00196       frame[2].fX = pxt - bordersize;    frame[2].fY = frame[1].fY;
00197       frame[3].fX = frame[2].fX;         frame[3].fY = pyt + bordersize;
00198       frame[4].fX = pxt;                 frame[4].fY = pyt;
00199       frame[5].fX = pxt;                 frame[5].fY = pyl;
00200       frame[6].fX = pxl;                 frame[6].fY = pyl;
00201 
00202       if (bordermode == -1) gVirtualX->SetFillColor(TColor::GetColorBright(GetFillColor()));
00203       else                  gVirtualX->SetFillColor(TColor::GetColorDark(GetFillColor()));
00204       gVirtualX->DrawFillArea(7, frame);
00205 
00206       gVirtualX->SetFillColor(-1);
00207       SetFillColor(oldcolor);
00208    }
00209 
00210    if (!tops) return;
00211 
00212    // same for PostScript
00213    // Double_t dx   = (xt - xl) *Double_t(bordersize)/Double_t(pxt - pxl);
00214    // Int_t border = gVirtualPS->XtoPS(xt) - gVirtualPS->XtoPS(xt-dx);
00215 
00216    gPad->PaintBorderPS(xl, yl, xt, yt, bordermode, bordersize,
00217                          GetDarkColor(), GetLightColor());
00218 }
00219 
00220 
00221 //______________________________________________________________________________
00222 void TWbox::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00223 {
00224    // Save primitive as a C++ statement(s) on output stream out
00225 
00226    if (gROOT->ClassSaved(TWbox::Class())) {
00227       out<<"   ";
00228    } else {
00229       out<<"   TWbox *";
00230    }
00231    out<<"wbox = new TWbox("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2<<");"<<endl;
00232 
00233    SaveFillAttributes(out,"wbox",0,1001);
00234    SaveLineAttributes(out,"wbox",1,1,1);
00235 
00236    out<<"   wbox->Draw();"<<endl;
00237 }

Generated on Tue Jul 5 14:14:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1