Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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 <iostream>
13#include "TROOT.h"
14#include "Strlen.h"
15#include "TWbox.h"
16#include "TColor.h"
17#include "TStyle.h"
18#include "TVirtualPad.h"
19#include "TVirtualPadPainter.h"
20
21
22/** \class TWbox
23\ingroup BasicGraphics
24
25A TBox with a bordersize and a bordermode.
26Example:
27Begin_Macro(source)
28{
29 TWbox *twb = new TWbox(.1,.1,.9,.9,kRed+2,5,1);
30 twb->Draw();
31}
32End_Macro
33*/
34
35////////////////////////////////////////////////////////////////////////////////
36/// wbox normal constructor.
37///
38/// a WBOX is a box with a bordersize and a bordermode
39/// the bordersize is in pixels
40/// - bordermode = -1 box looks as it is behind the screen
41/// - bordermode = 0 no special effects
42/// - bordermode = 1 box looks as it is in front of the screen
43
45 Color_t color ,Short_t bordersize ,Short_t bordermode)
46 :TBox(x1,y1,x2,y2)
47{
48 fBorderSize = bordersize;
49 fBorderMode = bordermode;
50 SetFillColor(color);
51 SetFillStyle(1001);
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// wbox copy constructor.
56
57TWbox::TWbox(const TWbox &wbox) : TBox(wbox)
58{
59 wbox.TWbox::Copy(*this);
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// assignment operator
64
65TWbox &TWbox::operator=(const TWbox &src)
66{
67 src.TWbox::Copy(*this);
68 return *this;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Copy this wbox to wbox.
73
74void TWbox::Copy(TObject &obj) const
75{
76 TBox::Copy(obj);
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Draw this wbox with its current attributes.
83
84void TWbox::Draw(Option_t *option)
85{
86 AppendPad(option);
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Draw this wbox with new coordinates.
91
93 Color_t color ,Short_t bordersize ,Short_t bordermode)
94{
95 TWbox *newwbox = new TWbox(x1,y1,x2,y2,color,bordersize,bordermode);
96 newwbox->SetBit(kCanDelete);
97 newwbox->AppendPad();
98 return newwbox;
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Execute action corresponding to one event.
103///
104/// This member function is called when a WBOX object is clicked.
105
106void 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
115{
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Draw this wbox with new coordinates.
121
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
137 Color_t color, Short_t bordersize, Short_t bordermode,
138 Bool_t /* tops */)
139{
140 if (bordermode == 0)
141 return;
142
143 auto oldcolor = GetFillColor();
144 SetFillColor(color);
145
146 PaintBorderOn(gPad, x1, y1, x2, y2, bordersize, bordermode);
147
148 SetFillColor(oldcolor);
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Paint a 3D border around a box.
153/// Used also by the pad painter
154
156 Double_t x1, Double_t y1,Double_t x2 ,Double_t y2,
157 Short_t bordersize, Short_t bordermode, Bool_t with_selection)
158{
159 if (bordermode == 0)
160 return;
161 if (bordersize <= 0)
162 bordersize = 2;
163
164 auto pp = pad->GetPainter();
165 if (!pp)
166 return;
167
168 Double_t ww = pad->GetWw(), wh = pad->GetWh();
169
170 if (pp->GetPS()) {
171 // SL: need to calculate page size to get real coordiantes for border
172 // TODO: Code can be removed if border not need to be exact pixel size
173 Float_t xsize = 20, ysize = 26;
174 gStyle->GetPaperSize(xsize, ysize);
175 Double_t ratio = wh/ww;
176 if (xsize * ratio > ysize)
177 xsize = ysize/ratio;
178 else
179 ysize = xsize*ratio;
180 ww = 72 / 2.54 * xsize;
181 wh = 72 / 2.54 * ysize;
182 }
183
184 const Double_t realBsX = bordersize / (pad->GetAbsWNDC() * ww) * (pad->GetX2() - pad->GetX1());
185 const Double_t realBsY = bordersize / (pad->GetAbsHNDC() * wh) * (pad->GetY2() - pad->GetY1());
186
187 // GetColorDark() and GetColorBright() use GetFillColor()
188 Color_t fillcolor = GetFillColor();
189 Color_t light = !fillcolor ? 0 : GetLightColor();
190 Color_t dark = !fillcolor ? 0 : GetDarkColor();
191
192 Double_t xl, xt, yl, yt;
193
194 // Compute real left bottom & top right of the box in pixels
195 if (pad->XtoPixel(x1) < pad->XtoPixel(x2)) {
196 xl = x1;
197 xt = x2;
198 } else {
199 xl = x2;
200 xt = x1;
201 }
202 if (pad->YtoPixel(y1) > pad->YtoPixel(y2)) {
203 yl = y1;
204 yt = y2;
205 } else {
206 yl = y2;
207 yt = y1;
208 }
209
210 Double_t frameXs[7] = {}, frameYs[7] = {};
211
212 // Draw top&left part of the box
213 frameXs[0] = xl; frameYs[0] = yl;
214 frameXs[1] = xl + realBsX; frameYs[1] = yl + realBsY;
215 frameXs[2] = frameXs[1]; frameYs[2] = yt - realBsY;
216 frameXs[3] = xt - realBsX; frameYs[3] = frameYs[2];
217 frameXs[4] = xt; frameYs[4] = yt;
218 frameXs[5] = xl; frameYs[5] = yt;
219 frameXs[6] = xl; frameYs[6] = yl;
220
221 SetFillColor(bordermode == -1 ? dark : light);
222 pp->SetAttFill(*this);
223 pp->DrawFillArea(7, frameXs, frameYs);
224
225 // Draw bottom&right part of the box
226 frameXs[0] = xl; frameYs[0] = yl;
227 frameXs[1] = xl + realBsX; frameYs[1] = yl + realBsY;
228 frameXs[2] = xt - realBsX; frameYs[2] = frameYs[1];
229 frameXs[3] = frameXs[2]; frameYs[3] = yt - realBsY;
230 frameXs[4] = xt; frameYs[4] = yt;
231 frameXs[5] = xt; frameYs[5] = yl;
232 frameXs[6] = xl; frameYs[6] = yl;
233
234 SetFillColor(bordermode == -1 ? light : dark);
235 pp->SetAttFill(*this);
236 pp->DrawFillArea(7, frameXs, frameYs);
237
238 SetFillColor(fillcolor);
239
240 if (with_selection) {
241 Color_t oldlinecolor = GetLineColor();
242 SetLineColor(GetFillColor() != 2 ? 2 : 4);
243 pp->SetAttLine(*this);
244 pp->DrawBox(xl + realBsX, yl + realBsY, xt - realBsX, yt - realBsY, TVirtualPadPainter::kHollow);
245 SetLineColor(oldlinecolor);
246 }
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Save primitive as a C++ statement(s) on output stream out
251
252void TWbox::SavePrimitive(std::ostream &out, Option_t *option)
253{
254 SavePrimitiveConstructor(out, Class(), "wbox", TString::Format("%g, %g, %g, %g", fX1, fY1, fX2, fY2), kFALSE);
255
256 SaveFillAttributes(out, "wbox", -1, -1);
257 SaveLineAttributes(out, "wbox", 1, 1, 1);
258
259 SavePrimitiveDraw(out, "wbox", option);
260}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
short Short_t
Signed Short integer 2 bytes (short).
Definition RtypesCore.h:53
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
short Color_t
Color number (short).
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
externTStyle * gStyle
Definition TStyle.h:442
#define gPad
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual Bool_t IsTransparent() const
Definition TAttFill.h:49
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
Create a Box.
Definition TBox.h:22
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:540
Double_t fX1
X of 1st point.
Definition TBox.h:28
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TBox.cxx:232
Double_t fY2
Y of 2nd point.
Definition TBox.h:31
Double_t fX2
X of 2nd point.
Definition TBox.h:30
Double_t fY1
Y of 1st point.
Definition TBox.h:29
void Copy(TObject &box) const override
Copy a Box.
Definition TBox.cxx:112
Mother of all ROOT objects.
Definition TObject.h:42
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:204
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:888
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:845
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:777
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2385
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Double_t GetX2() const =0
virtual Int_t YtoPixel(Double_t y) const =0
virtual UInt_t GetWh() const =0
virtual Double_t GetY1() const =0
virtual TVirtualPadPainter * GetPainter()=0
virtual Double_t GetAbsWNDC() const =0
virtual Double_t GetAbsHNDC() const =0
virtual Double_t GetY2() const =0
virtual Int_t XtoPixel(Double_t x) const =0
virtual UInt_t GetWw() const =0
virtual Double_t GetX1() const =0
Definition TWbox.h:20
TWbox()
Definition TWbox.h:27
void Paint(Option_t *option="") override
Paint this box with its current attributes.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
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)
Int_t GetDarkColor() const
Definition TWbox.h:42
void Draw(Option_t *option="") override
Draw this box with its current attributes.
Int_t GetLightColor() const
Definition TWbox.h:43
virtual TWbox * 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)
Short_t fBorderSize
window box bordersize in pixels
Definition TWbox.h:23
TWbox & operator=(const TWbox &src)
Short_t fBorderMode
Bordermode (-1=down, 0 = no border, 1=up).
Definition TWbox.h:24
static TClass * Class()
void PaintBorderOn(TVirtualPad *pad, Double_t x1, Double_t y1, Double_t x2, Double_t y2, Short_t bordersize, Short_t bordermode, Bool_t with_selection=kFALSE)
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
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)
void Copy(TObject &wbox) const override
Copy a Box.
h1 SetFillColor(kGreen)
double ratio(double numerator, double denominator)
Definition MathFuncs.h:106
a SetFillStyle(0)