Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
18 ClassImp(TFrame);
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 
31 TFrame::TFrame(): TWbox()
32 {
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Frame normal constructor.
37 
38 TFrame::TFrame(Double_t x1, Double_t y1,Double_t x2, Double_t y2)
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 
54 TFrame::~TFrame()
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 
79 void TFrame::ExecuteEvent(Int_t event, Int_t px, Int_t py)
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 
145 void TFrame::Pop()
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 
159 void TFrame::UseCurrentStyle()
160 {
161  if (gStyle->IsReading()) {
162  SetFillColor(gStyle->GetFrameFillColor());
163  SetLineColor(gStyle->GetFrameLineColor());
164  SetFillStyle(gStyle->GetFrameFillStyle());
165  SetLineStyle(gStyle->GetFrameLineStyle());
166  SetLineWidth(gStyle->GetFrameLineWidth());
167  SetBorderSize(gStyle->GetFrameBorderSize());
168  SetBorderMode(gStyle->GetFrameBorderMode());
169  } else {
170  gStyle->SetFrameFillColor(GetFillColor());
171  gStyle->SetFrameLineColor(GetLineColor());
172  gStyle->SetFrameFillStyle(GetFillStyle());
173  gStyle->SetFrameLineStyle(GetLineStyle());
174  gStyle->SetFrameLineWidth(GetLineWidth());
175  gStyle->SetFrameBorderSize(GetBorderSize());
176  gStyle->SetFrameBorderMode(GetBorderMode());
177  }
178 }