Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 
21 ClassImp(TWbox);
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 normal constructor.
38 ///
39 /// a WBOX is a box with a bordersize and a bordermode
40 /// the bordersize is in pixels
41 /// - bordermode = -1 box looks as it is behind the screen
42 /// - bordermode = 0 no special effects
43 /// - bordermode = 1 box looks as it is in front of the screen
44 
45 TWbox::TWbox(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
46  Color_t color ,Short_t bordersize ,Short_t bordermode)
47  :TBox(x1,y1,x2,y2)
48 {
49  fBorderSize = bordersize;
50  fBorderMode = bordermode;
51  SetFillColor(color);
52  SetFillStyle(1001);
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// wbox copy constructor.
57 
58 TWbox::TWbox(const TWbox &wbox) : TBox(wbox)
59 {
60  wbox.TWbox::Copy(*this);
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// assignment operator
65 
66 TWbox &TWbox::operator=(const TWbox &src)
67 {
68  src.TWbox::Copy(*this);
69  return *this;
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Copy this wbox to wbox.
74 
75 void TWbox::Copy(TObject &obj) const
76 {
77  TBox::Copy(obj);
78  ((TWbox&)obj).fBorderSize = fBorderSize;
79  ((TWbox&)obj).fBorderMode = fBorderMode;
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Draw this wbox with its current attributes.
84 
85 void TWbox::Draw(Option_t *option)
86 {
87  AppendPad(option);
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Draw this wbox with new coordinates.
92 
93 void TWbox::DrawWbox(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
94  Color_t color ,Short_t bordersize ,Short_t bordermode)
95 {
96  TWbox *newwbox = new TWbox(x1,y1,x2,y2,color,bordersize,bordermode);
97  newwbox->SetBit(kCanDelete);
98  newwbox->AppendPad();
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Execute action corresponding to one event.
103 ///
104 /// This member function is called when a WBOX object is clicked.
105 
106 void TWbox::ExecuteEvent(Int_t event, Int_t px, Int_t py)
107 {
108  TBox::ExecuteEvent(event, px, py);
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Paint this wbox with its current attributes.
113 
114 void TWbox::Paint(Option_t *)
115 {
116  PaintWbox(fX1, fY1, fX2, fY2, GetFillColor(), fBorderSize, fBorderMode);
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Draw this wbox with new coordinates.
121 
122 void TWbox::PaintWbox(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
123  Color_t color, Short_t bordersize, Short_t bordermode)
124 {
125  // Draw first wbox as a normal filled box
126  TBox::PaintBox(x1, y1, x2, y2);
127 
128  // then paint 3d frame (depending on bordermode)
129  if (!IsTransparent())
130  PaintFrame(x1, y1, x2, y2, color, bordersize, bordermode, kTRUE);
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Paint a 3D frame around a box.
135 
136 void TWbox::PaintFrame(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
137  Color_t color, Short_t bordersize, Short_t bordermode,
138  Bool_t tops)
139 {
140  if (bordermode == 0) return;
141  if (bordersize <= 0) bordersize = 2;
142 
143  Short_t pxl,pyl,pxt,pyt,px1,py1,px2,py2;
144  Double_t xl, xt, yl, yt;
145 
146  // Compute real left bottom & top right of the box in pixels
147  px1 = gPad->XtoPixel(x1); py1 = gPad->YtoPixel(y1);
148  px2 = gPad->XtoPixel(x2); py2 = gPad->YtoPixel(y2);
149  if (px1 < px2) {pxl = px1; pxt = px2; xl = x1; xt = x2; }
150  else {pxl = px2; pxt = px1; xl = x2; xt = x1;}
151  if (py1 > py2) {pyl = py1; pyt = py2; yl = y1; yt = y2;}
152  else {pyl = py2; pyt = py1; yl = y2; yt = y1;}
153 
154  if (!gPad->IsBatch()) {
155  TPoint frame[7];
156 
157  // GetDarkColor() and GetLightColor() use GetFillColor()
158  Color_t oldcolor = GetFillColor();
159  SetFillColor(color);
160  TAttFill::Modify();
161 
162  // Draw top&left part of the box
163  frame[0].fX = pxl; frame[0].fY = pyl;
164  frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
165  frame[2].fX = frame[1].fX; frame[2].fY = pyt + bordersize;
166  frame[3].fX = pxt - bordersize; frame[3].fY = frame[2].fY;
167  frame[4].fX = pxt; frame[4].fY = pyt;
168  frame[5].fX = pxl; frame[5].fY = pyt;
169  frame[6].fX = pxl; frame[6].fY = pyl;
170 
171  if (bordermode == -1) gVirtualX->SetFillColor(GetDarkColor());
172  else gVirtualX->SetFillColor(GetLightColor());
173  gVirtualX->DrawFillArea(7, frame);
174 
175  // Draw bottom&right part of the box
176  frame[0].fX = pxl; frame[0].fY = pyl;
177  frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
178  frame[2].fX = pxt - bordersize; frame[2].fY = frame[1].fY;
179  frame[3].fX = frame[2].fX; frame[3].fY = pyt + bordersize;
180  frame[4].fX = pxt; frame[4].fY = pyt;
181  frame[5].fX = pxt; frame[5].fY = pyl;
182  frame[6].fX = pxl; frame[6].fY = pyl;
183 
184  if (bordermode == -1) gVirtualX->SetFillColor(TColor::GetColorBright(GetFillColor()));
185  else gVirtualX->SetFillColor(TColor::GetColorDark(GetFillColor()));
186  gVirtualX->DrawFillArea(7, frame);
187 
188  gVirtualX->SetFillColor(-1);
189  SetFillColor(oldcolor);
190  }
191 
192  if (!tops) return;
193 
194  // same for PostScript
195  // Double_t dx = (xt - xl) *Double_t(bordersize)/Double_t(pxt - pxl);
196  // Int_t border = gVirtualPS->XtoPS(xt) - gVirtualPS->XtoPS(xt-dx);
197 
198  gPad->PaintBorderPS(xl, yl, xt, yt, bordermode, bordersize,
199  GetDarkColor(), GetLightColor());
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// Save primitive as a C++ statement(s) on output stream out
204 
205 void TWbox::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
206 {
207  if (gROOT->ClassSaved(TWbox::Class())) {
208  out<<" ";
209  } else {
210  out<<" TWbox *";
211  }
212  out<<"wbox = new TWbox("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2<<");"<<std::endl;
213 
214  SaveFillAttributes(out,"wbox",0,1001);
215  SaveLineAttributes(out,"wbox",1,1,1);
216 
217  out<<" wbox->Draw();"<<std::endl;
218 }