Logo ROOT   6.08/07
Reference Guide
TFrame.cxx
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Rene Brun 31/10/96
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 "TVirtualPad.h"
15 #include "TFrame.h"
16 #include "TStyle.h"
17 
19 
20 /** \class TFrame
21 \ingroup BasicGraphics
22 
23 Define a Frame.
24 
25 A `TFrame` is a `TWbox` for drawing histogram frames.
26 */
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Frame default constructor.
30 
32 {
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Frame normal constructor.
37 
39  :TWbox(x1,y1,x2,y2)
40 {
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Frame copy constructor.
45 
46 TFrame::TFrame(const TFrame &frame) : TWbox(frame)
47 {
48  ((TFrame&)frame).Copy(*this);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Frame default destructor.
53 
55 {
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Copy this frame to frame.
60 
61 void TFrame::Copy(TObject &frame) const
62 {
63  TWbox::Copy(frame);
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Draw this frame with its current attributes.
68 
69 void TFrame::Draw(Option_t *option)
70 {
71  AppendPad(option);
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Execute action corresponding to one event.
76 ///
77 /// This member function is called when a TFrame object is clicked.
78 
80 {
81  if (!gPad) return;
82 
83  if (!gPad->IsEditable()) return;
84 
85  TWbox::ExecuteEvent(event, px, py);
86 
87  Bool_t opaque = gPad->OpaqueMoving();
88 
89  if ((event == kButton1Up) || ((opaque)&&(event == kButton1Motion))) {
90  // update pad margins
91  Double_t xmin = gPad->GetUxmin();
92  Double_t xmax = gPad->GetUxmax();
93  Double_t ymin = gPad->GetUymin();
94  Double_t ymax = gPad->GetUymax();
95  Double_t dx = xmax-xmin;
96  Double_t dy = ymax-ymin;
97  Double_t leftMargin = (fX1-gPad->GetX1())/(gPad->GetX2()-gPad->GetX1());
98  Double_t topMargin = (gPad->GetY2()-fY2)/(gPad->GetY2()-gPad->GetY1());
99  Double_t rightMargin = (gPad->GetX2()-fX2)/(gPad->GetX2()-gPad->GetX1());
100  Double_t bottomMargin = (fY1-gPad->GetY1())/(gPad->GetY2()-gPad->GetY1());
101  // margin may get very small negative values
102  if (leftMargin < 0) leftMargin = 0;
103  if (topMargin < 0) topMargin = 0;
104  if (rightMargin < 0) rightMargin = 0;
105  if (bottomMargin < 0) bottomMargin = 0;
106  gPad->SetLeftMargin(leftMargin);
107  gPad->SetRightMargin(rightMargin);
108  gPad->SetBottomMargin(bottomMargin);
109  gPad->SetTopMargin(topMargin);
110  Double_t dxr = dx/(1 - gPad->GetLeftMargin() - gPad->GetRightMargin());
111  Double_t dyr = dy/(1 - gPad->GetBottomMargin() - gPad->GetTopMargin());
112 
113  // Range() could change the size of the pad pixmap and therefore should
114  // be called before the other paint routines
115  gPad->Range(xmin - dxr*gPad->GetLeftMargin(),
116  ymin - dyr*gPad->GetBottomMargin(),
117  xmax + dxr*gPad->GetRightMargin(),
118  ymax + dyr*gPad->GetTopMargin());
119  gPad->RangeAxis(xmin, ymin, xmax, ymax);
120  fX1 = xmin;
121  fY1 = ymin;
122  fX2 = xmax;
123  fY2 = ymax;
124  }
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Paint this wbox with its current attributes.
129 
130 void TFrame::Paint(Option_t *option)
131 {
132  const TPickerStackGuard stackGuard(this);
133 
134  if (!gPad->PadInHighlightMode() || (gPad->PadInHighlightMode() && this == gPad->GetSelected())) {
135  TWbox::Paint(option);
136 
137  gPad->PaintBox(fX1,fY1,fX2,fY2,"s");
138  }
139 
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Do not pop frame's, if allowed they would cover the picture they frame.
144 
146 {
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Save primitive as a C++ statement(s) on output stream out
151 
152 void TFrame::SavePrimitive(std::ostream &, Option_t * /*= ""*/)
153 {
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Replace current frame attributes by current style.
158 
160 {
161  if (gStyle->IsReading()) {
169  } else {
177  }
178 }
Style_t GetFrameLineStyle() const
Definition: TStyle.h:229
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:49
float xmin
Definition: THbookFile.cxx:93
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TWbox.cxx:115
void SetFrameBorderMode(Int_t mode=1)
Definition: TStyle.h:368
virtual void SetBorderMode(Short_t bordermode)
Definition: TWbox.h:53
const char Option_t
Definition: RtypesCore.h:62
virtual void UseCurrentStyle()
Replace current frame attributes by current style.
Definition: TFrame.cxx:159
float ymin
Definition: THbookFile.cxx:93
void Copy(TObject &wbox) const
Copy this wbox to wbox.
Definition: TWbox.cxx:84
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
Double_t fY2
Y of 2nd point.
Definition: TBox.h:45
void SetFrameLineWidth(Width_t width=1)
Definition: TStyle.h:366
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:44
Color_t GetFrameLineColor() const
Definition: TStyle.h:227
void SetFrameLineStyle(Style_t styl=0)
Definition: TStyle.h:365
Color_t GetFrameFillColor() const
Definition: TStyle.h:226
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:41
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:165
Double_t fY1
Y of 1st point.
Definition: TBox.h:43
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:40
static const double x2[5]
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:362
Short_t GetBorderSize() const
Definition: TWbox.h:43
virtual ~TFrame()
Frame default destructor.
Definition: TFrame.cxx:54
virtual void Draw(Option_t *option="")
Draw this frame with its current attributes.
Definition: TFrame.cxx:69
Int_t GetFrameBorderMode() const
Definition: TStyle.h:232
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:54
A TBox with a bordersize and a bordermode.
Definition: TWbox.h:24
Width_t GetFrameBorderSize() const
Definition: TStyle.h:231
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
float ymax
Definition: THbookFile.cxx:93
Short_t GetBorderMode() const
Definition: TWbox.h:42
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
void SetFrameLineColor(Color_t color=1)
Definition: TStyle.h:363
Double_t fX2
X of 2nd point.
Definition: TBox.h:44
Style_t GetFrameFillStyle() const
Definition: TStyle.h:228
Double_t fX1
X of 1st point.
Definition: TBox.h:42
float xmax
Definition: THbookFile.cxx:93
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TFrame.cxx:79
Define a Frame.
Definition: TFrame.h:21
void SetFrameFillStyle(Style_t styl=0)
Definition: TStyle.h:364
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:39
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:35
void Copy(TObject &frame) const
Copy this frame to frame.
Definition: TFrame.cxx:61
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t IsReading() const
Definition: TStyle.h:290
Width_t GetFrameLineWidth() const
Definition: TStyle.h:230
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TFrame.cxx:152
virtual void Paint(Option_t *option="")
Paint this wbox with its current attributes.
Definition: TFrame.cxx:130
TFrame()
Frame default constructor.
Definition: TFrame.cxx:31
#define gPad
Definition: TVirtualPad.h:289
virtual void Paint(Option_t *option="")
Paint this wbox with its current attributes.
Definition: TWbox.cxx:123
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:36
virtual void Pop()
Do not pop frame&#39;s, if allowed they would cover the picture they frame.
Definition: TFrame.cxx:145
void SetFrameBorderSize(Width_t size=1)
Definition: TStyle.h:367