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
53
54////////////////////////////////////////////////////////////////////////////////
55/// wbox copy constructor.
56
58{
59 wbox.TWbox::Copy(*this);
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// assignment operator
64
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);
77 ((TWbox&)obj).fBorderSize = fBorderSize;
78 ((TWbox&)obj).fBorderMode = fBorderMode;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Draw this wbox with its current attributes.
83
88
89////////////////////////////////////////////////////////////////////////////////
90/// Draw this wbox with new coordinates.
91
100
101////////////////////////////////////////////////////////////////////////////////
102/// Execute action corresponding to one event.
103///
104/// This member function is called when a WBOX object is clicked.
105
107{
108 TBox::ExecuteEvent(event, px, py);
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Paint this wbox with its current attributes.
113
118
119////////////////////////////////////////////////////////////////////////////////
120/// Draw this wbox with new coordinates.
121
124{
125 // Draw first wbox as a normal filled box
127
128 // then paint 3d frame (depending on bordermode)
129 if (!IsTransparent())
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Paint a 3D frame around a box.
135
138 Bool_t /* tops */)
139{
140 if (bordermode == 0)
141 return;
142
143 auto oldcolor = GetFillColor();
144 SetFillColor(color);
145
147
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Paint a 3D border around a box.
153/// Used also by the pad painter
154
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;
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()
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
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
235 pp->SetAttFill(*this);
236 pp->DrawFillArea(7, frameXs, frameYs);
237
239
240 if (with_selection) {
242 SetLineColor(GetFillColor() != 2 ? 2 : 4);
243 pp->SetAttLine(*this);
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}
short Color_t
Color number (short)
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t SetFillStyle
Option_t Option_t SetLineColor
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t SetFillColor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char y1
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
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)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:243
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)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:289
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:635
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:201
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:842
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:774
@ 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:2384
void GetPaperSize(Float_t &xsize, Float_t &ysize) const
Set paper size for PostScript output.
Definition TStyle.cxx:1184
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
A TBox with a bordersize and a bordermode.
Definition TWbox.h:20
TWbox()
Definition TWbox.h:27
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:136
void Paint(Option_t *option="") override
Paint this wbox with its current attributes.
Definition TWbox.cxx:114
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TWbox.cxx:252
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:122
Int_t GetDarkColor() const
Definition TWbox.h:42
void Draw(Option_t *option="") override
Draw this wbox with its current attributes.
Definition TWbox.cxx:84
Int_t GetLightColor() const
Definition TWbox.h:43
Short_t fBorderSize
window box bordersize in pixels
Definition TWbox.h:23
TWbox & operator=(const TWbox &src)
assignment operator
Definition TWbox.cxx:65
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)
Paint a 3D border around a box.
Definition TWbox.cxx:155
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TWbox.cxx:106
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)
Draw this wbox with new coordinates.
Definition TWbox.cxx:92
void Copy(TObject &wbox) const override
Copy this wbox to wbox.
Definition TWbox.cxx:74