ROOT logo
// @(#)root/graf:$Id: TWbox.cxx 31676 2009-12-08 15:44:11Z couet $
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TROOT.h"
#include "Strlen.h"
#include "TWbox.h"
#include "TColor.h"
#include "TVirtualPad.h"
#include "TVirtualX.h"
#include "TPoint.h"


ClassImp(TWbox)


//______________________________________________________________________________
//
// a TWbox is a TBox with a bordersize and a bordermode.
//
//Begin_Html
/*
<img src="gif/wbox.gif">
*/
//End_Html


//______________________________________________________________________________
TWbox::TWbox(): TBox()
{
   // wbox default constructor.

   fBorderSize  = 0;
   fBorderMode  = 0;
}


//______________________________________________________________________________
TWbox::TWbox(Double_t x1, Double_t y1,Double_t x2, Double_t  y2,
             Color_t color ,Short_t bordersize ,Short_t bordermode)
       :TBox(x1,y1,x2,y2)
{
   // wbox normal constructor.
   //
   // a WBOX is a box with a bordersize and a bordermode
   // the bordersize is in pixels
   // bordermode = -1 box looks as it is behind the screen
   // bordermode = 0  no special effects
   // bordermode = 1  box looks as it is in front of the screen

   fBorderSize  = bordersize;
   fBorderMode  = bordermode;
   SetFillColor(color);
   SetFillStyle(1001);
}


//______________________________________________________________________________
TWbox::~TWbox()
{
   // wbox default destructor.
}


//______________________________________________________________________________
TWbox::TWbox(const TWbox &wbox) : TBox(wbox)
{
   // wbox copy constructor.

   ((TWbox&)wbox).Copy(*this);
}


//______________________________________________________________________________
void TWbox::Copy(TObject &obj) const
{
   // Copy this wbox to wbox.

   TBox::Copy(obj);
   ((TWbox&)obj).fBorderSize  = fBorderSize;
   ((TWbox&)obj).fBorderMode  = fBorderMode;
}


//______________________________________________________________________________
void TWbox::Draw(Option_t *option)
{
   // Draw this wbox with its current attributes.

   AppendPad(option);
}


//______________________________________________________________________________
void TWbox::DrawWbox(Double_t x1, Double_t y1,Double_t x2, Double_t  y2,
                     Color_t color ,Short_t bordersize ,Short_t bordermode)
{
   // Draw this wbox with new coordinates.

   TWbox *newwbox = new TWbox(x1,y1,x2,y2,color,bordersize,bordermode);
   newwbox->SetBit(kCanDelete);
   newwbox->AppendPad();
}


//______________________________________________________________________________
void TWbox::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
   // Execute action corresponding to one event.
   //
   //  This member function is called when a WBOX object is clicked.

   TBox::ExecuteEvent(event, px, py);
}


//______________________________________________________________________________
void TWbox::Paint(Option_t *)
{
   // Paint this wbox with its current attributes.

   PaintWbox(fX1, fY1, fX2, fY2, GetFillColor(), fBorderSize, fBorderMode);
}


//______________________________________________________________________________
void TWbox::PaintWbox(Double_t x1, Double_t y1, Double_t x2, Double_t  y2,
                      Color_t color, Short_t bordersize, Short_t bordermode)
{
   // Draw this wbox with new coordinates.

   // Draw first wbox as a normal filled box
   TBox::PaintBox(x1, y1, x2, y2);

   // then paint 3d frame (depending on bordermode)
   if (!IsTransparent())
      PaintFrame(x1, y1, x2, y2, color, bordersize, bordermode, kTRUE);
}


//______________________________________________________________________________
void TWbox::PaintFrame(Double_t x1, Double_t y1,Double_t x2, Double_t  y2,
                       Color_t color, Short_t bordersize, Short_t bordermode,
                       Bool_t tops)
{
   // Paint a 3D frame around a box.

   if (bordermode == 0) return;
   if (bordersize <= 0) bordersize = 2;

   Short_t pxl,pyl,pxt,pyt,px1,py1,px2,py2;
   Double_t xl, xt, yl, yt;

   // Compute real left bottom & top right of the box in pixels
   px1 = gPad->XtoPixel(x1);   py1 = gPad->YtoPixel(y1);
   px2 = gPad->XtoPixel(x2);   py2 = gPad->YtoPixel(y2);
   if (px1 < px2) {pxl = px1; pxt = px2; xl = x1; xt = x2; }
   else           {pxl = px2; pxt = px1; xl = x2; xt = x1;}
   if (py1 > py2) {pyl = py1; pyt = py2; yl = y1; yt = y2;}
   else           {pyl = py2; pyt = py1; yl = y2; yt = y1;}

   if (!gPad->IsBatch()) {
      TPoint frame[7];

      // GetDarkColor() and GetLightColor() use GetFillColor()
      Color_t oldcolor = GetFillColor();
      SetFillColor(color);
      TAttFill::Modify();

      // Draw top&left part of the box
      frame[0].fX = pxl;                 frame[0].fY = pyl;
      frame[1].fX = pxl + bordersize;    frame[1].fY = pyl - bordersize;
      frame[2].fX = frame[1].fX;         frame[2].fY = pyt + bordersize;
      frame[3].fX = pxt - bordersize;    frame[3].fY = frame[2].fY;
      frame[4].fX = pxt;                 frame[4].fY = pyt;
      frame[5].fX = pxl;                 frame[5].fY = pyt;
      frame[6].fX = pxl;                 frame[6].fY = pyl;

      if (bordermode == -1) gVirtualX->SetFillColor(GetDarkColor());
      else                  gVirtualX->SetFillColor(GetLightColor());
      gVirtualX->DrawFillArea(7, frame);

      // Draw bottom&right part of the box
      frame[0].fX = pxl;                 frame[0].fY = pyl;
      frame[1].fX = pxl + bordersize;    frame[1].fY = pyl - bordersize;
      frame[2].fX = pxt - bordersize;    frame[2].fY = frame[1].fY;
      frame[3].fX = frame[2].fX;         frame[3].fY = pyt + bordersize;
      frame[4].fX = pxt;                 frame[4].fY = pyt;
      frame[5].fX = pxt;                 frame[5].fY = pyl;
      frame[6].fX = pxl;                 frame[6].fY = pyl;

      if (bordermode == -1) gVirtualX->SetFillColor(TColor::GetColorBright(GetFillColor()));
      else                  gVirtualX->SetFillColor(TColor::GetColorDark(GetFillColor()));
      gVirtualX->DrawFillArea(7, frame);

      gVirtualX->SetFillColor(-1);
      SetFillColor(oldcolor);
   }

   if (!tops) return;

   // same for PostScript
   // Double_t dx   = (xt - xl) *Double_t(bordersize)/Double_t(pxt - pxl);
   // Int_t border = gVirtualPS->XtoPS(xt) - gVirtualPS->XtoPS(xt-dx);

   gPad->PaintBorderPS(xl, yl, xt, yt, bordermode, bordersize,
                         GetDarkColor(), GetLightColor());
}


//______________________________________________________________________________
void TWbox::SavePrimitive(ostream &out, Option_t * /*= ""*/)
{
   // Save primitive as a C++ statement(s) on output stream out

   if (gROOT->ClassSaved(TWbox::Class())) {
      out<<"   ";
   } else {
      out<<"   TWbox *";
   }
   out<<"wbox = new TWbox("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2<<");"<<endl;

   SaveFillAttributes(out,"wbox",0,1001);
   SaveLineAttributes(out,"wbox",1,1,1);

   out<<"   wbox->Draw();"<<endl;
}
 TWbox.cxx:1
 TWbox.cxx:2
 TWbox.cxx:3
 TWbox.cxx:4
 TWbox.cxx:5
 TWbox.cxx:6
 TWbox.cxx:7
 TWbox.cxx:8
 TWbox.cxx:9
 TWbox.cxx:10
 TWbox.cxx:11
 TWbox.cxx:12
 TWbox.cxx:13
 TWbox.cxx:14
 TWbox.cxx:15
 TWbox.cxx:16
 TWbox.cxx:17
 TWbox.cxx:18
 TWbox.cxx:19
 TWbox.cxx:20
 TWbox.cxx:21
 TWbox.cxx:22
 TWbox.cxx:23
 TWbox.cxx:24
 TWbox.cxx:25
 TWbox.cxx:26
 TWbox.cxx:27
 TWbox.cxx:28
 TWbox.cxx:29
 TWbox.cxx:30
 TWbox.cxx:31
 TWbox.cxx:32
 TWbox.cxx:33
 TWbox.cxx:34
 TWbox.cxx:35
 TWbox.cxx:36
 TWbox.cxx:37
 TWbox.cxx:38
 TWbox.cxx:39
 TWbox.cxx:40
 TWbox.cxx:41
 TWbox.cxx:42
 TWbox.cxx:43
 TWbox.cxx:44
 TWbox.cxx:45
 TWbox.cxx:46
 TWbox.cxx:47
 TWbox.cxx:48
 TWbox.cxx:49
 TWbox.cxx:50
 TWbox.cxx:51
 TWbox.cxx:52
 TWbox.cxx:53
 TWbox.cxx:54
 TWbox.cxx:55
 TWbox.cxx:56
 TWbox.cxx:57
 TWbox.cxx:58
 TWbox.cxx:59
 TWbox.cxx:60
 TWbox.cxx:61
 TWbox.cxx:62
 TWbox.cxx:63
 TWbox.cxx:64
 TWbox.cxx:65
 TWbox.cxx:66
 TWbox.cxx:67
 TWbox.cxx:68
 TWbox.cxx:69
 TWbox.cxx:70
 TWbox.cxx:71
 TWbox.cxx:72
 TWbox.cxx:73
 TWbox.cxx:74
 TWbox.cxx:75
 TWbox.cxx:76
 TWbox.cxx:77
 TWbox.cxx:78
 TWbox.cxx:79
 TWbox.cxx:80
 TWbox.cxx:81
 TWbox.cxx:82
 TWbox.cxx:83
 TWbox.cxx:84
 TWbox.cxx:85
 TWbox.cxx:86
 TWbox.cxx:87
 TWbox.cxx:88
 TWbox.cxx:89
 TWbox.cxx:90
 TWbox.cxx:91
 TWbox.cxx:92
 TWbox.cxx:93
 TWbox.cxx:94
 TWbox.cxx:95
 TWbox.cxx:96
 TWbox.cxx:97
 TWbox.cxx:98
 TWbox.cxx:99
 TWbox.cxx:100
 TWbox.cxx:101
 TWbox.cxx:102
 TWbox.cxx:103
 TWbox.cxx:104
 TWbox.cxx:105
 TWbox.cxx:106
 TWbox.cxx:107
 TWbox.cxx:108
 TWbox.cxx:109
 TWbox.cxx:110
 TWbox.cxx:111
 TWbox.cxx:112
 TWbox.cxx:113
 TWbox.cxx:114
 TWbox.cxx:115
 TWbox.cxx:116
 TWbox.cxx:117
 TWbox.cxx:118
 TWbox.cxx:119
 TWbox.cxx:120
 TWbox.cxx:121
 TWbox.cxx:122
 TWbox.cxx:123
 TWbox.cxx:124
 TWbox.cxx:125
 TWbox.cxx:126
 TWbox.cxx:127
 TWbox.cxx:128
 TWbox.cxx:129
 TWbox.cxx:130
 TWbox.cxx:131
 TWbox.cxx:132
 TWbox.cxx:133
 TWbox.cxx:134
 TWbox.cxx:135
 TWbox.cxx:136
 TWbox.cxx:137
 TWbox.cxx:138
 TWbox.cxx:139
 TWbox.cxx:140
 TWbox.cxx:141
 TWbox.cxx:142
 TWbox.cxx:143
 TWbox.cxx:144
 TWbox.cxx:145
 TWbox.cxx:146
 TWbox.cxx:147
 TWbox.cxx:148
 TWbox.cxx:149
 TWbox.cxx:150
 TWbox.cxx:151
 TWbox.cxx:152
 TWbox.cxx:153
 TWbox.cxx:154
 TWbox.cxx:155
 TWbox.cxx:156
 TWbox.cxx:157
 TWbox.cxx:158
 TWbox.cxx:159
 TWbox.cxx:160
 TWbox.cxx:161
 TWbox.cxx:162
 TWbox.cxx:163
 TWbox.cxx:164
 TWbox.cxx:165
 TWbox.cxx:166
 TWbox.cxx:167
 TWbox.cxx:168
 TWbox.cxx:169
 TWbox.cxx:170
 TWbox.cxx:171
 TWbox.cxx:172
 TWbox.cxx:173
 TWbox.cxx:174
 TWbox.cxx:175
 TWbox.cxx:176
 TWbox.cxx:177
 TWbox.cxx:178
 TWbox.cxx:179
 TWbox.cxx:180
 TWbox.cxx:181
 TWbox.cxx:182
 TWbox.cxx:183
 TWbox.cxx:184
 TWbox.cxx:185
 TWbox.cxx:186
 TWbox.cxx:187
 TWbox.cxx:188
 TWbox.cxx:189
 TWbox.cxx:190
 TWbox.cxx:191
 TWbox.cxx:192
 TWbox.cxx:193
 TWbox.cxx:194
 TWbox.cxx:195
 TWbox.cxx:196
 TWbox.cxx:197
 TWbox.cxx:198
 TWbox.cxx:199
 TWbox.cxx:200
 TWbox.cxx:201
 TWbox.cxx:202
 TWbox.cxx:203
 TWbox.cxx:204
 TWbox.cxx:205
 TWbox.cxx:206
 TWbox.cxx:207
 TWbox.cxx:208
 TWbox.cxx:209
 TWbox.cxx:210
 TWbox.cxx:211
 TWbox.cxx:212
 TWbox.cxx:213
 TWbox.cxx:214
 TWbox.cxx:215
 TWbox.cxx:216
 TWbox.cxx:217
 TWbox.cxx:218
 TWbox.cxx:219
 TWbox.cxx:220
 TWbox.cxx:221
 TWbox.cxx:222
 TWbox.cxx:223
 TWbox.cxx:224
 TWbox.cxx:225
 TWbox.cxx:226
 TWbox.cxx:227
 TWbox.cxx:228
 TWbox.cxx:229
 TWbox.cxx:230
 TWbox.cxx:231
 TWbox.cxx:232
 TWbox.cxx:233
 TWbox.cxx:234
 TWbox.cxx:235