//*CMZ :  2.23/02 07/09/99  08.07.25  by  Rene Brun
//*CMZ :  2.21/07 05/03/99  11.25.23  by  Rene Brun
//*CMZ :  2.20/05 15/12/98  09.17.21  by  Rene Brun
//*CMZ :  2.20/00 02/11/98  15.29.52  by  Fons Rademakers
//*-- Author :    Rene Brun   12/12/94

//*KEEP,CopyRight,T=C.
/*************************************************************************
 * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
 * Authors: Rene Brun and Fons Rademakers.                               *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/AA_LICENSE.                      *
 * For the list of contributors see $ROOTSYS/AA_CREDITS.                 *
 *************************************************************************/
//*KEND.

#include <fstream.h>

//*KEEP,TROOT.
#include "TROOT.h"
//*KEEP,Strlen.
#include "Strlen.h"
//*KEEP,TWbox.
#include "TWbox.h"
//*KEEP,TVirtualPad.
#include "TVirtualPad.h"
//*KEEP,TVirtualX.
#include "TVirtualX.h"
//*KEEP,TPoint.
#include "TPoint.h"
//*KEND.
ClassImp(TWbox)

const Int_t kFraming = BIT(6);  // check also definition in TButton

//______________________________________________________________________________
//
// a TWbox is a TBox with a bordersize and a bordermode.
//
//
/*

*/
//

//______________________________________________________________________________
 TWbox::TWbox(): TBox()
{
//*-*-*-*-*-*-*-*-*-*-*wbox default constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  ========================

}

//______________________________________________________________________________
 TWbox::TWbox(Coord_t x1, Coord_t y1,Coord_t x2, Coord_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)
{
   ((TWbox&)wbox).Copy(*this);
}

//______________________________________________________________________________
 void TWbox::Copy(TObject &obj)
{
//*-*-*-*-*-*-*-*-*-*-*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(Coord_t x1, Coord_t y1,Coord_t x2, Coord_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(Coord_t x1, Coord_t y1, Coord_t x2, Coord_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(Coord_t x1, Coord_t y1,Coord_t x2, Coord_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;
   Float_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(GetLightColor());
      else                  gVirtualX->SetFillColor(GetDarkColor());
      gVirtualX->DrawFillArea(7, frame);

//*-* If this wbox is a button, highlight it
      if (InheritsFrom("TButton") && bordermode == -1) {
         if (TestBit(kFraming)) {  // bit set in TButton::SetFraming
            if (GetFillColor() != 2) gVirtualX->SetLineColor(2);
            else                     gVirtualX->SetLineColor(4);
            gVirtualX->DrawBox(px1+2,py1-2,px2-2,py2+2, TVirtualX::kHollow);
         }
      }
      gVirtualX->SetFillColor(-1);
      SetFillColor(oldcolor);
   }

   if (!tops) return;

//*-*- same for PostScript
//   Float_t dx   = (xt - xl) *Float_t(bordersize)/Float_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::Print(Option_t *option)
{
//*-*-*-*-*-*-*-*-*-*-*Dump this wbox with its attributes*-*-*-*-*-*-*-*-*-*
//*-*                  ==================================
   TBox::Print(option);
}

//______________________________________________________________________________
 void TWbox::SavePrimitive(ofstream &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;
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.