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 "TVirtualPad.h"
18#include "TVirtualX.h"
19#include "TPoint.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 (!gPad) return;
141 if (bordermode == 0) return;
142 if (bordersize <= 0) bordersize = 2;
143
144 Short_t pxl,pyl,pxt,pyt,px1,py1,px2,py2;
145 Double_t xl, xt, yl, yt;
146
147 // Compute real left bottom & top right of the box in pixels
148 px1 = gPad->XtoPixel(x1); py1 = gPad->YtoPixel(y1);
149 px2 = gPad->XtoPixel(x2); py2 = gPad->YtoPixel(y2);
150 if (px1 < px2) {pxl = px1; pxt = px2; xl = x1; xt = x2; }
151 else {pxl = px2; pxt = px1; xl = x2; xt = x1;}
152 if (py1 > py2) {pyl = py1; pyt = py2; yl = y1; yt = y2;}
153 else {pyl = py2; pyt = py1; yl = y2; yt = y1;}
154
155 if (!gPad->IsBatch()) {
156 TPoint frame[7];
157
158 // GetDarkColor() and GetLightColor() use GetFillColor()
160 SetFillColor(color);
162
163 // Draw top&left part of the box
164 frame[0].fX = pxl; frame[0].fY = pyl;
165 frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
166 frame[2].fX = frame[1].fX; frame[2].fY = pyt + bordersize;
167 frame[3].fX = pxt - bordersize; frame[3].fY = frame[2].fY;
168 frame[4].fX = pxt; frame[4].fY = pyt;
169 frame[5].fX = pxl; frame[5].fY = pyt;
170 frame[6].fX = pxl; frame[6].fY = pyl;
171
172 if (bordermode == -1) gVirtualX->SetFillColor(GetDarkColor());
173 else gVirtualX->SetFillColor(GetLightColor());
174 gVirtualX->DrawFillArea(7, frame);
175
176 // Draw bottom&right part of the box
177 frame[0].fX = pxl; frame[0].fY = pyl;
178 frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
179 frame[2].fX = pxt - bordersize; frame[2].fY = frame[1].fY;
180 frame[3].fX = frame[2].fX; frame[3].fY = pyt + bordersize;
181 frame[4].fX = pxt; frame[4].fY = pyt;
182 frame[5].fX = pxt; frame[5].fY = pyl;
183 frame[6].fX = pxl; frame[6].fY = pyl;
184
185 if (bordermode == -1) gVirtualX->SetFillColor(TColor::GetColorBright(GetFillColor()));
186 else gVirtualX->SetFillColor(TColor::GetColorDark(GetFillColor()));
187 gVirtualX->DrawFillArea(7, frame);
188
189 gVirtualX->SetFillColor(-1);
191 }
192
193 if (!tops) return;
194
195 // same for PostScript
196 // Double_t dx = (xt - xl) *Double_t(bordersize)/Double_t(pxt - pxl);
197 // Int_t border = gVirtualPS->XtoPS(xt) - gVirtualPS->XtoPS(xt-dx);
198
199 gPad->PaintBorderPS(xl, yl, xt, yt, bordermode, bordersize,
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Save primitive as a C++ statement(s) on output stream out
205
206void TWbox::SavePrimitive(std::ostream &out, Option_t *option)
207{
208 SavePrimitiveConstructor(out, Class(), "wbox", TString::Format("%g, %g, %g, %g", fX1, fY1, fX2, fY2), kFALSE);
209
210 SaveFillAttributes(out, "wbox", 0, 1001);
211 SaveLineAttributes(out, "wbox", 1, 1, 1);
212
213 SavePrimitiveDraw(out, "wbox", option);
214}
short Color_t
Color number (short)
Definition RtypesCore.h:99
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 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
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:31
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:215
virtual Bool_t IsTransparent() const
Definition TAttFill.h:47
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:238
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:274
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:677
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:231
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:111
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:2095
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:2138
Mother of all ROOT objects.
Definition TObject.h:41
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
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:822
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:771
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
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
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:206
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 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