ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TWbox.cxx
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Rene Brun 12/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "Riostream.h"
13 #include "TROOT.h"
14 #include "Strlen.h"
15 #include "TWbox.h"
16 #include "TColor.h"
17 #include "TVirtualPad.h"
18 #include "TVirtualX.h"
19 #include "TPoint.h"
20 
22 
23 /** \class TWbox
24 \ingroup BasicGraphics
25 
26 A TBox with a bordersize and a bordermode.
27 Example:
28 Begin_Macro(source)
29 {
30  TWbox *twb = new TWbox(.1,.1,.9,.9,kRed+2,5,1);
31  twb->Draw();
32 }
33 End_Macro
34 */
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// wbox default constructor.
38 
39 TWbox::TWbox(): TBox()
40 {
41  fBorderSize = 0;
42  fBorderMode = 0;
43 }
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// wbox normal constructor.
47 ///
48 /// a WBOX is a box with a bordersize and a bordermode
49 /// the bordersize is in pixels
50 /// - bordermode = -1 box looks as it is behind the screen
51 /// - bordermode = 0 no special effects
52 /// - bordermode = 1 box looks as it is in front of the screen
53 
55  Color_t color ,Short_t bordersize ,Short_t bordermode)
56  :TBox(x1,y1,x2,y2)
57 {
58  fBorderSize = bordersize;
59  fBorderMode = bordermode;
60  SetFillColor(color);
61  SetFillStyle(1001);
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// wbox default destructor.
66 
68 {
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// wbox copy constructor.
73 
74 TWbox::TWbox(const TWbox &wbox) : TBox(wbox)
75 {
76  fBorderSize = 0;
77  fBorderMode = 0;
78  ((TWbox&)wbox).Copy(*this);
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Copy this wbox to wbox.
83 
84 void TWbox::Copy(TObject &obj) const
85 {
86  TBox::Copy(obj);
87  ((TWbox&)obj).fBorderSize = fBorderSize;
88  ((TWbox&)obj).fBorderMode = fBorderMode;
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Draw this wbox with its current attributes.
93 
94 void TWbox::Draw(Option_t *option)
95 {
96  AppendPad(option);
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Draw this wbox with new coordinates.
101 
103  Color_t color ,Short_t bordersize ,Short_t bordermode)
104 {
105  TWbox *newwbox = new TWbox(x1,y1,x2,y2,color,bordersize,bordermode);
106  newwbox->SetBit(kCanDelete);
107  newwbox->AppendPad();
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Execute action corresponding to one event.
112 ///
113 /// This member function is called when a WBOX object is clicked.
114 
116 {
117  TBox::ExecuteEvent(event, px, py);
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Paint this wbox with its current attributes.
122 
124 {
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Draw this wbox with new coordinates.
130 
132  Color_t color, Short_t bordersize, Short_t bordermode)
133 {
134  // Draw first wbox as a normal filled box
135  TBox::PaintBox(x1, y1, x2, y2);
136 
137  // then paint 3d frame (depending on bordermode)
138  if (!IsTransparent())
139  PaintFrame(x1, y1, x2, y2, color, bordersize, bordermode, kTRUE);
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Paint a 3D frame around a box.
144 
146  Color_t color, Short_t bordersize, Short_t bordermode,
147  Bool_t tops)
148 {
149  if (bordermode == 0) return;
150  if (bordersize <= 0) bordersize = 2;
151 
152  Short_t pxl,pyl,pxt,pyt,px1,py1,px2,py2;
153  Double_t xl, xt, yl, yt;
154 
155  // Compute real left bottom & top right of the box in pixels
156  px1 = gPad->XtoPixel(x1); py1 = gPad->YtoPixel(y1);
157  px2 = gPad->XtoPixel(x2); py2 = gPad->YtoPixel(y2);
158  if (px1 < px2) {pxl = px1; pxt = px2; xl = x1; xt = x2; }
159  else {pxl = px2; pxt = px1; xl = x2; xt = x1;}
160  if (py1 > py2) {pyl = py1; pyt = py2; yl = y1; yt = y2;}
161  else {pyl = py2; pyt = py1; yl = y2; yt = y1;}
162 
163  if (!gPad->IsBatch()) {
164  TPoint frame[7];
165 
166  // GetDarkColor() and GetLightColor() use GetFillColor()
167  Color_t oldcolor = GetFillColor();
168  SetFillColor(color);
170 
171  // Draw top&left part of the box
172  frame[0].fX = pxl; frame[0].fY = pyl;
173  frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
174  frame[2].fX = frame[1].fX; frame[2].fY = pyt + bordersize;
175  frame[3].fX = pxt - bordersize; frame[3].fY = frame[2].fY;
176  frame[4].fX = pxt; frame[4].fY = pyt;
177  frame[5].fX = pxl; frame[5].fY = pyt;
178  frame[6].fX = pxl; frame[6].fY = pyl;
179 
180  if (bordermode == -1) gVirtualX->SetFillColor(GetDarkColor());
181  else gVirtualX->SetFillColor(GetLightColor());
182  gVirtualX->DrawFillArea(7, frame);
183 
184  // Draw bottom&right part of the box
185  frame[0].fX = pxl; frame[0].fY = pyl;
186  frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
187  frame[2].fX = pxt - bordersize; frame[2].fY = frame[1].fY;
188  frame[3].fX = frame[2].fX; frame[3].fY = pyt + bordersize;
189  frame[4].fX = pxt; frame[4].fY = pyt;
190  frame[5].fX = pxt; frame[5].fY = pyl;
191  frame[6].fX = pxl; frame[6].fY = pyl;
192 
193  if (bordermode == -1) gVirtualX->SetFillColor(TColor::GetColorBright(GetFillColor()));
194  else gVirtualX->SetFillColor(TColor::GetColorDark(GetFillColor()));
195  gVirtualX->DrawFillArea(7, frame);
196 
197  gVirtualX->SetFillColor(-1);
198  SetFillColor(oldcolor);
199  }
200 
201  if (!tops) return;
202 
203  // same for PostScript
204  // Double_t dx = (xt - xl) *Double_t(bordersize)/Double_t(pxt - pxl);
205  // Int_t border = gVirtualPS->XtoPS(xt) - gVirtualPS->XtoPS(xt-dx);
206 
207  gPad->PaintBorderPS(xl, yl, xt, yt, bordermode, bordersize,
209 }
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Save primitive as a C++ statement(s) on output stream out
213 
214 void TWbox::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
215 {
216  if (gROOT->ClassSaved(TWbox::Class())) {
217  out<<" ";
218  } else {
219  out<<" TWbox *";
220  }
221  out<<"wbox = new TWbox("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2<<");"<<std::endl;
222 
223  SaveFillAttributes(out,"wbox",0,1001);
224  SaveLineAttributes(out,"wbox",1,1,1);
225 
226  out<<" wbox->Draw();"<<std::endl;
227 }
void Copy(TObject &box) const
Copy a Box.
Definition: TBox.cxx:111
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TWbox.cxx:115
const char Option_t
Definition: RtypesCore.h:62
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TBox.cxx:212
Create a Box.
Definition: TBox.h:44
static Int_t GetColorDark(Int_t color)
Static function: Returns the dark color number corresponding to n If the TColor object does not exist...
Definition: TColor.cxx:1165
Double_t fY2
Definition: TBox.h:53
SCoord_t fX
Definition: TPoint.h:37
virtual ~TWbox()
wbox default destructor.
Definition: TWbox.cxx:67
Short_t fBorderMode
Definition: TWbox.h:37
#define gROOT
Definition: TROOT.h:344
SCoord_t fY
Definition: TPoint.h:38
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
Float_t py
Definition: hprod.C:33
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:164
Double_t fY1
Definition: TBox.h:51
static const double x2[5]
Short_t fBorderSize
Definition: TWbox.h:36
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:257
void Class()
Definition: Class.C:29
virtual void Modify()
Change current fill area attributes if necessary.
Definition: TAttFill.cxx:206
Int_t GetDarkColor() const
Definition: TWbox.h:53
virtual void PaintWbox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Color_t color=33, Short_t bordersize=5, Short_t bordermode=-1)
Draw this wbox with new coordinates.
Definition: TWbox.cxx:131
virtual void Draw(Option_t *option="")
Draw this wbox with its current attributes.
Definition: TWbox.cxx:94
virtual void DrawWbox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Color_t color=33, Short_t bordersize=5, Short_t bordermode=-1)
Draw this wbox with new coordinates.
Definition: TWbox.cxx:102
A TBox with a bordersize and a bordermode.
Definition: TWbox.h:33
char * out
Definition: TBase64.cxx:29
short Color_t
Definition: RtypesCore.h:79
Definition: TPoint.h:33
static Int_t GetColorBright(Int_t color)
Static function: Returns the bright color number corresponding to n If the TColor object does not exi...
Definition: TColor.cxx:1133
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
Double_t fX2
Definition: TBox.h:52
virtual Color_t GetFillColor() const
Definition: TAttFill.h:43
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition: TAttFill.cxx:229
Double_t fX1
tool tip associated with box
Definition: TBox.h:50
short Short_t
Definition: RtypesCore.h:35
virtual void PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option="")
Draw this box with new coordinates.
Definition: TBox.cxx:623
#define gVirtualX
Definition: TVirtualX.h:362
virtual Bool_t IsTransparent() const
Definition: TAttFill.h:57
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
virtual void 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.
Definition: TWbox.cxx:145
void Copy(TObject &wbox) const
Copy this wbox to wbox.
Definition: TWbox.cxx:84
Int_t GetLightColor() const
Definition: TWbox.h:54
Mother of all ROOT objects.
Definition: TObject.h:58
Float_t px
Definition: hprod.C:33
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TWbox.cxx:214
#define gPad
Definition: TVirtualPad.h:288
virtual void Paint(Option_t *option="")
Paint this wbox with its current attributes.
Definition: TWbox.cxx:123
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj