Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPad.cxx
Go to the documentation of this file.
1// @(#)root/gpad:$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 <cstring>
13#include <cstdlib>
14#include <iostream>
15#include <locale>
16#include <memory>
17#include <cmath>
18
19#include "TROOT.h"
20#include "TBuffer.h"
21#include "TBoxInteractive.h"
22#include "TError.h"
23#include "TMath.h"
24#include "TSystem.h"
25#include "TStyle.h"
26#include "TFile.h"
27#include "TH1.h"
28#include "TH2.h"
29#include "TH3.h"
30#include "TClass.h"
31#include "TBaseClass.h"
32#include "TClassTable.h"
33#include "TVirtualPS.h"
34#include "TVirtualViewer3D.h"
35#include "TView.h"
36#include "TPoint.h"
37#include "TGraph.h"
38#include "TMultiGraph.h"
39#include "THStack.h"
40#include "TPaveText.h"
41#include "TPaveStats.h"
42#include "TGroupButton.h"
43#include "TBrowser.h"
44#include "TVirtualGL.h"
45#include "TString.h"
46#include "TDataMember.h"
47#include "TMethod.h"
48#include "TDataType.h"
49#include "TFrame.h"
50#include "TWbox.h"
51#include "TExec.h"
52#include "TDatime.h"
53#include "TColor.h"
54#include "TCanvas.h"
55#include "TCanvasImp.h"
56#include "TPluginManager.h"
57#include "TEnv.h"
58#include "TImage.h"
59#include "TViewer3DPad.h"
60#include "TCreatePrimitives.h"
61#include "TLegend.h"
62#include "TAtt3D.h"
63#include "TVirtualPadPainter.h"
64#include "strlcpy.h"
65
66#include "TVirtualMutex.h"
67
68#include <cstdio>
69
70static Int_t gReadLevel = 0;
71
73
74/** \class TPad
75\ingroup gpad
76
77The most important graphics class in the ROOT system.
78
79A Pad is contained in a Canvas.
80
81A Pad may contain other pads (unlimited pad hierarchy).
82
83A pad is a linked list of primitives of any type (graphics objects,
84histograms, detectors, tracks, etc.).
85
86Adding a new element into a pad is in general performed by the Draw
87member function of the object classes.
88
89It is important to realize that the pad is a linked list of references
90to the original object.
91For example, in case of a histogram, the histogram.Draw() operation
92only stores a reference to the histogram object and not a graphical
93representation of this histogram.
94When the mouse is used to change (say the bin content), the bin content
95of the original histogram is changed.
96
97The convention used in ROOT is that a Draw operation only adds
98a reference to the object. The effective drawing is performed
99when the canvas receives a signal to be painted.
100
101\image html gpad_pad1.png
102
103This signal is generally sent when typing carriage return in the
104command input or when a graphical operation has been performed on one
105of the pads of this canvas.
106When a Canvas/Pad is repainted, the member function Paint for all
107objects in the Pad linked list is invoked.
108
109\image html gpad_pad2.png
110
111When the mouse is moved on the Pad, The member function DistancetoPrimitive
112is called for all the elements in the pad. DistancetoPrimitive returns
113the distance in pixels to this object.
114
115When the object is within the distance window, the member function
116ExecuteEvent is called for this object.
117
118In ExecuteEvent, move, changes can be performed on the object.
119
120For examples of DistancetoPrimitive and ExecuteEvent functions,
121see classes
122~~~ {.cpp}
123 TLine::DistancetoPrimitive, TLine::ExecuteEvent
124 TBox::DistancetoPrimitive, TBox::ExecuteEvent
125 TH1::DistancetoPrimitive, TH1::ExecuteEvent
126~~~
127A Pad supports linear and log scales coordinate systems.
128The transformation coefficients are explained in TPad::ResizePad.
129*/
130
132
133 public:
135
136 template<typename T>
137 TPadDrawOperation(Int_t n, T *x, T *y, EKind kind, Int_t arg = 1, Bool_t ndc = kFALSE)
138 {
139 fX.assign(x, x + n);
140 fY.assign(y, y + n);
141 fKind = kind;
142 fArg = arg; // operation arg like line width
143 fNDC = ndc;
144 }
145 virtual ~TPadDrawOperation() = default;
146
147 void Draw(TPad &pad, TVirtualPadPainter *pp, Bool_t withXor)
148 {
149 auto doFill = [pp, withXor](Int_t n, Double_t *xx, Double_t *yy) {
150 Color_t col = kBlack;
151 if (!withXor)
152 col = TColor::GetColor(0, 0, 0, 0.25);
153 pp->SetAttFill({col, 1001});
154 pp->DrawFillArea(n, xx, yy);
155 };
156
157 if (fKind == drawFill)
158 doFill(fX.size(), fX.data(), fY.data());
159 else if (fKind == drawLine) {
160 pp->SetAttLine({kBlack, 1, (Width_t)fArg});
161 if (fNDC)
162 pp->DrawPolyLineNDC(fX.size(), fX.data(), fY.data());
163 else
164 pp->DrawPolyLine(fX.size(), fX.data(), fY.data());
165 } else {
166 Double_t dx = (pad.GetX2() - pad.GetX1()) / pad.GetPadWidth() * 5;
167 Double_t dy = (pad.GetY2() - pad.GetY1()) / pad.GetPadHeight() * 5;
168
169 for (std::size_t i = 0; i < fX.size(); ++i) {
170 Double_t mx = fX[i], my = fY[i];
171 if (!fArg) {
172 // fill diamond
173 Double_t xc[5] = { mx, mx + dx, mx, mx - dx, mx };
174 Double_t yc[5] = { my - dy, my, my + dy, my, my - dy };
175 doFill(5, xc, yc);
176 } else {
177 // rectangle
178 pp->SetAttLine({kBlack, 1, (Width_t)fArg});
179 Double_t xl[5] = { mx - dx, mx + dx, mx + dx, mx - dx, mx - dx };
180 Double_t yl[5] = { my - dy, my - dy, my + dy, my + dy, my - dy };
181 pp->DrawPolyLine(5, xl, yl);
182 }
183 }
184 }
185 }
186
187 protected:
188 std::vector<Double_t> fX, fY;
192};
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Pad default constructor.
197
199{
201 fTip = nullptr;
202 fPadPointer = nullptr;
203 fPrimitives = nullptr;
204 fExecs = nullptr;
205 fCanvas = nullptr;
206 fPadPaint = 0;
207 fPixmapID = -1;
208 fGLDevice = -1;
211 fTheta = 30;
212 fPhi = 30;
213 fNumber = 0;
216 fCrosshair = 0;
217 fCrosshairPos = 0;
218 fPadView3D = nullptr;
219 fMother = (TPad*)gPad;
220
221 fAbsHNDC = 0.;
222 fAbsPixeltoXk = 0.;
223 fAbsPixeltoYk = 0.;
224 fAbsWNDC = 0.;
225 fAbsXlowNDC = 0.;
226 fAbsYlowNDC = 0.;
227 fBorderMode = 0;
228 fBorderSize = 0;
229 fPixeltoX = 0;
230 fPixeltoXk = 0.;
231 fPixeltoY = 0.;
232 fPixeltoYk = 0.;
233 fUtoAbsPixelk = 0.;
234 fUtoPixel = 0.;
235 fUtoPixelk = 0.;
236 fVtoAbsPixelk = 0.;
237 fVtoPixel = 0.;
238 fVtoPixelk = 0.;
239 fXtoAbsPixelk = 0.;
240 fXtoPixel = 0.;
241 fXtoPixelk = 0.;
242 fYtoAbsPixelk = 0.;
243 fYtoPixel = 0.;
244 fYtoPixelk = 0.;
245 fXUpNDC = 0.;
246 fYUpNDC = 0.;
247
249 fAspectRatio = 0.;
250
253 fCGnx = 0;
254 fCGny = 0;
255
256 fLogx = 0;
257 fLogy = 0;
258 fLogz = 0;
259 fGridx = false;
260 fGridy = false;
261 fTickx = 0;
262 fTicky = 0;
263 fFrame = nullptr;
264 fView = nullptr;
265
266 fUxmin = fUymin = fUxmax = fUymax = 0;
267
268 // Set default world coordinates to NDC [0,1]
269 fX1 = 0;
270 fX2 = 1;
271 fY1 = 0;
272 fY2 = 1;
273
274 // Set default pad range
275 fXlowNDC = 0;
276 fYlowNDC = 0;
277 fWNDC = 1;
278 fHNDC = 1;
279
280 fViewer3D = nullptr;
282
283 // the following line is temporarily disabled. It has side effects
284 // when the pad is a TDrawPanelHist or a TFitPanel.
285 // the line was supposed to fix a problem with DrawClonePad
286 // gROOT->SetSelectedPad(this);
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Pad constructor.
291///
292/// A pad is a linked list of primitives.
293/// A pad is contained in a canvas. It may contain other pads.
294/// A pad has attributes. When a pad is created, the attributes
295/// defined in the current style are copied to the pad attributes.
296///
297/// \param[in] name pad name
298/// \param[in] title pad title
299/// \param[in] xlow [0,1] is the position of the bottom left point of the pad
300/// expressed in the mother pad reference system
301/// \param[in] ylow [0,1] is the Y position of this point.
302/// \param[in] xup [0,1] is the x position of the top right point of the pad
303/// expressed in the mother pad reference system
304/// \param[in] yup [0,1] is the Y position of this point.
305/// \param[in] color pad color
306/// \param[in] bordersize border size in pixels
307/// \param[in] bordermode border mode
308/// - bordermode = -1 box looks as it is behind the screen
309/// - bordermode = 0 no special effects
310/// - bordermode = 1 box looks as it is in front of the screen
311
312TPad::TPad(const char *name, const char *title, Double_t xlow,
313 Double_t ylow, Double_t xup, Double_t yup,
314 Color_t color, Short_t bordersize, Short_t bordermode)
315 : TVirtualPad(name,title,xlow,ylow,xup,yup,color,bordersize,bordermode)
316{
318 fTip = nullptr;
319 fBorderSize = bordersize;
320 fBorderMode = bordermode;
321 if (gPad) fCanvas = gPad->GetCanvas();
322 else fCanvas = (TCanvas*)this;
323 fMother = (TPad*)gPad;
324 fPrimitives = new TList;
325 fExecs = new TList;
326 fPadPointer = nullptr;
327 fTheta = 30;
328 fPhi = 30;
333 fFrame = nullptr;
334 fView = nullptr;
335 fPadPaint = 0;
336 fPadView3D = nullptr;
337 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
340 fNumber = 0;
343 fCrosshair = 0;
344 fCrosshairPos = 0;
345
346 fVtoAbsPixelk = 0.;
347 fVtoPixelk = 0.;
348 fVtoPixel = 0.;
349 fAbsPixeltoXk = 0.;
350 fPixeltoXk = 0.;
351 fPixeltoX = 0;
352 fAbsPixeltoYk = 0.;
353 fPixeltoYk = 0.;
354 fPixeltoY = 0.;
355 fXlowNDC = 0;
356 fYlowNDC = 0;
357 fWNDC = 1;
358 fHNDC = 1;
359 fXUpNDC = 0.;
360 fYUpNDC = 0.;
361 fAbsXlowNDC = 0.;
362 fAbsYlowNDC = 0.;
363 fAbsWNDC = 0.;
364 fAbsHNDC = 0.;
365 fXtoAbsPixelk = 0.;
366 fXtoPixelk = 0.;
367 fXtoPixel = 0.;
368 fYtoAbsPixelk = 0.;
369 fYtoPixelk = 0.;
370 fYtoPixel = 0.;
371 fUtoAbsPixelk = 0.;
372 fUtoPixelk = 0.;
373 fUtoPixel = 0.;
374
375 fUxmin = fUymin = fUxmax = fUymax = 0;
379
381 fAspectRatio = 0.;
382
385 fCGnx = 0;
386 fCGny = 0;
387
388 fViewer3D = nullptr;
389
391 // Set default world coordinates to NDC [0,1]
392 fX1 = 0;
393 fX2 = 1;
394 fY1 = 0;
395 fY2 = 1;
396
397 if (!gPad) {
398 Error("TPad", "You must create a TCanvas before creating a TPad");
399 MakeZombie();
400 return;
401 }
402
403 TContext ctxt(kTRUE);
404
405 Bool_t zombie = kFALSE;
406
407 if ((xlow < 0) || (xlow > 1) || (ylow < 0) || (ylow > 1)) {
408 Error("TPad", "illegal bottom left position: x=%f, y=%f", xlow, ylow);
409 zombie = kTRUE;
410 } else if ((xup < 0) || (xup > 1) || (yup < 0) || (yup > 1)) {
411 Error("TPad", "illegal top right position: x=%f, y=%f", xup, yup);
412 zombie = kTRUE;
413 } else if (xup-xlow <= 0) {
414 Error("TPad", "illegal width: %f", xup-xlow);
415 zombie = kTRUE;
416 } else if (yup-ylow <= 0) {
417 Error("TPad", "illegal height: %f", yup-ylow);
418 zombie = kTRUE;
419 }
420
421 if (zombie) {
422 // error in creating pad occurred, make this pad a zombie
423 MakeZombie();
424 return;
425 }
426
427
431
432 fUxmin = fUymin = fUxmax = fUymax = 0;
433
434 // Set pad parameters and Compute conversion coefficients
435 SetPad(name, title, xlow, ylow, xup, yup, color, bordersize, bordermode);
436 Range(0, 0, 1, 1);
439}
440
441
442////////////////////////////////////////////////////////////////////////////////
443/// Pad destructor.
444
446{
447 if (ROOT::Detail::HasBeenDeleted(this)) return;
448 Close();
451 auto primitives = fPrimitives;
452 // In some cases, fPrimitives has the kMustCleanup bit set which will lead
453 // its destructor to call RecursiveRemove and since this pad is still
454 // likely to be (indirectly) in the list of cleanups, we must set
455 // fPrimitives to nullptr to avoid TPad::RecursiveRemove from calling
456 // a member function of a partially destructed object.
457 fPrimitives = nullptr;
458 delete primitives;
460 delete fViewer3D;
461
462 // Required since we overload TObject::Hash.
464 if (this == gPad)
465 gPad = nullptr;
466}
467
468////////////////////////////////////////////////////////////////////////////////
469/// Add an object to list of primitives with specified draw option
470/// When \par modified set to kTRUE (default) pad will be marked as modified
471/// Let avoid usage of gPad when drawing object(s) in canvas or in subpads.
472///
473/// ~~~{.cpp}
474/// auto c1 = new TCanvas("c1","Canvas with subpads", 600, 600);
475/// c1->Divide(2,2);
476///
477/// for (Int_t n = 1; n <= 4; ++n) {
478/// auto h1 = new TH1I(TString::Format("hist_%d",n), "Random hist", 100, -5, 5);
479/// h1->FillRandom("gaus", 2000 + n*1000);
480/// c1->GetPad(n)->Add(h1);
481/// }
482/// ~~~
483
484void TPad::Add(TObject *obj, Option_t *opt, Bool_t modified)
485{
486 if (!obj)
487 return;
488
489 if (!fPrimitives)
490 fPrimitives = new TList;
491
492 obj->SetBit(kMustCleanup);
493
494 fPrimitives->Add(obj, opt);
495
496 if (modified)
497 Modified();
498}
499
500////////////////////////////////////////////////////////////////////////////////
501/// Add an object as first in list of primitives with specified draw option
502/// When \par modified set to kTRUE (default) pad will be marked as modified
503/// Let avoid usage of gPad when drawing object(s) in canvas or in subpads.
504
505void TPad::AddFirst(TObject *obj, Option_t *opt, Bool_t modified)
506{
507 if (!obj)
508 return;
509
510 if (!fPrimitives)
511 fPrimitives = new TList;
512
513 obj->SetBit(kMustCleanup);
514
515 fPrimitives->AddFirst(obj, opt);
516
517 if (modified)
518 Modified();
519}
520
521////////////////////////////////////////////////////////////////////////////////
522/// Add a new TExec object to the list of Execs.
523///
524/// When an event occurs in the pad (mouse click, etc) the list of C++ commands
525/// in the list of Execs are executed via TPad::AutoExec.
526///
527/// When a pad event occurs (mouse move, click, etc) all the commands
528/// contained in the fExecs list are executed in the order found in the list.
529///
530/// This facility is activated by default. It can be deactivated by using
531/// the canvas "Option" menu.
532///
533/// The following examples of TExec commands are provided in the tutorials:
534/// macros exec1.C and exec2.C.
535///
536/// ### Example1 of use of exec1.C
537///
538/// ~~~ {.cpp}
539/// Root > TFile f("hsimple.root")
540/// Root > hpx.Draw()
541/// Root > c1.AddExec("ex1",".x exec1.C")
542/// ~~~
543///
544/// At this point you can use the mouse to click on the contour of
545/// the histogram hpx. When the mouse is clicked, the bin number and its
546/// contents are printed.
547///
548/// ### Example2 of use of exec1.C
549///
550/// ~~~ {.cpp}
551/// Root > TFile f("hsimple.root")
552/// Root > hpxpy.Draw()
553/// Root > c1.AddExec("ex2",".x exec2.C")
554/// ~~~
555///
556/// When moving the mouse in the canvas, a second canvas shows the
557/// projection along X of the bin corresponding to the Y position
558/// of the mouse. The resulting histogram is fitted with a gaussian.
559/// A "dynamic" line shows the current bin position in Y.
560/// This more elaborated example can be used as a starting point
561/// to develop more powerful interactive applications exploiting the C++
562/// interpreter as a development engine.
563
564void TPad::AddExec(const char *name, const char *command)
565{
566 if (!fExecs) fExecs = new TList;
567 TExec *ex = new TExec(name,command);
568 fExecs->Add(ex);
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Execute the list of Execs when a pad event occurs.
573
575{
576 TIter next(fExecs);
577 while (auto exec = static_cast<TExec *>(next()))
578 exec->Exec();
579
580 if (GetCrosshair())
582}
583
584////////////////////////////////////////////////////////////////////////////////
585/// Browse pad.
586
588{
589 cd();
591}
592
593////////////////////////////////////////////////////////////////////////////////
594/// Build a legend from the graphical objects in the pad.
595///
596/// A simple method to build automatically a TLegend from the primitives in a TPad.
597///
598/// Only those deriving from TAttLine, TAttMarker and TAttFill are added, excluding
599/// TPave and TFrame derived classes.
600///
601/// \return The built TLegend
602///
603/// \param[in] x1, y1, x2, y2 The TLegend coordinates
604/// \param[in] title The legend title. By default it is " "
605/// \param[in] option The TLegend option
606///
607/// The caller program owns the returned TLegend.
608///
609/// If the pad contains some TMultiGraph or THStack the individual
610/// graphs or histograms in them are added to the TLegend.
611///
612/// ### Automatic placement of the legend
613/// If `x1` is equal to `x2` and `y1` is equal to `y2` the legend will be automatically
614/// placed to avoid overlapping with the existing primitives already displayed.
615/// `x1` is considered as the width of the legend and `y1` the height. By default
616/// the legend is automatically placed with width = `x1`= `x2` = 0.3 and
617/// height = `y1`= `y2` = 0.21.
618
620 const char* title, Option_t *option)
621{
622 TList *lop = GetListOfPrimitives();
623 if (!lop) return nullptr;
624 TList *lof = nullptr;
625 TLegend *leg = nullptr;
626 TObject *obj = nullptr;
627 TIter next(lop);
628 TString mes;
629 TString opt;
630
631 auto AddEntryFromListOfFunctions = [&]() {
632 TIter nextobj(lof);
633 while ((obj = nextobj())) {
634 if (obj->InheritsFrom(TNamed::Class())) {
635 if (strlen(obj->GetTitle()))
636 mes = obj->GetTitle();
637 else
638 mes = obj->GetName();
639 } else {
640 mes = obj->ClassName();
641 }
642 leg->AddEntry(obj, mes.Data(), "lpf");
643 }
644 };
645
646 while(auto o = next()) {
647 if ((o->InheritsFrom(TAttLine::Class()) || o->InheritsFrom(TAttMarker::Class()) ||
648 o->InheritsFrom(TAttFill::Class())) &&
649 ( !(o->InheritsFrom(TFrame::Class())) && !(o->InheritsFrom(TPave::Class())) )) {
650 if (!leg)
651 leg = new TLegend(x1, y1, x2, y2, title);
652 if (o->InheritsFrom(TNamed::Class()) && strlen(o->GetTitle()))
653 mes = o->GetTitle();
654 else if (strlen(o->GetName()))
655 mes = o->GetName();
656 else
657 mes = o->ClassName();
658 if (option && strlen(option)) {
659 opt = option;
660 } else {
661 if (o->InheritsFrom(TAttLine::Class()))
662 opt += "l";
663 if (o->InheritsFrom(TAttMarker::Class()))
664 opt += "p";
665 if (o->InheritsFrom(TAttFill::Class()))
666 opt += "f";
667 }
668 leg->AddEntry(o,mes.Data(), opt.Data());
669 if (o->InheritsFrom(TH1::Class())) {
670 lof = ((TH1 *)o)->GetListOfFunctions();
671 AddEntryFromListOfFunctions();
672 }
673 if (o->InheritsFrom(TGraph::Class())) {
674 lof = ((TGraph *)o)->GetListOfFunctions();
675 AddEntryFromListOfFunctions();
676 }
677 } else if (o->InheritsFrom(TMultiGraph::Class())) {
678 if (!leg)
679 leg = new TLegend(x1, y1, x2, y2, title);
680 TList * grlist = ((TMultiGraph *)o)->GetListOfGraphs();
681 TIter nextgraph(grlist);
682 TGraph *gr = nullptr;
683 while ((obj = nextgraph())) {
684 gr = (TGraph*) obj;
685 if (strlen(gr->GetTitle()))
686 mes = gr->GetTitle();
687 else if (strlen(gr->GetName()))
688 mes = gr->GetName();
689 else
690 mes = gr->ClassName();
691 if (option && strlen(option))
692 opt = option;
693 else
694 opt = "lpf";
695 leg->AddEntry(obj, mes.Data(), opt);
696 }
697 lof = ((TMultiGraph *)o)->GetListOfFunctions();
698 AddEntryFromListOfFunctions();
699 } else if (o->InheritsFrom(THStack::Class())) {
700 if (!leg)
701 leg = new TLegend(x1, y1, x2, y2, title);
702 TList * hlist = ((THStack *)o)->GetHists();
703 TIter nexthist(hlist);
704 while ((obj = nexthist())) {
705 TH1 *hist = (TH1*) obj;
706 if (strlen(hist->GetTitle()))
707 mes = hist->GetTitle();
708 else if (strlen(hist->GetName()))
709 mes = hist->GetName();
710 else
711 mes = hist->ClassName();
712 if (option && strlen(option))
713 opt = option;
714 else
715 opt = "lpf";
716 leg->AddEntry( obj, mes.Data(), opt );
717 }
718 }
719 opt = "";
720 }
721 if (leg) {
722 TContext ctxt(this, kTRUE);
723 leg->Draw();
724 } else {
725 Info("BuildLegend", "No object(s) to build a TLegend.");
726 }
727 return leg;
728}
729
730////////////////////////////////////////////////////////////////////////////////
731/// Set Current pad.
732///
733/// When a canvas/pad is divided via TPad::Divide, one can directly
734/// set the current path to one of the subdivisions.
735/// See TPad::Divide for the convention to number sub-pads.
736///
737/// Returns the new current pad, or 0 in case of failure.
738///
739/// For example:
740/// ~~~ {.cpp}
741/// c1.Divide(2,3); // create 6 pads (2 divisions along x, 3 along y).
742/// ~~~
743/// To set the current pad to the bottom right pad, do
744/// ~~~ {.cpp}
745/// c1.cd(6);
746/// ~~~
747/// Note1: c1.cd() is equivalent to c1.cd(0) and sets the current pad
748/// to c1 itself.
749///
750/// Note2: after a statement like c1.cd(6), the global variable gPad
751/// points to the current pad. One can use gPad to set attributes
752/// of the current pad.
753///
754/// Note3: One can get a pointer to one of the sub-pads of pad with:
755/// TPad *subpad = (TPad*)pad->GetPad(subpadnumber);
756
758{
759 if (!subpadnumber) {
760 gPad = this;
761 if (!gPad->IsBatch() && GetPainter()) GetPainter()->SelectDrawable(fPixmapID);
762 if (!fPrimitives) fPrimitives = new TList;
763 return gPad;
764 }
765
766 if (!fPrimitives) fPrimitives = new TList;
767 TIter next(fPrimitives);
768 while (auto obj = next()) {
769 if (obj->InheritsFrom(TPad::Class())) {
770 Int_t n = ((TPad*)obj)->GetNumber();
771 if (n == subpadnumber) {
772 return ((TPad*)obj)->cd();
773 }
774 }
775 }
776 return nullptr;
777}
778
779////////////////////////////////////////////////////////////////////////////////
780/// Delete all pad primitives.
781///
782/// If the bit kClearAfterCR has been set for this pad, the Clear function
783/// will execute only after having pressed a CarriageReturn
784/// Set the bit with `mypad->SetBit(TPad::kClearAfterCR)`
785
787{
788 if (!IsEditable()) return;
789
791
792 if (!fPadPaint) {
795 if (fFrame) {
797 fFrame = nullptr;
798 }
799 }
800 if (fCanvas) fCanvas->Cleared(this);
801
802 cd();
803
804 if (TestBit(kClearAfterCR)) {
805 // Intentional do not use the return value of getchar,
806 // we just want to get it and forget it
807 getchar();
808 }
809
810 auto pp = GetPainter();
811 // If pad painter uses PS, TPad::Clear() start new page
812 if (pp && pp->GetPS())
813 pp->NewPage();
814
816 fCrosshairPos = 0;
818 fCollideGrid.clear();
819 fCGnx = 0;
820 fCGny = 0;
822}
823
824////////////////////////////////////////////////////////////////////////////////
825/// Clipping routine: Cohen Sutherland algorithm.
826///
827/// - If Clip ==2 the segment is outside the boundary.
828/// - If Clip ==1 the segment has one point outside the boundary.
829/// - If Clip ==0 the segment is inside the boundary.
830///
831/// \param[inout] x[],y[] Segment coordinates (2 points)
832/// \param[in] xclipl,yclipb,xclipr,yclipt Clipping boundary
833
834Int_t TPad::Clip(Float_t *x, Float_t *y, Float_t xclipl, Float_t yclipb, Float_t xclipr, Float_t yclipt)
835{
836 const Float_t kP=10000;
837 Int_t clip = 0;
838
839 for (Int_t i=0;i<2;i++) {
840 if (TMath::Abs(xclipl-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipl;
841 if (TMath::Abs(xclipr-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipr;
842 if (TMath::Abs(yclipb-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipb;
843 if (TMath::Abs(yclipt-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipt;
844 }
845
846 // Compute the first endpoint codes.
847 Int_t code1 = ClippingCode(x[0],y[0],xclipl,yclipb,xclipr,yclipt);
848 Int_t code2 = ClippingCode(x[1],y[1],xclipl,yclipb,xclipr,yclipt);
849
850 Double_t xt=0, yt=0;
851 Int_t clipped = 0; //this variable could be used in a future version
852 while(code1 + code2) {
853 clipped = 1;
854
855 // The line lies entirely outside the clipping boundary
856 if (code1&code2) {
857 clip = 2;
858 return clip;
859 }
860
861 // The line is subdivided into several parts
862 Int_t ic = code1;
863 if (ic == 0) ic = code2;
864 if (ic & 0x1) {
865 yt = y[0] + (y[1]-y[0])*(xclipl-x[0])/(x[1]-x[0]);
866 xt = xclipl;
867 }
868 if (ic & 0x2) {
869 yt = y[0] + (y[1]-y[0])*(xclipr-x[0])/(x[1]-x[0]);
870 xt = xclipr;
871 }
872 if (ic & 0x4) {
873 xt = x[0] + (x[1]-x[0])*(yclipb-y[0])/(y[1]-y[0]);
874 yt = yclipb;
875 }
876 if (ic & 0x8) {
877 xt = x[0] + (x[1]-x[0])*(yclipt-y[0])/(y[1]-y[0]);
878 yt = yclipt;
879 }
880 if (ic == code1) {
881 x[0] = xt;
882 y[0] = yt;
883 code1 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
884 } else {
885 x[1] = xt;
886 y[1] = yt;
887 code2 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
888 }
889 }
890 clip = clipped;
891 return clip;
892}
893
894/// @copydoc TPad::Clip(Float_t*,Float_t*,Float_t,Float_t,Float_t,Float_t)
895
897{
898 const Double_t kP = 10000;
899 Int_t clip = 0;
900
901 for (Int_t i=0;i<2;i++) {
902 if (TMath::Abs(xclipl-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipl;
903 if (TMath::Abs(xclipr-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipr;
904 if (TMath::Abs(yclipb-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipb;
905 if (TMath::Abs(yclipt-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipt;
906 }
907
908 // Compute the first endpoint codes.
909 Int_t code1 = 0;
910 if (x[0] < xclipl) code1 = code1 | 0x1;
911 if (x[0] > xclipr) code1 = code1 | 0x2;
912 if (y[0] < yclipb) code1 = code1 | 0x4;
913 if (y[0] > yclipt) code1 = code1 | 0x8;
914 Int_t code2 = 0;
915 if (x[1] < xclipl) code2 = code2 | 0x1;
916 if (x[1] > xclipr) code2 = code2 | 0x2;
917 if (y[1] < yclipb) code2 = code2 | 0x4;
918 if (y[1] > yclipt) code2 = code2 | 0x8;
919
920 Double_t xt=0, yt=0;
921 Int_t clipped = 0; //this variable could be used in a future version
922 while(code1 + code2) {
923 clipped = 1;
924
925 // The line lies entirely outside the clipping boundary
926 if (code1&code2) {
927 clip = 2;
928 return clip;
929 }
930
931 // The line is subdivided into several parts
932 Int_t ic = code1;
933 if (ic == 0) ic = code2;
934 if (ic & 0x1) {
935 yt = y[0] + (y[1]-y[0])*(xclipl-x[0])/(x[1]-x[0]);
936 xt = xclipl;
937 }
938 if (ic & 0x2) {
939 yt = y[0] + (y[1]-y[0])*(xclipr-x[0])/(x[1]-x[0]);
940 xt = xclipr;
941 }
942 if (ic & 0x4) {
943 xt = x[0] + (x[1]-x[0])*(yclipb-y[0])/(y[1]-y[0]);
944 yt = yclipb;
945 }
946 if (ic & 0x8) {
947 xt = x[0] + (x[1]-x[0])*(yclipt-y[0])/(y[1]-y[0]);
948 yt = yclipt;
949 }
950 if (ic == code1) {
951 x[0] = xt;
952 y[0] = yt;
953 code1 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
954 } else {
955 x[1] = xt;
956 y[1] = yt;
957 code2 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
958 }
959 }
960 clip = clipped;
961 return clip;
962}
963
964////////////////////////////////////////////////////////////////////////////////
965/// Compute the endpoint codes for TPad::Clip.
966
968{
969 Int_t code = 0;
970 if (x < xcl1) code = code | 0x1;
971 if (x > xcl2) code = code | 0x2;
972 if (y < ycl1) code = code | 0x4;
973 if (y > ycl2) code = code | 0x8;
974 return code;
975}
976
977////////////////////////////////////////////////////////////////////////////////
978/// Clip polygon using the Sutherland-Hodgman algorithm.
979///
980/// \param[in] n Number of points in the polygon to
981/// be clipped
982/// \param[in] x,y Polygon x[n], y[n] do be clipped vertices
983/// \param[in] xclipl,yclipb,xclipr,yclipt Clipping boundary
984/// \param[out] nn Number of points in xc and yc
985/// \param[out] xc,yc Clipped polygon vertices. The Int_t
986/// returned by this function is
987/// the number of points in the clipped
988/// polygon. These vectors must
989/// be allocated by the calling function.
990/// A size of 2*n for each is
991/// enough.
992///
993/// Sutherland and Hodgman's polygon-clipping algorithm uses a divide-and-conquer
994/// strategy: It solves a series of simple and identical problems that, when
995/// combined, solve the overall problem. The simple problem is to clip a polygon
996/// against a single infinite clip edge. Four clip edges, each defining one boundary
997/// of the clip rectangle, successively clip a polygon against a clip rectangle.
998///
999/// Steps of Sutherland-Hodgman's polygon-clipping algorithm:
1000///
1001/// * Polygons can be clipped against each edge of the window one at a time.
1002/// Windows/edge intersections, if any, are easy to find since the X or Y coordinates
1003/// are already known.
1004/// * Vertices which are kept after clipping against one window edge are saved for
1005/// clipping against the remaining edges.
1006/// * Note that the number of vertices usually changes and will often increases.
1007///
1008/// The clip boundary determines a visible and invisible region. The edges from
1009/// vertex i to vertex i+1 can be one of four types:
1010///
1011/// * Case 1 : Wholly inside visible region - save endpoint
1012/// * Case 2 : Exit visible region - save the intersection
1013/// * Case 3 : Wholly outside visible region - save nothing
1014/// * Case 4 : Enter visible region - save intersection and endpoint
1015
1017{
1018 if (n <= 0)
1019 return 0;
1020
1021 Int_t nc, nc2;
1022 Double_t x1, y1, x2, y2, slope; // Segment to be clipped
1023
1024 std::vector<Double_t> xc2(nn), yc2(nn);
1025
1026 // Clip against the left boundary
1027 x1 = x[n - 1];
1028 y1 = y[n - 1];
1029 nc2 = 0;
1030 Int_t i;
1031 for (i = 0; i < n; i++) {
1032 x2 = x[i]; y2 = y[i];
1033 if (x1 == x2) {
1034 slope = 0;
1035 } else {
1036 slope = (y2-y1)/(x2-x1);
1037 }
1038 if (x1 >= xclipl) {
1039 if (x2 < xclipl) {
1040 xc2[nc2] = xclipl; yc2[nc2++] = slope*(xclipl-x1)+y1;
1041 } else {
1042 xc2[nc2] = x2; yc2[nc2++] = y2;
1043 }
1044 } else {
1045 if (x2 >= xclipl) {
1046 xc2[nc2] = xclipl; yc2[nc2++] = slope*(xclipl-x1)+y1;
1047 xc2[nc2] = x2; yc2[nc2++] = y2;
1048 }
1049 }
1050 x1 = x2; y1 = y2;
1051 }
1052
1053 // Clip against the top boundary
1054 if (nc2 > 0) {
1055 x1 = xc2[nc2 - 1];
1056 y1 = yc2[nc2 - 1];
1057 }
1058 nc = 0;
1059 for (i = 0; i < nc2; i++) {
1060 x2 = xc2[i]; y2 = yc2[i];
1061 if (y1 == y2) {
1062 slope = 0;
1063 } else {
1064 slope = (x2-x1)/(y2-y1);
1065 }
1066 if (y1 <= yclipt) {
1067 if (y2 > yclipt) {
1068 xc[nc] = x1+(yclipt-y1)*slope; yc[nc++] = yclipt;
1069 } else {
1070 xc[nc] = x2; yc[nc++] = y2;
1071 }
1072 } else {
1073 if (y2 <= yclipt) {
1074 xc[nc] = x1+(yclipt-y1)*slope; yc[nc++] = yclipt;
1075 xc[nc] = x2; yc[nc++] = y2;
1076 }
1077 }
1078 x1 = x2; y1 = y2;
1079 }
1080
1081 // Clip against the right boundary
1082 if (nc > 0) {
1083 x1 = xc[nc - 1];
1084 y1 = yc[nc - 1];
1085 nc2 = 0;
1086 for (i = 0; i < nc; i++) {
1087 x2 = xc[i]; y2 = yc[i];
1088 if (x1 == x2) {
1089 slope = 0;
1090 } else {
1091 slope = (y2-y1)/(x2-x1);
1092 }
1093 if (x1 <= xclipr) {
1094 if (x2 > xclipr) {
1095 xc2[nc2] = xclipr; yc2[nc2++] = slope*(xclipr-x1)+y1;
1096 } else {
1097 xc2[nc2] = x2; yc2[nc2++] = y2;
1098 }
1099 } else {
1100 if (x2 <= xclipr) {
1101 xc2[nc2] = xclipr; yc2[nc2++] = slope*(xclipr-x1)+y1;
1102 xc2[nc2] = x2; yc2[nc2++] = y2;
1103 }
1104 }
1105 x1 = x2; y1 = y2;
1106 }
1107
1108 // Clip against the bottom boundary
1109 if (nc2 > 0) {
1110 x1 = xc2[nc2 - 1];
1111 y1 = yc2[nc2 - 1];
1112 }
1113 nc = 0;
1114 for (i = 0; i < nc2; i++) {
1115 x2 = xc2[i]; y2 = yc2[i];
1116 if (y1 == y2) {
1117 slope = 0;
1118 } else {
1119 slope = (x2-x1)/(y2-y1);
1120 }
1121 if (y1 >= yclipb) {
1122 if (y2 < yclipb) {
1123 xc[nc] = x1+(yclipb-y1)*slope; yc[nc++] = yclipb;
1124 } else {
1125 xc[nc] = x2; yc[nc++] = y2;
1126 }
1127 } else {
1128 if (y2 >= yclipb) {
1129 xc[nc] = x1+(yclipb-y1)*slope; yc[nc++] = yclipb;
1130 xc[nc] = x2; yc[nc++] = y2;
1131 }
1132 }
1133 x1 = x2; y1 = y2;
1134 }
1135 }
1136
1137 if (nc < 3)
1138 nc = 0;
1139 return nc;
1140}
1141
1142////////////////////////////////////////////////////////////////////////////////
1143/// Delete all primitives in pad and pad itself.
1144/// Pad cannot be used anymore after this call.
1145/// Emits signal "Closed()".
1146
1148{
1149 if (ROOT::Detail::HasBeenDeleted(this)) return;
1150 if (!fMother) return;
1152
1153 if (fPrimitives)
1154 fPrimitives->Clear();
1155 if (fView) {
1157 fView = nullptr;
1158 }
1159 if (fFrame) {
1161 fFrame = nullptr;
1162 }
1163
1164 // emit signal
1165 if (IsA() != TCanvas::Class())
1166 Closed();
1167
1168 if (fPixmapID != -1) {
1169 if (gPad) {
1170 if (!gPad->IsBatch() && GetPainter())
1172 }
1173 fPixmapID = -1;
1174
1175 if (!gROOT->GetListOfCanvases()) return;
1176 if (fMother == this) {
1177 gROOT->GetListOfCanvases()->Remove(this);
1178 return; // in case of TCanvas
1179 }
1180
1181 // remove from the mother's list of primitives
1182 if (fMother) {
1183 fMother->Remove(this, kFALSE); // do not produce modified
1184
1185 if (gPad == this)
1186 fMother->cd();
1187 }
1188 if (fCanvas) {
1189 if (fCanvas->GetPadSave() == this)
1191 if (fCanvas->GetSelectedPad() == this)
1192 fCanvas->SetSelectedPad(nullptr);
1193 if (fCanvas->GetClickSelectedPad() == this)
1194 fCanvas->SetClickSelectedPad(nullptr);
1195 }
1196 }
1197
1198 fMother = nullptr;
1199 if (gROOT->GetSelectedPad() == this)
1200 gROOT->SetSelectedPad(nullptr);
1201}
1202
1203////////////////////////////////////////////////////////////////////////////////
1204/// Copy the pixmap of the pad to the canvas.
1205
1207{
1208 int px, py;
1209 XYtoAbsPixel(fX1, fY2, px, py);
1210
1211 if (fPixmapID != -1)
1212 if (auto pp = GetPainter())
1213 pp->CopyDrawable(fPixmapID, px, py);
1214
1215 // if pixmap copied, stored XOR operations are no longer valid
1216 fDrawOperXor.clear();
1217}
1218
1219////////////////////////////////////////////////////////////////////////////////
1220/// Copy the sub-pixmaps of the pad to the canvas.
1221
1223{
1224 if (!fPrimitives)
1225 fPrimitives = new TList;
1226 TIter next(GetListOfPrimitives());
1227 while (auto obj = next()) {
1228 if (auto pad = dynamic_cast<TPad*>(obj)) {
1229 pad->CopyPixmap();
1230 pad->CopyPixmaps();
1231 }
1232 }
1233
1234 if (this == gPad)
1236}
1237
1238////////////////////////////////////////////////////////////////////////////////
1239/// Remove TExec name from the list of Execs.
1240
1241void TPad::DeleteExec(const char *name)
1242{
1243 if (!fExecs) fExecs = new TList;
1245 if (!ex) return;
1246 fExecs->Remove(ex);
1247 delete ex;
1248}
1249
1250////////////////////////////////////////////////////////////////////////////////
1251/// Compute distance from point px,py to a box.
1252///
1253/// Compute the closest distance of approach from point px,py to the
1254/// edges of this pad.
1255/// The distance is computed in pixels units.
1256
1258{
1259 Int_t pxl, pyl, pxt, pyt;
1260 Int_t px1 = gPad->XtoAbsPixel(fX1);
1261 Int_t py1 = gPad->YtoAbsPixel(fY1);
1262 Int_t px2 = gPad->XtoAbsPixel(fX2);
1263 Int_t py2 = gPad->YtoAbsPixel(fY2);
1264 if (px1 < px2) {pxl = px1; pxt = px2;}
1265 else {pxl = px2; pxt = px1;}
1266 if (py1 < py2) {pyl = py1; pyt = py2;}
1267 else {pyl = py2; pyt = py1;}
1268
1269 // Are we inside the box?
1270 // ======================
1271 if ( (px > pxl && px < pxt) && (py > pyl && py < pyt) ) {
1272 if (GetFillStyle()) return 0; //*-* if pad is filled
1273 }
1274
1275 // Are we on the edges?
1276 // ====================
1277 Int_t dxl = TMath::Abs(px - pxl);
1278 if (py < pyl) dxl += pyl - py;
1279 if (py > pyt) dxl += py - pyt;
1280 Int_t dxt = TMath::Abs(px - pxt);
1281 if (py < pyl) dxt += pyl - py;
1282 if (py > pyt) dxt += py - pyt;
1283 Int_t dyl = TMath::Abs(py - pyl);
1284 if (px < pxl) dyl += pxl - px;
1285 if (px > pxt) dyl += px - pxt;
1286 Int_t dyt = TMath::Abs(py - pyt);
1287 if (px < pxl) dyt += pxl - px;
1288 if (px > pxt) dyt += px - pxt;
1289
1290 Int_t distance = dxl;
1291 if (dxt < distance) distance = dxt;
1292 if (dyl < distance) distance = dyl;
1293 if (dyt < distance) distance = dyt;
1294
1295 return distance - Int_t(0.5*fLineWidth);
1296}
1297
1298////////////////////////////////////////////////////////////////////////////////
1299/// Automatic pad generation by division.
1300///
1301/// - The current canvas is divided in nx by ny equal divisions (pads).
1302/// - xmargin defines the horizontal spacing around each pad as a percentage of the canvas
1303/// width. Therefore, the distance between two adjacent pads along the x-axis is equal
1304/// to twice the xmargin value.
1305/// - ymargin defines the vertical spacing around each pad as a percentage of the canvas
1306/// height. Therefore, the distance between two adjacent pads along the y-axis is equal
1307/// to twice the ymargin value.
1308/// - color is the color of the new pads. If 0, color is the canvas color.
1309///
1310/// Pads are automatically named `canvasname_n` where `n` is the division number
1311/// starting from top left pad.
1312///
1313/// Example if canvasname=c1 , nx=2, ny=3:
1314///
1315/// \image html gpad_pad3.png
1316///
1317/// Once a pad is divided into sub-pads, one can set the current pad
1318/// to a subpad with a given division number as illustrated above
1319/// with TPad::cd(subpad_number).
1320///
1321/// For example, to set the current pad to c1_4, one can do:
1322/// ~~~ {.cpp}
1323/// c1->cd(4)
1324/// ~~~
1325/// __Note1:__ c1.cd() is equivalent to c1.cd(0) and sets the current pad
1326/// to c1 itself.
1327///
1328/// __Note2:__ after a statement like c1.cd(6), the global variable gPad
1329/// points to the current pad. One can use gPad to set attributes
1330/// of the current pad.
1331///
1332/// __Note3:__ in case xmargin < 0 or ymargin < 0, there is no space
1333/// between pads. The current pad margins are recomputed to
1334/// optimize the layout in order to have similar frames' areas.
1335/// See the following example:
1336///
1337/// ~~~ {.cpp}
1338/// void divpad(Int_t nx=3, Int_t ny=2) {
1339/// gStyle->SetOptStat(0);
1340/// auto C = new TCanvas();
1341/// C->SetMargin(0.3, 0.3, 0.3, 0.3);
1342/// C->Divide(nx,ny,-1);
1343/// Int_t number = 0;
1344/// auto h = new TH1F("","",100,-3.3,3.3);
1345/// h->GetXaxis()->SetLabelFont(43);
1346/// h->GetXaxis()->SetLabelSize(12);
1347/// h->GetYaxis()->SetLabelFont(43);
1348/// h->GetYaxis()->SetLabelSize(12);
1349/// h->GetYaxis()->SetNdivisions(505);
1350/// h->SetMaximum(30*nx*ny);
1351/// h->SetFillColor(42);
1352/// for (Int_t i=0;i<nx*ny;i++) {
1353/// number++;
1354/// C->cd(number);
1355/// h->FillRandom("gaus",1000);
1356/// h->DrawCopy();
1357/// }
1358/// }
1359/// ~~~
1360
1361void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color)
1362{
1363 if (!IsEditable()) return;
1364
1365 if (gThreadXAR) {
1366 void *arr[7];
1367 arr[1] = this; arr[2] = (void*)&nx;arr[3] = (void*)& ny;
1368 arr[4] = (void*)&xmargin; arr[5] = (void *)& ymargin; arr[6] = (void *)&color;
1369 if ((*gThreadXAR)("PDCD", 7, arr, nullptr)) return;
1370 }
1371
1372 TContext ctxt(kTRUE);
1373
1374 cd();
1375 if (nx <= 0) nx = 1;
1376 if (ny <= 0) ny = 1;
1377 Int_t ix, iy;
1378 Double_t x1, y1, x2, y2, dx, dy;
1379 TPad *pad;
1380 TString name, title;
1381 Int_t n = 0;
1382 if (color == 0) color = GetFillColor();
1383 if (xmargin >= 0 && ymargin >= 0) {
1384 //general case
1385 dy = 1/Double_t(ny);
1386 dx = 1/Double_t(nx);
1387 for (iy=0;iy<ny;iy++) {
1388 y2 = 1 - iy*dy - ymargin;
1389 y1 = y2 - dy + 2*ymargin;
1390 if (y1 < 0) y1 = 0;
1391 if (y1 > y2) continue;
1392 for (ix=0;ix<nx;ix++) {
1393 x1 = ix*dx + xmargin;
1394 x2 = x1 +dx -2*xmargin;
1395 if (x1 > x2) continue;
1396 n++;
1397 name.Form("%s_%d", GetName(), n);
1398 pad = new TPad(name.Data(), name.Data(), x1, y1, x2, y2, color);
1399 pad->SetNumber(n);
1400 pad->Draw();
1401 }
1402 }
1403 } else {
1404 // special case when xmargin < 0 or ymargin < 0
1405 Double_t xl = GetLeftMargin();
1406 Double_t xr = GetRightMargin();
1408 Double_t yt = GetTopMargin();
1409 xl /= (1-xl+xr)*nx;
1410 xr /= (1-xl+xr)*nx;
1411 yb /= (1-yb+yt)*ny;
1412 yt /= (1-yb+yt)*ny;
1413 SetLeftMargin(xl);
1414 SetRightMargin(xr);
1415 SetBottomMargin(yb);
1416 SetTopMargin(yt);
1417 dx = (1-xl-xr)/nx;
1418 dy = (1-yb-yt)/ny;
1419 Int_t number = 0;
1420 for (Int_t i=0;i<nx;i++) {
1421 x1 = i*dx+xl;
1422 x2 = x1 + dx;
1423 if (i == 0) x1 = 0;
1424 if (i == nx-1) x2 = 1-xr;
1425 for (Int_t j=0;j<ny;j++) {
1426 number = j*nx + i +1;
1427 y2 = 1 -j*dy -yt;
1428 y1 = y2 - dy;
1429 if (j == 0) y2 = 1-yt;
1430 if (j == ny-1) y1 = 0;
1431 name.Form("%s_%d", GetName(), number);
1432 title.Form("%s_%d", GetTitle(), number);
1433 pad = new TPad(name.Data(), title.Data(), x1, y1, x2, y2, color);
1434 pad->SetNumber(number);
1435 pad->SetBorderMode(0);
1436 if (i == 0) pad->SetLeftMargin(xl*nx);
1437 else pad->SetLeftMargin(0);
1438 pad->SetRightMargin(0);
1439 pad->SetTopMargin(0);
1440 if (j == ny-1) pad->SetBottomMargin(yb*ny);
1441 else pad->SetBottomMargin(0);
1442 pad->Draw();
1443 }
1444 }
1445 }
1446 Modified();
1447}
1448
1449////////////////////////////////////////////////////////////////////////////////
1450/// Divide the canvas according to ratios.
1451///
1452/// The current canvas is divided in nx by ny according to the width and height ratios.
1453/// If the ratios are not specified they are assumed to be equal.
1454///
1455/// Pads are automatically named `canvasname_n` where `n` is the division number
1456/// starting from top left pad.
1457///
1458/// Top and left margins can be defined.
1459
1461 const std::vector<double>& widthRatios,
1462 const std::vector<double>& heightRatios,
1463 const double canvasTopMargin,
1464 const double canvasLeftMargin
1465 )
1466{
1467 cd();
1468
1469 int wrs = widthRatios.size();
1470 int hrs = heightRatios.size();
1471 int nxl = TMath::Min(nx,wrs), nyl = TMath::Min(ny,hrs);
1472
1473 if (wrs==0) nxl = nx;
1474 if (hrs==0) nyl = ny;
1475
1476 int pn = 1;
1477 double xr = 0.;
1478 double yr = 0.;
1479 double x = 0.;
1480 double y = 1.;
1481 double x1, y1, x2, y2;
1482
1483 // Check the validity of the margins
1484 if (canvasTopMargin <0 || canvasTopMargin >1 ) {
1485 Error("DivideRatios", "The canvas top margin must be >= 0 and <= 1");
1486 return;
1487 } else {
1488 y = 1.- canvasTopMargin;
1489 }
1490 if (canvasLeftMargin <0 || canvasLeftMargin >1 ) {
1491 Error("DivideRatios", "The canvas left margin must be >= 0 and <= 1");
1492 return;
1493 }
1494
1495 // Check the validity of the ratios
1496 double sumOfHeightRatios = canvasTopMargin;
1497 if (hrs) {
1498 for (int i=0; i<nyl; i++) {
1499 yr = heightRatios[i];
1500 sumOfHeightRatios = sumOfHeightRatios + yr;
1501 if (yr <0 || yr >1 ) {
1502 Error("DivideRatios", "Y ratios plus the top margin must be >= 0 and <= 1");
1503 return;
1504 }
1505 }
1506 }
1507 if (sumOfHeightRatios > 1.) {
1508 Error("DivideRatios", "The sum of Y ratios plus the top margin must be <= 1 %g",sumOfHeightRatios);
1509 return;
1510 }
1511 double sumOfWidthRatios = canvasLeftMargin;
1512 if (wrs) {
1513 for (int j=0; j<nxl; j++) {
1514 xr = widthRatios[j];
1515 sumOfWidthRatios = sumOfWidthRatios +xr;
1516 if (xr <0 || xr >1 ) {
1517 Error("DivideRatios", "X ratios must be >= 0 and <= 1");
1518 return;
1519 }
1520 }
1521 }
1522 if (sumOfWidthRatios > 1.) {
1523 Error("DivideRatios", "The sum of X ratios must be <= 1 %g ",sumOfWidthRatios);
1524 return;
1525 }
1526
1527 // Create the pads according to the ratios
1528 for (int i=0; i<nyl; i++) {
1529 x = canvasLeftMargin;
1530 if (hrs) yr = heightRatios[i];
1531 else yr = 1./nyl;
1532 for (int j=0; j<nxl; j++) {
1533 if (wrs) xr = widthRatios[j];
1534 else xr = 1./nxl;
1535 x1 = TMath::Max(0., x);
1536 y1 = TMath::Max(0., y - yr);
1537 x2 = TMath::Min(1., x + xr);
1538 y2 = TMath::Min(1., y);
1539 auto pad = new TPad(TString::Format("%s_%d", GetName(), pn),
1540 TString::Format("%s_%d", GetName(), pn),
1541 x1, y1, x2 ,y2);
1542 pad->SetNumber(pn);
1543 pad->Draw();
1544 x = x + xr;
1545 pn++;
1546 }
1547 y = y - yr;
1548 }
1549}
1550
1551////////////////////////////////////////////////////////////////////////////////
1552/// "n" is the total number of sub-pads. The number of sub-pads along the X
1553/// and Y axis are computed according to the square root of n.
1554
1555void TPad::DivideSquare(Int_t n, Float_t xmargin, Float_t ymargin, Int_t color)
1556{
1557 Int_t w = 1, h = 1;
1558 if (!fCanvas) {
1559 Error("DivideSquare", "No canvas associated with this pad.");
1560 return;
1561 }
1565 if (w*h < n) w++;
1566 } else {
1569 if (w*h < n) h++;
1570 }
1571
1572 Divide( w, h, xmargin, ymargin, color);
1573}
1574
1575////////////////////////////////////////////////////////////////////////////////
1576/// Draw Pad in Current pad (re-parent pad if necessary).
1577
1579{
1580 // if no canvas opened yet create a default canvas
1581 if (!gPad) {
1582 gROOT->MakeDefCanvas();
1583 }
1584
1585 // pad cannot be in itself and it can only be in one other pad at a time
1586 if (!fPrimitives) fPrimitives = new TList;
1587 if (gPad != this) {
1589 fMother->Remove(this, kFALSE);
1590 TPad *oldMother = fMother;
1591 fCanvas = gPad->GetCanvas();
1592 //
1593 fMother = (TPad*)gPad;
1594 if (oldMother != fMother || fPixmapID == -1) ResizePad();
1595 }
1596
1597 if (fCanvas && fCanvas->IsWeb()) {
1598 Modified();
1600 } else {
1601 Paint();
1602 }
1603
1604 if (gPad->IsRetained() && gPad != this && fMother)
1605 fMother->Add(this, option);
1606}
1607
1608////////////////////////////////////////////////////////////////////////////////
1609/// Draw class inheritance tree of the class to which obj belongs.
1610///
1611/// If a class B inherits from a class A, description of B is drawn
1612/// on the right side of description of A.
1613///
1614/// Member functions overridden by B are shown in class A with a blue line
1615/// crossing-out the corresponding member function.
1616
1618{
1619 if (!classobj) return;
1620 char dname[256];
1621 const Int_t kMAXLEVELS = 10;
1622 TClass *clevel[kMAXLEVELS], *cl, *cll;
1623 TBaseClass *base, *cinherit;
1624 TText *ptext = nullptr;
1625 TString opt=option;
1626 Double_t x,y,dy,y1,v1,v2,dv;
1627 Int_t nd,nf,nc,nkd,nkf,i,j;
1628 TPaveText *pt;
1629 Int_t maxlev = 4;
1630 if (opt.Contains("2")) maxlev = 2;
1631 if (opt.Contains("3")) maxlev = 3;
1632 if (opt.Contains("5")) maxlev = 5;
1633 if (opt.Contains("6")) maxlev = 6;
1634 if (opt.Contains("7")) maxlev = 7;
1635
1636 // Clear and Set Pad range
1637 Double_t xpad = 20.5;
1638 Double_t ypad = 27.5;
1639 Clear();
1640 Range(0,0,xpad,ypad);
1641
1642 // Find number of levels
1643 Int_t nlevel = 0;
1644 TClass *obj = (TClass*)classobj;
1645 clevel[nlevel] = obj;
1646 TList *lbase = obj->GetListOfBases();
1647 while(lbase) {
1648 base = (TBaseClass*)lbase->First();
1649 if (!base) break;
1650 if (!base->GetClassPointer()) break;
1651 nlevel++;
1652 clevel[nlevel] = base->GetClassPointer();
1653 lbase = clevel[nlevel]->GetListOfBases();
1654 if (nlevel >= maxlev-1) break;
1655 }
1656 Int_t maxelem = 0;
1657 Int_t ncdraw = 0;
1658 Int_t ilevel, nelem;
1659 for (ilevel=nlevel;ilevel>=0;ilevel--) {
1660 cl = clevel[ilevel];
1661 nelem = cl->GetNdata() + cl->GetNmethods();
1662 if (nelem > maxelem) maxelem = nelem;
1663 nc = (nelem/50) + 1;
1664 ncdraw += nc;
1665 }
1666
1667 Double_t tsizcm = 0.40;
1668 Double_t x1 = 0.25;
1669 Double_t x2 = 0;
1670 Double_t dx = 3.5;
1671 if (ncdraw > 4) {
1672 dx = dx - 0.42*Double_t(ncdraw-5);
1673 if (dx < 1.3) dx = 1.3;
1674 tsizcm = tsizcm - 0.03*Double_t(ncdraw-5);
1675 if (tsizcm < 0.27) tsizcm = 0.27;
1676 }
1677 Double_t tsiz = 1.2*tsizcm/ypad;
1678
1679 // Now loop on levels
1680 for (ilevel=nlevel;ilevel>=0;ilevel--) {
1681 cl = clevel[ilevel];
1682 nelem = cl->GetNdata() + cl->GetNmethods();
1683 if (nelem > maxelem) maxelem = nelem;
1684 nc = (nelem/50) + 1;
1685 dy = 0.45;
1686 if (ilevel < nlevel) x1 = x2 + 0.5;
1687 x2 = x1 + nc*dx;
1688 v2 = ypad - 0.5;
1689 lbase = cl->GetListOfBases();
1690 cinherit = nullptr;
1691 if (lbase) cinherit = (TBaseClass*)lbase->First();
1692
1693 do {
1694 nd = cl->GetNdata();
1695 nf = cl->GetNmethods() - 2; //do not show default constructor and destructor
1696 if (cl->GetListOfMethods()->FindObject("Dictionary")) {
1697 nf -= 6; // do not count the Dictionary/ClassDef functions
1698 }
1699 nkf= nf/nc +1;
1700 nkd= nd/nc +1;
1701 if (nd == 0) nkd=0;
1702 if (nf == 0) nkf=0;
1703 y1 = v2 - 0.7;
1704 v1 = y1 - Double_t(nkf+nkd+nc-1)*dy;
1705 dv = v2 - v1;
1706
1707 // Create a new PaveText
1708 pt = new TPaveText(x1,v1,x2,v2);
1710 pt->SetFillColor(19);
1711 pt->Draw();
1712 pt->SetTextColor(4);
1713 pt->SetTextFont(61);
1714 pt->SetTextAlign(12);
1715 pt->SetTextSize(tsiz);
1716 TBox *box = pt->AddBox(0,(y1+0.01-v1)/dv,0,(v2-0.01-v1)/dv);
1717 if (box) box->SetFillColor(17);
1718 pt->AddLine(0,(y1-v1)/dv,0,(y1-v1)/dv);
1719 TText *title = pt->AddText(0.5,(0.5*(y1+v2)-v1)/dv,(char*)cl->GetName());
1720 title->SetTextAlign(22);
1721 title->SetTextSize(0.6*(v2-y1)/ypad);
1722
1723 // Draw data Members
1724 i = 0;
1725 x = 0.03;
1726 y = y1 + 0.5*dy;
1727 TDataMember *d;
1728 TIter nextd(cl->GetListOfDataMembers());
1729 while ((d = (TDataMember *) nextd())) {
1730 if (i >= nkd) { i = 1; y = y1 - 0.5*dy; x += 1/Double_t(nc); }
1731 else { i++; y -= dy; }
1732
1733 // Take in account the room the array index will occupy
1734
1735 Int_t dim = d->GetArrayDim();
1736 Int_t indx = 0;
1737 snprintf(dname,256,"%s",d->GetName());
1738 Int_t ldname = 0;
1739 while (indx < dim ){
1740 ldname = strlen(dname);
1741 snprintf(&dname[ldname],256-ldname,"[%d]",d->GetMaxIndex(indx));
1742 indx++;
1743 }
1744 pt->AddText(x,(y-v1)/dv,dname);
1745 }
1746
1747 // Draw a separator line
1748 Double_t ysep;
1749 if (nd) {
1750 ysep = y1 - Double_t(nkd)*dy;
1751 pt->AddLine(0,(ysep-v1)/dv,0,(ysep-v1)/dv);
1752 ysep -= 0.5*dy;
1753 } else ysep = y1;
1754
1755 // Draw Member Functions
1756 Int_t fcount = 0;
1757 i = 0;
1758 x = 0.03;
1759 y = ysep + 0.5*dy;
1760 TMethod *m;
1761 TIter nextm(cl->GetListOfMethods());
1762 while ((m = (TMethod *) nextm())) {
1763 if (
1764 !strcmp( m->GetName(), "Dictionary" ) ||
1765 !strcmp( m->GetName(), "Class_Version" ) ||
1766 !strcmp( m->GetName(), "DeclFileName" ) ||
1767 !strcmp( m->GetName(), "DeclFileLine" ) ||
1768 !strcmp( m->GetName(), "ImplFileName" ) ||
1769 !strcmp( m->GetName(), "ImplFileLine" )
1770 ) continue;
1771 fcount++;
1772 if (fcount > nf) break;
1773 if (i >= nkf) { i = 1; y = ysep - 0.5*dy; x += 1/Double_t(nc); }
1774 else { i++; y -= dy; }
1775
1776 ptext = pt->AddText(x,(y-v1)/dv,m->GetName());
1777 // Check if method is overloaded in a derived class
1778 // If yes, Change the color of the text to blue
1779 for (j=ilevel-1;j>=0;j--) {
1780 if (cl == clevel[ilevel]) {
1781 if (clevel[j]->GetMethodAny((char*)m->GetName())) {
1782 ptext->SetTextColor(15);
1783 break;
1784 }
1785 }
1786 }
1787 }
1788
1789 // Draw second inheritance classes for this class
1790 cll = nullptr;
1791 if (cinherit) {
1792 cinherit = (TBaseClass*)lbase->After(cinherit);
1793 if (cinherit) {
1794 cl = cinherit->GetClassPointer();
1795 cll = cl;
1796 v2 = v1 -0.4;
1797 dy = 0.35;
1798 }
1799 }
1800 } while (cll);
1801 }
1802 Update();
1803}
1804
1805////////////////////////////////////////////////////////////////////////////////
1806/// Function called to draw a crosshair in the canvas
1807///
1808/// Example:
1809/// ~~~ {.cpp}
1810/// Root > TFile f("hsimple.root");
1811/// Root > hpxpy.Draw();
1812/// Root > c1.SetCrosshair();
1813/// ~~~
1814/// When moving the mouse in the canvas, a crosshair is drawn
1815///
1816/// - if the canvas fCrosshair = 1 , the crosshair spans the full canvas
1817/// - if the canvas fCrosshair > 1 , the crosshair spans only the pad
1818
1820{
1821 if (!gPad || (gPad->GetEvent() == kMouseEnter))
1822 return;
1823
1824 auto cpad = static_cast<TPad *>(gPad);
1825 auto canvas = cpad->GetCanvas();
1826
1827 if (cpad->GetEvent() == kButton1Down || cpad->GetEvent() == kButton1Up || cpad->GetEvent() == kMouseLeave) {
1828 if (fCrosshairPos)
1829 UpdateAsync();
1830 fCrosshairPos = 0;
1831 return;
1832 }
1833
1834 //erase old position and draw a line at current position
1835 Double_t umin, umax, vmin, vmax;
1836 Int_t px = cpad->GetEventX();
1837 Int_t py = cpad->GetEventY() + 1;
1838 if (canvas->GetCrosshair() > 1) {
1839 //crosshair only in the current pad
1840 umin = GetAbsXlowNDC();
1841 umax = GetAbsXlowNDC() + GetAbsWNDC();
1842 vmin = GetAbsYlowNDC();
1843 vmax = GetAbsYlowNDC() + GetAbsHNDC();
1844 } else {
1845 //default; crosshair spans the full canvas
1846 umin = 0;
1847 umax = 1;
1848 vmin = 0;
1849 vmax = 1;
1850 }
1851
1852 TAttLine att(kBlack, 1, 1);
1853 att.ModifyOn(*this);
1854
1855 Double_t uu[2], vv[2];
1856 uu[0] = umin; uu[1] = umax;
1857 vv[0] = vv[1] = 1. - 1. * py / canvas->GetWh();
1858 canvas->PaintPolyLineNDC(2, uu, vv, "icrosshair1");
1859 uu[0] = uu[1] = 1. * px / canvas->GetWw();
1860 vv[0] = vmin; vv[1] = vmax;
1861 canvas->PaintPolyLineNDC(2, uu, vv, "icrosshair2");
1862
1863 UpdateAsync();
1864 // just indication that crosshair was drawn before
1865 fCrosshairPos = px + 10000*py;
1866}
1867
1868////////////////////////////////////////////////////////////////////////////////
1869/// Draw an empty pad frame with X and Y axis.
1870///
1871/// \return The pointer to the histogram used to draw the frame.
1872///
1873/// \param[in] xmin X axis lower limit
1874/// \param[in] xmax X axis upper limit
1875/// \param[in] ymin Y axis lower limit
1876/// \param[in] ymax Y axis upper limit
1877/// \param[in] title Pad title.If title is of the form "stringt;stringx;stringy"
1878/// the pad title is set to stringt, the x axis title to
1879/// stringx, the y axis title to stringy.
1880///
1881/// #### Example:
1882///
1883/// Begin_Macro(source)
1884/// {
1885/// auto c = new TCanvas("c","c",200,10,500,300);
1886///
1887/// const Int_t n = 50;
1888/// auto g = new TGraph();
1889/// for (Int_t i=0;i<n;i++) g->SetPoint(i,i*0.1,100*sin(i*0.1+0.2));
1890///
1891/// auto frame = c->DrawFrame(0, -110, 2, 110);
1892/// frame->GetXaxis()->SetTitle("X axis");
1893///
1894/// g->Draw("L*");
1895/// }
1896/// End_Macro
1897
1899{
1900 if (!IsEditable())
1901 return nullptr;
1902
1903 if (this != gPad) {
1904 Warning("DrawFrame", "Must be called for the current pad only");
1905 if (gPad) return gPad->DrawFrame(xmin,ymin,xmax,ymax,title);
1906 }
1907
1908 cd();
1909
1910 TH1F *hframe = (TH1F*)FindObject("hframe");
1911 if (hframe) delete hframe;
1912 Int_t nbins = 1000;
1913 //if log scale in X, use variable bin size linear with log(x)
1914 //this gives a better precision when zooming on the axis
1915 if (fLogx && xmin > 0 && xmax > xmin) {
1916 Double_t xminl = TMath::Log(xmin);
1917 Double_t xmaxl = TMath::Log(xmax);
1918 Double_t dx = (xmaxl-xminl)/nbins;
1919 std::vector<Double_t> xbins(nbins+1);
1920 xbins[0] = xmin;
1921 for (Int_t i=1;i<=nbins;i++) {
1922 xbins[i] = TMath::Exp(xminl+i*dx);
1923 }
1924 hframe = new TH1F("hframe",title,nbins,xbins.data());
1925 } else {
1926 hframe = new TH1F("hframe",title,nbins,xmin,xmax);
1927 }
1928 hframe->SetBit(TH1::kNoStats);
1929 hframe->SetBit(kCanDelete);
1930 hframe->SetMinimum(ymin);
1931 hframe->SetMaximum(ymax);
1932 hframe->GetYaxis()->SetLimits(ymin,ymax);
1933 hframe->SetDirectory(nullptr);
1934 hframe->Draw(" ");
1935 Update();
1936 cd();
1937 return hframe;
1938}
1939
1940////////////////////////////////////////////////////////////////////////////////
1941/// Static function to Display Color Table in a pad.
1942
1944{
1945 Int_t i, j;
1946 Int_t color;
1947 Double_t xlow, ylow, xup, yup, hs, ws;
1948 Double_t x1, y1, x2, y2;
1949 x1 = y1 = 0;
1950 x2 = y2 = 20;
1951
1952 gPad->SetFillColor(0);
1953 gPad->Clear();
1954 gPad->Range(x1,y1,x2,y2);
1955
1956 TText text(0,0,"");
1957 text.SetTextFont(61);
1958 text.SetTextSize(0.07);
1959 text.SetTextAlign(22);
1960
1961 TBox box;
1962
1963 // Draw color table boxes.
1964 hs = (y2-y1)/Double_t(5);
1965 ws = (x2-x1)/Double_t(10);
1966 for (i=0;i<10;i++) {
1967 xlow = x1 + ws*(Double_t(i)+0.1);
1968 xup = x1 + ws*(Double_t(i)+0.9);
1969 for (j=0;j<5;j++) {
1970 ylow = y1 + hs*(Double_t(j)+0.1);
1971 yup = y1 + hs*(Double_t(j)+0.9);
1972 color = 10*j + i;
1973 box.SetFillStyle(1001);
1974 box.SetFillColor(color);
1975 box.DrawBox(xlow, ylow, xup, yup);
1976 box.SetFillStyle(0);
1977 box.SetLineColor(1);
1978 box.DrawBox(xlow, ylow, xup, yup);
1979 if (color == 1) text.SetTextColor(0);
1980 else text.SetTextColor(1);
1981 text.DrawText(0.5*(xlow+xup), 0.5*(ylow+yup), TString::Format("%d",color).Data());
1982 }
1983 }
1984}
1985
1986////////////////////////////////////////////////////////////////////////////////
1987/// Execute action corresponding to one event.
1988///
1989/// This member function is called when a TPad object is clicked.
1990///
1991/// If the mouse is clicked in one of the 4 corners of the pad (pA,pB,pC,pD)
1992/// the pad is resized with the rubber rectangle.
1993///
1994/// If the mouse is clicked inside the pad, the pad is moved.
1995///
1996/// If the mouse is clicked on the 4 edges (pL,pR,pTop,pBot), the pad is scaled
1997/// parallel to this edge.
1998///
1999/// \image html gpad_pad4.png
2000///
2001/// Note that this function reuses internal TBoxInteractive class
2002/// designed for TBox movement avoiding code duplication
2003
2005{
2006 if (!IsEditable() && event != kMouseEnter)
2007 return;
2008 TVirtualPad &parent = *GetMother();
2009 if (!parent.IsEditable())
2010 return;
2011
2013
2014 if (fXlowNDC < 0 && event != kButton1Down) return;
2015 if (fYlowNDC < 0 && event != kButton1Down) return;
2016
2017 Int_t newcode = gROOT->GetEditorMode();
2018 if (newcode && (newcode != kEditor))
2019 parent.FreeInteractive(this); // delete any interactive object
2020 switch (newcode) {
2021 case kPad:
2023 break;
2024 case kMarker:
2025 case kText:
2026 case kEditor:
2027 TCreatePrimitives::Text(event,px,py,newcode);
2028 break;
2029 case kLine:
2031 break;
2032 case kArrow:
2034 break;
2035 case kCurlyLine:
2037 break;
2038 case kCurlyArc:
2040 break;
2041 case kPolyLine:
2043 break;
2044 case kCutG:
2046 break;
2047 case kArc:
2049 break;
2050 case kEllipse:
2052 break;
2053 case kButton:
2054 case kPave:
2055 case kPaveLabel:
2056 case kPaveText:
2057 case kPavesText:
2058 case kDiamond:
2059 TCreatePrimitives::Pave(event,px,py,newcode);
2060 return;
2061 default:
2062 break;
2063 }
2064 if (newcode)
2065 return;
2066
2067 auto inter = parent.GetInteractive<TBoxInteractive>(this);
2068
2069 auto setNewValues = [&inter, &parent, this]() {
2070 // Get parent corners pixels coordinates
2071 Int_t parentpx1 = parent.XtoAbsPixel(parent.GetX1());
2072 Int_t parentpx2 = parent.XtoAbsPixel(parent.GetX2());
2073 Int_t parentpy1 = parent.YtoAbsPixel(parent.GetY1());
2074 Int_t parentpy2 = parent.YtoAbsPixel(parent.GetY2());
2075
2076 // Get pad new corners pixels coordinates
2077 Int_t apx1 = TMath::Max(inter->px1, parentpx1);
2078 Int_t apx2 = TMath::Min(inter->px2, parentpx2);
2079 Int_t apy1 = TMath::Min(inter->py1, parentpy1);
2080 Int_t apy2 = TMath::Max(inter->py2, parentpy2);
2081
2082 // Compute new pad positions in the NDC space of parent
2083 fXlowNDC = Double_t(apx1 - parentpx1)/Double_t(parentpx2 - parentpx1);
2084 fYlowNDC = Double_t(apy1 - parentpy1)/Double_t(parentpy2 - parentpy1);
2085 fWNDC = Double_t(apx2 - apx1)/Double_t(parentpx2 - parentpx1);
2086 fHNDC = Double_t(apy2 - apy1)/Double_t(parentpy2 - parentpy1);
2087 };
2088
2089
2090 switch (event) {
2091
2092 case kMouseEnter:
2093 if (fTip)
2095 break;
2096
2097 case kArrowKeyPress:
2098 case kButton1Down:
2102 // No break !!!
2103
2104 case kMouseMotion: {
2105 TBoxInteractive dummy(kFALSE);
2106 if (!inter) inter = &dummy;
2107 // use pad itself to calculate its pixel coordinates
2108 inter->CalcPixelCoord(*this, GetX1(), GetY1(), GetX2(), GetY2());
2109
2110 if (TestBit(kCannotMove) || !inter->SelectCorner(px, py)) {
2111 // refuse interactive changes
2112 parent.FreeInteractive(this);
2113 } else {
2114 inter->SetCursor(parent, event == kButton1Down);
2115 fResizing = inter->IsResizing() && (event != kMouseMotion);
2116 }
2117
2118 break;
2119 }
2120
2121 case kArrowKeyRelease:
2122 case kButton1Motion: {
2123 if (!inter)
2124 return;
2125
2126 Double_t ratio = HasFixedAspectRatio() ? fAspectRatio : 0.;
2127
2128 if (!inter->ProcessMouseMove(parent, px, py, kTRUE, kTRUE, ratio))
2129 return;
2130
2131 // paint if necessary
2132 inter->ApplyChanges(parent);
2133
2134 if (inter->IsOpaque(parent)) {
2135 setNewValues();
2136 ResizePad();
2137 parent.ShowGuidelines(this, event, inter->GetGuideChar(), true);
2138 Modified(kTRUE);
2139 }
2140
2141 break;
2142 }
2143
2144 case kButton1Up:
2145 if (inter && inter->IsOpaque(parent))
2146 parent.ShowGuidelines(this, event);
2147
2148 if (gROOT->IsEscaped()) {
2149 gROOT->SetEscape(kFALSE);
2150 if (inter && inter->IsOpaque(parent)) {
2151 fXlowNDC = inter->oldX1;
2152 fYlowNDC = inter->oldY1;
2153 fWNDC = inter->oldX2;
2154 fHNDC = inter->oldY2;
2155 ResizePad();
2156 Modified(kTRUE);
2157
2158 }
2159 } else if (inter && !inter->IsOpaque(parent) && (inter->newX1 != inter->newX2)) {
2160 setNewValues();
2161 ResizePad();
2162 Modified(kTRUE);
2163 }
2164
2165 RangeChanged();
2166
2167 fResizing = kFALSE;
2168 parent.FreeInteractive(this);
2169
2170 break;
2171
2172 case kButton1Locate:
2173
2174 ExecuteEvent(kButton1Down, px, py);
2175
2176 while (true) {
2177 px = py = 0;
2178 event = GetCanvasImp()->RequestLocator(px, py);
2179
2181
2182 if (event != -1) { // button is released
2183 ExecuteEvent(kButton1Up, px, py);
2184 return;
2185 }
2186 }
2187
2188 case kButton2Down:
2189
2190 Pop();
2191 break;
2192
2193 }
2194}
2195
2197 public:
2198
2201 Double_t px1old = 0, py1old = 0, px2old = 0, py2old = 0;
2202
2204 {
2205 Double_t zbx1 = pad.GetUxmin();
2206 Double_t zbx2 = pad.GetUxmax();
2207 Double_t zby1 = pad.GetUymin();
2208 Double_t zby2 = pad.GetUymax();
2209 if (axisNumber == 1) {
2210 zbx1 = px1old;
2211 zbx2 = px2old;
2212 } else {
2213 zby1 = py1old;
2214 zby2 = py2old;
2215 }
2216
2217 if (pad.OpaqueMoving()) {
2218 TAttLine{kBlack, 1, 1}.ModifyOn(pad);
2219 Double_t xx[4], yy[4];
2220
2221 if (axisNumber == 1) {
2222 xx[0] = xx[1] = zbx1;
2223 xx[2] = xx[3] = zbx2;
2224 yy[0] = yy[2] = zby1;
2225 yy[1] = yy[3] = zby2;
2226 } else {
2227 xx[0] = xx[2] = zbx1;
2228 xx[1] = xx[3] = zbx2;
2229 yy[0] = yy[1] = zby1;
2230 yy[2] = yy[3] = zby2;
2231 }
2232 pad.PaintPolyLine(2, xx, yy, "iaxiszoom1");
2233 pad.PaintPolyLine(2, xx+2, yy+2, "iaxiszoom2");
2234 } else {
2235 pad.PaintBox(zbx1, zby1, zbx2, zby2, "iaxiszoom");
2236 }
2237 pad.UpdateAsync();
2238 }
2239};
2240
2241
2242////////////////////////////////////////////////////////////////////////////////
2243/// Execute action corresponding to one event for a TAxis object
2244/// (called by TAxis::ExecuteEvent.)
2245/// This member function is called when an axis is clicked with the locator
2246///
2247/// The axis range is set between the position where the mouse is pressed
2248/// and the position where it is released.
2249///
2250/// If the mouse position is outside the current axis range when it is released
2251/// the axis is unzoomed with the corresponding proportions.
2252///
2253/// Note that the mouse does not need to be in the pad or even canvas
2254/// when it is released.
2255
2257{
2258 if (!IsEditable() || !axis)
2259 return;
2261
2262 TView *view = GetView();
2263
2264 // The CONT4 option, used to paint TH2, is a special case; it uses a 3D
2265 // drawing technique to paint a 2D plot.
2266 TString opt = axis->GetParent()->GetDrawOption();
2267 opt.ToLower();
2268 Bool_t kCont4 = kFALSE;
2269 if (strstr(opt,"cont4")) {
2270 view = nullptr;
2271 kCont4 = kTRUE;
2272 }
2273
2274 auto inter = dynamic_cast<TAxisInteractive *>(Interactive(axis));
2275
2276 switch (event) {
2277
2278 case kButton1Down:
2279 inter = new TAxisInteractive();
2280 Interactive(axis, inter);
2281
2282 inter->axisNumber = 1;
2283 if (!strcmp(axis->GetName(), "xaxis"))
2284 inter->axisNumber = IsVertical() ? 1 : 2;
2285 else if (!strcmp(axis->GetName(), "yaxis"))
2286 inter->axisNumber = IsVertical() ? 2 : 1;
2287 else if (!strcmp(axis->GetName(), "zaxis"))
2288 inter->axisNumber = 3;
2289 if (view) {
2290 view->GetDistancetoAxis(inter->axisNumber, px, py, inter->ratio1);
2291 } else if (inter->axisNumber == 1) {
2292 inter->ratio1 = (AbsPixeltoX(px) - GetUxmin()) / (GetUxmax() - GetUxmin());
2293 inter->px1old = GetUxmin() + inter->ratio1 * (GetUxmax() - GetUxmin());
2294 inter->py1old = GetUymin();
2295 inter->px2old = inter->px1old;
2296 inter->py2old = GetUymax();
2297 } else {
2298 inter->ratio1 = (AbsPixeltoY(py) - GetUymin()) / (GetUymax() - GetUymin());
2299 inter->px1old = GetUxmin();
2300 inter->py1old = GetUymin() + inter->ratio1 * (GetUymax() - GetUymin());
2301 inter->px2old = GetUxmax();
2302 inter->py2old = inter->py1old;
2303 }
2304 // No break !!!
2305
2306 case kButton1Motion:
2307 if (!inter)
2308 break;
2309 if (view) {
2310 view->GetDistancetoAxis(inter->axisNumber, px, py, inter->ratio2);
2311 } else if (inter->axisNumber == 1) {
2312 inter->ratio2 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
2313 inter->px2old = GetUxmin() + inter->ratio2 * (GetUxmax() - GetUxmin());
2314 } else {
2315 inter->ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
2316 inter->py2old = GetUymin() + inter->ratio2 * (GetUymax() - GetUymin());
2317 }
2318 inter->PaintZoomBox(*this);
2319 break;
2320
2321 case kWheelUp: {
2322 Int_t nbd = (axis->GetLast()-axis->GetFirst());
2323 Int_t inc = TMath::Max(nbd/100,1);
2324 Int_t bin1 = TMath::Max(1, axis->GetFirst() + inc);
2325 Int_t bin2 = TMath::Min(axis->GetNbins(), axis->GetLast() - inc);
2326 if (bin2 > bin1) {
2327 axis->SetRange(bin1, bin2);
2328 Modified();
2329 UpdateAsync();
2330 }
2331 break;
2332 }
2333
2334 case kWheelDown: {
2335 Int_t nbd = (axis->GetLast()-axis->GetFirst());
2336 Int_t inc = TMath::Max(nbd/100,1);
2337 Int_t bin1 = TMath::Max(1, axis->GetFirst()-inc);
2338 Int_t bin2 = TMath::Min(axis->GetNbins(), axis->GetLast()+inc);
2339 Bool_t resetAxisRange = (bin1 == 1 && axis->GetFirst() == 1 && bin2 == axis->GetNbins() && axis->GetLast() == axis->GetNbins());
2340 if (bin2 > bin1)
2341 axis->SetRange(bin1,bin2);
2342 if (resetAxisRange)
2344 if (bin2 > bin1) {
2345 Modified();
2346 UpdateAsync();
2347 }
2348 break;
2349 }
2350
2351 case kButton1Up:
2352 if (gROOT->IsEscaped()) {
2353 gROOT->SetEscape(kFALSE);
2354 break;
2355 }
2356
2357 if (view && inter) {
2358 view->GetDistancetoAxis(inter->axisNumber, px, py, inter->ratio2);
2359 if (inter->ratio1 > inter->ratio2)
2360 std::swap(inter->ratio1, inter->ratio2);
2361 if (inter->ratio2 - inter->ratio1 > 0.05) {
2362 auto hobj = static_cast<TH1 *>(axis->GetParent());
2363 if (inter->axisNumber == 3 && hobj && hobj->GetDimension() != 3) {
2364 Float_t zmin = hobj->GetMinimum();
2365 Float_t zmax = hobj->GetMaximum();
2366 if (GetLogz()) {
2367 if (zmin <= 0 && zmax > 0)
2368 zmin = TMath::Min((Double_t)1, (Double_t)0.001 * zmax);
2369 zmin = TMath::Log10(zmin);
2370 zmax = TMath::Log10(zmax);
2371 }
2372 Float_t newmin = zmin + (zmax - zmin) * inter->ratio1;
2373 Float_t newmax = zmin + (zmax - zmin) * inter->ratio2;
2374 if (newmin < zmin)
2375 newmin = hobj->GetBinContent(hobj->GetMinimumBin());
2376 if (newmax > zmax)
2377 newmax = hobj->GetBinContent(hobj->GetMaximumBin());
2378 if (GetLogz()){
2379 newmin = TMath::Exp(2.302585092994*newmin);
2380 newmax = TMath::Exp(2.302585092994*newmax);
2381 }
2382 hobj->SetMinimum(newmin);
2383 hobj->SetMaximum(newmax);
2384 hobj->SetBit(TH1::kIsZoomed);
2385 } else {
2386 Int_t first = axis->GetFirst();
2387 Int_t last = axis->GetLast();
2388 Int_t bin1 = TMath::Max(1, first + Int_t((last-first+1) * inter->ratio1));
2389 Int_t bin2 = TMath::Min(axis->GetNbins(), first + Int_t((last-first+1) * inter->ratio2));
2390 axis->SetRange(bin1, bin2);
2391 }
2392 delete view;
2393 SetView(nullptr);
2394 Modified();
2395 }
2396 } else if (inter) {
2398 if (inter->axisNumber == 1) {
2399 inter->ratio2 = (AbsPixeltoX(px) - GetUxmin()) / (GetUxmax() - GetUxmin());
2400 xmin = GetUxmin() + inter->ratio1 * (GetUxmax() - GetUxmin());
2401 xmax = GetUxmin() + inter->ratio2 * (GetUxmax() - GetUxmin());
2402 if (GetLogx() && !kCont4) {
2403 xmin = PadtoX(xmin);
2404 xmax = PadtoX(xmax);
2405 }
2406 } else if (inter->axisNumber == 2) {
2407 inter->ratio2 = (AbsPixeltoY(py) - GetUymin()) / (GetUymax() - GetUymin());
2408 xmin = GetUymin() + inter->ratio1 * (GetUymax() - GetUymin());
2409 xmax = GetUymin() + inter->ratio2 * (GetUymax() - GetUymin());
2410 if (GetLogy() && !kCont4) {
2411 xmin = PadtoY(xmin);
2412 xmax = PadtoY(xmax);
2413 }
2414 } else {
2415 inter->ratio2 = (AbsPixeltoY(py) - GetUymin()) / (GetUymax() - GetUymin());
2416 xmin = inter->ratio1;
2417 xmax = inter->ratio2;
2418 }
2419 if (xmin > xmax) {
2420 std::swap(xmin, xmax);
2421 std::swap(inter->ratio1, inter->ratio2);
2422 }
2423
2424 // xmin and xmax need to be adjusted in case of CONT4.
2425 if (kCont4) {
2426 Double_t low = axis->GetBinLowEdge(axis->GetFirst());
2427 Double_t up = axis->GetBinUpEdge(axis->GetLast());
2428 Double_t xmi = GetUxmin();
2429 Double_t xma = GetUxmax();
2430 xmin = ((xmin - xmi) / (xma - xmi)) * (up - low) + low;
2431 xmax = ((xmax - xmi) / (xma - xmi)) * (up - low) + low;
2432 }
2433
2434 if (!strcmp(axis->GetName(),"xaxis"))
2435 inter->axisNumber = 1;
2436 if (!strcmp(axis->GetName(),"yaxis"))
2437 inter->axisNumber = 2;
2438 if (inter->ratio2 - inter->ratio1 > 0.05) {
2439 //update object owning this axis
2440 TH1 *hobj1 = static_cast<TH1 *>(axis->GetParent());
2441 Int_t bin1 = TMath::Max(1, axis->FindFixBin(xmin));
2442 Int_t bin2 = TMath::Min(axis->GetNbins(), axis->FindFixBin(xmax));
2443 if (inter->axisNumber == 1)
2444 axis->SetRange(bin1,bin2);
2445 if (inter->axisNumber == 2 && hobj1) {
2446 if (hobj1->GetDimension() == 1) {
2447 if (hobj1->GetNormFactor() != 0) {
2448 Double_t norm = hobj1->GetSumOfWeights()/hobj1->GetNormFactor();
2449 xmin *= norm;
2450 xmax *= norm;
2451 }
2452 hobj1->SetMinimum(xmin);
2453 hobj1->SetMaximum(xmax);
2454 hobj1->SetBit(TH1::kIsZoomed);
2455 } else {
2456 axis->SetRange(bin1,bin2);
2457 }
2458 }
2459 //update all histograms in the pad
2460 TIter next(GetListOfPrimitives());
2461 while (auto obj = next()) {
2462 if (auto hobj = dynamic_cast<TH1 *> (obj)) {
2463 if (hobj == hobj1)
2464 continue;
2465 bin1 = hobj->GetXaxis()->FindFixBin(xmin);
2466 bin2 = hobj->GetXaxis()->FindFixBin(xmax);
2467 if (inter->axisNumber == 1) {
2468 hobj->GetXaxis()->SetRange(bin1,bin2);
2469 } else if (inter->axisNumber == 2) {
2470 if (hobj->GetDimension() == 1) {
2471 Double_t xxmin = xmin;
2472 Double_t xxmax = xmax;
2473 if (hobj->GetNormFactor() != 0) {
2474 Double_t norm = hobj->GetSumOfWeights()/hobj->GetNormFactor();
2475 xxmin *= norm;
2476 xxmax *= norm;
2477 }
2478 hobj->SetMinimum(xxmin);
2479 hobj->SetMaximum(xxmax);
2480 hobj->SetBit(TH1::kIsZoomed);
2481 } else {
2482 bin1 = hobj->GetYaxis()->FindFixBin(xmin);
2483 bin2 = hobj->GetYaxis()->FindFixBin(xmax);
2484 hobj->GetYaxis()->SetRange(bin1,bin2);
2485 }
2486 }
2487 }
2488 }
2489 Modified();
2490 }
2491 }
2492 Interactive(); // remove interactive object
2493 break;
2494 }
2495}
2496
2497////////////////////////////////////////////////////////////////////////////////
2498/// Switch feedback mode for the canvas
2499/// Only for internal use when implementing special painters
2500
2502{
2503 if (fCanvas)
2504 fCanvas->FeedbackMode(set);
2505}
2506
2507////////////////////////////////////////////////////////////////////////////////
2508/// Search if object named name is inside this pad or in pads inside this pad.
2509///
2510/// In case name is in several sub-pads the first one is returned.
2511
2512TObject *TPad::FindObject(const char *name) const
2513{
2514 if (!fPrimitives) return nullptr;
2516 if (found) return found;
2517 TIter next(GetListOfPrimitives());
2518 while (auto cur = next()) {
2519 if (cur->InheritsFrom(TPad::Class())) {
2520 found = ((TPad*)cur)->FindObject(name);
2521 if (found) return found;
2522 }
2523 }
2524 return nullptr;
2525}
2526
2527////////////////////////////////////////////////////////////////////////////////
2528/// Search if obj is in pad or in pads inside this pad.
2529///
2530/// In case obj is in several sub-pads the first one is returned.
2531
2533{
2534 if (!fPrimitives) return nullptr;
2535 TObject *found = fPrimitives->FindObject(obj);
2536 if (found) return found;
2537 TIter next(GetListOfPrimitives());
2538 while (auto cur = next()) {
2539 if (cur->InheritsFrom(TPad::Class())) {
2540 found = ((TPad*)cur)->FindObject(obj);
2541 if (found) return found;
2542 }
2543 }
2544 return nullptr;
2545}
2546
2547////////////////////////////////////////////////////////////////////////////////
2548/// Get canvas identifier.
2549
2551{
2552 return fCanvas ? fCanvas->GetCanvasID() : -1;
2553}
2554
2555////////////////////////////////////////////////////////////////////////////////
2556/// Get canvas implementation pointer if any
2557
2559{
2560 return fCanvas ? fCanvas->GetCanvasImp() : nullptr;
2561}
2562
2563////////////////////////////////////////////////////////////////////////////////
2564/// Get Event.
2565
2567{
2568 return fCanvas ? fCanvas->GetEvent() : 0;
2569}
2570
2571////////////////////////////////////////////////////////////////////////////////
2572/// Get X event.
2573
2575{
2576 return fCanvas ? fCanvas->GetEventX() : 0;
2577}
2578
2579////////////////////////////////////////////////////////////////////////////////
2580/// Get Y event.
2581
2583{
2584 return fCanvas ? fCanvas->GetEventY() : 0;
2585}
2586
2587////////////////////////////////////////////////////////////////////////////////
2588/// Get virtual canvas.
2589
2591{
2592 return fCanvas ? (TVirtualPad*) fCanvas : nullptr;
2593}
2594
2595////////////////////////////////////////////////////////////////////////////////
2596/// Get doublebuffer mode - 1 by default.
2597
2599{
2600 return fCanvas ? fCanvas->GetDoubleBuffer() : 1;
2601}
2602
2603////////////////////////////////////////////////////////////////////////////////
2604/// Get highlight color.
2605
2607{
2608 return fCanvas ? fCanvas->GetHighLightColor() : 0;
2609}
2610
2611////////////////////////////////////////////////////////////////////////////////
2612/// Static function (see also TPad::SetMaxPickDistance)
2613
2618
2619////////////////////////////////////////////////////////////////////////////////
2620/// Get selected.
2621
2623{
2624 if (fCanvas == this) return nullptr;
2625 return fCanvas ? fCanvas->GetSelected() : nullptr;
2626}
2627
2628////////////////////////////////////////////////////////////////////////////////
2629/// Get selected pad.
2630
2632{
2633 if (fCanvas == this) return nullptr;
2634 return fCanvas ? fCanvas->GetSelectedPad() : nullptr;
2635}
2636
2637////////////////////////////////////////////////////////////////////////////////
2638/// Get save pad.
2639
2641{
2642 if (fCanvas == this) return nullptr;
2643 return fCanvas ? fCanvas->GetPadSave() : nullptr;
2644}
2645
2646////////////////////////////////////////////////////////////////////////////////
2647/// Get canvas height
2648
2650{
2651 return fCanvas ? fCanvas->GetWh() : 0;
2652}
2653
2654////////////////////////////////////////////////////////////////////////////////
2655/// Get canvas width
2656
2658{
2659 return fCanvas ? fCanvas->GetWw() : 0;
2660}
2661
2662////////////////////////////////////////////////////////////////////////////////
2663/// Get pad width
2664
2666{
2667 // Very often pad width was calculated as XtoPixel(GetX2());
2668 // But if coordinate system broken such transformation fail.
2669 // Therefore use canvas width multiplied by absolute NDC width value
2670 // Keep fallback solution only when canvas width cannot be defined
2671
2672 auto cw = GetWw();
2673 if (!cw)
2674 return XtoPixel(GetX2());
2675
2676 return static_cast<UInt_t>(std::lround(cw * GetAbsWNDC()));
2677}
2678
2679////////////////////////////////////////////////////////////////////////////////
2680/// Get pad height
2681
2683{
2684 // Very often pad height was calculated as YtoPixel(GetY1())
2685 // But if coordinate system broken such transformation fail.
2686 // Therefore use canvas height multiplied by absolute NDC height value
2687 // Keep fallback solution only when canvas height cannot be defined
2688
2689 auto ch = GetWh();
2690 if (!ch)
2691 return YtoPixel(GetY1());
2692
2693 return static_cast<UInt_t>(std::lround(GetWh() * GetAbsHNDC()));
2694}
2695
2696////////////////////////////////////////////////////////////////////////////////
2697/// Hide tool tip depending on the event type. Typically tool tips
2698/// are hidden when event is not a kMouseEnter and not a kMouseMotion
2699/// event.
2700
2702{
2703 if (event != kMouseEnter && event != kMouseMotion && fTip)
2704 gPad->CloseToolTip(fTip);
2705}
2706
2707////////////////////////////////////////////////////////////////////////////////
2708/// Check if pad or any subpads need to be repaint
2709/// Returns flag with following mask:
2710/// 1 - some pad is modified
2711/// 2 - some pad is transparent (also trigger repaint in modified)
2712/// 4 - some pad has interactive XOR draw operations
2713
2715{
2716 Int_t mask = IsModified() ? 1 : 0;
2717 if (IsTransparent())
2718 mask |= 2;
2719 if (fDrawOper.size())
2720 mask |= 4;
2721
2722 TIter next(GetListOfPrimitives());
2723 while (auto obj = next())
2724 if (auto p = dynamic_cast<TPad *>(obj))
2725 mask |= p->IsAnyNeedRepaint();
2726
2727 return mask;
2728}
2729
2730////////////////////////////////////////////////////////////////////////////////
2731/// Is pad in batch mode ?
2732
2734{
2735 return fCanvas ? fCanvas->IsBatch() : kFALSE;
2736}
2737
2738////////////////////////////////////////////////////////////////////////////////
2739/// Is pad retained ?
2740
2742{
2743 return fCanvas ? fCanvas->IsRetained() : kFALSE;
2744}
2745
2746////////////////////////////////////////////////////////////////////////////////
2747/// Is web ?
2749{
2750 return fCanvas ? fCanvas->IsWeb() : kFALSE;
2751}
2752
2753////////////////////////////////////////////////////////////////////////////////
2754/// Is pad moving in opaque mode ?
2755
2757{
2758 return fCanvas ? fCanvas->OpaqueMoving() : kFALSE;
2759}
2760
2761////////////////////////////////////////////////////////////////////////////////
2762/// Is pad resizing in opaque mode ?
2763
2765{
2766 return fCanvas ? fCanvas->OpaqueResizing() : kFALSE;
2767}
2768
2769////////////////////////////////////////////////////////////////////////////////
2770/// Set pad in batch mode.
2771
2773{
2774 if (fCanvas) fCanvas->SetBatch(batch);
2775}
2776
2777////////////////////////////////////////////////////////////////////////////////
2778/// Set canvas size.
2779
2781{
2782 if (fCanvas) fCanvas->SetCanvasSize(ww,wh);
2783}
2784
2785////////////////////////////////////////////////////////////////////////////////
2786/// Set cursor type.
2787
2792
2793////////////////////////////////////////////////////////////////////////////////
2794/// Set double buffer mode ON or OFF.
2795
2800
2801////////////////////////////////////////////////////////////////////////////////
2802/// Set selected.
2803
2805{
2806 if (fCanvas) fCanvas->SetSelected(obj);
2807}
2808
2809////////////////////////////////////////////////////////////////////////////////
2810/// Update pad.
2811
2813{
2814 if (fCanvas) fCanvas->Update();
2815}
2816
2817////////////////////////////////////////////////////////////////////////////////
2818/// Asynchronous pad update.
2819/// In case of web-based canvas triggers update of the canvas on the client side,
2820/// but does not wait that real update is completed. Avoids blocking of caller thread.
2821/// Have to be used if called from other web-based widget to avoid logical dead-locks.
2822/// In case of normal canvas just canvas->Update() is performed.
2823
2825{
2826 if (fCanvas) fCanvas->UpdateAsync();
2827}
2828
2829////////////////////////////////////////////////////////////////////////////////
2830/// Get frame.
2831
2833{
2834 if (!fPrimitives) fPrimitives = new TList;
2836 if (!frame) frame = (TFrame*)GetListOfPrimitives()->FindObject("TFrame");
2837 fFrame = frame;
2838 if (!fFrame) {
2839 if (!frame) fFrame = new TFrame(0,0,1,1);
2840 Int_t framecolor = GetFrameFillColor();
2841 if (!framecolor) framecolor = GetFillColor();
2842 fFrame->SetFillColor(framecolor);
2849 } else {
2850 // Preexisting and now assigned to fFrame, let's make sure it is not
2851 // deleted twice (the bit might have been set in TPad::Streamer)
2853 }
2854 return fFrame;
2855}
2856
2857////////////////////////////////////////////////////////////////////////////////
2858/// Get primitive.
2859
2861{
2862 if (!fPrimitives) return nullptr;
2863 TIter next(fPrimitives);
2864 TObject *found, *obj;
2865 while ((obj=next())) {
2866 if (!strcmp(name, obj->GetName())) return obj;
2867 if (obj->InheritsFrom(TPad::Class())) continue;
2868 found = obj->FindObject(name);
2869 if (found) return found;
2870 }
2871 return nullptr;
2872}
2873
2874////////////////////////////////////////////////////////////////////////////////
2875/// Get a pointer to subpadnumber of this pad.
2876
2877TVirtualPad *TPad::GetPad(Int_t subpadnumber) const
2878{
2879 if (!subpadnumber) {
2880 return (TVirtualPad*)this;
2881 }
2882
2883 TObject *obj;
2884 if (!fPrimitives) return nullptr;
2885 TIter next(GetListOfPrimitives());
2886 while ((obj = next())) {
2887 if (obj->InheritsFrom(TVirtualPad::Class())) {
2888 TVirtualPad *pad = (TVirtualPad*)obj;
2889 if (pad->GetNumber() == subpadnumber) return pad;
2890 }
2891 }
2892 return nullptr;
2893}
2894
2895////////////////////////////////////////////////////////////////////////////////
2896/// Return lower and upper bounds of the pad in NDC coordinates.
2897
2898void TPad::GetPadPar(Double_t &xlow, Double_t &ylow, Double_t &xup, Double_t &yup)
2899{
2900 xlow = fXlowNDC;
2901 ylow = fYlowNDC;
2902 xup = fXlowNDC+fWNDC;
2903 yup = fYlowNDC+fHNDC;
2904}
2905
2906////////////////////////////////////////////////////////////////////////////////
2907/// Return pad world coordinates range.
2908
2910{
2911 x1 = fX1;
2912 y1 = fY1;
2913 x2 = fX2;
2914 y2 = fY2;
2915}
2916
2917////////////////////////////////////////////////////////////////////////////////
2918/// Return pad axis coordinates range.
2919
2921{
2922 xmin = fUxmin;
2923 ymin = fUymin;
2924 xmax = fUxmax;
2925 ymax = fUymax;
2926}
2927
2928////////////////////////////////////////////////////////////////////////////////
2929/// Highlight pad.
2930/// do not highlight when printing on Postscript
2931
2933{
2934 if (auto pp = GetPainter())
2935 if(!pp->IsNative())
2936 return;
2937
2938 if (color <= 0)
2939 return;
2940
2942
2943 // We do not want to have active(executable) buttons, etc highlighted
2944 // in this manner, unless we want to edit'em
2946 //When doing a DrawClone from the GUI you would do
2947 // - select an empty pad -
2948 // - right click on object -
2949 // - select DrawClone on menu -
2950 //
2951 // Without the SetSelectedPad(); in the HighLight function, the
2952 // above instruction lead to the clone to be drawn in the
2953 // same canvas as the original object. This is because the
2954 // 'right clicking' (via TCanvas::HandleInput) changes gPad
2955 // momentarily such that when DrawClone is called, it is
2956 // not the right value (for DrawClone). Should be FIXED.
2957 gROOT->SetSelectedPad(this);
2958 if (GetBorderMode() > 0)
2959 PaintBorder(set ? -color : -GetFillColor(), kFALSE);
2960 }
2961
2963}
2964
2965////////////////////////////////////////////////////////////////////////////////
2966/// List all primitives in pad.
2967
2969{
2971 std::cout <<IsA()->GetName()<<" fXlowNDC=" <<fXlowNDC<<" fYlowNDC="<<fYlowNDC<<" fWNDC="<<GetWNDC()<<" fHNDC="<<GetHNDC()
2972 <<" Name= "<<GetName()<<" Title= "<<GetTitle()<<" Option="<<option<<std::endl;
2974 if (!fPrimitives) return;
2977}
2978
2979////////////////////////////////////////////////////////////////////////////////
2980/// Internal method to create, provide or delete TInteractive instance
2981/// It is allowed the only instance of TInteractive object per pad
2982/// It can be assigned for the object when @param init is provided
2983/// Otherwise returns existing instance for the @param obj
2984/// If none of parameters are specified - existing instance will be deleted
2985
2987{
2988 if (obj && init) {
2989 init->SetObject(obj);
2990 fInteractive.reset(init);
2991 } else if (!obj)
2992 fInteractive.reset(nullptr);
2993
2994 if (!fInteractive || (fInteractive->GetObject() != obj))
2995 return nullptr;
2996
2997 return fInteractive.get();
2998}
2999
3000
3001////////////////////////////////////////////////////////////////////////////////
3002/// Increment (i==1) or set (i>1) the number of autocolor in the pad.
3003
3005{
3006 TString opt1 = opt;
3007 opt1.ToLower();
3008
3009 if (opt1.Contains("pfc") || opt1.Contains("plc") || opt1.Contains("pmc")) {
3010 if (i == 1) fNumPaletteColor++;
3011 else fNumPaletteColor = i;
3012 return fNumPaletteColor;
3013 }
3014
3015 return 0;
3016}
3017
3018////////////////////////////////////////////////////////////////////////////////
3019/// Get the next autocolor in the pad.
3020
3022{
3023 Int_t i = 0;
3024 Int_t ncolors = gStyle->GetNumberOfColors();
3025 if (fNumPaletteColor>1) {
3026 i = fNextPaletteColor*(ncolors/(fNumPaletteColor-1));
3027 if (i>=ncolors) i = ncolors-1;
3028 }
3031 return gStyle->GetColorPalette(i);
3032}
3033
3034////////////////////////////////////////////////////////////////////////////////
3035/// Initialise the grid used to find empty space when adding a box (Legend) in a pad
3036
3038{
3039 Int_t const cellSize = 10; // Size of an individual grid cell in pixels.
3040
3041 fCGnx = GetWw()/cellSize;
3042 fCGny = GetWh()/cellSize;
3043
3044 // Initialise the collide grid
3045 fCollideGrid.resize(fCGnx*fCGny);
3046 for (int i = 0; i < fCGnx; i++)
3047 for (int j = 0; j < fCGny; j++)
3048 fCollideGrid[i + j * fCGnx] = kTRUE;
3049
3050 // Fill the collide grid
3051 TIter iter(GetListOfPrimitives());
3052
3053 while(auto o = iter()) {
3054 if (o == oi)
3055 continue;
3056 if (o->InheritsFrom(TFrame::Class()))
3058 else if (o->InheritsFrom(TBox::Class()))
3060 else if (o->InheritsFrom(TH1::Class()))
3062 else if (o->InheritsFrom(TGraph::Class()))
3064 else if (o->InheritsFrom(TMultiGraph::Class())) {
3065 TIter nextgraph(((TMultiGraph *)o)->GetListOfGraphs());
3066 while (auto og = nextgraph())
3068 } else if (o->InheritsFrom(THStack::Class())) {
3069 TIter nexthist(((THStack *)o)->GetHists());
3070 while (auto oh = nexthist()) {
3071 if (oh->InheritsFrom(TH1::Class()))
3073 }
3074 }
3075 }
3076}
3077
3078////////////////////////////////////////////////////////////////////////////////
3079/// Check if a box of size w and h collide some primitives in the pad at
3080/// position i,j
3081
3083{
3084 for (int r = i; r < w + i; r++) {
3085 for (int c = j; c < h + j; c++) {
3086 if (!fCollideGrid[r + c * fCGnx])
3087 return kTRUE;
3088 }
3089 }
3090 return kFALSE;
3091}
3092
3093////////////////////////////////////////////////////////////////////////////////
3094/// Place a box in NDC space
3095///
3096/// \return `true` if the box could be placed, `false` if not.
3097///
3098/// \param[in] o pointer to the box to be placed
3099/// \param[in] w box width to be placed
3100/// \param[in] h box height to be placed
3101/// \param[out] xl x position of the bottom left corner of the placed box
3102/// \param[out] yb y position of the bottom left corner of the placed box
3103/// \param[in] option l=left, r=right, t=top, b=bottom, w=within margins. Order determines
3104/// priority for placement. Default is "lb" (prioritises horizontal over vertical)
3105
3107{
3108 FillCollideGrid(o);
3109
3110 Int_t iw = (int)(fCGnx*w);
3111 Int_t ih = (int)(fCGny*h);
3112
3113 Int_t nxbeg = 0;
3114 Int_t nybeg = 0;
3115 Int_t nxend = fCGnx-iw-1;
3116 Int_t nyend = fCGny-ih-1;
3117 Int_t dx = 1;
3118 Int_t dy = 1;
3119
3120 bool isFirstVertical = false;
3121 bool isFirstHorizontal = false;
3122
3123 for (std::size_t i = 0; option[i] != '\0'; ++i) {
3124 char letter = std::tolower(option[i]);
3125 if (letter == 'w') {
3126 nxbeg += fCGnx*GetLeftMargin();
3127 nybeg += fCGny*GetBottomMargin();
3128 nxend -= fCGnx*GetRightMargin();
3129 nyend -= fCGny*GetTopMargin();
3130 } else if (letter == 't' || letter == 'b') {
3131 isFirstVertical = !isFirstHorizontal;
3132 // go from top to bottom instead of bottom to top
3133 dy = letter == 't' ? -1 : 1;
3134 } else if (letter == 'l' || letter == 'r') {
3135 isFirstHorizontal = !isFirstVertical;
3136 // go from right to left instead of left to right
3137 dx = letter == 'r' ? -1 : 1;
3138 }
3139 }
3140
3141 if(dx < 0) std::swap(nxbeg, nxend);
3142 if(dy < 0) std::swap(nybeg, nyend);
3143
3144 auto attemptPlacement = [&](Int_t i, Int_t j) {
3145 if (Collide(i, j, iw, ih)) {
3146 return false;
3147 } else {
3148 xl = (Double_t)(i) / (Double_t)(fCGnx);
3149 yb = (Double_t)(j) / (Double_t)(fCGny);
3150 return true;
3151 }
3152 };
3153
3154 if(!isFirstVertical) {
3155 for (Int_t i = nxbeg; i != nxend; i += dx) {
3156 for (Int_t j = nybeg; j != nyend; j += dy) {
3157 if (attemptPlacement(i, j)) return true;
3158 }
3159 }
3160 } else {
3161 // prioritizing vertical over horizontal
3162 for (Int_t j = nybeg; j != nyend; j += dy) {
3163 for (Int_t i = nxbeg; i != nxend; i += dx) {
3164 if (attemptPlacement(i, j)) return true;
3165 }
3166 }
3167 }
3168
3169 return kFALSE;
3170}
3171
3172// Set the specific cell element in the grid to false, clamp to (fCGnx*fCGny) - 1 to avoid going out of bounds
3173#define NotFree(i, j) fCollideGrid[TMath::Max(TMath::Min(i + j * fCGnx, (fCGnx * fCGny) - 1), 0)] = kFALSE;
3174
3175////////////////////////////////////////////////////////////////////////////////
3176/// Mark as "not free" the cells along a line.
3177
3179{
3180 NotFree(x1, y1);
3181 NotFree(x2, y2);
3182 Int_t i, j, xt, yt;
3183
3184 // horizontal lines
3185 if (y1==y2) {
3186 for (i=x1+1; i<x2; i++) NotFree(i,y1);
3187 return;
3188 }
3189
3190 // vertical lines
3191 if (x1==x2) {
3192 for (i=y1+1; i<y2; i++) NotFree(x1,i);
3193 return;
3194 }
3195
3196 // other lines
3197 if (TMath::Abs(x2-x1)>TMath::Abs(y2-y1)) {
3198 if (x1>x2) {
3199 xt = x1; x1 = x2; x2 = xt;
3200 yt = y1; y1 = y2; y2 = yt;
3201 }
3202 for (i=x1+1; i<x2; i++) {
3203 j = (Int_t)((Double_t)(y2-y1)*(Double_t)((i-x1)/(Double_t)(x2-x1))+y1);
3204 NotFree(i,j);
3205 NotFree(i,(j+1));
3206 }
3207 } else {
3208 if (y1>y2) {
3209 yt = y1; y1 = y2; y2 = yt;
3210 xt = x1; x1 = x2; x2 = xt;
3211 }
3212 for (j=y1+1; j<y2; j++) {
3213 i = (Int_t)((Double_t)(x2-x1)*(Double_t)((j-y1)/(Double_t)(y2-y1))+x1);
3214 NotFree(i,j);
3215 NotFree((i+1),j);
3216 }
3217 }
3218}
3219
3220////////////////////////////////////////////////////////////////////////////////
3222{
3223 TBox *b = (TBox *)o;
3224 if (fCGnx==0||fCGny==0) return;
3225 Double_t xs = (fX2-fX1)/fCGnx;
3226 Double_t ys = (fY2-fY1)/fCGny;
3227
3228 Int_t x1 = (Int_t)((b->GetX1()-fX1)/xs);
3229 Int_t x2 = (Int_t)((b->GetX2()-fX1)/xs);
3230 Int_t y1 = (Int_t)((b->GetY1()-fY1)/ys);
3231 Int_t y2 = (Int_t)((b->GetY2()-fY1)/ys);
3232 for (int i = x1; i<=x2; i++) {
3233 for (int j = y1; j<=y2; j++) NotFree(i, j);
3234 }
3235}
3236
3237////////////////////////////////////////////////////////////////////////////////
3239{
3240 TFrame *f = (TFrame *)o;
3241 if (fCGnx==0||fCGny==0) return;
3242 Double_t xs = (fX2-fX1)/fCGnx;
3243 Double_t ys = (fY2-fY1)/fCGny;
3244
3245 Int_t x1 = (Int_t)((f->GetX1()-fX1)/xs);
3246 Int_t x2 = (Int_t)((f->GetX2()-fX1)/xs);
3247 Int_t y1 = (Int_t)((f->GetY1()-fY1)/ys);
3248 Int_t y2 = (Int_t)((f->GetY2()-fY1)/ys);
3249 Int_t i;
3250
3251 for (i = x1; i<=x2; i++) {
3252 NotFree(i, y1);
3253 NotFree(i, (y1-1));
3254 NotFree(i, (y1-2));
3255 }
3256 for (i = y1; i<=y2; i++) {
3257 NotFree(x1, i);
3258 NotFree((x1-1), i);
3259 NotFree((x1-2), i);
3260 }
3261}
3262
3263////////////////////////////////////////////////////////////////////////////////
3265{
3266 TGraph *g = (TGraph *)o;
3267 if (fCGnx==0||fCGny==0) return;
3268 Double_t xs = (fX2-fX1)/fCGnx;
3269 Double_t ys = (fY2-fY1)/fCGny;
3270
3271 Int_t n = g->GetN();
3272 Int_t s = TMath::Max(n/10,1);
3273 Double_t x1, x2, y1, y2;
3274 for (Int_t i=s; i<n; i=i+s) {
3275 g->GetPoint(TMath::Max(0,i-s),x1,y1);
3276 g->GetPoint(i ,x2,y2);
3277 if (fLogx) {
3278 if (x1 > 0) x1 = TMath::Log10(x1);
3279 else x1 = fUxmin;
3280 if (x2 > 0) x2 = TMath::Log10(x2);
3281 else x2 = fUxmin;
3282 }
3283 if (fLogy) {
3284 if (y1 > 0) y1 = TMath::Log10(y1);
3285 else y1 = fUymin;
3286 if (y2 > 0) y2 = TMath::Log10(y2);
3287 else y2 = fUymin;
3288 }
3289 LineNotFree((int)((x1-fX1)/xs), (int)((x2-fX1)/xs),
3290 (int)((y1-fY1)/ys), (int)((y2-fY1)/ys));
3291 }
3292}
3293
3294////////////////////////////////////////////////////////////////////////////////
3296{
3297 TH1 *h = (TH1 *)o;
3298 if (fCGnx==0||fCGny==0) return;
3299 if (o->InheritsFrom(TH2::Class())) return;
3300 if (o->InheritsFrom(TH3::Class())) return;
3301
3302 TString name = h->GetName();
3303 if (name.Index("hframe") >= 0) return;
3304
3305 Double_t xs = (fX2-fX1)/fCGnx;
3306 Double_t ys = (fY2-fY1)/fCGny;
3307
3308 bool haserrors = false;
3309 TString drawOption = h->GetDrawOption();
3310 drawOption.ToLower();
3311 drawOption.ReplaceAll("same","");
3312
3313 if (drawOption.Index("hist") < 0) {
3314 if (drawOption.Index("e") >= 0) haserrors = true;
3315 }
3316
3317 Int_t nx = h->GetNbinsX();
3318 Int_t x1, y1, y2;
3319 Int_t i, j;
3320 Double_t x1l, y1l, y2l;
3321
3322 for (i = 1; i<nx; i++) {
3323 if (haserrors) {
3324 x1l = h->GetBinCenter(i);
3325 if (fLogx) {
3326 if (x1l > 0) x1l = TMath::Log10(x1l);
3327 else x1l = fUxmin;
3328 }
3329 x1 = (Int_t)((x1l-fX1)/xs);
3330 y1l = h->GetBinContent(i)-h->GetBinErrorLow(i);
3331 if (fLogy) {
3332 if (y1l > 0) y1l = TMath::Log10(y1l);
3333 else y1l = fUymin;
3334 }
3335 y1 = (Int_t)((y1l-fY1)/ys);
3336 y2l = h->GetBinContent(i)+h->GetBinErrorUp(i);
3337 if (fLogy) {
3338 if (y2l > 0) y2l = TMath::Log10(y2l);
3339 else y2l = fUymin;
3340 }
3341 y2 = (Int_t)((y2l-fY1)/ys);
3342 for (j=y1; j<y2; j++) {
3343 NotFree(x1, j);
3344 }
3345 }
3346 x1l = h->GetBinLowEdge(i);
3347 if (fLogx) {
3348 if (x1l > 0) x1l = TMath::Log10(x1l);
3349 else x1l = fUxmin;
3350 }
3351 x1 = (Int_t)((x1l-fX1)/xs);
3352 y1l = h->GetBinContent(i);
3353 if (fLogy) {
3354 if (y1l > 0) y1l = TMath::Log10(y1l);
3355 else y1l = fUymin;
3356 }
3357 y1 = (Int_t)((y1l-fY1)/ys);
3358 NotFree(x1, y1);
3359 x1l = h->GetBinLowEdge(i)+h->GetBinWidth(i);
3360 if (fLogx) {
3361 if (x1l > 0) x1l = TMath::Log10(x1l);
3362 else x1l = fUxmin;
3363 }
3364 x1 = (int)((x1l-fX1)/xs);
3365 NotFree(x1, y1);
3366 }
3367
3368 // Extra objects in the list of function
3369 TPaveStats *ps = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
3370 if (ps) FillCollideGridTBox(ps);
3371}
3372
3373////////////////////////////////////////////////////////////////////////////////
3374/// This method draws the collide grid on top of the canvas. This is used for
3375/// debugging only. At some point it will be removed.
3376
3378{
3379 if (fCGnx==0||fCGny==0) return;
3380
3381 TContext ctxt(this, kTRUE);
3382
3383 TBox box;
3384 box.SetFillColorAlpha(kRed,0.5);
3385
3386 Double_t xs = (fX2-fX1)/fCGnx;
3387 Double_t ys = (fY2-fY1)/fCGny;
3388
3389 Double_t X1L, X2L, Y1L, Y2L;
3390 Double_t t = 0.15;
3391 Double_t Y1, Y2;
3392 Double_t X1 = fX1;
3393 Double_t X2 = X1+xs;
3394
3395 for (int i = 0; i<fCGnx; i++) {
3396 Y1 = fY1;
3397 Y2 = Y1+ys;
3398 for (int j = 0; j<fCGny; j++) {
3399 if (GetLogx()) {
3400 X1L = TMath::Power(10,X1);
3401 X2L = TMath::Power(10,X2);
3402 } else {
3403 X1L = X1;
3404 X2L = X2;
3405 }
3406 if (GetLogy()) {
3407 Y1L = TMath::Power(10,Y1);
3408 Y2L = TMath::Power(10,Y2);
3409 } else {
3410 Y1L = Y1;
3411 Y2L = Y2;
3412 }
3413 if (!fCollideGrid[i + j*fCGnx]) {
3414 box.SetFillColorAlpha(kBlack,t);
3415 box.DrawBox(X1L, Y1L, X2L, Y2L);
3416 } else {
3417 box.SetFillColorAlpha(kRed,t);
3418 box.DrawBox(X1L, Y1L, X2L, Y2L);
3419 }
3420 Y1 = Y2;
3421 Y2 = Y1+ys;
3422 if (t==0.15) t = 0.1;
3423 else t = 0.15;
3424 }
3425 X1 = X2;
3426 X2 = X1+xs;
3427 }
3428}
3429
3430////////////////////////////////////////////////////////////////////////////////
3431/// Short cut to call Modified() and Update() in a single call.
3432/// On Mac with Cocoa, it performs an additional ProcessEvents().
3433
3435{
3436 Modified();
3437 Update();
3438#ifdef R__HAS_COCOA
3440#endif
3441}
3442
3443////////////////////////////////////////////////////////////////////////////////
3444/// Convert x from pad to X.
3445
3447{
3448 if (fLogx && x < 50) return Double_t(TMath::Exp(2.302585092994*x));
3449 return x;
3450}
3451
3452////////////////////////////////////////////////////////////////////////////////
3453/// Convert y from pad to Y.
3454
3456{
3457 if (fLogy && y < 50) return Double_t(TMath::Exp(2.302585092994*y));
3458 return y;
3459}
3460
3461////////////////////////////////////////////////////////////////////////////////
3462/// Convert x from X to pad.
3463
3465{
3466 if (fLogx) {
3467 if (x > 0) x = TMath::Log10(x);
3468 else x = fUxmin;
3469 }
3470 return x;
3471}
3472
3473////////////////////////////////////////////////////////////////////////////////
3474/// Convert y from Y to pad.
3475
3477{
3478 if (fLogy) {
3479 if (y > 0) y = TMath::Log10(y);
3480 else y = fUymin;
3481 }
3482 return y;
3483}
3484
3485////////////////////////////////////////////////////////////////////////////////
3486/// Paint all primitives in pad.
3487
3488void TPad::Paint(Option_t * /* option */)
3489{
3490 if (!fPrimitives)
3491 fPrimitives = new TList;
3493 fViewer3D->PadPaint(this);
3495 if (GetGLDevice()!=-1 && gVirtualPS) {
3496 TContext ctxt(this, kFALSE);
3497 if (gGLManager) gGLManager->PrintViewer(GetViewer3D());
3498 }
3499 return;
3500 }
3501
3502 TVirtualPadPainter *oldpp = nullptr;
3503 Bool_t replace_pp = kFALSE;
3504
3505 if (fCanvas) {
3506 // check if special PS painter should be assigned to TCanvas
3507 replace_pp = fCanvas->EnsurePSPainter(kTRUE, oldpp);
3509 }
3510
3511 Bool_t began3DScene = kFALSE;
3512 fPadPaint = 1;
3513
3514 {
3515 TContext ctxt(this, kTRUE);
3516
3517 fDrawOperXor.clear();
3519 PaintDate();
3520
3521 auto lnk = GetListOfPrimitives()->FirstLink();
3522
3523 while (lnk) {
3524 TObject *obj = lnk->GetObject();
3525
3526 // Create a pad 3D viewer if none exists and we encounter a 3D shape
3527 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3528 GetViewer3D("pad");
3529 }
3530
3531 // Open a 3D scene if required
3532 if (fViewer3D && !fViewer3D->BuildingScene()) {
3534 began3DScene = kTRUE;
3535 }
3536
3537 obj->Paint(lnk->GetOption());
3538 lnk = lnk->Next();
3539 }
3540
3541 if (fCanvas && (fCanvas->fHilightPadBorder == this)) {
3542 auto col = GetHighLightColor();
3543 if (col > 0) PaintBorder(-col, kTRUE);
3544 }
3545
3546 PaintOperations(); // paint operations only for the pad
3547 }
3548
3549 fPadPaint = 0;
3551
3552 if (replace_pp && fCanvas)
3554
3555 // Close the 3D scene if we opened it. This must be done after modified
3556 // flag is cleared, as some viewers will invoke another paint by marking pad modified again
3557 if (began3DScene) {
3559 }
3560}
3561
3562////////////////////////////////////////////////////////////////////////////////
3563/// Paint the pad border.
3564/// Draw first a box as a normal filled box
3565
3566void TPad::PaintBorder(Color_t color, Bool_t /* tops */)
3567{
3568 auto pp = GetPainter();
3569 if (!pp)
3570 return;
3571
3572 pp->OnPad(this);
3573
3574 if (color >= 0) {
3575
3576 Bool_t do_paint_box = kTRUE;
3577
3579 if (!IsBatch() && (pp->IsCocoa() || (pp->IsNative() && (style > 3000) && (style < 3026))))
3580 pp->ClearDrawable();
3581
3582 // special only for transparent pads in plain X11;
3583 // Cocoa, GL, Web and PS implement transparency different
3584 if ((style >= 4000) && (style <= 4100) && pp->IsNative() && !pp->IsCocoa() && !pp->GetPS() && !(fCanvas && fCanvas->UseGL()) && !IsWeb() && !IsBatch()) {
3585 if (this == fMother) {
3586 style = 1001;
3587 } else {
3588 // copy all pixmaps
3589 do_paint_box = kFALSE;
3590 Int_t px, py;
3591 XYtoAbsPixel(GetX1(), GetY2(), px, py);
3592 if (fMother)
3593 fMother->CopyBackgroundPixmaps(this, px, py);
3594 pp->SetAttFill({color, 1001}); // use fill color producing opacity
3595 pp->SetOpacity(style - 4000);
3596 }
3597 } else if ((style >= 4000) && (style <= 4100) && pp->IsCocoa() && (this == fMother))
3598 style = 1001;
3599 else if ((color == 10) && (style > 3000) && (style < 3100))
3600 color = 1;
3601
3602 if (do_paint_box) {
3603 pp->SetAttFill({color, style});
3604 pp->SetAttLine(*this);
3605 PaintBox(fX1, fY1, fX2, fY2);
3606 }
3607 } else
3608 color = -color;
3609
3610 if (IsTransparent() || (fBorderMode == 0))
3611 return;
3612
3613 // then paint 3d frame (depending on bordermode)
3614 // Paint a 3D frame around the pad.
3615
3616 TWbox box;
3617 box.SetFillColor(color);
3618 box.SetFillStyle(GetFillStyle());
3620
3621 box.PaintBorderOn(this, fX1, fY1, fX2, fY2,
3624}
3625
3626////////////////////////////////////////////////////////////////////////////////
3627/// Paint a frame border with Postscript - no longer used
3628
3630{
3631 if (!gVirtualPS) return;
3632 gVirtualPS->DrawFrame(xl, yl, xt, yt, bmode,bsize,dark,light);
3633}
3634
3635////////////////////////////////////////////////////////////////////////////////
3636/// Paint the current date and time if the option `Date` is set on via `gStyle->SetOptDate()`
3637/// Paint the current file name if the option `File` is set on via `gStyle->SetOptFile()`
3638
3640{
3641 if (fCanvas == this) {
3642 if (gStyle->GetOptDate()) {
3643 TDatime dt;
3644 const char *dates;
3645 char iso[16];
3646 if (gStyle->GetOptDate() < 10) {
3647 //by default use format like "Wed Sep 25 17:10:35 2002"
3648 dates = dt.AsString();
3649 } else if (gStyle->GetOptDate() < 20) {
3650 //use ISO format like 2002-09-25
3651 strlcpy(iso,dt.AsSQLString(),16);
3652 dates = iso;
3653 } else {
3654 //use ISO format like 2002-09-25 17:10:35
3655 dates = dt.AsSQLString();
3656 }
3657 TText tdate(gStyle->GetDateX(),gStyle->GetDateY(),dates);
3663 tdate.SetNDC();
3664 tdate.Paint();
3665 }
3666 if (gStyle->GetOptFile() && gFile) {
3667 TText tfile(1. - gStyle->GetDateX(),gStyle->GetDateY(),gFile->GetName());
3671 tfile.SetTextAlign(31);
3673 tfile.SetNDC();
3674 tfile.Paint();
3675 }
3676 }
3677}
3678
3679////////////////////////////////////////////////////////////////////////////////
3680/// Paint histogram/graph frame.
3681
3683{
3684 if (!fPrimitives) fPrimitives = new TList;
3685 TList *glist = GetListOfPrimitives();
3686 TFrame *frame = GetFrame();
3687 frame->SetX1(xmin);
3688 frame->SetX2(xmax);
3689 frame->SetY1(ymin);
3690 frame->SetY2(ymax);
3691 if (!glist->FindObject(fFrame)) {
3692 glist->AddFirst(frame);
3694 }
3695 frame->Paint();
3696}
3697
3698////////////////////////////////////////////////////////////////////////////////
3699/// Traverse pad hierarchy and (re)paint only modified pads.
3700
3702{
3704 if (IsModified()) {
3705 fViewer3D->PadPaint(this);
3707 }
3708 TList *pList = GetListOfPrimitives();
3709 auto lnk = pList ? pList->FirstLink() : nullptr;
3710 while (lnk) {
3711 auto obj = lnk->GetObject();
3712 if (obj->InheritsFrom(TPad::Class()))
3713 ((TPad*)obj)->PaintModified();
3714 lnk = lnk->Next();
3715 }
3716 return;
3717 }
3718
3719 TVirtualPS *saveps = gVirtualPS;
3721 gVirtualPS = nullptr;
3722
3723 TVirtualPadPainter *oldpp = nullptr;
3724 Bool_t replace_pp = kFALSE;
3725
3726 if (fCanvas) {
3727 // check if special PS painter should be assigned to TCanvas
3728 replace_pp = fCanvas->EnsurePSPainter(kTRUE, oldpp);
3730 }
3731
3732 Bool_t began3DScene = kFALSE;
3733 fPadPaint = 1;
3734 {
3735 TContext ctxt(this, kTRUE);
3736
3737 auto pp = GetPainter();
3738 Bool_t useXor = pp && pp->IsNative() && !pp->IsCocoa();
3739 Bool_t needRepaint = IsModified() || IsTransparent() || (!useXor && fDrawOper.size());
3740
3741 if (needRepaint)
3743
3744 PaintDate();
3745
3746 TList *pList = GetListOfPrimitives();
3747 auto lnk = pList ? pList->FirstLink() : nullptr;
3748
3749 while (lnk) {
3750 TObject *obj = lnk->GetObject();
3751 if (obj->InheritsFrom(TPad::Class())) {
3752 ((TPad*)obj)->PaintModified();
3753 } else if (needRepaint) {
3754
3755 // Create a pad 3D viewer if none exists and we encounter a
3756 // 3D shape
3757 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3758 GetViewer3D("pad");
3759 }
3760
3761 // Open a 3D scene if required
3762 if (fViewer3D && !fViewer3D->BuildingScene()) {
3764 began3DScene = kTRUE;
3765 }
3766
3767 obj->Paint(lnk->GetOption());
3768 }
3769 lnk = lnk->Next();
3770 }
3771
3772 // when XOR is not available - paint operations at the ned
3773 if (!useXor && needRepaint)
3775 }
3776
3777 fPadPaint = 0;
3779
3780 // This must be done after modified flag is cleared, as some
3781 // viewers will invoke another paint by marking pad modified again
3782 if (began3DScene && fViewer3D)
3784
3785 if (replace_pp && fCanvas)
3787
3788 gVirtualPS = saveps;
3789}
3790
3791////////////////////////////////////////////////////////////////////////////////
3792/// Perform buffered paint operations
3793/// Used for interactivity functionality immediately after normal painting is performed
3794/// Only when withXor is specified global window context used to perform
3795/// inversion of window, otherwise only draw operations for the current pad are done
3796
3798{
3799 auto pp = GetPainter();
3800 if (!pp)
3801 return;
3802
3803 // IMPORTANT - only when XOR used change gPad only for coordinates calculation
3804 // selected device should never be changed - therefore not use cd()
3805 auto savepad = gPad;
3806 if (withXor)
3807 gPad = this;
3808
3809 pp->OnPad(this);
3810
3811 if (withXor)
3812 for (auto &oper : fDrawOperXor)
3813 oper.second->Draw(*this, pp, withXor);
3814
3815 fDrawOperXor.clear();
3816
3817 for (auto &oper : fDrawOper)
3818 oper.second->Draw(*this, pp, withXor);
3819
3820 if (withXor)
3821 std::swap(fDrawOperXor, fDrawOper);
3822 else
3823 fDrawOper.clear();
3824
3825 if (withXor) {
3826 gPad = savepad;
3827
3828 TIter next(GetListOfPrimitives());
3829 while (auto obj = next()) {
3830 if (auto pad = dynamic_cast<TPad *>(obj))
3831 pad->PaintOperations(withXor);
3832 }
3833 }
3834}
3835
3836////////////////////////////////////////////////////////////////////////////////
3837/// Paint box in CurrentPad World coordinates.
3838///
3839/// - if option[0] = 's' the box is forced to be paint with style=0
3840/// - if option[0] = 'l' the box contour is drawn
3841/// - if option[0] = 'i' the interactive xor box will be painted
3842
3844{
3845 auto pp = GetPainter();
3846 if (!pp)
3847 return;
3848
3849 if (option && *option == 'i') {
3850 Double_t x[5] = {x1, x2, x2, x1, x1};
3851 Double_t y[5] = {y1, y1, y2, y2, y1};
3853 fDrawOper[option] = std::make_unique<TPadDrawOperation>(5, x, y, drawKind, pp->GetLineWidth());
3854 return;
3855 }
3856
3857 pp->OnPad(this);
3858
3859 Style_t style = pp->GetAttFill().GetFillStyle();
3860 Bool_t draw_border = kFALSE, draw_fill = kFALSE, skip_fill = kFALSE;
3861 if (option && *option == 's')
3862 skip_fill = draw_border = kTRUE;
3863 else if (option && *option == 'l')
3864 draw_border = kTRUE;
3865
3866 if (style >= 3100 && style < 4000) {
3867 Double_t xb[4] = {x1, x1, x2, x2};
3868 Double_t yb[4] = {y1, y2, y2, y1};
3869 PaintFillAreaHatches(4, xb, yb, style);
3870 } else if (style >= 0 && style < 1000) {
3871 draw_border = kTRUE;
3872 } else if (style >= 1000 && style < 2000) {
3873 draw_fill = kTRUE;
3874 } else if (style > 3000 && style < 3100) {
3875 draw_fill = style < 3026;
3876 } else if (style >= 4000 && style <= 4100) {
3877 // transparency styles, supported now by all painters
3878 draw_fill = style > 4000;
3879 } else if (style > 0)
3880 draw_border = kTRUE;
3881
3882 if (draw_fill && !skip_fill)
3883 pp->DrawBox(x1, y1, x2, y2, TVirtualPadPainter::kFilled);
3884
3885 if (draw_border)
3886 pp->DrawBox(x1, y1, x2, y2, TVirtualPadPainter::kHollow);
3887
3888 Modified();
3889}
3890
3891////////////////////////////////////////////////////////////////////////////////
3892/// Copy pixmaps of pads laying below pad "stop" into pad "stop". This
3893/// gives the effect of pad "stop" being transparent.
3894
3896{
3897 Int_t px, py;
3898 XYtoAbsPixel(GetX1(), GetY2(), px, py);
3899 /// Copy pixmap of this pad as background of the current pad.
3900 if (auto pp = GetPainter())
3901 pp->CopyDrawable(GetPixmapID(), px - x, py - y);
3902
3903 TIter next(GetListOfPrimitives());
3904 while (auto obj = next()) {
3905 if (obj == stop)
3906 break;
3907 if (auto pad = dynamic_cast<TPad *>(obj))
3908 pad->CopyBackgroundPixmaps(stop, x, y);
3909 }
3910}
3911
3912////////////////////////////////////////////////////////////////////////////////
3913
3915{
3916 Warning("PaintFillArea", "Float_t signature is obsolete. Use Double_t signature.");
3917}
3918
3919////////////////////////////////////////////////////////////////////////////////
3920/// Paint fill area in CurrentPad World coordinates.
3921///
3922/// If option[0] == 'C' no clipping
3923/// If option[0] == 'i' paint during ExecuteEvent (interactive)
3924
3926{
3927 if (nn < 3)
3928 return;
3930 Bool_t mustClip = kTRUE;
3933 } else {
3934 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
3935 if (option && (*option == 'C')) mustClip = kFALSE;
3936 }
3937
3938 std::vector<Double_t> xclip, yclip;
3939
3940 if (mustClip) {
3941 Int_t nc = 2*nn+1;
3942 xclip.resize(nc, 0.);
3943 yclip.resize(nc, 0.);
3944 Int_t n = ClipPolygon(nn, xx, yy, nc, xclip.data(), yclip.data(), xmin, ymin, xmax, ymax);
3945 if (!n)
3946 return;
3947 nn = n;
3948 xx = xclip.data();
3949 yy = yclip.data();
3950 }
3951
3952 if (option && *option == 'i') {
3953 fDrawOper[option] = std::make_unique<TPadDrawOperation>(nn, xx, yy, TPadDrawOperation::drawFill);
3954 return;
3955 }
3956
3957 auto pp = GetPainter();
3958 if (!pp)
3959 return;
3960
3961 pp->OnPad(this);
3962
3963 // Paint the fill area with hatches
3964 Int_t fillstyle = pp->GetFillStyle();
3965 if (fillstyle >= 3100 && fillstyle < 4000)
3966 PaintFillAreaHatches(nn, xx, yy, fillstyle);
3967 else
3968 pp->DrawFillArea(nn, xx, yy);
3969
3970 Modified();
3971}
3972
3973////////////////////////////////////////////////////////////////////////////////
3974/// Paint fill area in CurrentPad NDC coordinates.
3975
3977{
3978 std::vector<Double_t> xw(n), yw(n);
3979 for (int i=0; i<n; i++) {
3980 xw[i] = fX1 + x[i]*(fX2 - fX1);
3981 yw[i] = fY1 + y[i]*(fY2 - fY1);
3982 }
3983 PaintFillArea(n, xw.data(), yw.data(), option);
3984}
3985
3986////////////////////////////////////////////////////////////////////////////////
3987/// This function paints hatched fill area according to the FillStyle value
3988/// The convention for the Hatch is the following:
3989///
3990/// `FillStyle = 3ijk`
3991///
3992/// - i (1-9) : specify the space between each hatch
3993/// 1 = minimum 9 = maximum
3994/// the final spacing is i*GetHatchesSpacing(). The hatches spacing
3995/// is set by SetHatchesSpacing()
3996/// - j (0-9) : specify angle between 0 and 90 degrees
3997/// * 0 = 0
3998/// * 1 = 10
3999/// * 2 = 20
4000/// * 3 = 30
4001/// * 4 = 45
4002/// * 5 = Not drawn
4003/// * 6 = 60
4004/// * 7 = 70
4005/// * 8 = 80
4006/// * 9 = 90
4007/// - k (0-9) : specify angle between 90 and 180 degrees
4008/// * 0 = 180
4009/// * 1 = 170
4010/// * 2 = 160
4011/// * 3 = 150
4012/// * 4 = 135
4013/// * 5 = Not drawn
4014/// * 6 = 120
4015/// * 7 = 110
4016/// * 8 = 100
4017/// * 9 = 90
4018
4020{
4021 static Double_t ang1[10] = { 0., 10., 20., 30., 45.,5., 60., 70., 80., 89.99};
4022 static Double_t ang2[10] = {180.,170.,160.,150.,135.,5.,120.,110.,100., 89.99};
4023
4024 Int_t fasi = FillStyle % 1000;
4025 Int_t idSPA = fasi / 100;
4026 Int_t iAng2 = (fasi - 100 * idSPA) / 10;
4027 Int_t iAng1 = fasi % 10;
4028 Double_t dy = 0.003 * idSPA * gStyle->GetHatchesSpacing();
4030 auto pp = GetPainter();
4031 if (!pp)
4032 return;
4033
4034 // Save the current line attributes and change to draw hatches
4035 TAttLine saveatt = pp->GetAttLine();
4036
4037 pp->SetAttLine({ pp->GetAttFill().GetFillColor(), 1, lw });
4038
4039 // Draw the hatches
4040 if (ang1[iAng1] != 5.)
4041 PaintHatches(dy, ang1[iAng1], nn, xx, yy);
4042 if (ang2[iAng2] != 5.)
4043 PaintHatches(dy, ang2[iAng2], nn, xx, yy);
4044
4045 pp->SetAttLine(saveatt);
4046}
4047
4048////////////////////////////////////////////////////////////////////////////////
4049/// This routine draw hatches inclined with the
4050/// angle "angle" and spaced of "dy" in normalized device
4051/// coordinates in the surface defined by n,xx,yy.
4052
4054 Int_t nn, Double_t *xx, Double_t *yy)
4055{
4056 Int_t i, i1, i2, nbi;
4057 Double_t ratiox, ratioy, ymin, ymax, yrot, ycur;
4058 const Double_t angr = TMath::Pi()*(180.-angle)/180.;
4059 const Double_t epsil = 0.0001;
4060
4061 std::vector<Double_t> xli;
4062 std::vector<Double_t> yli;
4063
4064 Double_t xt1, xt2, yt1, yt2;
4065 Double_t x, y, x1, x2, y1, y2, a, b, xi, xip, xin, yi, yip;
4066
4067 Double_t rwxmin = gPad->GetX1();
4068 Double_t rwxmax = gPad->GetX2();
4069 Double_t rwymin = gPad->GetY1();
4070 Double_t rwymax = gPad->GetY2();
4071 ratiox = 1./(rwxmax-rwxmin);
4072 ratioy = 1./(rwymax-rwymin);
4073
4074 Double_t sina = TMath::Sin(angr), sinb;
4075 Double_t cosa = TMath::Cos(angr), cosb;
4076 if (TMath::Abs(cosa) <= epsil) cosa=0.;
4077 if (TMath::Abs(sina) <= epsil) sina=0.;
4078 sinb = -sina;
4079 cosb = cosa;
4080
4081 // Values needed to compute the hatches in TRUE normalized space (NDC)
4082 Int_t iw = (Int_t)gPad->GetWw();
4083 Int_t ih = (Int_t)gPad->GetWh();
4084 Double_t x1p,y1p,x2p,y2p;
4085 gPad->GetPadPar(x1p,y1p,x2p,y2p);
4086 iw = (Int_t)(iw*x2p)-(Int_t)(iw*x1p);
4087 ih = (Int_t)(ih*y2p)-(Int_t)(ih*y1p);
4088 Double_t wndc = TMath::Min(1.,(Double_t)iw/(Double_t)ih);
4089 Double_t hndc = TMath::Min(1.,(Double_t)ih/(Double_t)iw);
4090
4091 // Search ymin and ymax
4092 ymin = 1.;
4093 ymax = 0.;
4094 for (i=1; i<=nn; i++) {
4095 x = wndc*ratiox*(xx[i-1]-rwxmin);
4096 y = hndc*ratioy*(yy[i-1]-rwymin);
4097 yrot = sina*x+cosa*y;
4098 if (yrot > ymax) ymax = yrot;
4099 if (yrot < ymin) ymin = yrot;
4100 }
4101
4102 Int_t yindx = (Int_t) (ymax/dy);
4103
4104 while (dy * yindx >= ymin) {
4105 ycur = dy * yindx--;
4106 nbi = 0;
4107
4108 xli.clear();
4109 yli.clear();
4110
4111 for (i=2; i<=nn+1; i++) {
4112 i2 = i;
4113 i1 = i-1;
4114 if (i == nn+1) i2=1;
4115
4116 x1 = wndc*ratiox*(xx[i1-1]-rwxmin);
4117 y1 = hndc*ratioy*(yy[i1-1]-rwymin);
4118 x2 = wndc*ratiox*(xx[i2-1]-rwxmin);
4119 y2 = hndc*ratioy*(yy[i2-1]-rwymin);
4120
4121 xt1 = cosa*x1-sina*y1;
4122 yt1 = sina*x1+cosa*y1;
4123 xt2 = cosa*x2-sina*y2;
4124 yt2 = sina*x2+cosa*y2;
4125
4126 // Line segment parallel to oy
4127 if (xt1 == xt2) {
4128 if (yt1 < yt2) {
4129 yi = yt1;
4130 yip = yt2;
4131 } else {
4132 yi = yt2;
4133 yip = yt1;
4134 }
4135 if ((yi <= ycur) && (ycur < yip)) {
4136 nbi++;
4137 xli.push_back(xt1);
4138 }
4139 continue;
4140 }
4141
4142 // Line segment parallel to ox
4143 if (yt1 == yt2) {
4144 if (yt1 == ycur) {
4145 nbi++;
4146 xli.push_back(xt1);
4147 nbi++;
4148 xli.push_back(xt2);
4149 }
4150 continue;
4151 }
4152
4153 // Other line segment
4154 a = (yt1-yt2)/(xt1-xt2);
4155 b = (yt2*xt1-xt2*yt1)/(xt1-xt2);
4156
4157 if (xt1 < xt2) {
4158 xi = xt1;
4159 xip = xt2;
4160 } else {
4161 xi = xt2;
4162 xip = xt1;
4163 }
4164
4165 xin = (ycur-b)/a;
4166
4167 if ((xi <= xin) && (xin < xip) &&
4168 (TMath::Min(yt1,yt2) <= ycur) &&
4169 (ycur < TMath::Max(yt1,yt2))) {
4170 nbi++;
4171 xli.push_back(xin);
4172 }
4173 }
4174
4175 // Sorting of the x coordinates intersections
4176 std::sort(xli.begin(), xli.end());
4177
4178 // Draw the hatches
4179 if ((nbi%2 != 0) || (nbi == 0))
4180 continue;
4181
4182 for (i=0; i<nbi; ++i) {
4183 // Rotate back the hatches - first calculate y coordinate
4184 Double_t ytmp = sinb*xli[i] + cosb*ycur;
4185 xli[i] = cosb*xli[i] - sinb*ycur;
4186 // Convert hatches' positions from true NDC to WC to handle clipping
4187 xli[i] = (xli[i]/wndc)*(rwxmax-rwxmin)+rwxmin;
4188 ytmp = (ytmp/hndc)*(rwymax-rwymin)+rwymin;
4189 yli.push_back(ytmp);
4190 }
4191
4192 gPad->PaintSegments(nbi/2, xli.data(), yli.data());
4193 }
4194}
4195
4196////////////////////////////////////////////////////////////////////////////////
4197/// Paint line in CurrentPad World coordinates.
4198
4200{
4201 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
4202
4203 //If line is totally clipped, return
4205 if (Clip(x,y,fUxmin,fUymin,fUxmax,fUymax) == 2) return;
4206 } else {
4207 if (Clip(x,y,fX1,fY1,fX2,fY2) == 2) return;
4208 }
4209
4210 if (auto pp = GetPainter()) {
4211 pp->OnPad(this);
4212 pp->DrawLine(x[0], y[0], x[1], y[1]);
4213 }
4214
4215 Modified();
4216}
4217
4218////////////////////////////////////////////////////////////////////////////////
4219/// Paint line in normalized coordinates.
4220
4222{
4223 if (auto pp = GetPainter()) {
4224 pp->OnPad(this);
4225 pp->DrawLineNDC(u1, v1, u2, v2);
4226 }
4227
4228 Modified();
4229}
4230
4231////////////////////////////////////////////////////////////////////////////////
4232/// Paint 3-D line in the CurrentPad.
4233
4235{
4236 if (!fView) return;
4237
4238 // convert from 3-D to 2-D pad coordinate system
4239 Double_t xpad[6];
4240 Double_t temp[3];
4241 Int_t i;
4242 for (i=0;i<3;i++) temp[i] = p1[i];
4243 fView->WCtoNDC(temp, &xpad[0]);
4244 for (i=0;i<3;i++) temp[i] = p2[i];
4245 fView->WCtoNDC(temp, &xpad[3]);
4246 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4247}
4248
4249////////////////////////////////////////////////////////////////////////////////
4250/// Paint 3-D line in the CurrentPad.
4251
4253{
4254 if (!fView) return;
4255
4256 // convert from 3-D to 2-D pad coordinate system
4257 Double_t xpad[6];
4258 Double_t temp[3];
4259 Int_t i;
4260 for (i=0;i<3;i++) temp[i] = p1[i];
4261 fView->WCtoNDC(temp, &xpad[0]);
4262 for (i=0;i<3;i++) temp[i] = p2[i];
4263 fView->WCtoNDC(temp, &xpad[3]);
4264 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4265}
4266
4267////////////////////////////////////////////////////////////////////////////////
4268/// Paint 3-D marker in the CurrentPad.
4269
4271{
4272 if (!fView) return;
4273
4274 Double_t rmin[3], rmax[3];
4275 fView->GetRange(rmin, rmax);
4276
4277 // convert from 3-D to 2-D pad coordinate system
4278 Double_t xpad[3];
4279 Double_t temp[3];
4280 temp[0] = x;
4281 temp[1] = y;
4282 temp[2] = z;
4283 if (x<rmin[0] || x>rmax[0]) return;
4284 if (y<rmin[1] || y>rmax[1]) return;
4285 if (z<rmin[2] || z>rmax[2]) return;
4286 fView->WCtoNDC(temp, &xpad[0]);
4287 PaintPolyMarker(1, &xpad[0], &xpad[1]);
4288}
4289
4290////////////////////////////////////////////////////////////////////////////////
4291/// Paint polyline in CurrentPad World coordinates.
4292///
4293/// If option[0] == 'C' no clipping
4294/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4295
4297{
4298 auto pp = GetPainter();
4299 if ((n < 2) || !pp)
4300 return;
4301
4303 Bool_t mustClip = kTRUE, interactive = option && *option == 'i';
4306 } else {
4307 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4308 if (option && (*option == 'C')) mustClip = kFALSE;
4309 }
4310 Int_t i1 = -1, np = 1, iclip = 0;
4311 for (Int_t i = 0; i < n - 1; i++) {
4312 Double_t x1 = x[i];
4313 Double_t y1 = y[i];
4314 Double_t x2 = x[i+1];
4315 Double_t y2 = y[i+1];
4316 if (mustClip) {
4317 iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4318 if (iclip == 2) {
4319 i1 = -1;
4320 continue;
4321 }
4322 }
4323 np++;
4324 if (i1 < 0)
4325 i1 = i;
4326 if (iclip == 0 && i < n-2)
4327 continue;
4328 if (interactive)
4329 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawLine, pp->GetLineWidth());
4330 else {
4331 pp->OnPad(this);
4332 pp->DrawPolyLine(np, &x[i1], &y[i1]);
4333 }
4334 if (iclip) {
4335 x[i] = x1;
4336 y[i] = y1;
4337 x[i+1] = x2;
4338 y[i+1] = y2;
4339 }
4340 i1 = -1;
4341 np = 1;
4342 }
4343
4344 if (!interactive)
4345 Modified();
4346}
4347
4348////////////////////////////////////////////////////////////////////////////////
4349/// Paint polyline in CurrentPad World coordinates.
4350///
4351/// If option[0] == 'C' no clipping
4352/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4353
4355{
4356 auto pp = GetPainter();
4357 if ((n < 2) || !pp)
4358 return;
4359
4361 Bool_t mustClip = kTRUE, interactive = option && *option == 'i';
4364 } else {
4365 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4366 if (option && (*option == 'C')) mustClip = kFALSE;
4367 }
4368
4369 Int_t i1 = -1, np = 1, iclip = 0;
4370
4371 for (Int_t i = 0; i < n-1; i++) {
4372 Double_t x1 = x[i];
4373 Double_t y1 = y[i];
4374 Double_t x2 = x[i+1];
4375 Double_t y2 = y[i+1];
4376 if (mustClip) {
4377 iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4378 if (iclip == 2) {
4379 i1 = -1;
4380 continue;
4381 }
4382 }
4383 np++;
4384 if (i1 < 0)
4385 i1 = i;
4386 if (iclip == 0 && i < n-2)
4387 continue;
4388 if (interactive)
4389 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawLine, pp->GetLineWidth());
4390 else {
4391 pp->OnPad(this);
4392 pp->DrawPolyLine(np, &x[i1], &y[i1]);
4393 }
4394 if (iclip) {
4395 x[i] = x1;
4396 y[i] = y1;
4397 x[i+1] = x2;
4398 y[i+1] = y2;
4399 }
4400 i1 = -1;
4401 np = 1;
4402 }
4403
4404 if (!interactive)
4405 Modified();
4406}
4407
4408////////////////////////////////////////////////////////////////////////////////
4409/// Paint polyline in CurrentPad NDC coordinates.
4410
4412{
4413 auto pp = GetPainter();
4414 if ((n < 2) || !pp)
4415 return;
4416
4417 if (option && *option == 'i') {
4418 fDrawOper[option] = std::make_unique<TPadDrawOperation>(n, x, y, TPadDrawOperation::drawLine, pp->GetLineWidth(), kTRUE);
4419 return;
4420 }
4421
4422 pp->OnPad(this);
4423 pp->DrawPolyLineNDC(n, x, y);
4424
4425 Modified();
4426}
4427
4428////////////////////////////////////////////////////////////////////////////////
4429/// Paint 3-D polyline in the CurrentPad.
4430
4432{
4433 if (!fView) return;
4434
4435 // Loop on each individual line
4436 for (Int_t i = 1; i < n; i++)
4437 PaintLine3D(&p[3*i-3], &p[3*i]);
4438
4439 Modified();
4440}
4441
4442////////////////////////////////////////////////////////////////////////////////
4443/// Paint polymarker in CurrentPad World coordinates.
4444///
4445/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4446
4448{
4449 Int_t n = TMath::Abs(nn);
4451 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4453 } else {
4454 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4455 }
4456 Int_t i,i1=-1,np=0;
4457 for (i=0; i<n; i++) {
4458 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4459 np++;
4460 if (i1 < 0) i1 = i;
4461 if (i < n-1) continue;
4462 }
4463 if (np == 0)
4464 continue;
4465 if (option && *option == 'i')
4466 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawMarker, option[1] == 'f' ? 0 : 1);
4467 else if (auto pp = GetPainter()) {
4468 pp->OnPad(this);
4469 pp->DrawPolyMarker(np, &x[i1], &y[i1]);
4470 }
4471 i1 = -1;
4472 np = 0;
4473 }
4474 Modified();
4475}
4476
4477////////////////////////////////////////////////////////////////////////////////
4478/// Paint polymarker in CurrentPad World coordinates.
4479///
4480/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4481
4483{
4484 Int_t n = TMath::Abs(nn);
4486 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4488 } else {
4489 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4490 }
4491 Int_t i,i1=-1,np=0;
4492 for (i=0; i<n; i++) {
4493 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4494 np++;
4495 if (i1 < 0) i1 = i;
4496 if (i < n-1) continue;
4497 }
4498 if (np == 0)
4499 continue;
4500
4501 if (option && *option == 'i')
4502 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawMarker, option[1] == 'f' ? 0 : 1);
4503 else if (auto pp = GetPainter()) {
4504 pp->OnPad(this);
4505 pp->DrawPolyMarker(np, &x[i1], &y[i1]);
4506 }
4507 i1 = -1;
4508 np = 0;
4509 }
4510 Modified();
4511}
4512
4513////////////////////////////////////////////////////////////////////////////////
4514/// Paint N individual segments
4515/// Provided arrays should have 2*n elements
4516/// IMPORTANT! Provided arrays can be modified after function call!
4517
4519{
4520 if (n < 1)
4521 return;
4522
4524 Bool_t mustClip = kTRUE, isAny = kFALSE;
4527 } else {
4528 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4529 if (option && *option == 'C') mustClip = kFALSE;
4530 }
4531
4532 if (!mustClip)
4533 isAny = kTRUE;
4534 else {
4535 for (Int_t i = 0; i < 2*n; i+=2) {
4536 Int_t iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4537 if (iclip == 2)
4538 x[i] = y[i] = x[i+1] = y[i+1] = 0;
4539 else
4540 isAny = kTRUE;
4541 }
4542 }
4543
4544 if (isAny)
4545 if (auto pp = GetPainter()) {
4546 pp->OnPad(this);
4547 pp->DrawSegments(n, x, y);
4548 }
4549
4550 Modified();
4551}
4552
4553
4554////////////////////////////////////////////////////////////////////////////////
4555/// Paint N individual segments in NDC coordinates
4556/// Provided arrays should have 2*n elements
4557/// IMPORTANT! Provided arrays can be modified after function call!
4558
4560{
4561 if (auto pp = GetPainter()) {
4562 pp->OnPad(this);
4563 pp->DrawSegmentsNDC(n, u, v);
4564 }
4565
4566 Modified();
4567}
4568
4569
4570////////////////////////////////////////////////////////////////////////////////
4571/// Paint text in CurrentPad World coordinates.
4572
4574{
4575 Modified();
4576
4577 if (auto pp = GetPainter()) {
4578 pp->OnPad(this);
4579 pp->DrawText(x, y, text, TVirtualPadPainter::kClear);
4580 }
4581}
4582
4583////////////////////////////////////////////////////////////////////////////////
4584/// Paint text in CurrentPad World coordinates.
4585
4586void TPad::PaintText(Double_t x, Double_t y, const wchar_t *text)
4587{
4588 Modified();
4589
4590 if (auto pp = GetPainter()) {
4591 pp->OnPad(this);
4592 pp->DrawText(x, y, text, TVirtualPadPainter::kClear);
4593 }
4594}
4595
4596////////////////////////////////////////////////////////////////////////////////
4597/// Paint text with URL in CurrentPad World coordinates.
4598
4599void TPad::PaintTextUrl(Double_t x, Double_t y, const char *text, const char *url)
4600{
4601 Modified();
4602
4603 if (auto pp = GetPainter()) {
4604 pp->OnPad(this);
4605 pp->DrawTextUrl(x, y, text, url);
4606 }
4607}
4608
4609////////////////////////////////////////////////////////////////////////////////
4610/// Paint text in CurrentPad NDC coordinates.
4611
4613{
4614 Modified();
4615
4616 if (auto pp = GetPainter()) {
4617 pp->OnPad(this);
4618 pp->DrawTextNDC(u, v, text, TVirtualPadPainter::kClear);
4619 }
4620}
4621
4622////////////////////////////////////////////////////////////////////////////////
4623/// Paint text in CurrentPad NDC coordinates.
4624
4626{
4627 Modified();
4628
4629 if (auto pp = GetPainter()) {
4630 pp->OnPad(this);
4631 pp->DrawTextNDC(u, v, text, TVirtualPadPainter::kClear);
4632 }
4633}
4634
4635////////////////////////////////////////////////////////////////////////////////
4636/// Search for an object at pixel position px,py.
4637///
4638/// Check if point is in this pad.
4639///
4640/// If yes, check if it is in one of the sub-pads
4641///
4642/// If found in the pad, compute closest distance of approach
4643/// to each primitive.
4644///
4645/// If one distance of approach is found to be within the limit Distancemaximum
4646/// the corresponding primitive is selected and the routine returns.
4647
4649{
4650 //the two following statements are necessary under NT (multithreaded)
4651 //when a TCanvas object is being created and a thread calling TPad::Pick
4652 //before the TPad constructor has completed in the other thread
4653 if (!gPad) return nullptr; //Andy Haas
4654 if (!GetListOfPrimitives()) return nullptr; //Andy Haas
4655
4656 Int_t dist;
4657 // Search if point is in pad itself
4658 Double_t x = AbsPixeltoX(px);
4659 Double_t y = AbsPixeltoY(py);
4660 if (this != gPad->GetCanvas()) {
4661 if (!((x >= fX1 && x <= fX2) && (y >= fY1 && y <= fY2))) return nullptr;
4662 }
4663
4664 // search for a primitive in this pad or its sub-pads
4665 static TObjOptLink dummyLink(nullptr,""); //place holder for when no link available
4666
4667 TContext ctxt(this, kFALSE); // since no drawing will be done, don't use cd() for efficiency reasons
4668
4669 TPad *pick = nullptr;
4670 TPad *picked = this;
4671 pickobj = nullptr;
4673 dummyLink.SetObject(this);
4674 pickobj = &dummyLink;
4675 }
4676
4677 // Loop backwards over the list of primitives. The first non-pad primitive
4678 // found is the selected one. However, we have to keep going down the
4679 // list to see if there is maybe a pad overlaying the primitive. In that
4680 // case look into the pad for a possible primitive. Once a pad has been
4681 // found we can terminate the loop.
4682 Bool_t gotPrim = kFALSE; // true if found a non pad primitive
4684
4685 //We can have 3d stuff in pad. If canvas prefers to draw
4686 //such stuff with OpenGL, the selection of 3d objects is
4687 //a gl viewer business so, in first cycle we do not
4688 //call DistancetoPrimitive for TAtt3D descendants.
4689 //In case of gl we first try to select 2d object first.
4690
4691 while (lnk) {
4692 TObject *obj = lnk->GetObject();
4693
4694 //If canvas prefers GL, all 3d objects must be drawn/selected by
4695 //gl viewer
4696 if (obj->InheritsFrom(TAtt3D::Class()) && fEmbeddedGL) {
4697 lnk = lnk->Prev();
4698 continue;
4699 }
4700
4701 fPadPointer = obj;
4702 if (obj->InheritsFrom(TPad::Class())) {
4703 pick = ((TPad*)obj)->Pick(px, py, pickobj);
4704 if (pick) {
4705 picked = pick;
4706 break;
4707 }
4708 } else if (!gROOT->GetEditorMode()) {
4709 if (!gotPrim) {
4710 if (!obj->TestBit(kCannotPick)) {
4711 dist = obj->DistancetoPrimitive(px, py);
4712 if (dist < fgMaxPickDistance) {
4713 pickobj = lnk;
4714 gotPrim = kTRUE;
4715 if (dist == 0) break;
4716 }
4717 }
4718 }
4719 }
4720
4721 lnk = lnk->Prev();
4722 }
4723
4724 //if no primitive found, check if we have a TView
4725 //if yes, return the view except if you are in the lower or upper X range
4726 //of the pad.
4727 //In case canvas prefers gl, fView existence
4728 //automatically means viewer3d existence. (?)
4729
4730 if (fView && !gotPrim) {
4731 Double_t dx = 0.05*(fUxmax-fUxmin);
4732 if ((x > fUxmin + dx) && (x < fUxmax-dx)) {
4733
4734 if (fEmbeddedGL) {
4735 //No 2d stuff was selected, but we have gl-viewer. Let it select an object in
4736 //scene (or select itself). In any case it'll internally call
4737 //gPad->SetSelected(ptr) as, for example, hist painter does.
4738 py -= Int_t((1 - GetHNDC() - GetYlowNDC()) * GetWh());
4739 px -= Int_t(GetXlowNDC() * GetWw());
4741 }
4742 else
4743 dummyLink.SetObject(fView);
4744 }
4745 }
4746
4747 if (picked->InheritsFrom(TButton::Class())) {
4748 TButton *button = (TButton*)picked;
4749 if (!button->IsEditable()) pickobj = nullptr;
4750 }
4751
4752 if (TestBit(kCannotPick)) {
4753
4754 if (picked == this) {
4755 // cannot pick pad itself!
4756 picked = nullptr;
4757 }
4758
4759 }
4760
4761 return picked;
4762}
4763
4764////////////////////////////////////////////////////////////////////////////////
4765/// Pop pad to the top of the stack.
4766
4768{
4770 return;
4771 if (!fPrimitives)
4772 fPrimitives = new TList;
4773 if (this == fMother->GetListOfPrimitives()->Last())
4774 return;
4775
4777 while (auto obj = next())
4778 if (obj == this) {
4779 TString opt = next.GetOption();
4780 fMother->Remove(this, kFALSE); // do not issue modified
4781 fMother->Add(this, opt.Data());
4782 return;
4783 }
4784}
4785
4786////////////////////////////////////////////////////////////////////////////////
4787/// This method is equivalent to `SaveAs("filename")`. See TPad::SaveAs for details.
4788
4789void TPad::Print(const char *filename) const
4790{
4791 ((TPad*)this)->SaveAs(filename);
4792}
4793
4794////////////////////////////////////////////////////////////////////////////////
4795/// Save Canvas contents in a file in one of various formats.
4796///
4797/// \anchor TPadPrint
4798/// option can be:
4799///
4800/// - `ps`: a Postscript file is produced (default). [See special cases](\ref TPadPrintPS).
4801/// - `Portrait`: Postscript file is produced (Portrait)
4802/// - `Landscape`: Postscript file is produced (Landscape)
4803/// - `eps`: an Encapsulated Postscript file is produced
4804/// - `Preview`: an [Encapsulated Postscript file with preview](\ref TPadPrintPreview) is produced.
4805/// - `pdf`: a PDF file is produced NOTE: TMathText will be converted to TLatex; q.e.d., symbols only available in TMathText will not render properly.
4806/// - `Title:`: The character string after `Title:` becomes a table
4807/// of content entry (for PDF files).
4808/// - `EmbedFonts`: a [PDF file with embedded fonts](\ref TPadPrintEmbedFonts) is generated.
4809/// - `svg`: a SVG file is produced
4810/// - `tex`: a TeX file is produced
4811/// - `Standalone`: a [standalone TeX file](\ref TPadPrintStandalone) is produced.
4812/// - `gif`: a GIF file is produced
4813/// - `gif+NN`: an animated GIF file is produced, where NN is delay in 10ms units NOTE: See other variants for looping animation in TASImage::WriteImage
4814/// - `xpm`: a XPM file is produced
4815/// - `png`: a PNG file is produced
4816/// - `jpg`: a JPEG file is produced. NOTE: JPEG's lossy compression will make all sharp edges fuzzy.
4817/// - `tiff`: a TIFF file is produced
4818/// - `cxx`: a C++ macro file is produced
4819/// - `xml`: a XML file
4820/// - `json`: a JSON file
4821/// - `root`: a ROOT binary file
4822///
4823/// `filename` = 0 - filename is defined by `GetName` and its
4824/// extension is defined with the option
4825///
4826/// When Postscript output is selected (`ps`, `eps`), the canvas is saved
4827/// to `filename.ps` or `filename.eps`. The aspect ratio of the canvas is preserved
4828/// on the Postscript file. When the "ps" option is selected, the Postscript
4829/// page will be landscape format if the canvas is in landscape format, otherwise
4830/// portrait format is selected.
4831///
4832/// The physical size of the Postscript page is the one selected in the
4833/// current style. This size can be modified via TStyle::SetPaperSize.
4834///
4835/// Examples:
4836/// ~~~ {.cpp}
4837/// gStyle->SetPaperSize(TStyle::kA4); //default
4838/// gStyle->SetPaperSize(TStyle::kUSLetter);
4839/// ~~~
4840/// where TStyle::kA4 and TStyle::kUSLetter are defined in the enum
4841/// EPaperSize in TStyle.h
4842///
4843/// An alternative is to call:
4844/// ~~~ {.cpp}
4845/// gStyle->SetPaperSize(20,26); same as kA4
4846/// or gStyle->SetPaperSize(20,24); same as kUSLetter
4847/// ~~~
4848/// The above numbers take into account some margins and are in centimeters.
4849///
4850/// \anchor TPadPrintPreview
4851/// ### The "Preview" option
4852///
4853/// The "Preview" option allows to generate a preview (in the TIFF format) within
4854/// the Encapsulated Postscript file. This preview can be used by programs like
4855/// MSWord to visualize the picture on screen. The "Preview" option relies on the
4856/// ["epstool" command](http://www.cs.wisc.edu/~ghost/gsview/epstool.htm).
4857///
4858/// Example:
4859/// ~~~ {.cpp}
4860/// canvas->Print("example.eps","Preview");
4861/// ~~~
4862///
4863/// \anchor TPadPrintEmbedFonts
4864/// ### The "EmbedFonts" option
4865///
4866/// The "EmbedFonts" option allows to embed the fonts used in a PDF file inside
4867/// that file. This option relies on the ["gs" command](https://ghostscript.com).
4868///
4869/// Example:
4870/// ~~~ {.cpp}
4871/// canvas->Print("example.pdf","EmbedFonts");
4872/// ~~~
4873///
4874/// \anchor TPadPrintStandalone
4875/// ### The "Standalone" option
4876/// The "Standalone" option allows to generate a TeX file ready to be processed by
4877/// tools like `pdflatex`.
4878///
4879/// Example:
4880/// ~~~ {.cpp}
4881/// canvas->Print("example.tex","Standalone");
4882/// ~~~
4883///
4884/// \anchor TPadPrintPS
4885/// ### Writing several canvases to the same Postscript or PDF file:
4886///
4887/// - if the Postscript or PDF file name finishes with "(", the file is not closed
4888/// - if the Postscript or PDF file name finishes with ")" and the file has been opened
4889/// with "(", the file is closed.
4890///
4891/// Example:
4892/// ~~~ {.cpp}
4893/// {
4894/// TCanvas c1("c1");
4895/// h1.Draw();
4896/// c1.Print("c1.ps("); //write canvas and keep the ps file open
4897/// h2.Draw();
4898/// c1.Print("c1.ps"); canvas is added to "c1.ps"
4899/// h3.Draw();
4900/// c1.Print("c1.ps)"); canvas is added to "c1.ps" and ps file is closed
4901/// }
4902/// ~~~
4903/// In the previous example replacing "ps" by "pdf" will create a multi-pages PDF file.
4904///
4905/// Note that the following sequence writes the canvas to "c1.ps" and closes the ps file.:
4906/// ~~~ {.cpp}
4907/// TCanvas c1("c1");
4908/// h1.Draw();
4909/// c1.Print("c1.ps");
4910/// ~~~
4911/// The `TCanvas::Print("file.ps(")` mechanism is very useful, but it can be
4912/// a little inconvenient to have the action of opening/closing a file
4913/// being atomic with printing a page. Particularly if pages are being
4914/// generated in some loop one needs to detect the special cases of first
4915/// and last page and then munge the argument to Print() accordingly.
4916///
4917/// The "[" and "]" can be used instead of "(" and ")" to open / close without
4918/// actual printing.
4919///
4920/// Example:
4921/// ~~~ {.cpp}
4922/// c1.Print("file.ps["); // No actual print, just open file.ps
4923/// for (int i=0; i<10; ++i) {
4924/// // fill canvas for context i
4925/// // ...
4926///
4927/// c1.Print("file.ps"); // actually print canvas to file
4928/// }// end loop
4929/// c1.Print("file.ps]"); // No actual print, just close.
4930/// ~~~
4931/// As before, the same macro is valid for PDF files.
4932///
4933/// It is possible to print a canvas into an animated GIF file by specifying the
4934/// file name as "myfile.gif+" or "myfile.gif+NN", where NN*10ms is delay
4935/// between the subimages' display. If NN is omitted the delay between
4936/// subimages is zero. Each picture is added in the animation thanks to a loop
4937/// similar to the following one:
4938/// ~~~ {.cpp}
4939/// for (int i=0; i<10; ++i) {
4940/// // fill canvas for context i
4941/// // ...
4942///
4943/// c1.Print("file.gif+5"); // print canvas to GIF file with 50ms delays
4944/// }// end loop
4945/// ~~~
4946/// The delay between each frame must be specified in each Print() statement.
4947/// If the file "myfile.gif" already exists, the new frame are appended at
4948/// the end of the file. To avoid this, delete it first with `gSystem->Unlink(myfile.gif);`
4949/// If you want the gif file to repeat or loop forever, check TASImage::WriteImage documentation
4950
4952{
4953 auto canv = GetCanvas();
4954 if (!canv)
4955 return;
4956
4957 TString psname, fs1 = filename;
4958
4959 // "[" and "]" are special characters for ExpandPathName. When they are at the end
4960 // of the file name (see help) they must be removed before doing ExpandPathName.
4961 if (fs1.EndsWith("[")) {
4962 fs1.Replace((fs1.Length()-1),1," ");
4963 gSystem->ExpandPathName(fs1);
4964 fs1.Replace((fs1.Length()-1),1,"[");
4965 } else if (fs1.EndsWith("]")) {
4966 fs1.Replace((fs1.Length()-1),1," ");
4967 gSystem->ExpandPathName(fs1);
4968 fs1.Replace((fs1.Length()-1),1,"]");
4969 } else {
4970 gSystem->ExpandPathName(fs1);
4971 }
4972
4973 // Set the default option as "Postscript" (Should be a data member of TPad)
4974 const char *opt_default = "ps";
4975
4976 TString opt = !option ? opt_default : option;
4977 Bool_t image = kFALSE;
4978 Bool_t title = opt.Contains("Title:");
4979
4980 if (!fs1.Length()) {
4981 psname = GetName();
4982 psname += opt;
4983 } else {
4984 psname = fs1;
4985 }
4986
4987 // lines below protected against case like c1->SaveAs( "../ps/cs.ps" );
4988 if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
4989 psname = GetName();
4990 psname.Append(fs1);
4991 psname.Prepend("/");
4992 psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
4993 }
4994
4995 // Save pad/canvas in alternative formats
4997 if (!title && opt.Contains("gif+")) {
4998 gtype = TImage::kAnimGif;
4999 image = kTRUE;
5000 } else if (!title && opt.Contains("gif")) {
5001 gtype = TImage::kGif;
5002 image = kTRUE;
5003 } else if (!title && opt.Contains("png")) {
5004 gtype = TImage::kPng;
5005 image = kTRUE;
5006 } else if (!title && opt.Contains("jpg")) {
5007 gtype = TImage::kJpeg;
5008 image = kTRUE;
5009 } else if (!title && opt.Contains("tiff")) {
5010 gtype = TImage::kTiff;
5011 image = kTRUE;
5012 } else if (!title && opt.Contains("xpm")) {
5013 gtype = TImage::kXpm;
5014 image = kTRUE;
5015 } else if (!title && opt.Contains("bmp")) {
5016 gtype = TImage::kBmp;
5017 image = kTRUE;
5018 } else if (!title && opt.Contains("svg")) {
5019 gtype = TImage::kSvg;
5020 } else if (!title && opt.Contains("pdf")) {
5021 gtype = TImage::kPdf;
5022 } else if (!title && opt.Contains("html")) {
5023 gtype = TImage::kHtml;
5024 }
5025
5026 auto pp = GetPainter();
5027 Bool_t isweb = canv->IsWeb();
5028 Bool_t isbatch = gROOT->IsBatch() || canv->IsBatch();
5029
5030 // for a moment special handling of web canvas - check if can save directly
5031 if (isweb && pp)
5032 if (pp->SaveAsImage(this, psname.Data(), gtype) != TVirtualPadPainter::kSaveNotImplemented)
5033 return;
5034
5035 // to create HTML file web-based canvas functionality is invoked
5036 if (gtype == TImage::kHtml) {
5037 auto cmd = TString::Format("TWebCanvas::ProduceImage((TPad *) 0x%zx, \"%s\");", (size_t) this, psname.Data());
5038 Long_t res = gROOT->ProcessLine(cmd);
5039 if (!res)
5040 Error("Print", "Fail create HTML file %s", psname.Data());
5041 return;
5042 }
5043
5044 if (((!isbatch && image) || isweb) && pp) {
5045 Color_t hc = canv->GetHighLightColor();
5046
5047 if (!isweb) {
5048 canv->SetHighLightColor(-1);
5049 Modified();
5050 }
5051 canv->Update();
5052
5053 auto res = pp->SaveAsImage(this, psname.Data(), gtype);
5054
5055 if (!isweb)
5056 canv->SetHighLightColor(hc);
5057
5059 Warning("Print", "Unsupported image format %s, fallback to TImageDump", psname.Data());
5060 else if ((res == TVirtualPadPainter::kSaveOk) && !gSystem->AccessPathName(psname.Data()))
5061 Info("Print", "file %s has been created", psname.Data());
5062
5064 return;
5065 }
5066
5067 //==============Save pad/canvas as a C++ script==============================
5068 if (!title && opt.Contains("cxx")) {
5069 GetCanvas()->SaveSource(psname, "");
5070 return;
5071 }
5072
5073 //==============Save pad/canvas as a root file===============================
5074 if (!title && opt.Contains("root")) {
5075 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5076 return;
5077 }
5078
5079 //==============Save pad/canvas as a XML file================================
5080 if (!title && opt.Contains("xml")) {
5081 // Plugin XML driver
5082 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5083 return;
5084 }
5085
5086 //==============Save pad/canvas as a JSON file================================
5087 if (!title && opt.Contains("json")) {
5088 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5089 return;
5090 }
5091
5092 //==============Save pad/canvas as a SVG file================================
5093 if (gtype == TImage::kSvg) {
5094 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5095
5096 Bool_t noScreen = kFALSE, wasModified = IsModified();
5097 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5098 noScreen = kTRUE;
5100 }
5101
5102 TContext ctxt(this, kTRUE);
5103
5104 if (!gVirtualPS) {
5105 // Plugin Postscript/SVG driver
5106 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "svg")) {
5107 if (h->LoadPlugin() == -1)
5108 return;
5109 h->ExecPlugin(0);
5110 }
5111 }
5112
5113 // Create a new SVG file
5114 if (gVirtualPS) {
5115 gVirtualPS->SetName(psname);
5116 gVirtualPS->Open(psname);
5119 }
5120
5121 Paint();
5122 if (noScreen)
5124 if (wasModified && !IsBatch())
5125 Modified(kTRUE);
5126
5127 if (!gSystem->AccessPathName(psname))
5128 Info("Print", "SVG file %s has been created", psname.Data());
5129
5130 delete gVirtualPS;
5131 gVirtualPS = nullptr;
5132
5133 return;
5134 }
5135
5136 //==============Save pad/canvas as a TeX file================================
5137 if (!title && (opt.Contains("tex") || opt.Contains("Standalone"))) {
5138 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5139
5140 Bool_t noScreen = kFALSE, wasModified = IsModified();
5141 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5142 noScreen = kTRUE;
5144 }
5145
5146 TContext ctxt(this, kTRUE);
5147
5148 if (!gVirtualPS) {
5149 // Plugin Postscript/SVG driver
5150 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "tex")) {
5151 if (h->LoadPlugin() == -1)
5152 return;
5153 h->ExecPlugin(0);
5154 }
5155 }
5156
5157 Bool_t standalone = kFALSE;
5158 if (strstr(opt,"Standalone")) standalone = kTRUE;
5159
5160 // Create a new TeX file
5161 if (gVirtualPS) {
5162 gVirtualPS->SetName(psname);
5163 if (standalone) gVirtualPS->SetTitle("Standalone");
5164 gVirtualPS->Open(psname);
5167 }
5168 Paint();
5169 if (noScreen)
5171 if (wasModified && !IsBatch())
5172 Modified(kTRUE);
5173
5174 if (!gSystem->AccessPathName(psname)) {
5175 if (standalone) {
5176 Info("Print", "Standalone TeX file %s has been created", psname.Data());
5177 } else{
5178 Info("Print", "TeX file %s has been created", psname.Data());
5179 }
5180 }
5181
5182 delete gVirtualPS;
5183 gVirtualPS = nullptr;
5184
5185 return;
5186 }
5187
5188 //==============Save pad/canvas as a Postscript file=========================
5189
5190 // in case we read directly from a Root file and the canvas
5191 // is not on the screen, set batch mode
5192
5193 Bool_t mustOpen = kTRUE, mustClose = kTRUE,
5194 copen = kFALSE, cclose = kFALSE, copenb = kFALSE, ccloseb = kFALSE;
5195 if (!image) {
5196 // The parenthesis mechanism is only valid for PS and PDF files.
5197 copen = psname.EndsWith("("); if (copen) psname[psname.Length()-1] = 0;
5198 cclose = psname.EndsWith(")"); if (cclose) psname[psname.Length()-1] = 0;
5199 copenb = psname.EndsWith("["); if (copenb) psname[psname.Length()-1] = 0;
5200 ccloseb = psname.EndsWith("]"); if (ccloseb) psname[psname.Length()-1] = 0;
5201 }
5202 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5203 if (gVirtualPS) mustOpen = mustClose = kFALSE;
5204 if (copen || copenb) mustClose = kFALSE;
5205 if (cclose || ccloseb) mustClose = kTRUE;
5206
5207 Bool_t noScreen = kFALSE, wasModified = IsModified();
5208 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5209 noScreen = kTRUE;
5211 }
5212 Int_t pstype = 111;
5213 Double_t xcanvas = GetCanvas()->XtoPixel(GetCanvas()->GetX2());
5214 Double_t ycanvas = GetCanvas()->YtoPixel(GetCanvas()->GetY1());
5215 Double_t ratio = ycanvas/xcanvas;
5216 if (ratio < 1) pstype = 112;
5217 if (strstr(opt,"Portrait")) pstype = 111;
5218 if (strstr(opt,"Landscape")) pstype = 112;
5219 if (strstr(opt,"eps")) pstype = 113;
5220 if (strstr(opt,"Preview")) pstype = 113;
5221
5222 TContext ctxt(this, kTRUE);
5223 TVirtualPS *psave = gVirtualPS;
5224
5225 if (!gVirtualPS || mustOpen) {
5226
5227 const char *pluginName = "ps"; // Plugin Postscript driver
5228 if (opt.Contains("pdf") || title || opt.Contains("EmbedFonts"))
5229 pluginName = "pdf";
5230 else if (image)
5231 pluginName = "image"; // Plugin TImageDump driver
5232
5233 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", pluginName)) {
5234 if (h->LoadPlugin() == -1)
5235 return;
5236 h->ExecPlugin(0);
5237 }
5238
5239 // Create a new Postscript, PDF or image file
5240 if (gVirtualPS)
5241 gVirtualPS->SetName(psname);
5242 const Ssiz_t titlePos = opt.Index("Title:");
5243 if (titlePos != kNPOS) {
5244 if (gVirtualPS)
5245 gVirtualPS->SetTitle(opt.Data()+titlePos+6);
5246 opt.Replace(titlePos,opt.Length(),"pdf");
5247 }
5248 if (gVirtualPS)
5249 gVirtualPS->Open(psname,pstype);
5250 if (gVirtualPS)
5252 if (!copenb) {
5253 if (!opt.Contains("pdf") || image) {
5255 }
5256 Paint();
5257 }
5258 if (noScreen) GetCanvas()->SetBatch(kFALSE);
5259
5260 if (mustClose) {
5261 gROOT->GetListOfSpecials()->Remove(gVirtualPS);
5262 delete gVirtualPS;
5263 gVirtualPS = psave;
5264 } else {
5265 gROOT->GetListOfSpecials()->Add(gVirtualPS);
5266 gVirtualPS = nullptr;
5267 }
5268
5269 if (!gSystem->AccessPathName(psname)) {
5270 if (!copen) Info("Print", "%s file %s has been created", opt.Data(), psname.Data());
5271 else Info("Print", "%s file %s has been created using the current canvas", opt.Data(), psname.Data());
5272 }
5273 } else {
5274 // Append to existing Postscript, PDF or GIF file
5275 if (!ccloseb) {
5277 Paint();
5278 }
5279 const Ssiz_t titlePos = opt.Index("Title:");
5280 if (titlePos != kNPOS) {
5281 gVirtualPS->SetTitle(opt.Data() + titlePos + 6);
5282 opt.Replace(titlePos, opt.Length(), "pdf");
5283 } else if (!ccloseb) {
5284 gVirtualPS->SetTitle("PDF");
5285 }
5286 if (mustClose) {
5287 if (cclose) Info("Print", "Current canvas added to %s file %s and file closed", opt.Data(), psname.Data());
5288 else Info("Print", "%s file %s has been closed", opt.Data(), psname.Data());
5289 gROOT->GetListOfSpecials()->Remove(gVirtualPS);
5290 delete gVirtualPS;
5291 gVirtualPS = nullptr;
5292 } else {
5293 Info("Print", "Current canvas added to %s file %s", opt.Data(), psname.Data());
5294 gVirtualPS = nullptr;
5295 }
5296 }
5297
5298 if (wasModified && !IsBatch())
5299 Modified(kTRUE);
5300
5301 if (opt.Contains("Preview"))
5302 gSystem->Exec(TString::Format("epstool --quiet -t6p %s %s", psname.Data(), psname.Data()).Data());
5303 if (opt.Contains("EmbedFonts")) {
5304 gSystem->Exec(TString::Format("gs -quiet -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=pdf_temp.pdf -f %s",
5305 psname.Data()).Data());
5306 gSystem->Rename("pdf_temp.pdf", psname.Data());
5307 }
5308
5309}
5310
5311////////////////////////////////////////////////////////////////////////////////
5312/// Set world coordinate system for the pad.
5313/// Emits signal "RangeChanged()", in the slot get the range
5314/// via GetRange().
5315
5317{
5318 if ((x1 >= x2) || (y1 >= y2)) {
5319 Error("Range", "illegal world coordinates range: x1=%f, y1=%f, x2=%f, y2=%f",x1,y1,x2,y2);
5320 return;
5321 }
5322
5323 fUxmin = x1;
5324 fUxmax = x2;
5325 fUymin = y1;
5326 fUymax = y2;
5327
5328 if (fX1 == x1 && fY1 == y1 && fX2 == x2 && fY2 == y2) return;
5329
5330 fX1 = x1;
5331 fY1 = y1;
5332 fX2 = x2;
5333 fY2 = y2;
5334
5335 // compute pad conversion coefficients
5336 ResizePad();
5337
5338 if (gPad == this && GetPainter())
5340
5341 // emit signal
5342 RangeChanged();
5343}
5344
5345////////////////////////////////////////////////////////////////////////////////
5346/// Set axis coordinate system for the pad.
5347/// The axis coordinate system is a subset of the world coordinate system
5348/// xmin,ymin is the origin of the current coordinate system,
5349/// xmax is the end of the X axis, ymax is the end of the Y axis.
5350/// By default a margin of 10 per cent is left on all sides of the pad
5351/// Emits signal "RangeAxisChanged()", in the slot get the axis range
5352/// via GetRangeAxis().
5353
5355{
5356 if ((xmin >= xmax) || (ymin >= ymax)) {
5357 Error("RangeAxis", "illegal axis coordinates range: xmin=%f, ymin=%f, xmax=%f, ymax=%f",
5358 xmin, ymin, xmax, ymax);
5359 return;
5360 }
5361
5362 fUxmin = xmin;
5363 fUymin = ymin;
5364 fUxmax = xmax;
5365 fUymax = ymax;
5366
5367 // emit signal
5369}
5370
5371////////////////////////////////////////////////////////////////////////////////
5372/// Recursively remove object from a pad and its sub-pads.
5373
5375{
5376 if (fCanvas) {
5377 if (obj == fCanvas->GetSelected()) fCanvas->SetSelected(nullptr);
5378 if (obj == fCanvas->GetClickSelected()) fCanvas->SetClickSelected(nullptr);
5379 }
5380 if (obj == fView) fView = nullptr;
5381 if (!fPrimitives) return;
5382 Int_t nold = fPrimitives->GetSize();
5384 if (nold != fPrimitives->GetSize()) fModified = kTRUE;
5385}
5386
5387////////////////////////////////////////////////////////////////////////////////
5388/// Remove object from list of primitives
5389/// When \par modified set to kTRUE (default) pad will be marked as modified - if object really removed
5390/// Returns result of GetListOfPrimitives()->Remove(obj) or nullptr if list of primitives not exists
5391
5393{
5394 TObject *res = nullptr;
5395 if (fPrimitives)
5396 res = fPrimitives->Remove(obj);
5397 if (res && modified)
5398 Modified();
5399 return res;
5400}
5401
5402////////////////////////////////////////////////////////////////////////////////
5403/// Redraw the frame axis.
5404///
5405/// Redrawing axis may be necessary in case of superimposed histograms
5406/// when one or more histograms have a fill color.
5407///
5408/// Instead of calling this function, it may be more convenient
5409/// to call directly `h1->Draw("sameaxis")` where h1 is the pointer
5410/// to the first histogram drawn in the pad.
5411///
5412/// By default, if the pad has the options gridx or/and gridy activated,
5413/// the grid is not drawn by this function.
5414///
5415/// If option="g" is specified, this will force the drawing of the grid
5416/// on top of the picture
5417///
5418/// To redraw the axis tick marks do:
5419/// ~~~ {.cpp}
5420/// gPad->RedrawAxis();
5421/// ~~~
5422/// To redraw the axis grid do:
5423/// ~~~ {.cpp}
5424/// gPad->RedrawAxis("G");
5425/// ~~~
5426/// To redraw the axis tick marks and the axis grid do:
5427/// ~~~ {.cpp}
5428/// gPad->RedrawAxis();
5429/// gPad->RedrawAxis("G");
5430/// ~~~
5431///
5432/// If option="f" is specified, this will force the drawing of the frame
5433/// around the plot.
5434
5436{
5437 TString opt = option;
5438 opt.ToLower();
5439
5440 TContext ctxt(this, kTRUE);
5441
5442 TH1 *hobj = nullptr;
5443
5444 // Get the first histogram drawing the axis in the list of primitives
5445 if (!fPrimitives) fPrimitives = new TList;
5446 TIter next(fPrimitives);
5447 TObject *obj;
5448 while ((obj = next())) {
5449 if (obj->InheritsFrom(TH1::Class())) {
5450 hobj = (TH1*)obj;
5451 break;
5452 }
5453 if (obj->InheritsFrom(TMultiGraph::Class())) {
5454 TMultiGraph *mg = (TMultiGraph*)obj;
5455 if (mg) hobj = mg->GetHistogram();
5456 break;
5457 }
5458 if (obj->InheritsFrom(TGraph::Class())) {
5459 TGraph *g = (TGraph*)obj;
5460 if (g) hobj = g->GetHistogram();
5461 break;
5462 }
5463 if (obj->InheritsFrom(THStack::Class())) {
5464 THStack *hs = (THStack*)obj;
5465 if (hs) hobj = hs->GetHistogram();
5466 break;
5467 }
5468 }
5469
5470 if (hobj) {
5471 if (opt.Contains("g")) hobj->DrawCopy("sameaxig");
5472 else hobj->DrawCopy("sameaxis");
5473 }
5474
5475 if (opt.Contains("f")) {
5476 auto b = new TBox(gPad->GetUxmin(), gPad->GetUymin(),
5477 gPad->GetUxmax(), gPad->GetUymax());
5478 b->SetFillStyle(0);
5479 b->SetLineStyle(gPad->GetFrameLineStyle());
5480 b->SetLineWidth(gPad->GetFrameLineWidth());
5481 b->SetLineColor(gPad->GetFrameLineColor());
5482 b->Draw();
5483 }
5484}
5485
5486////////////////////////////////////////////////////////////////////////////////
5487/// Compute pad conversion coefficients.
5488///
5489/// ### Conversion from x to px
5490///
5491/// \f[\frac{x-xmin}{xrange} = \frac{px-pxlow}{pxrange}\f]
5492/// with:
5493/// \f[ xrange = xmax-xmin \f]
5494/// \f[ pxrange = pxmax-pxmin \f]
5495///
5496/// \f[
5497/// \Rightarrow px = \frac{pxrange(x-xmin)}{xrange} + pxlow = fXtoPixelk + fXtoPixel \times x
5498/// \f]
5499///
5500/// \f[
5501/// \Rightarrow fXtoPixelk = pxlow - pxrange \frac{xmin}{xrange}
5502/// \f]
5503/// \f[
5504/// fXtoPixel = \frac{pxrange}{xrange}
5505/// \f]
5506/// where:
5507/// \f[
5508/// pxlow = fAbsXlowNDC \times fCw
5509/// \f]
5510/// \f[
5511/// pxrange = fAbsWNDC \times fCw
5512/// \f]
5513///
5514/// ### Conversion from y to py
5515///
5516/// \f[\frac{y-ymin}{yrange} = \frac{py-pylow}{pyrange}\f]
5517/// with:
5518/// \f[ yrange = ymax-ymin \f]
5519/// \f[ pyrange = pymax-pymin \f]
5520///
5521/// \f[
5522/// \Rightarrow py = \frac{pyrange(y-xmin)}{yrange} + pylow = fYtoPixelk + fYtoPixel \times y
5523/// \f]
5524///
5525/// \f[
5526/// \Rightarrow fYtoPixelk = pylow - pyrange \frac{ymin}{yrange}
5527/// \f]
5528/// \f[
5529/// fYtoPixel = \frac{pyrange}{yrange}
5530/// \f]
5531/// where:
5532/// \f[
5533/// pylow = fAbsYlowNDC \times fCh
5534/// \f]
5535/// \f[
5536/// pyrange = fAbsHNDC \times fCh
5537/// \f]
5538///
5539/// ### Conversion from px to x
5540///
5541/// \f[
5542/// \Rightarrow x = \frac{xrange(px-pxlow)}{pxrange}+ xmin = fPixeltoXk + fPixeltoX \times px
5543/// \f]
5544///
5545/// \f[
5546/// \Rightarrow fPixeltoXk = xmin - pxlow \times\frac{xrange}{pxrange}
5547/// \f]
5548/// \f[
5549/// fPixeltoX = \frac{xrange}{pxrange}
5550/// \f]
5551///
5552/// ### Conversion from py to y
5553///
5554/// \f[
5555/// \Rightarrow y = \frac{yrange(py-pylow)}{pyrange}+ ymin = fPixeltoYk + fPixeltoY \times py
5556/// \f]
5557///
5558/// \f[
5559/// \Rightarrow fPixeltoYk = ymin - pylow \times\frac{yrange}{pyrange}
5560/// \f]
5561/// \f[
5562/// fPixeltoY = \frac{yrange}{pyrange}
5563/// \f]
5564///
5565/// ### Computation of the coefficients in case of LOG scales
5566///
5567/// #### Conversion from pixel coordinates to world coordinates
5568///
5569/// \f[
5570/// u = \frac{Log(x) - Log(xmin)}{Log(xmax) - Log(xmin)} = \frac{Log(x/xmin)}{Log(xmax/xmin)} = \frac{px - pxlow}{pxrange}
5571/// \f]
5572///
5573/// \f[ \Rightarrow Log(\frac{x}{xmin}) = u \times Log(\frac{xmax}{xmin}) \f]
5574/// \f[ x = xmin \times e^{(u \times Log(\frac{xmax}{xmin})} \f]
5575/// Let:
5576/// \f[ alfa = \frac{Log(\frac{xmax}{xmin})}{fAbsWNDC} \f]
5577///
5578/// \f[ x = xmin \times e^{(-alfa \times pxlow)} + e^{(alfa \times px)} \f]
5579/// \f[ x = fPixeltoXk \times e^{(fPixeltoX \times px)} \f]
5580/// \f[ ==> fPixeltoXk = xmin \times e^{(-alfa*pxlow)} \f]
5581/// \f[ fPixeltoX = alfa \f]
5582///
5583/// \f[
5584/// v = \frac{Log(y) - Log(ymin)}{Log(ymax) - Log(ymin)} = \frac{Log(y/ymin)}{Log(ymax/ymin)} = \frac{py - pylow}{pyrange}
5585/// \f]
5586/// Let:
5587/// \f[ beta = Log(\frac{ymax}{ymin}) \f]
5588/// \f[ Log(\frac{y}{ymin}) = beta \times pylow - beta \times py \f]
5589/// \f[ \frac{y}{ymin} = e^{(beta \times pylow - beta \times py)} \f]
5590/// \f[ y = ymin \times e^{(beta \times pylow)} \times e^{(-beta \times py)}\f]
5591/// \f[ \Rightarrow y = fPixeltoYk \times e^{(fPixeltoY \times py)} \f]
5592/// \f[ fPixeltoYk = ymin \times e^{(beta \times pylow)} \f]
5593/// \f[ fPixeltoY = -beta \f]
5594///
5595/// #### Conversion from World coordinates to pixel coordinates
5596///
5597/// \f[ px = pxlow + u*pxrange \f]
5598/// \f[ = pxlow + Log(x/xmin)/alfa \f]
5599/// \f[ = pxlow -Log(xmin)/alfa + Log(x)/alfa \f]
5600/// \f[ = fXtoPixelk + fXtoPixel*Log(x) \f]
5601/// \f[ \Rightarrow fXtoPixelk = pxlow -Log(xmin)/alfa \f]
5602/// \f[ \Rightarrow fXtoPixel = 1/alfa \f]
5603///
5604/// \f[ py = pylow - Log(y/ymin)/beta \f]
5605/// \f[ = fYtoPixelk + fYtoPixel*Log(y) \f]
5606/// \f[ \Rightarrow fYtoPixelk = pylow - Log(ymin)/beta \f]
5607/// \f[ fYtoPixel = 1/beta \f]
5608
5610{
5611
5612 if (!gPad) {
5613 Error("ResizePad", "Cannot resize pad. No current pad available.");
5614 return;
5615 }
5616 if (gPad->GetWw()==0.0||gPad->GetWh()==0.0) {
5617 Warning("ResizePad", "gPad has at least one zero dimension.");
5618 return;
5619 }
5620 if (fX1==fX2||fY1==fY2) {
5621 Warning("ResizePad", "The pad has at least one zero dimension.");
5622 return;
5623 }
5624 // Recompute subpad positions in case pad has been moved/resized
5625 TPad *parent = fMother;
5626 if (this == gPad->GetCanvas()) {
5629 fAbsWNDC = fWNDC;
5630 fAbsHNDC = fHNDC;
5631 }
5632 else {
5633 if (parent->GetAbsHNDC()==0.0||parent->GetAbsWNDC()==0.0||fHNDC==0.0||fWNDC==0.0) {
5634 Warning("ResizePad", "The parent pad has at least one zero dimension.");
5635 return;
5636 }
5637 fAbsXlowNDC = fXlowNDC*parent->GetAbsWNDC() + parent->GetAbsXlowNDC();
5638 fAbsYlowNDC = fYlowNDC*parent->GetAbsHNDC() + parent->GetAbsYlowNDC();
5639 fAbsWNDC = fWNDC*parent->GetAbsWNDC();
5640 fAbsHNDC = fHNDC*parent->GetAbsHNDC();
5641 }
5642
5643 Double_t ww = (Double_t)gPad->GetWw();
5644 Double_t wh = (Double_t)gPad->GetWh();
5645 Double_t pxlow = fAbsXlowNDC*ww;
5646 Double_t pylow = (1-fAbsYlowNDC)*wh;
5647 Double_t pxrange = fAbsWNDC*ww;
5648 Double_t pyrange = -fAbsHNDC*wh;
5649
5650 // Linear X axis
5651 Double_t rounding = 0.; // was used before to adjust somehow wrong int truncation by coordinates transformation
5652 Double_t xrange = fX2 - fX1;
5653 fXtoAbsPixelk = rounding + pxlow - pxrange*fX1/xrange; //origin at left
5654 fXtoPixelk = rounding + -pxrange*fX1/xrange;
5655 fXtoPixel = pxrange/xrange;
5656 fAbsPixeltoXk = fX1 - pxlow*xrange/pxrange;
5657 fPixeltoXk = fX1;
5658 fPixeltoX = xrange/pxrange;
5659 // Linear Y axis
5660 Double_t yrange = fY2 - fY1;
5661 fYtoAbsPixelk = rounding + pylow - pyrange*fY1/yrange; //origin at top
5662 fYtoPixelk = rounding + -pyrange - pyrange*fY1/yrange;
5663 fYtoPixel = pyrange/yrange;
5664 fAbsPixeltoYk = fY1 - pylow*yrange/pyrange;
5665 fPixeltoYk = fY1;
5666 fPixeltoY = yrange/pyrange;
5667
5668 // Coefficients to convert from pad NDC coordinates to pixel coordinates
5669
5670 fUtoAbsPixelk = rounding + pxlow;
5671 fUtoPixelk = rounding;
5672 fUtoPixel = pxrange;
5673 fVtoAbsPixelk = rounding + pylow;
5674 fVtoPixelk = -pyrange;
5675 fVtoPixel = pyrange;
5676
5677 // Coefficients to convert from canvas pixels to pad world coordinates
5678
5679 // Resize all sub-pads
5680 if (!fPrimitives)
5681 fPrimitives = new TList;
5682 TIter next(GetListOfPrimitives());
5683 while (auto obj = next()) {
5684 if (obj->InheritsFrom(TPad::Class()))
5685 ((TPad *)obj)->ResizePad(option);
5686 }
5687
5688 // Reset all current sizes
5689 if (gPad->IsBatch())
5690 fPixmapID = 0;
5691 else if (auto pp = GetPainter()) {
5692 if (pp->IsNative()) {
5693 // TODO: check if this is necessary
5694 auto attl = pp->GetAttLine();
5695 attl.SetLineColor(-1);
5696 pp->SetAttLine(attl);
5697 auto attt = pp->GetAttText();
5698 attt.SetTextSize(-1);
5699 pp->OnPad(this);
5700 pp->SetAttText(attt);
5701 // create or re-create off-screen pixmap
5702 if (fPixmapID) {
5703 int w = TMath::Abs(XtoPixel(fX2) - XtoPixel(fX1));
5704 int h = TMath::Abs(YtoPixel(fY2) - YtoPixel(fY1));
5705 //protection in case of wrong pad parameters.
5706 //without this protection, the OpenPixmap or ResizePixmap crashes with
5707 //the message "Error in <RootX11ErrorHandler>: BadValue (integer parameter out of range for operation)"
5708 //resulting in a frozen xterm
5711 Warning("ResizePad", "Inf/NaN propagated to the pad. Check drawn objects.");
5712 if (w <= 0 || w > 10000) {
5713 Warning("ResizePad", "%s width changed from %d to %d\n",GetName(),w,10);
5714 w = 10;
5715 }
5716 if (h <= 0 || h > 10000) {
5717 Warning("ResizePad", "%s height changed from %d to %d\n",GetName(),h,10);
5718 h = 10;
5719 }
5720 if (fPixmapID == -1) // this case is handled via the ctor
5721 fPixmapID = pp->CreateDrawable(w, h);
5722 else if (pp->ResizeDrawable(fPixmapID, w, h)) {
5723 Resized();
5724 Modified(kTRUE);
5725 }
5726 }
5727 }
5728 }
5729 if (fView) {
5730 if (gPad == this) {
5731 fView->ResizePad();
5732 } else {
5733 TContext ctxt(this, kTRUE);
5734 fView->ResizePad();
5735 }
5736 }
5737}
5738
5739////////////////////////////////////////////////////////////////////////////////
5740/// Save the pad content in a file.
5741///
5742/// The file's format used to save the pad is determined by the `filename` extension:
5743///
5744/// - if `filename` is empty, the file produced is `padname.ps`
5745/// - if `filename` starts with a dot, the padname is added in front
5746/// - if `filename` ends with `.ps`, a Postscript file is produced
5747/// - if `filename` ends with `.eps`, an Encapsulated Postscript file is produced
5748/// - if `filename` ends with `.pdf`, a PDF file is produced NOTE: TMathText will be converted to TLatex; q.e.d., symbols only available in TMathText will not render properly.
5749/// - if `filename` ends with `.svg`, a SVG file is produced
5750/// - if `filename` ends with `.tex`, a TeX file is produced
5751/// - if `filename` ends with `.gif`, a GIF file is produced
5752/// - if `filename` ends with `.gif+NN`, an animated GIF file is produced See comments in TASImage::WriteImage for meaning of NN and other .gif sufix variants
5753/// - if `filename` ends with `.xpm`, a XPM file is produced
5754/// - if `filename` ends with `.png`, a PNG file is produced
5755/// - if `filename` ends with `.bmp`, a BMP file is produced
5756/// - if `filename` ends with `.jpg` or `.jpeg` a JPEG file is produced NOTE: JPEG's lossy compression will make all sharp edges fuzzy.
5757/// - if `filename` ends with `.tiff`, a TIFF file is produced
5758/// - if `filename` ends with `.C`, `.cxx`,`.cpp` or `.cc`, a C++ macro file is produced
5759/// - if `filename` ends with `.root`, a Root file is produced
5760/// - if `filename` ends with `.xml`, a XML file is produced
5761/// - if `filename` ends with `.json`, a JSON file is produced
5762///
5763/// \remarks
5764/// - The parameter `option` is not used.
5765/// - This method calls [TPad::Print(const char *filename, Option_t *option)](\ref TPadPrint)
5766/// the value of `option` is determined by the `filename` extension.
5767/// - Postscript and PDF formats allow to have [several pictures in one file](\ref TPadPrintPS).
5768
5769void TPad::SaveAs(const char *filename, Option_t * /*option*/) const
5770{
5771 TString psname;
5772 Int_t lenfil = filename ? strlen(filename) : 0;
5773
5774 if (!lenfil) { psname = GetName(); psname.Append(".ps"); }
5775 else psname = filename;
5776
5777 // lines below protected against case like c1->SaveAs( "../ps/cs.ps" );
5778 if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
5779 psname = GetName();
5780 psname.Append(filename);
5781 psname.Prepend("/");
5782 psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
5783 }
5784
5785 if (psname.EndsWith(".gif"))
5786 ((TPad*)this)->Print(psname,"gif");
5787 else if (psname.Contains(".gif+"))
5788 ((TPad*)this)->Print(psname,"gif+");
5789 else if (psname.EndsWith(".C") || psname.EndsWith(".cxx") || psname.EndsWith(".cpp") || psname.EndsWith(".cc"))
5790 ((TPad*)this)->Print(psname,"cxx");
5791 else if (psname.EndsWith(".root"))
5792 ((TPad*)this)->Print(psname,"root");
5793 else if (psname.EndsWith(".xml"))
5794 ((TPad*)this)->Print(psname,"xml");
5795 else if (psname.EndsWith(".json"))
5796 ((TPad*)this)->Print(psname,"json");
5797 else if (psname.EndsWith(".html"))
5798 ((TPad*)this)->Print(psname,"html");
5799 else if (psname.EndsWith(".eps"))
5800 ((TPad*)this)->Print(psname,"eps");
5801 else if (psname.EndsWith(".pdf") || psname.EndsWith(".pdf[") || psname.EndsWith(".pdf]") || psname.EndsWith(".pdf("))
5802 ((TPad*)this)->Print(psname,"pdf");
5803 else if (psname.EndsWith(".svg"))
5804 ((TPad*)this)->Print(psname,"svg");
5805 else if (psname.EndsWith(".tex"))
5806 ((TPad*)this)->Print(psname,"tex");
5807 else if (psname.EndsWith(".xpm"))
5808 ((TPad*)this)->Print(psname,"xpm");
5809 else if (psname.EndsWith(".png"))
5810 ((TPad*)this)->Print(psname,"png");
5811 else if (psname.EndsWith(".jpg") || psname.EndsWith(".jpeg"))
5812 ((TPad*)this)->Print(psname,"jpg");
5813 else if (psname.EndsWith(".bmp"))
5814 ((TPad*)this)->Print(psname,"bmp");
5815 else if (psname.EndsWith(".tiff"))
5816 ((TPad*)this)->Print(psname,"tiff");
5817 else
5818 ((TPad*)this)->Print(psname,"ps");
5819}
5820
5821////////////////////////////////////////////////////////////////////////////////
5822/// Save primitives in this pad on the C++ source file out.
5823
5824void TPad::SavePrimitive(std::ostream &out, Option_t * option /*= ""*/)
5825{
5826 TContext ctxt(this, kFALSE); // not interactive
5827
5828 TString padName = GetName();
5829
5830 // check for space in the pad name
5831 auto p = padName.Index(" ");
5832 if (p != kNPOS)
5833 padName.Resize(p);
5834
5835 TString opt = option;
5836 if (!opt.Contains("toplevel")) {
5837 static Int_t pcounter = 0;
5838 padName += TString::Format("__%d", pcounter++);
5839 padName = gInterpreter->MapCppName(padName);
5840 }
5841
5842 const char *pname = padName.Data();
5843 const char *cname = padName.Data();
5844
5845 if (padName.Length() == 0) {
5846 pname = "unnamed";
5847 if (this == gPad->GetCanvas())
5848 cname = "c1";
5849 else
5850 cname = "pad";
5851 }
5852
5853 // Write pad parameters
5854 if (this != gPad->GetCanvas()) {
5855 out << " \n";
5856 out << "// ------------>Primitives in pad: " << GetName() << "\n";
5857 out << " TPad *" << cname << " = new TPad(\"" << GetName() << "\", \""
5858 << TString(GetTitle()).ReplaceSpecialCppChars() << "\", " << fXlowNDC << ", " << fYlowNDC << ", "
5859 << fXlowNDC + fWNDC << ", " << fYlowNDC + fHNDC << ");\n";
5860 out << " " << cname << "->Draw();\n";
5861 out << " " << cname << "->cd();\n";
5862 }
5863 out << " " << cname << "->Range(" << fX1 << "," << fY1 << "," << fX2 << "," << fY2 << ");\n";
5864 TView *view = GetView();
5865 if (view) {
5866 Double_t rmin[3], rmax[3];
5867 view->GetRange(rmin, rmax);
5868 out << " TView::CreateView(1)->SetRange(" << rmin[0] << ", " << rmin[1] << ", " << rmin[2] << ", " << rmax[0]
5869 << ", " << rmax[1] << ", " << rmax[2] << ");\n";
5870 }
5871
5872 SaveFillAttributes(out, cname, -1, -1);
5873
5874 if (GetBorderMode() != 1)
5875 out << " " << cname << "->SetBorderMode(" << GetBorderMode() << ");\n";
5876 if (GetBorderSize() != 4)
5877 out << " " << cname << "->SetBorderSize(" << GetBorderSize() << ");\n";
5878 if (GetLogx())
5879 out << " " << cname << "->SetLogx();\n";
5880 if (GetLogy())
5881 out << " " << cname << "->SetLogy();\n";
5882 if (GetLogz())
5883 out << " " << cname << "->SetLogz();\n";
5884 if (GetGridx())
5885 out << " " << cname << "->SetGridx();\n";
5886 if (GetGridy())
5887 out << " " << cname << "->SetGridy();\n";
5888 if (GetTickx())
5889 out << " " << cname << "->SetTickx(" << GetTickx() << ");\n";
5890 if (GetTicky())
5891 out << " " << cname << "->SetTicky(" << GetTicky() << ");\n";
5892 if (GetTheta() != 30)
5893 out << " " << cname << "->SetTheta(" << GetTheta() << ");\n";
5894 if (GetPhi() != 30)
5895 out << " " << cname << "->SetPhi(" << GetPhi() << ");\n";
5896 if (TMath::Abs(fLeftMargin - 0.1) > 0.01)
5897 out << " " << cname << "->SetLeftMargin(" << GetLeftMargin() << ");\n";
5898 if (TMath::Abs(fRightMargin - 0.1) > 0.01)
5899 out << " " << cname << "->SetRightMargin(" << GetRightMargin() << ");\n";
5900 if (TMath::Abs(fTopMargin - 0.1) > 0.01)
5901 out << " " << cname << "->SetTopMargin(" << GetTopMargin() << ");\n";
5902 if (TMath::Abs(fBottomMargin - 0.1) > 0.01)
5903 out << " " << cname << "->SetBottomMargin(" << GetBottomMargin() << ");\n";
5904
5906 out << " " << cname << "->SetFrameFillColor(" << TColor::SavePrimitiveColor(GetFrameFillColor()) << ");\n";
5907 if (GetFrameFillStyle() != 1001)
5908 out << " " << cname << "->SetFrameFillStyle(" << GetFrameFillStyle() << ");\n";
5909 if (GetFrameLineStyle() != 1)
5910 out << " " << cname << "->SetFrameLineStyle(" << GetFrameLineStyle() << ");\n";
5911 if (GetFrameLineColor() != 1)
5912 out << " " << cname << "->SetFrameLineColor(" << TColor::SavePrimitiveColor(GetFrameLineColor()) << ");\n";
5913 if (GetFrameLineWidth() != 1)
5914 out << " " << cname << "->SetFrameLineWidth(" << GetFrameLineWidth() << ");\n";
5915 if (GetFrameBorderMode() != 0)
5916 out << " " << cname << "->SetFrameBorderMode(" << GetFrameBorderMode() << ");\n";
5917 if (GetFrameBorderSize() != 1)
5918 out << " " << cname << "->SetFrameBorderSize(" << GetFrameBorderSize() << ");\n";
5919
5920 TFrame *frame = fFrame;
5921 if (!frame)
5922 frame = (TFrame *)GetPrimitive("TFrame");
5923 if (frame) {
5924 if (frame->GetFillColor() != GetFillColor())
5925 out << " " << cname << "->SetFrameFillColor(" << TColor::SavePrimitiveColor(frame->GetFillColor()) << ");\n";
5926 if (frame->GetFillStyle() != 1001)
5927 out << " " << cname << "->SetFrameFillStyle(" << frame->GetFillStyle() << ");\n";
5928 if (frame->GetLineStyle() != 1)
5929 out << " " << cname << "->SetFrameLineStyle(" << frame->GetLineStyle() << ");\n";
5930 if (frame->GetLineColor() != 1)
5931 out << " " << cname << "->SetFrameLineColor(" << TColor::SavePrimitiveColor(frame->GetLineColor()) << ");\n";
5932 if (frame->GetLineWidth() != 1)
5933 out << " " << cname << "->SetFrameLineWidth(" << frame->GetLineWidth() << ");\n";
5934 if (frame->GetBorderMode() != 0)
5935 out << " " << cname << "->SetFrameBorderMode(" << frame->GetBorderMode() << ");\n";
5936 if (frame->GetBorderSize() != 1)
5937 out << " " << cname << "->SetFrameBorderSize(" << frame->GetBorderSize() << ");\n";
5938 }
5939
5940 TIter next(GetListOfPrimitives());
5941
5942 while (auto obj = next()) {
5943 obj->SavePrimitive(out, (Option_t *)next.GetOption());
5944 if (obj->InheritsFrom(TPad::Class())) {
5945 if (opt.Contains("toplevel"))
5946 out << " " << pname << "->cd();\n";
5947 else
5948 out << " " << cname << "->cd();\n";
5949 }
5950 }
5951 out << " " << cname << "->Modified();\n";
5952}
5953
5954////////////////////////////////////////////////////////////////////////////////
5955/// Fix pad aspect ratio to current value if fixed is true.
5956
5958{
5959 if (fixed) {
5960 if (!fFixedAspectRatio) {
5961 if (fHNDC != 0.)
5963 else {
5964 Error("SetAspectRatio", "cannot fix aspect ratio, height of pad is 0");
5965 return;
5966 }
5968 }
5969 } else {
5971 fAspectRatio = 0;
5972 }
5973}
5974
5975////////////////////////////////////////////////////////////////////////////////
5976/// Set pad editable yes/no
5977/// If a pad is not editable:
5978/// - one cannot modify the pad and its objects via the mouse.
5979/// - one cannot add new objects to the pad
5980
5982{
5983 fEditable = mode;
5984
5985 TObject *obj;
5986 if (!fPrimitives) fPrimitives = new TList;
5987 TIter next(GetListOfPrimitives());
5988 while ((obj = next())) {
5989 if (obj->InheritsFrom(TPad::Class())) {
5990 TPad *pad = (TPad*)obj;
5991 pad->SetEditable(mode);
5992 }
5993 }
5994}
5995
5996////////////////////////////////////////////////////////////////////////////////
5997/// Override TAttFill::FillStyle for TPad because we want to handle style=0
5998/// as style 4000.
5999
6001{
6002 if (fstyle == 0) fstyle = 4000;
6003 TAttFill::SetFillStyle(fstyle);
6004}
6005
6006////////////////////////////////////////////////////////////////////////////////
6007/// Set Lin/Log scale for X
6008/// - value = 0 X scale will be linear
6009/// - value = 1 X scale will be logarithmic (base 10)
6010/// - value > 1 reserved for possible support of base e or other
6011
6013{
6014 fLogx = value;
6015 delete fView; fView = nullptr;
6016 Modified();
6018}
6019
6020////////////////////////////////////////////////////////////////////////////////
6021/// Set Lin/Log scale for Y
6022/// - value = 0 Y scale will be linear
6023/// - value = 1 Y scale will be logarithmic (base 10)
6024/// - value > 1 reserved for possible support of base e or other
6025
6027{
6028 fLogy = value;
6029 delete fView; fView = nullptr;
6030 Modified();
6032}
6033
6034////////////////////////////////////////////////////////////////////////////////
6035/// Set Lin/Log scale for Z
6036
6038{
6039 fLogz = value;
6040 delete fView; fView = nullptr;
6041 Modified();
6043}
6044
6045////////////////////////////////////////////////////////////////////////////////
6046/// Set canvas range for pad and resize the pad. If the aspect ratio
6047/// was fixed before the call it will be un-fixed.
6048
6050{
6051 // Reorder points to make sure xlow,ylow is bottom left point and
6052 // xup,yup is top right point.
6053 if (xup < xlow) {
6054 Double_t x = xlow;
6055 xlow = xup;
6056 xup = x;
6057 }
6058 if (yup < ylow) {
6059 Double_t y = ylow;
6060 ylow = yup;
6061 yup = y;
6062 }
6063
6064 // Check if the new pad position is valid.
6065 if ((xlow < 0) || (xlow > 1) || (ylow < 0) || (ylow > 1)) {
6066 Error("TPad", "illegal bottom left position: x=%f, y=%f", xlow, ylow);
6067 return;
6068 }
6069 if ((xup < 0) || (xup > 1) || (yup < 0) || (yup > 1)) {
6070 Error("TPad", "illegal top right position: x=%f, y=%f", xup, yup);
6071 return;
6072 }
6073 if (xup-xlow <= 0) {
6074 Error("TPad", "illegal width: %f", xup-xlow);
6075 return;
6076 }
6077 if (yup-ylow <= 0) {
6078 Error("TPad", "illegal height: %f", yup-ylow);
6079 return;
6080 }
6081
6082 fXlowNDC = xlow;
6083 fYlowNDC = ylow;
6084 fXUpNDC = xup;
6085 fYUpNDC = yup;
6086 fWNDC = xup - xlow;
6087 fHNDC = yup - ylow;
6088
6090
6091 ResizePad();
6092}
6093
6094////////////////////////////////////////////////////////////////////////////////
6095/// Set all pad parameters.
6096
6097void TPad::SetPad(const char *name, const char *title,
6098 Double_t xlow, Double_t ylow, Double_t xup, Double_t yup,
6099 Color_t color, Short_t bordersize, Short_t bordermode)
6100{
6101 fName = name;
6102 fTitle = title;
6103 SetFillStyle(1001);
6108 if (color >= 0) SetFillColor(color);
6110 if (bordersize < 0) fBorderSize = gStyle->GetPadBorderSize();
6111 else fBorderSize = bordersize;
6112 if (bordermode < -1) fBorderMode = gStyle->GetPadBorderMode();
6113 else fBorderMode = bordermode;
6114
6115 SetPad(xlow, ylow, xup, yup);
6116}
6117
6118////////////////////////////////////////////////////////////////////////////////
6119/// Set the current TView. Delete previous view if view=0
6120
6122{
6123 if (!view) delete fView;
6124 fView = view;
6125}
6126
6127////////////////////////////////////////////////////////////////////////////////
6128/// Set postscript fill area attributes.
6129///
6130/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6131
6133{
6134 if (auto pp = GetPainter())
6135 if (pp->GetPS())
6136 pp->SetAttFill({color, style});
6137}
6138
6139////////////////////////////////////////////////////////////////////////////////
6140/// Set postscript line attributes.
6141///
6142/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6143
6145{
6146 if (auto pp = GetPainter())
6147 if (pp->GetPS())
6148 pp->SetAttLine({color, style, lwidth});
6149}
6150
6151////////////////////////////////////////////////////////////////////////////////
6152/// Set postscript marker attributes.
6153///
6154/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6155
6157{
6158 if (auto pp = GetPainter())
6159 if (pp->GetPS())
6160 pp->SetAttMarker({color, style, msize});
6161}
6162
6163////////////////////////////////////////////////////////////////////////////////
6164/// Set postscript text attributes.
6165///
6166/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6167
6169{
6170 if (auto pp = GetPainter())
6171 if (pp->GetPS()) {
6172 if (font % 10 > 2) {
6173 Float_t wh = (Float_t) XtoPixel(GetX2());
6174 Float_t hh = (Float_t) YtoPixel(GetY1());
6175 Float_t dy;
6176 if (wh < hh) {
6177 dy = AbsPixeltoX(Int_t(tsize)) - AbsPixeltoX(0);
6178 tsize = dy/(GetX2()-GetX1());
6179 } else {
6180 dy = AbsPixeltoY(0) - AbsPixeltoY(Int_t(tsize));
6181 tsize = dy/(GetY2()-GetY1());
6182 }
6183 }
6184 pp->OnPad(this);
6185 pp->SetAttText({align, angle, color, font, tsize});
6186 }
6187}
6188
6189////////////////////////////////////////////////////////////////////////////////
6190/// Draw Arrows to indicated equal distances of Objects with given BBoxes.
6191/// Used by ShowGuidelines
6192
6194{
6195 Int_t lineColor = TColor::GetColor(239, 202, 0);
6196 Int_t x1,x2,y1,y2;
6197 x1 = x2 = y1 = y2 = 0;
6198 if (mode == 'x') {
6199 if (aBBox.fX<bBBox.fX) {
6200 x1 = aBBox.fX+aBBox.fWidth;
6201 x2 = bBBox.fX;
6202 }
6203 else {
6204 x1 = bBBox.fX+bBBox.fWidth;
6205 x2 = aBBox.fX;
6206 }
6207
6208 if ((aBBox.fY > bBBox.fY) && (aBBox.fY + aBBox.fHeight < bBBox.fY + bBBox.fHeight))
6209 y1 = y2 = aBBox.fY + TMath::Nint(0.5*(Double_t)(aBBox.fHeight))+1;
6210 else if ((bBBox.fY > aBBox.fY) && (bBBox.fY + bBBox.fHeight < aBBox.fY + aBBox.fHeight))
6211 y1 = y2 = bBBox.fY + TMath::Nint(0.5*(Double_t)(bBBox.fHeight))+1;
6212 else if (aBBox.fY>bBBox.fY) y1 = y2 = aBBox.fY-TMath::Nint(0.5*(Double_t)(aBBox.fY-(bBBox.fY+bBBox.fHeight)));
6213 else y1 = y2 = bBBox.fY-TMath::Nint(0.5*(Double_t)(bBBox.fY-(aBBox.fY+aBBox.fHeight)));
6214 }
6215 else if (mode == 'y') {
6216 if (aBBox.fY<bBBox.fY) {
6217 y1 = aBBox.fY+aBBox.fHeight;
6218 y2 = bBBox.fY;
6219 }
6220 else {
6221 y1 = bBBox.fY+bBBox.fHeight;
6222 y2 = aBBox.fY;
6223 }
6224 if ((aBBox.fX > bBBox.fX) && (aBBox.fX + aBBox.fWidth < bBBox.fX + bBBox.fWidth))
6225 x1 = x2 = aBBox.fX + TMath::Nint(0.5*(Double_t)(aBBox.fWidth))+1;
6226 else if ((bBBox.fX > aBBox.fX) && (bBBox.fX + bBBox.fWidth < aBBox.fX + aBBox.fWidth))
6227 x1 = x2 = bBBox.fX + TMath::Nint(0.5*(Double_t)(bBBox.fWidth))+1;
6228 else if (aBBox.fX>bBBox.fX) x1 = x2 = aBBox.fX+TMath::Nint(0.5*(Double_t)(bBBox.fX+bBBox.fWidth-aBBox.fX));
6229 else x1 = x2 = bBBox.fX+TMath::Nint(0.5*(Double_t)(aBBox.fX+aBBox.fWidth-bBBox.fX));
6230 }
6231
6232 TArrow *A = new TArrow(gPad->PixeltoX(x1), gPad->PixeltoY(y1-gPad->VtoPixel(0)), gPad->PixeltoX(x2), gPad->PixeltoY(y2-gPad->VtoPixel(0)), 0.01, "<|>");
6233 A->SetBit(kCanDelete);
6234 A->SetFillColor(lineColor);
6235 A->SetLineWidth(1);
6236 A->SetLineColor(lineColor);
6237 A->Draw();
6238
6239 return;
6240}
6241
6242////////////////////////////////////////////////////////////////////////////////
6243/// struct used by ShowGuidelines to store the distance Field between objects
6244/// in the canvas.
6245
6246struct dField {
6250 char fdir;
6251
6252
6254 : fa(nullptr), fb(nullptr), fdist(0), fdir(' ')
6255 {}
6256
6257 dField(TAttBBox2D *a, TAttBBox2D *b, Int_t dist, char direction)
6258 : fa(a), fb(b), fdist(dist), fdir(direction)
6259 {}
6260};
6261
6262////////////////////////////////////////////////////////////////////////////////
6263/// Shows lines to indicate if a TAttBBox2D object is aligned to
6264/// the center or to another object, shows distance arrows if two
6265/// objects on screen have the same distance to another object
6266/// Call from primitive in Execute Event, in ButtonMotion after
6267/// the new coordinates have been set, to 'stick'
6268/// once when button is up to delete lines
6269///
6270/// modes: t (Top), b (bottom), l (left), r (right), i (inside)
6271/// in resize modes (t,b,l,r) only size arrows are sticky
6272///
6273/// in mode, the function gets the point on the element that is clicked to
6274/// move (i) or resize (all others). The expected values are:
6275/// \image html gpad_pad5.png
6276
6277void TPad::ShowGuidelines(TObject *object, const Int_t event, const char mode, const bool cling )
6278{
6279 // When the object is moved with arrow or when the ShowGuideLines flag
6280 // is off we do show guide lines.
6281 if ((event == kArrowKeyRelease) || (event == kArrowKeyPress) ||
6282 !gEnv->GetValue("Canvas.ShowGuideLines", 0)) return;
6283
6284 std::vector<dField> curDist;
6285 std::vector<dField> otherDist;
6286 Int_t pMX, pMY;
6287 Double_t MX, MY;
6288 Int_t threshold;
6289 TList *prims;
6290 UInt_t n;
6291 Rectangle_t aBBox, bBBox;
6292 aBBox = bBBox = Rectangle_t();
6293 TLine *L;
6294 TArrow *A;
6295 Int_t dSizeArrow = 12; // distance of arrows indicating same size from BBox in px
6296 Bool_t movedX, movedY; // make sure the current object is moved just once
6297 movedX = movedY = false;
6298 Bool_t resize = false; // indicates resize mode
6299 Bool_t log = gPad->GetLogx() || gPad->GetLogy();
6300 if (mode != 'i') resize = true;
6301
6302 TPad *is_pad = dynamic_cast<TPad *>( object );
6303
6304 TContext ctxt(kTRUE);
6305
6306 if (is_pad && is_pad->GetMother())
6307 is_pad->GetMother()->cd();
6308
6309 static TPad *tmpGuideLinePad = nullptr;
6310
6311 //delete all existing Guidelines and create new invisible pad
6312 if (tmpGuideLinePad) {
6313 ctxt.PadDeleted(tmpGuideLinePad);
6314 auto guidePadClicked = (object == tmpGuideLinePad); // in case of funny button click combination.
6315 tmpGuideLinePad->Delete();
6316 tmpGuideLinePad = nullptr;
6317 if (guidePadClicked) return;
6318 }
6319
6320 // Get Primitives
6321 prims = gPad->GetListOfPrimitives();
6322 n = TMath::Min(15,prims->GetSize());
6323 Int_t lineColor = TColor::GetColor(239, 202, 0);
6324
6325 TAttBBox2D *cur = dynamic_cast<TAttBBox2D *>( object );
6326 if (cur) {
6327 //create invisible TPad above gPad
6328 if (!tmpGuideLinePad){
6329 tmpGuideLinePad = new TPad("tmpGuideLinePad", "tmpGuideLinePad", 0, 0, 1, 1);
6330 Double_t x1, y1, x2, y2;
6331 gPad->GetRange(x1, y1, x2, y2);
6332 tmpGuideLinePad->Range(x1, y1, x2, y2);
6333 tmpGuideLinePad->SetFillStyle(0);
6334 tmpGuideLinePad->SetFillColor(0);
6335 tmpGuideLinePad->Draw();
6336 tmpGuideLinePad->cd();
6337 gPad->GetRange(x1, y1, x2, y2);
6338 }
6339 if (cling && !log) threshold = 7;
6340 else threshold = 1;
6341
6342 Rectangle_t BBox = cur->GetBBox();
6343 TPoint center = cur->GetBBoxCenter();
6344
6345 otherDist.clear();
6346 curDist.clear();
6347
6348 switch (event) {
6349
6350 case kButton1Down:
6351 case kButton1Motion:
6352 MX = gPad->GetX1() + 0.5 * (gPad->GetX2()-gPad->GetX1());
6353 MY = gPad->GetY1() + 0.5 * (gPad->GetY2()-gPad->GetY1());
6354 pMX = gPad->XtoPixel(MX);
6355 pMY = gPad->YtoPixel(MY);
6356 // Middlelines
6357 if (TMath::Abs(pMX-center.GetX())<threshold) {
6358 if (cling && (!resize)) {
6359 cur->SetBBoxCenterX(pMX);
6360 center = cur->GetBBoxCenter();
6361 BBox = cur->GetBBox();
6362 center = cur->GetBBoxCenter();
6363 }
6364 L = new TLine(MX, gPad->GetY1(), MX, gPad->GetY2());
6365 L->SetBit(kCanDelete);
6366 L->SetLineColor(lineColor);
6367 L->Draw();
6368 }
6369 if (TMath::Abs(pMY-center.GetY())<threshold) {
6370 if (cling && (!resize)) {
6371 cur->SetBBoxCenterY(pMY);
6372 center = cur->GetBBoxCenter();
6373 BBox = cur->GetBBox();
6374 center = cur->GetBBoxCenter();
6375 }
6376 L = new TLine(gPad->GetX1(), MY, gPad->GetX2(), MY);
6377 L->SetBit(kCanDelete);
6378 L->SetLineColor(lineColor);
6379 L->Draw();
6380 }
6381 // Alignment to other objects
6382 for (UInt_t i = 0; i<n; i++) {
6383 TAttBBox2D *other = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6384 if (other) {
6385 if (other != cur) {
6386 TPoint centerOther = other->GetBBoxCenter();
6387 if (TMath::Abs(center.GetX()-centerOther.GetX())<threshold) {
6388 if (cling && (!resize)) {
6389 cur->SetBBoxCenterX(centerOther.GetX());
6390 BBox = cur->GetBBox();
6391 center = cur->GetBBoxCenter();
6392 }
6393 L = new TLine(gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(center.GetY()-gPad->VtoPixel(0)),
6394 gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)));
6395 L->SetLineColor(lineColor);
6396 L->Draw();
6397 L->SetBit(kCanDelete);
6398 }
6399 if (TMath::Abs(center.GetY()-centerOther.GetY())<threshold) {
6400 if (cling && (!resize)) {
6401 cur->SetBBoxCenterY(centerOther.GetY());
6402 BBox = cur->GetBBox();
6403 center = cur->GetBBoxCenter();
6404 }
6405 L = new TLine(gPad->PixeltoX(center.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)),
6406 gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)));
6407 L->SetBit(kCanDelete);
6408 L->SetLineColor(lineColor);
6409 L->Draw();
6410 }
6411 }
6412 }
6413 }
6414 // Get Distances between objects
6415 for (UInt_t i = 0; i<n; i++) {
6416 TAttBBox2D *a = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6417 if (a) {
6418 aBBox = a->GetBBox();
6419 for (UInt_t j = i+1; j<n; j++) {
6420 TAttBBox2D *b = dynamic_cast<TAttBBox2D *>( prims->At(j) );
6421 if (b) {
6422 bBBox = b->GetBBox();
6423
6424 //only when bounding boxes overlap in x or y direction
6425 if (((aBBox.fX<bBBox.fX) && (bBBox.fX-aBBox.fX<=aBBox.fWidth))||((aBBox.fX>bBBox.fX) && (aBBox.fX-bBBox.fX<=bBBox.fWidth))){ //BBoxes overlap in x direction
6426 if ((aBBox.fY+aBBox.fHeight<bBBox.fY)||(bBBox.fY+bBBox.fHeight<aBBox.fY)) {//No overlap in Y-direction required
6427 dField abDist = dField();
6428 if (aBBox.fY>bBBox.fY) abDist = dField(a, b, TMath::Abs(aBBox.fY-(bBBox.fY+bBBox.fHeight)), 'y');
6429 else abDist = dField(a, b, TMath::Abs(bBBox.fY-(aBBox.fY+aBBox.fHeight)), 'y');
6430 if ((b != cur)&&(a != cur)) otherDist.push_back(abDist);
6431 else curDist.push_back(abDist);
6432 }
6433 } else if (((aBBox.fY<bBBox.fY) && (bBBox.fY-aBBox.fY<=aBBox.fHeight))||((aBBox.fY>bBBox.fY) && (aBBox.fY-bBBox.fY<=bBBox.fHeight))) { //BBoxes overlap in y direction
6434 if ((aBBox.fX+aBBox.fWidth<bBBox.fX)||(bBBox.fX+bBBox.fWidth<aBBox.fX)) {//No overlap in x-direction required
6435 dField abDist = dField();
6436 if (aBBox.fX>bBBox.fX) abDist = dField(a, b, TMath::Abs(aBBox.fX-(bBBox.fX+bBBox.fWidth)), 'x');
6437 else abDist = dField(a, b, TMath::Abs(bBBox.fX-(aBBox.fX+aBBox.fWidth)), 'x');
6438 if ((b != cur)&&(a != cur)) otherDist.push_back(abDist);
6439 else curDist.push_back(abDist);
6440 }
6441 }
6442 }
6443 }
6444 }
6445 }
6446 // Show equal distances
6447 for (UInt_t i = 0; i<curDist.size(); i++) {
6448 for (UInt_t j = 0; j<otherDist.size(); j++) {
6449 if ((curDist[i].fdir == otherDist[j].fdir) && (otherDist[j].fdir=='x') && (TMath::Abs(curDist[i].fdist-otherDist[j].fdist)<threshold)) {
6450 if (cling && (!movedX) && (!resize)) {
6451 if ((cur->GetBBoxCenter().fX < curDist[i].fb->GetBBoxCenter().fX)||(cur->GetBBoxCenter().fX < curDist[i].fa->GetBBoxCenter().fX))
6452 cur->SetBBoxCenterX(cur->GetBBoxCenter().fX - otherDist[j].fdist + curDist[i].fdist);
6453 else cur->SetBBoxCenterX(cur->GetBBoxCenter().fX + otherDist[j].fdist - curDist[i].fdist);
6454 movedX = true;
6455 }
6456 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'x');
6457 DrawDist(otherDist[j].fa->GetBBox(), otherDist[j].fb->GetBBox(), 'x');
6458 }
6459 if ((curDist[i].fdir == otherDist[j].fdir) && (otherDist[j].fdir=='y') && (TMath::Abs(curDist[i].fdist-otherDist[j].fdist)<threshold)) {
6460 if (cling && (!movedY) && (!resize)) {
6461 if ((cur->GetBBoxCenter().fY < curDist[i].fb->GetBBoxCenter().fY)||(cur->GetBBoxCenter().fY < curDist[i].fa->GetBBoxCenter().fY))
6462 cur->SetBBoxCenterY(cur->GetBBoxCenter().fY - otherDist[j].fdist + curDist[i].fdist);
6463 else cur->SetBBoxCenterY(cur->GetBBoxCenter().fY + otherDist[j].fdist - curDist[i].fdist);
6464 movedY = true;
6465 }
6466 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'y');
6467 DrawDist(otherDist[j].fa->GetBBox(), otherDist[j].fb->GetBBox(), 'y');
6468 }
6469 }
6470 for (UInt_t j = i; j<curDist.size(); j++) {
6471 if (i!=j) {
6472 if ((curDist[i].fdir == curDist[j].fdir) && (curDist[j].fdir=='x') && (TMath::Abs(curDist[i].fdist-curDist[j].fdist)<threshold)) {
6473 if (cling && (!movedX) && (!resize)) {
6474 if ((cur->GetBBoxCenter().fX < curDist[i].fb->GetBBoxCenter().fX)||(cur->GetBBoxCenter().fX < curDist[i].fa->GetBBoxCenter().fX))
6475 cur->SetBBoxCenterX(cur->GetBBoxCenter().fX - floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6476 else cur->SetBBoxCenterX(cur->GetBBoxCenter().fX + floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6477 }
6478 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'x');
6479 DrawDist(curDist[j].fa->GetBBox(), curDist[j].fb->GetBBox(), 'x');
6480 }
6481
6482 if ((curDist[i].fdir == curDist[j].fdir) && (curDist[j].fdir=='y') && (TMath::Abs(curDist[i].fdist-curDist[j].fdist)<threshold)) {
6483 if (cling && (!movedY) && (!resize)) {
6484 if ((cur->GetBBoxCenter().fY < curDist[i].fb->GetBBoxCenter().fY)||(cur->GetBBoxCenter().fY < curDist[i].fa->GetBBoxCenter().fY))
6485 cur->SetBBoxCenterY(cur->GetBBoxCenter().fY - floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6486 else cur->SetBBoxCenterY(cur->GetBBoxCenter().fY + floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6487 }
6488 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'y');
6489 DrawDist(curDist[j].fa->GetBBox(), curDist[j].fb->GetBBox(), 'y');
6490 }
6491 }
6492 }
6493 }
6494 if (resize) {
6495 // Show equal Sizes
6496 for (UInt_t i = 0; i<n; i++) {
6497 TAttBBox2D *a = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6498 if (a && (cur != a)) {
6499 aBBox = a->GetBBox();
6500
6501 if ((TMath::Abs(aBBox.fWidth - BBox.fWidth)<threshold) && (mode != 't') && (mode != 'b')) {
6502 if (cling) {
6503 if (mode == 'l') cur->SetBBoxX1(BBox.fX + BBox.fWidth - aBBox.fWidth);
6504 if (mode == 'r') cur->SetBBoxX2(BBox.fX + aBBox.fWidth);
6505 if ((mode == '1')||(mode == '4')) cur->SetBBoxX1(BBox.fX + BBox.fWidth - aBBox.fWidth);
6506 if ((mode == '2')||(mode == '3')) cur->SetBBoxX2(BBox.fX + aBBox.fWidth);
6507 BBox = cur->GetBBox();
6508 }
6509
6510 A = new TArrow(gPad->PixeltoX(aBBox.fX), gPad->PixeltoY(aBBox.fY-dSizeArrow-gPad->VtoPixel(0)),
6511 gPad->PixeltoX(aBBox.fX+aBBox.fWidth), gPad->PixeltoY(aBBox.fY-dSizeArrow-gPad->VtoPixel(0)), 0.01, "<|>");
6512 A->SetBit(kCanDelete);
6513 A->SetLineColor(lineColor);
6514 A->SetFillColor(lineColor);
6515 A->Draw();
6516
6517 A = new TArrow(gPad->PixeltoX(BBox.fX), gPad->PixeltoY(BBox.fY-dSizeArrow-gPad->VtoPixel(0)),
6518 gPad->PixeltoX(BBox.fX+BBox.fWidth), gPad->PixeltoY(BBox.fY-dSizeArrow-gPad->VtoPixel(0)), 0.01, "<|>");
6519 A->SetBit(kCanDelete);
6520 A->SetLineColor(lineColor);
6521 A->SetFillColor(lineColor);
6522 A->Draw();
6523 }
6524 if ((TMath::Abs(aBBox.fHeight - BBox.fHeight)<threshold) && (mode != 'r') && (mode != 'l')) {
6525 if (cling) {
6526 if (mode == 't') cur->SetBBoxY1(BBox.fY + BBox.fHeight - aBBox.fHeight);
6527 if (mode == 'b') cur->SetBBoxY2(BBox.fY + aBBox.fHeight);
6528 if ((mode == '1')||(mode == '2')) cur->SetBBoxY1(BBox.fY + BBox.fHeight - aBBox.fHeight);
6529 if ((mode == '3')||(mode == '4')) cur->SetBBoxY2(BBox.fY + aBBox.fHeight);
6530 BBox = cur->GetBBox();
6531 }
6532 A = new TArrow(gPad->PixeltoX(aBBox.fX-dSizeArrow), gPad->PixeltoY(aBBox.fY-gPad->VtoPixel(0)),
6533 gPad->PixeltoX(aBBox.fX-dSizeArrow), gPad->PixeltoY(aBBox.fY+aBBox.fHeight-gPad->VtoPixel(0)), 0.01, "<|>");
6534 A->SetBit(kCanDelete);
6535 A->SetLineColor(lineColor);
6536 A->SetFillColor(lineColor);
6537 A->Draw();
6538
6539 A = new TArrow(gPad->PixeltoX(BBox.fX-dSizeArrow), gPad->PixeltoY(BBox.fY-gPad->VtoPixel(0)),
6540 gPad->PixeltoX(BBox.fX-dSizeArrow), gPad->PixeltoY(BBox.fY+BBox.fHeight-gPad->VtoPixel(0)), 0.01, "<|>");
6541 A->SetBit(kCanDelete);
6542 A->SetLineColor(lineColor);
6543 A->SetFillColor(lineColor);
6544 A->Draw();
6545 }
6546 }
6547 }
6548 }
6549
6550 break;
6551
6552 case kButton1Up:
6553 if (tmpGuideLinePad) {
6554 // All the arrows and lines in that pad are also deleted because
6555 // they all have the bit kCanDelete on.
6556 tmpGuideLinePad->Delete();
6557 tmpGuideLinePad = nullptr;
6558 }
6559 break;
6560 }
6561 }
6562
6564}
6565
6566////////////////////////////////////////////////////////////////////////////////
6567/// Return kTRUE if the crosshair has been activated (via SetCrosshair).
6568
6570{
6571 return (Bool_t)GetCrosshair();
6572}
6573
6574////////////////////////////////////////////////////////////////////////////////
6575/// Return the crosshair type (from the mother canvas)
6576/// crosshair type = 0 means no crosshair.
6577
6579{
6580 if (this == (TPad*)fCanvas)
6581 return fCrosshair;
6582 return fCanvas ? fCanvas->GetCrosshair() : 0;
6583}
6584
6585////////////////////////////////////////////////////////////////////////////////
6586/// Set crosshair active/inactive.
6587/// - If crhair != 0, a crosshair will be drawn in the pad and its sub-pads.
6588/// - If the canvas crhair = 1 , the crosshair spans the full canvas.
6589/// - If the canvas crhair > 1 , the crosshair spans only the pad.
6590
6592{
6593 if (!fCanvas) return;
6594 fCrosshair = crhair;
6595 fCrosshairPos = 0;
6596
6597 if (this != (TPad*)fCanvas) fCanvas->SetCrosshair(crhair);
6598}
6599
6600////////////////////////////////////////////////////////////////////////////////
6601/// static function to set the maximum Pick Distance fgMaxPickDistance
6602/// This parameter is used in TPad::Pick to select an object if
6603/// its DistancetoPrimitive returns a value < fgMaxPickDistance
6604/// The default value is 5 pixels. Setting a smaller value will make
6605/// picking more precise but also more difficult
6606
6608{
6609 fgMaxPickDistance = maxPick;
6610}
6611
6612////////////////////////////////////////////////////////////////////////////////
6613/// Set tool tip text associated with this pad. The delay is in
6614/// milliseconds (minimum 250). To remove tool tip call method with
6615/// text = 0.
6616
6617void TPad::SetToolTipText(const char *text, Long_t delayms)
6618{
6619 if (fTip) {
6621 fTip = nullptr;
6622 }
6623
6624 if (text && strlen(text))
6625 fTip = CreateToolTip((TBox*)nullptr, text, delayms);
6626}
6627
6628////////////////////////////////////////////////////////////////////////////////
6629/// Set pad vertical (default) or horizontal
6630
6632{
6633 if (vert) ResetBit(kHori);
6634 else SetBit(kHori);
6635}
6636
6637////////////////////////////////////////////////////////////////////////////////
6638/// Stream a class object.
6639
6641{
6642 UInt_t R__s, R__c;
6643 Int_t nch, nobjects;
6644 Float_t single;
6645 TObject *obj;
6646 if (b.IsReading()) {
6647 Version_t v = b.ReadVersion(&R__s, &R__c);
6648 if (v > 5) {
6649 if (!gPad)
6650 gPad = new TCanvas(GetName());
6651 fMother = (TPad*)gPad;
6653 TContext ctxt(this, kFALSE);
6654 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
6655 gReadLevel++;
6656 gROOT->SetReadingObject(kTRUE);
6657
6658 b.ReadClassBuffer(TPad::Class(), this, v, R__s, R__c);
6659
6660 //Set the kCanDelete bit in all objects in the pad such that when the pad
6661 //is deleted all objects in the pad are deleted too.
6662 //Also set must cleanup bit which normally set for all primitives add to pad,
6663 // but may be reset in IO like TH1::Streamer does
6664 TIter next(fPrimitives);
6665 while ((obj = next())) {
6666 obj->SetBit(kCanDelete);
6667 obj->SetBit(kMustCleanup);
6668 }
6669
6670 fModified = kTRUE;
6671 fPadPointer = nullptr;
6672 gReadLevel--;
6673 if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
6674 gROOT->SetReadingObject(kFALSE);
6675 return;
6676 }
6677
6678 //====process old versions before automatic schema evolution
6679 if (v < 5) { //old TPad in single precision
6680 if (v < 3) { //old TPad derived from TWbox
6681 b.ReadVersion(); // TVirtualPad::Streamer(b)
6682 b.ReadVersion(); // TWbox::Streamer(b)
6683 b.ReadVersion(); // TBox::Streamer(b)
6687 b >> single; fX1 = single;
6688 b >> single; fY1 = single;
6689 b >> single; fX2 = single;
6690 b >> single; fY2 = single;
6691 b >> fBorderSize;
6692 b >> fBorderMode;
6694 } else { //new TPad
6697 b >> single; fX1 = single;
6698 b >> single; fY1 = single;
6699 b >> single; fX2 = single;
6700 b >> single; fY2 = single;
6701 b >> fBorderSize;
6702 b >> fBorderMode;
6703 }
6704 b >> fLogx;
6705 b >> fLogy;
6706 b >> fLogz;
6707 b >> single; fXtoAbsPixelk = single;
6708 b >> single; fXtoPixelk = single;
6709 b >> single; fXtoPixel = single;
6710 b >> single; fYtoAbsPixelk = single;
6711 b >> single; fYtoPixelk = single;
6712 b >> single; fYtoPixel = single;
6713 b >> single; fUtoAbsPixelk = single;
6714 b >> single; fUtoPixelk = single;
6715 b >> single; fUtoPixel = single;
6716 b >> single; fVtoAbsPixelk = single;
6717 b >> single; fVtoPixelk = single;
6718 b >> single; fVtoPixel = single;
6719 b >> single; fAbsPixeltoXk = single;
6720 b >> single; fPixeltoXk = single;
6721 b >> single; fPixeltoX = single;
6722 b >> single; fAbsPixeltoYk = single;
6723 b >> single; fPixeltoYk = single;
6724 b >> single; fPixeltoY = single;
6725 b >> single; fXlowNDC = single;
6726 b >> single; fYlowNDC = single;
6727 b >> single; fWNDC = single;
6728 b >> single; fHNDC = single;
6729 b >> single; fAbsXlowNDC = single;
6730 b >> single; fAbsYlowNDC = single;
6731 b >> single; fAbsWNDC = single;
6732 b >> single; fAbsHNDC = single;
6733 b >> single; fUxmin = single;
6734 b >> single; fUymin = single;
6735 b >> single; fUxmax = single;
6736 b >> single; fUymax = single;
6737 } else {
6740 b >> fX1;
6741 b >> fY1;
6742 b >> fX2;
6743 b >> fY2;
6744 b >> fBorderSize;
6745 b >> fBorderMode;
6746 b >> fLogx;
6747 b >> fLogy;
6748 b >> fLogz;
6749 b >> fXtoAbsPixelk;
6750 b >> fXtoPixelk;
6751 b >> fXtoPixel;
6752 b >> fYtoAbsPixelk;
6753 b >> fYtoPixelk;
6754 b >> fYtoPixel;
6755 b >> fUtoAbsPixelk;
6756 b >> fUtoPixelk;
6757 b >> fUtoPixel;
6758 b >> fVtoAbsPixelk;
6759 b >> fVtoPixelk;
6760 b >> fVtoPixel;
6761 b >> fAbsPixeltoXk;
6762 b >> fPixeltoXk;
6763 b >> fPixeltoX;
6764 b >> fAbsPixeltoYk;
6765 b >> fPixeltoYk;
6766 b >> fPixeltoY;
6767 b >> fXlowNDC;
6768 b >> fYlowNDC;
6769 b >> fWNDC;
6770 b >> fHNDC;
6771 b >> fAbsXlowNDC;
6772 b >> fAbsYlowNDC;
6773 b >> fAbsWNDC;
6774 b >> fAbsHNDC;
6775 b >> fUxmin;
6776 b >> fUymin;
6777 b >> fUxmax;
6778 b >> fUymax;
6779 }
6780
6781 if (!gPad)
6782 gPad = new TCanvas(GetName());
6783 if (gReadLevel == 0)
6785 else
6786 fMother = (TPad *)gPad;
6787 if (!fMother)
6788 fMother = (TPad *)gPad;
6789 if (fMother)
6791 gPad = fMother;
6792 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
6793 //-------------------------
6794 // read objects and their drawing options
6795 // b >> fPrimitives;
6796 gReadLevel++;
6797 gROOT->SetReadingObject(kTRUE);
6798 fPrimitives = new TList;
6799 b >> nobjects;
6800 if (nobjects > 0) {
6801 TContext ctxt(this, kFALSE);
6802 char drawoption[64];
6803 for (Int_t i = 0; i < nobjects; i++) {
6804 b >> obj;
6805 b >> nch;
6806 b.ReadFastArray(drawoption,nch);
6807 fPrimitives->AddLast(obj, drawoption);
6808 gPad = this; // gPad may be modified in b >> obj if obj is a pad
6809 }
6810 }
6811 gReadLevel--;
6812 gROOT->SetReadingObject(kFALSE);
6813 //////////////////////////////////////////////////////////////////////////
6814
6815 if (v > 3) {
6816 b >> fExecs;
6817 }
6818 fName.Streamer(b);
6819 fTitle.Streamer(b);
6820 b >> fPadPaint;
6821 fModified = kTRUE;
6822 b >> fGridx;
6823 b >> fGridy;
6824 b >> fFrame;
6825 b >> fView;
6826 if (v < 5) {
6827 b >> single; fTheta = single;
6828 b >> single; fPhi = single;
6829 } else {
6830 b >> fTheta;
6831 b >> fPhi;
6832 }
6833 fPadPointer = nullptr;
6834 b >> fNumber;
6835 b >> fAbsCoord;
6836 if (v > 1) {
6837 b >> fTickx;
6838 b >> fTicky;
6839 } else {
6840 fTickx = fTicky = 0;
6841 }
6842 if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
6843 b.CheckByteCount(R__s, R__c, TPad::IsA());
6844 //====end of old versions
6845
6846 } else {
6847 b.WriteClassBuffer(TPad::Class(),this);
6848 }
6849}
6850
6851////////////////////////////////////////////////////////////////////////////////
6852/// Force a copy of current style for all objects in pad.
6853
6855{
6856 if (gStyle->IsReading()) {
6868 fLogx = gStyle->GetOptLogx();
6869 fLogy = gStyle->GetOptLogy();
6870 fLogz = gStyle->GetOptLogz();
6871 } else {
6886 }
6887
6888 if (!fPrimitives) fPrimitives = new TList;
6889 TIter next(GetListOfPrimitives());
6890 TObject *obj;
6891
6892 while ((obj = next())) {
6893 obj->UseCurrentStyle();
6894 }
6895
6896 TPaveText *title = (TPaveText*)FindObject("title");
6897 if (title) {
6898 if (gStyle->IsReading()) {
6900 title->SetTextFont(gStyle->GetTitleFont(""));
6903 if (!gStyle->GetOptTitle()) delete title;
6904 } else {
6906 gStyle->SetTitleFont(title->GetTextFont());
6909 }
6910 }
6912
6913 if (gStyle->IsReading()) Modified();
6914}
6915
6916////////////////////////////////////////////////////////////////////////////////
6917/// Loop and sleep until a primitive with name=pname is found in the pad.
6918///
6919/// If emode is given, the editor is automatically set to emode, ie
6920/// it is not required to have the editor control bar.
6921///
6922/// The possible values for emode are:
6923/// - emode = "" (default). User will select the mode via the editor bar
6924/// - emode = "Arc", "Line", "Arrow", "Button", "Diamond", "Ellipse",
6925/// - emode = "Pad","pave", "PaveLabel","PaveText", "PavesText",
6926/// - emode = "PolyLine", "CurlyLine", "CurlyArc", "Text", "Marker", "CutG"
6927///
6928/// If emode is specified and it is not valid, "PolyLine" is assumed. If emode
6929/// is not specified or ="", an attempt is to use pname[1...]
6930///
6931/// for example if pname="TArc", emode="Arc" will be assumed.
6932/// When this function is called within a macro, the macro execution
6933/// is suspended until a primitive corresponding to the arguments
6934/// is found in the pad.
6935///
6936/// If CRTL/C is typed in the pad, the function returns 0.
6937///
6938/// While this function is executing, one can use the mouse, interact
6939/// with the graphics pads, use the Inspector, Browser, TreeViewer, etc.
6940///
6941/// Examples:
6942/// ~~~ {.cpp}
6943/// c1.WaitPrimitive(); // Return the first created primitive
6944/// // whatever it is.
6945/// // If a double-click with the mouse is executed
6946/// // in the pad or any key pressed, the function
6947/// // returns 0.
6948/// c1.WaitPrimitive("ggg"); // Set the editor in mode "PolyLine/Graph"
6949/// // Create a polyline, then using the context
6950/// // menu item "SetName", change the name
6951/// // of the created TGraph to "ggg"
6952/// c1.WaitPrimitive("TArc");// Set the editor in mode "Arc". Returns
6953/// // as soon as a TArc object is created.
6954/// c1.WaitPrimitive("lat","Text"); // Set the editor in Text/Latex mode.
6955/// // Create a text object, then Set its name to "lat"
6956/// ~~~
6957/// The following macro waits for 10 primitives of any type to be created.
6958///
6959/// ~~~ {.cpp}
6960///{
6961/// TCanvas c1("c1");
6962/// TObject *obj;
6963/// for (Int_t i=0;i<10;i++) {
6964/// obj = gPad->WaitPrimitive();
6965/// if (!obj) break;
6966/// printf("Loop i=%d, found objIsA=%s, name=%s\n",
6967/// i,obj->ClassName(),obj->GetName());
6968/// }
6969///}
6970/// ~~~
6971///
6972/// If ROOT runs in batch mode a call to this method does nothing.
6973
6974TObject *TPad::WaitPrimitive(const char *pname, const char *emode)
6975{
6976 if (!gPad || IsWeb())
6977 return nullptr;
6978
6979 if (emode && strlen(emode)) gROOT->SetEditorMode(emode);
6980 if (gROOT->GetEditorMode() == 0 && pname && strlen(pname) > 2) gROOT->SetEditorMode(&pname[1]);
6981
6982 if (!fPrimitives) fPrimitives = new TList;
6984 TObject *oldlast = gPad->GetListOfPrimitives() ? gPad->GetListOfPrimitives()->Last() : nullptr;
6985 TObject *obj = nullptr;
6986 Bool_t testlast = kFALSE;
6987 Bool_t hasname = pname && (strlen(pname) > 0);
6988 if ((!pname || !pname[0]) && (!emode || !emode[0])) testlast = kTRUE;
6989 if (testlast) gROOT->SetEditorMode();
6990 while (!gSystem->ProcessEvents() && gROOT->GetSelectedPad() && gPad) {
6991 if (gROOT->GetEditorMode() == 0) {
6992 if (hasname) {
6993 obj = FindObject(pname);
6994 if (obj) return obj;
6995 }
6996 if (testlast) {
6997 if (!gPad->GetListOfPrimitives()) return nullptr;
6998 obj = gPad->GetListOfPrimitives()->Last();
6999 if (obj != oldlast) return obj;
7000 Int_t event = GetEvent();
7001 if (event == kButton1Double || event == kKeyPress) {
7002 //the following statement is required against other loop executions
7003 //before returning
7004 fCanvas->HandleInput((EEventType)-1,0,0);
7005 return nullptr;
7006 }
7007 }
7008 }
7009 gSystem->Sleep(10);
7010 }
7011
7012 return nullptr;
7013}
7014
7015////////////////////////////////////////////////////////////////////////////////
7016/// Create a tool tip and return its pointer.
7017
7018TObject *TPad::CreateToolTip(const TBox *box, const char *text, Long_t delayms)
7019{
7020 if (gPad->IsBatch()) return nullptr;
7021 return (TObject*)gROOT->ProcessLineFast(TString::Format("new TGToolTip((TBox*)0x%zx,\"%s\",%d)",
7022 (size_t)box,text,(Int_t)delayms).Data());
7023}
7024
7025////////////////////////////////////////////////////////////////////////////////
7026/// Delete tool tip object.
7027
7029{
7030 // delete tip;
7031 if (!tip) return;
7032 gROOT->ProcessLineFast(TString::Format("delete (TGToolTip*)0x%zx", (size_t)tip).Data());
7033}
7034
7035////////////////////////////////////////////////////////////////////////////////
7036/// Reset tool tip, i.e. within time specified in CreateToolTip the
7037/// tool tip will pop up.
7038
7040{
7041 if (!tip) return;
7042 // tip->Reset(this);
7043 gROOT->ProcessLineFast(TString::Format("((TGToolTip*)0x%zx)->Reset((TPad*)0x%zx)",
7044 (size_t)tip,(size_t)this).Data());
7045}
7046
7047////////////////////////////////////////////////////////////////////////////////
7048/// Hide tool tip.
7049
7051{
7052 if (!tip) return;
7053 // tip->Hide();
7054 gROOT->ProcessLineFast(TString::Format("((TGToolTip*)0x%zx)->Hide()", (size_t)tip).Data());
7055}
7056
7057////////////////////////////////////////////////////////////////////////////////
7058/// Deprecated: use TPad::GetViewer3D() instead
7059
7061{
7062 ::Info("TPad::x3d()", "This function is deprecated. Use %s->GetViewer3D(\"x3d\") instead",this->GetName());
7063
7064 // Default on GetViewer3D is pad - for x3d it was x3d...
7065 if (!type || !type[0]) {
7066 type = "x3d";
7067 }
7069}
7070
7071////////////////////////////////////////////////////////////////////////////////
7072/// Create/obtain handle to 3D viewer. Valid types are:
7073/// - 'pad' - pad drawing via TViewer3DPad
7074/// any others registered with plugin manager supporting TVirtualViewer3D
7075/// If an invalid/null type is requested then the current viewer is returned
7076/// (if any), otherwise a default 'pad' type is returned
7077
7079{
7080 Bool_t validType = kFALSE;
7081
7082 if ((!type || !*type || (strstr(type, "gl") && !strstr(type, "ogl"))) && (!fCanvas || !fCanvas->UseGL()))
7083 type = "pad";
7084
7085 if (type && *type) {
7086 if (gPluginMgr->FindHandler("TVirtualViewer3D", type))
7087 validType = kTRUE;
7088 }
7089
7090 // Invalid/null type requested?
7091 if (!validType) {
7092 // Return current viewer if there is one
7093 if (fViewer3D)
7094 return fViewer3D;
7095 // otherwise default to the pad
7096 else
7097 type = "pad";
7098 }
7099
7100 // Ensure we can create the new viewer before removing any existing one
7101 TVirtualViewer3D *newViewer = nullptr;
7102
7103 Bool_t createdExternal = kFALSE;
7104
7105 // External viewers need to be created via plugin manager via interface...
7106 if (!strstr(type,"pad")) {
7107 newViewer = TVirtualViewer3D::Viewer3D(this, type);
7108
7109 if (!newViewer) {
7110 Warning("GetViewer3D", "Cannot create 3D viewer of type: %s", type);
7111 // Return the existing viewer
7112 return fViewer3D;
7113 }
7114
7115 if (strstr(type, "gl") && !strstr(type, "ogl")) {
7118 Modified();
7119 } else {
7120 createdExternal = kTRUE;
7121 }
7122
7123 } else {
7124 newViewer = new TViewer3DPad(*this);
7125 }
7126
7127 // If we had a previous viewer destroy it now
7128 // In this case we do take responsibility for destroying viewer
7129 // c.f. ReleaseViewer3D
7130 delete fViewer3D;
7131
7132 // Set and return new viewer
7133 fViewer3D = newViewer;
7134
7135 // Ensure any new external viewer is painted
7136 // For internal TViewer3DPad type we assume this is being
7137 // create on demand due to a paint - so this is not required
7138 if (createdExternal) {
7139 Modified();
7140 Update();
7141 }
7142
7143 return fViewer3D;
7144}
7145
7146////////////////////////////////////////////////////////////////////////////////
7147/// Release current (external) viewer
7148
7150{
7151 fViewer3D = nullptr;
7152
7153 // We would like to ensure the pad is repainted
7154 // when external viewer is closed down. However
7155 // a modify/paint call here will repaint the pad
7156 // before the external viewer window actually closes.
7157 // So the pad would have to be redraw twice over.
7158 // Currently we just have to live with the pad staying blank
7159 // any click in pad will refresh.
7160}
7161
7162////////////////////////////////////////////////////////////////////////////////
7163/// Get GL device.
7164
7166{
7167 return fGLDevice;
7168}
7169
7170////////////////////////////////////////////////////////////////////////////////
7171/// Emit RecordPave() signal.
7172
7174{
7175 Emit("RecordPave(const TObject*)", (Longptr_t)obj);
7176}
7177
7178////////////////////////////////////////////////////////////////////////////////
7179/// Emit RecordLatex() signal.
7180
7182{
7183 Emit("RecordLatex(const TObject*)", (Longptr_t)obj);
7184}
7185
7186////////////////////////////////////////////////////////////////////////////////
7187/// Get pad painter from TCanvas.
7188
7190{
7191 if (!fCanvas) return nullptr;
7192 return fCanvas->GetCanvasPainter();
7193}
7194
7195////////////////////////////////////////////////////////////////////////////////
7196/// Return the bounding Box of the Pad
7197
7199{
7200 Rectangle_t BBox{0, 0, 0, 0};
7201 if (gPad) {
7202 BBox.fX = gPad->XtoPixel(fXlowNDC * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1());
7203 BBox.fY = gPad->YtoPixel((fYlowNDC + fHNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1());
7204 BBox.fWidth = gPad->XtoPixel((fXlowNDC + fWNDC) * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1()) -
7205 gPad->XtoPixel(fXlowNDC * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1());
7206 BBox.fHeight = gPad->YtoPixel((fYlowNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1()) -
7207 gPad->YtoPixel((fYlowNDC + fHNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1());
7208 }
7209 return BBox;
7210}
7211
7212////////////////////////////////////////////////////////////////////////////////
7213/// Return the center of the Pad as TPoint in pixels
7214
7216{
7217 TPoint p(0, 0);
7218 if (gPad) {
7219 Double_t x = ((fXlowNDC + 0.5 * fWNDC) * (gPad->GetX2() - gPad->GetX1())) + gPad->GetX1();
7220 Double_t y = ((fYlowNDC + 0.5 * fHNDC) * (gPad->GetY2() - gPad->GetY1())) + gPad->GetY1();
7221 p.SetX(gPad->XtoPixel(x));
7222 p.SetY(gPad->YtoPixel(y));
7223 }
7224 return p;
7225}
7226
7227////////////////////////////////////////////////////////////////////////////////
7228/// Set center of the Pad
7229
7231{
7232 if (!gPad)
7233 return;
7234 fXlowNDC = (gPad->PixeltoX(p.GetX()) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1()) - 0.5 * fWNDC;
7235 fYlowNDC =
7236 (gPad->PixeltoY(p.GetY() - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - 0.5 * fHNDC;
7237 ResizePad();
7238}
7239
7240////////////////////////////////////////////////////////////////////////////////
7241/// Set X coordinate of the center of the Pad
7242
7244{
7245 if (!gPad)
7246 return;
7247 fXlowNDC = (gPad->PixeltoX(x) - gPad->GetX1())/(gPad->GetX2()-gPad->GetX1())-0.5*fWNDC;
7248 ResizePad();
7249}
7250
7251////////////////////////////////////////////////////////////////////////////////
7252/// Set Y coordinate of the center of the Pad
7253
7255{
7256 if (!gPad)
7257 return;
7258 fYlowNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - 0.5 * fHNDC;
7259 ResizePad();
7260}
7261
7262////////////////////////////////////////////////////////////////////////////////
7263/// Set lefthandside of BoundingBox to a value
7264/// (resize in x direction on left)
7265
7267{
7268 if (!gPad)
7269 return;
7270 fXlowNDC = (gPad->PixeltoX(x) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1());
7272 ResizePad();
7273}
7274
7275////////////////////////////////////////////////////////////////////////////////
7276/// Set right hand side of BoundingBox to a value
7277/// (resize in x direction on right)
7278
7280{
7281 if (!gPad)
7282 return;
7283 fWNDC = (gPad->PixeltoX(x) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1()) - fXlowNDC;
7284 ResizePad();
7285}
7286
7287////////////////////////////////////////////////////////////////////////////////
7288/// Set top of BoundingBox to a value (resize in y direction on top)
7289
7291{
7292 if (!gPad)
7293 return;
7294 fHNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - fYlowNDC;
7295 ResizePad();
7296}
7297
7298////////////////////////////////////////////////////////////////////////////////
7299/// Set bottom of BoundingBox to a value
7300/// (resize in y direction on bottom)
7301
7303{
7304 if (!gPad)
7305 return;
7306 fYlowNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1());
7308 ResizePad();
7309}
7310
7311////////////////////////////////////////////////////////////////////////////////
7312/// Mark pad modified
7313/// Will be repainted when TCanvas::Update() will be called next time
7314
7316{
7317 if (!fModified && flag) Emit("Modified()");
7318 fModified = flag;
7319}
7320
7321////////////////////////////////////////////////////////////////////////////////
7322/// Convert absolute pixel into X/Y coordinates
7323
7325{
7326 x = AbsPixeltoX(xpixel);
7327 y = AbsPixeltoY(ypixel);
7328}
7329
7330
7331////////////////////////////////////////////////////////////////////////////////
7332/// Convert pixel to X coordinate
7333
7335{
7336 if (fAbsCoord) return fAbsPixeltoXk + px*fPixeltoX;
7337 else return fPixeltoXk + px*fPixeltoX;
7338}
7339
7340////////////////////////////////////////////////////////////////////////////////
7341/// Convert pixel to Y coordinate
7342
7344{
7345 if (fAbsCoord) return fAbsPixeltoYk + py*fPixeltoY;
7346 else return fPixeltoYk + py*fPixeltoY;
7347}
7348
7349////////////////////////////////////////////////////////////////////////////////
7350/// Convert pixel to X/Y coordinates
7351
7353{
7354 x = PixeltoX(xpixel);
7355 y = PixeltoY(ypixel);
7356}
7357
7358////////////////////////////////////////////////////////////////////////////////
7359/// Convert X/Y into absolute pixel coordinates - integer
7360
7361void TPad::XYtoAbsPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const
7362{
7363 xpixel = XtoAbsPixel(x);
7364 ypixel = YtoAbsPixel(y);
7365}
7366
7367////////////////////////////////////////////////////////////////////////////////
7368/// Check value for valid range for pixel values
7369
7371{
7372 return v < -kMaxPixel ? -kMaxPixel : (v > kMaxPixel ? kMaxPixel : v);
7373}
7374
7375////////////////////////////////////////////////////////////////////////////////
7376/// Convert X/Y into absolute pixel coordinates - doble
7377/// Introduced to avoid pixel rounding problems
7378
7380{
7383}
7384
7385////////////////////////////////////////////////////////////////////////////////
7386/// Convert X/Y into pixel coordinates - integer
7387
7388void TPad::XYtoPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const
7389{
7390 xpixel = XtoPixel(x);
7391 ypixel = YtoPixel(y);
7392}
7393
7394////////////////////////////////////////////////////////////////////////////////
7395/// Convert X/Y into pixel coordinates - double
7396
7402
7403////////////////////////////////////////////////////////////////////////////////
7404/// Convert X NDC to pixel
7405
7410
7411////////////////////////////////////////////////////////////////////////////////
7412/// Convert Y NDC to pixel
7413
7418
7419////////////////////////////////////////////////////////////////////////////////
7420/// Convert X NDC to absolute pixel
7421
7426
7427////////////////////////////////////////////////////////////////////////////////
7428/// Convert Y NDC to absolute pixel
7429
7434
7435////////////////////////////////////////////////////////////////////////////////
7436/// Convert X coordinate to absolute pixel
7437
7442
7443////////////////////////////////////////////////////////////////////////////////
7444/// Convert X coordinate to pixel
7445
7450
7451////////////////////////////////////////////////////////////////////////////////
7452/// Convert Y coordinate to absolute pixel
7453
7458
7459////////////////////////////////////////////////////////////////////////////////
7460/// Convert a vertical distance [y1,y2] to pixel
7461
7463{
7464 double h1 = fYtoAbsPixelk + y1 * fYtoPixel;
7465 double h2 = fYtoAbsPixelk + y2 * fYtoPixel;
7466 return TMath::Nint(pixel_boundary(std::abs(h1 - h2)));
7467}
7468
7469////////////////////////////////////////////////////////////////////////////////
7470/// Convert a horizontal distance [x1,x2] to pixel
7471
7473{
7474 double w1 = fXtoAbsPixelk + x1 * fXtoPixel;
7475 double w2 = fXtoAbsPixelk + x2 * fXtoPixel;
7476 return TMath::Nint(pixel_boundary(std::abs(w1 - w2)));
7477}
7478
7479
7480////////////////////////////////////////////////////////////////////////////////
7481/// Convert Y coordinate to pixel
7482
EEventType
Definition Buttons.h:15
@ kMouseMotion
Definition Buttons.h:23
@ kWheelUp
Definition Buttons.h:18
@ kButton2Down
Definition Buttons.h:17
@ kKeyPress
Definition Buttons.h:20
@ kArrowKeyRelease
Definition Buttons.h:21
@ kButton1Double
Definition Buttons.h:24
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kWheelDown
Definition Buttons.h:18
@ kArrowKeyPress
Definition Buttons.h:21
@ kMouseLeave
Definition Buttons.h:23
@ kButton1Down
Definition Buttons.h:17
@ kButton1Locate
Definition Buttons.h:22
@ kMouseEnter
Definition Buttons.h:23
@ kMarker
Definition Buttons.h:34
@ kCurlyArc
Definition Buttons.h:38
@ kPad
Definition Buttons.h:30
@ kPolyLine
Definition Buttons.h:28
@ kDiamond
Definition Buttons.h:37
@ kEditor
Definition Buttons.h:30
@ kPave
Definition Buttons.h:31
@ kArrow
Definition Buttons.h:33
@ kPaveText
Definition Buttons.h:32
@ kCutG
Definition Buttons.h:38
@ kLine
Definition Buttons.h:33
@ kPavesText
Definition Buttons.h:32
@ kCurlyLine
Definition Buttons.h:38
@ kPaveLabel
Definition Buttons.h:31
@ kButton
Definition Buttons.h:37
@ kEllipse
Definition Buttons.h:32
@ kText
Definition Buttons.h:30
@ kArc
Definition Buttons.h:33
ECursor
Definition GuiTypes.h:373
@ kHand
Definition GuiTypes.h:375
const Int_t kMaxPixel
Max value for an int.
Definition GuiTypes.h:370
#define SafeDelete(p)
Definition RConfig.hxx:507
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
cudaEvent_t event
short Style_t
Style number (short)
Definition RtypesCore.h:97
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Color_t
Color number (short)
Definition RtypesCore.h:100
float Size_t
Attribute size (float)
Definition RtypesCore.h:104
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:90
short Version_t
Class version identifier (short)
Definition RtypesCore.h:80
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
short Width_t
Line width (short)
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:132
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
@ kRed
Definition Rtypes.h:66
@ kBlack
Definition Rtypes.h:65
#define gDirectory
Definition TDirectory.h:385
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
#define gFile
Definition TFile.h:439
winID h TVirtualViewer3D TVirtualGLPainter p
winID h TVirtualViewer3D vv
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t SetFillStyle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void SetCursor
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 WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t style
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t button
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char mx
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:142
float xmin
float ymin
float xmax
float ymax
#define gInterpreter
Double_t pixel_boundary(Double_t v)
Check value for valid range for pixel values.
Definition TPad.cxx:7370
static Int_t gReadLevel
Definition TPad.cxx:70
#define NotFree(i, j)
Definition TPad.cxx:3173
R__EXTERN TPluginManager * gPluginMgr
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:417
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define gGLManager
Definition TVirtualGL.h:158
#define R__LOCKGUARD(mutex)
R__EXTERN TVirtualPS * gVirtualPS
Definition TVirtualPS.h:93
#define gPad
R__EXTERN Int_t(* gThreadXAR)(const char *xact, Int_t nb, void **ar, Int_t *iret)
Draw all kinds of Arrows.
Definition TArrow.h:29
void Draw(Option_t *option="") override
Draw this arrow with its current attributes.
Definition TArrow.cxx:116
static TClass * Class()
Abstract base class for elements drawn in the editor.
Definition TAttBBox2D.h:19
virtual void SetBBoxCenterY(const Int_t y)=0
virtual void SetBBoxCenterX(const Int_t x)=0
virtual void SetBBoxX1(const Int_t x)=0
virtual void SetBBoxY1(const Int_t y)=0
virtual void SetBBoxX2(const Int_t x)=0
virtual void SetBBoxY2(const Int_t y)=0
virtual Rectangle_t GetBBox()=0
virtual TPoint GetBBoxCenter()
virtual void Streamer(TBuffer &)
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:33
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
static TClass * Class()
virtual Bool_t IsTransparent() const
Definition TAttFill.h:49
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
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:240
Line Attributes class.
Definition TAttLine.h:21
virtual void Streamer(TBuffer &)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
static TClass * Class()
Width_t fLineWidth
Line width.
Definition TAttLine.h:26
virtual void ModifyOn(TVirtualPad &pad)
Change current line attributes on specified pad.
Definition TAttLine.cxx:255
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:176
static TClass * Class()
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition TAttPad.cxx:98
Color_t GetFrameFillColor() const
Definition TAttPad.h:53
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition TAttPad.cxx:108
Color_t GetFrameLineColor() const
Definition TAttPad.h:54
Style_t GetFrameLineStyle() const
Definition TAttPad.h:56
Float_t fRightMargin
RightMargin.
Definition TAttPad.h:22
Style_t GetFrameFillStyle() const
Definition TAttPad.h:55
Float_t fLeftMargin
LeftMargin.
Definition TAttPad.h:21
Float_t fTopMargin
TopMargin.
Definition TAttPad.h:24
Float_t GetLeftMargin() const
Definition TAttPad.h:44
Width_t GetFrameLineWidth() const
Definition TAttPad.h:57
Float_t GetBottomMargin() const
Definition TAttPad.h:43
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition TAttPad.cxx:118
Float_t GetRightMargin() const
Definition TAttPad.h:45
Int_t GetFrameBorderMode() const
Definition TAttPad.h:59
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition TAttPad.cxx:128
Width_t GetFrameBorderSize() const
Definition TAttPad.h:58
Float_t fBottomMargin
BottomMargin.
Definition TAttPad.h:23
Float_t GetTopMargin() const
Definition TAttPad.h:46
virtual void Streamer(TBuffer &)
Stream an object of class TAttPad.
Definition TAttPad.cxx:149
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:39
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:48
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:35
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:38
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:37
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:49
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:36
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
void PaintZoomBox(TPad &pad)
Definition TPad.cxx:2203
Double_t px1old
Definition TPad.cxx:2201
Double_t py1old
Definition TPad.cxx:2201
Double_t px2old
Definition TPad.cxx:2201
Double_t ratio2
Definition TPad.cxx:2200
Double_t py2old
Definition TPad.cxx:2201
Double_t ratio1
Definition TPad.cxx:2200
Class to manage histogram axis.
Definition TAxis.h:32
@ kAxisRange
Definition TAxis.h:66
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:529
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x
Definition TAxis.cxx:422
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:480
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition TAxis.h:166
Int_t GetNbins() const
Definition TAxis.h:127
virtual TObject * GetParent() const
Definition TAxis.h:130
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1068
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:539
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:469
Each class (see TClass) has a linked list of its base class(es).
Definition TBaseClass.h:33
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
void CalcPixelCoord(const TVirtualPad &parent, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Calculate pixel coordinates.
Create a Box.
Definition TBox.h:22
virtual void SetY2(Double_t y2)
Definition TBox.h:65
static TClass * Class()
virtual void SetX1(Double_t x1)
Definition TBox.h:62
virtual void SetX2(Double_t x2)
Definition TBox.h:63
virtual void SetY1(Double_t y1)
Definition TBox.h:64
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Buffer base class used for serializing objects.
Definition TBuffer.h:43
A TButton object is a user interface object.
Definition TButton.h:18
static TClass * Class()
ABC describing GUI independent main window (with menubar, scrollbars and a drawing area).
Definition TCanvasImp.h:31
virtual Int_t RequestLocator(Int_t &x, Int_t &y)
Request current mouse pointer, redirect to gVirtualX.
The Canvas class.
Definition TCanvas.h:23
UInt_t GetWindowHeight() const
Definition TCanvas.h:167
TObject * GetClickSelected() const
Definition TCanvas.h:147
void ClearPadSave()
Definition TCanvas.h:145
TVirtualPad * GetClickSelectedPad() const
Definition TCanvas.h:152
void SetClickSelectedPad(TPad *pad)
Definition TCanvas.h:218
void SetSelectedPad(TPad *pad)
Definition TCanvas.h:217
void SetDoubleBuffer(Int_t mode=1) override
Set Double Buffer On/Off.
Definition TCanvas.cxx:1995
TCanvasImp * GetCanvasImp() const override
Definition TCanvas.h:163
Bool_t IsRetained() const override
Definition TCanvas.h:183
Int_t GetEventY() const override
Definition TCanvas.h:142
Bool_t IsBatch() const override
Definition TCanvas.h:178
TVirtualPadPainter * GetCanvasPainter()
Access and (probably) creation of pad painter.
Definition TCanvas.cxx:2678
Color_t GetHighLightColor() const override
Definition TCanvas.h:143
Bool_t EnsurePSPainter(Bool_t create, TVirtualPadPainter *&oldp)
Replace canvas painter For internal use only - when creating PS images.
Definition TCanvas.cxx:2688
Bool_t IsGrayscale()
Check whether this canvas is to be drawn in grayscale mode.
Definition TCanvas.cxx:2626
void SaveSource(const char *filename="", Option_t *option="")
Save primitives in this canvas as a C++ macro file.
Definition TCanvas.cxx:1834
virtual void HandleInput(EEventType button, Int_t x, Int_t y)
Handle Input Events.
Definition TCanvas.cxx:1241
void UpdateAsync() override
Asynchronous canvas update.
Definition TCanvas.cxx:2599
TObject * GetSelected() const override
Definition TCanvas.h:146
Int_t GetEventX() const override
Definition TCanvas.h:141
void SetCanvasSize(UInt_t ww, UInt_t wh) override
Set Width and Height of canvas to ww and wh respectively.
Definition TCanvas.cxx:1972
TVirtualPad * GetSelectedPad() const override
Definition TCanvas.h:151
void SetCursor(ECursor cursor) override
Set cursor.
Definition TCanvas.cxx:1986
Int_t GetCanvasID() const override
Definition TCanvas.h:162
UInt_t GetWindowWidth() const
Definition TCanvas.h:166
void SetClickSelected(TObject *obj)
Definition TCanvas.h:216
TVirtualPad * GetPadSave() const override
Definition TCanvas.h:144
void Update() override
Update canvas pad buffers.
Definition TCanvas.cxx:2519
virtual void Cleared(TVirtualPad *pad)
Emit pad Cleared signal.
Definition TCanvas.cxx:783
UInt_t GetWw() const override
Definition TCanvas.h:168
Bool_t OpaqueMoving() const override
Definition TCanvas.h:187
UInt_t GetWh() const override
Definition TCanvas.h:169
void FeedbackMode(Bool_t set) override
Turn rubberband feedback mode on or off.
Definition TCanvas.cxx:1138
Int_t GetDoubleBuffer() const override
Definition TCanvas.h:139
static TClass * Class()
void SetSelected(TObject *obj) override
Set selected canvas.
Definition TCanvas.cxx:2144
Int_t GetEvent() const override
Definition TCanvas.h:140
Bool_t IsWeb() const override
Is web canvas.
Definition TCanvas.cxx:1516
void SetBatch(Bool_t batch=kTRUE) override
Toggle batch mode.
Definition TCanvas.cxx:1954
Bool_t UseGL() const
Definition TCanvas.h:235
TVirtualPad * fHilightPadBorder
! pad which border will be hilghlighrt when paint canvas
Definition TCanvas.h:70
Bool_t OpaqueResizing() const override
Definition TCanvas.h:188
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition TClass.cxx:3875
Int_t GetNmethods()
Return the number of methods of this class Note that in case the list of methods is not yet created,...
Definition TClass.cxx:4694
Int_t GetNdata()
Return the number of data members of this class Note that in case the list of data members is not yet...
Definition TClass.cxx:4675
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3833
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3699
void ls(Option_t *option="") const override
List (ls) all objects in this collection.
void Browse(TBrowser *b) override
Browse this collection (called by TBrowser).
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1939
static TString SavePrimitiveColor(Int_t ci)
Convert color in C++ statement which can be used in SetColor directives Produced statement either inc...
Definition TColor.cxx:2569
static void SetGrayscale(Bool_t set=kTRUE)
Set whether all colors should return grayscale values.
Definition TColor.cxx:2617
static void Pave(Int_t event, Int_t px, Int_t py, Int_t mode)
Create a new pavetext in gPad.
static void Line(Int_t event, Int_t px, Int_t py, Int_t mode)
Create a new line/arrow in this gPad.
static void PolyLine(Int_t event, Int_t px, Int_t py, Int_t mode)
Create a new PolyLine in gPad.
static void Text(Int_t event, Int_t px, Int_t py, Int_t mode)
Create a new TLatex at the cursor position in gPad.
static void Ellipse(Int_t event, Int_t px, Int_t py, Int_t mode)
Create a new arc/ellipse in this gPad.
static void Pad(Int_t event, Int_t px, Int_t py, Int_t)
Create a new pad in gPad.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
const char * AsSQLString() const
Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.
Definition TDatime.cxx:148
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition TDatime.cxx:98
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
Definition TExec.h:26
Define a Frame.
Definition TFrame.h:19
static TClass * Class()
void Paint(Option_t *option="") override
Paint this wbox with its current attributes.
Definition TFrame.cxx:127
void UseCurrentStyle() override
Replace current frame attributes by current style.
Definition TFrame.cxx:157
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
static TClass * Class()
@ kClipFrame
Clip to the frame boundary.
Definition TGraph.h:75
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:9170
static TClass * Class()
virtual Double_t GetNormFactor() const
Definition TH1.h:545
virtual Int_t GetDimension() const
Definition TH1.h:527
@ kNoStats
Don't draw stats box.
Definition TH1.h:403
@ kIsZoomed
Bit set when zooming on Y axis.
Definition TH1.h:407
virtual Double_t GetSumOfWeights() const
Return the sum of weights across all bins excluding under/overflows.
Definition TH1.h:559
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:652
TAxis * GetYaxis()
Definition TH1.h:572
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3193
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:653
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition TH1.cxx:3258
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition TH1.cxx:8868
static TClass * Class()
static TClass * Class()
The Histogram stack class.
Definition THStack.h:40
TH1 * GetHistogram() const
Returns a pointer to the histogram used to draw the axis.
Definition THStack.cxx:482
static TClass * Class()
EImageFileTypes
Definition TImage.h:37
@ kBmp
Definition TImage.h:46
@ kPng
Definition TImage.h:41
@ kPdf
Definition TImage.h:59
@ kJpeg
Definition TImage.h:42
@ kXpm
Definition TImage.h:38
@ kAnimGif
Definition TImage.h:56
@ kUnknown
Definition TImage.h:55
@ kSvg
Definition TImage.h:58
@ kHtml
Definition TImage.h:57
@ kTiff
Definition TImage.h:50
@ kGif
Definition TImage.h:49
Option_t * GetOption() const
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
Use the TLine constructor to create a simple line.
Definition TLine.h:22
Iterator of linked list.
Definition TList.h:196
Option_t * GetOption() const override
Returns the object option stored in the list.
Definition TList.cxx:1274
A doubly linked list.
Definition TList.h:38
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition TList.cxx:460
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:532
virtual TObjLink * LastLink() const
Definition TList.h:110
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:708
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:894
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:952
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition TList.cxx:149
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:823
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:789
virtual TObjLink * FirstLink() const
Definition TList.h:107
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:487
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition TList.cxx:97
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition TMultiGraph.h:34
TH1F * GetHistogram()
Returns a pointer to the histogram used to draw the axis.
static TClass * Class()
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
static TClass * Class()
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Mother of all ROOT objects.
Definition TObject.h:42
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Computes distance from point (px,py) to the object.
Definition TObject.cxx:283
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:461
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:995
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
Definition TObject.cxx:907
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:444
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:424
virtual void Delete(Option_t *option="")
Delete this object.
Definition TObject.cxx:267
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:886
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:548
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:506
void MakeZombie()
Definition TObject.h:55
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Definition TObject.cxx:630
void ResetBit(UInt_t f)
Definition TObject.h:203
@ kCannotPick
if object in a pad cannot be picked
Definition TObject.h:76
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:73
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1070
std::vector< Double_t > fX
Definition TPad.cxx:188
void Draw(TPad &pad, TVirtualPadPainter *pp, Bool_t withXor)
Definition TPad.cxx:147
std::vector< Double_t > fY
Definition TPad.cxx:188
TPadDrawOperation(Int_t n, T *x, T *y, EKind kind, Int_t arg=1, Bool_t ndc=kFALSE)
Definition TPad.cxx:137
virtual ~TPadDrawOperation()=default
The most important graphics class in the ROOT system.
Definition TPad.h:32
Short_t GetBorderMode() const override
Definition TPad.h:209
Bool_t OpaqueMoving() const override
Is pad moving in opaque mode ?
Definition TPad.cxx:2756
void PaintTextNDC(Double_t u, Double_t v, const char *text) override
Paint text in CurrentPad NDC coordinates.
Definition TPad.cxx:4612
Int_t GetTicky() const override
Definition TPad.h:252
virtual Int_t Clip(Float_t *x, Float_t *y, Float_t xclipl, Float_t yclipb, Float_t xclipr, Float_t yclipt)
Clipping routine: Cohen Sutherland algorithm.
Definition TPad.cxx:834
virtual void HideToolTip(Int_t event)
Hide tool tip depending on the event type.
Definition TPad.cxx:2701
Double_t fAbsYlowNDC
Absolute Y top left corner of pad in NDC [0,1].
Definition TPad.h:76
std::map< std::string, std::unique_ptr< TPadDrawOperation > > fDrawOper
Definition TPad.h:39
Double_t fXtoAbsPixelk
Conversion coefficient for X World to absolute pixel.
Definition TPad.h:47
void SetAttMarkerPS(Color_t color, Style_t style, Size_t msize) override
Set postscript marker attributes.
Definition TPad.cxx:6156
virtual void DivideSquare(Int_t n, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
"n" is the total number of sub-pads.
Definition TPad.cxx:1555
void AbsCoordinates(Bool_t set) override
Definition TPad.h:175
static TClass * Class()
Bool_t IsBatch() const override
Is pad in batch mode ?
Definition TPad.cxx:2733
Double_t GetUymax() const override
Returns the maximum y-coordinate value visible on the pad. If log axis the returned value is in decad...
Definition TPad.h:247
void AddExec(const char *name, const char *command) override
Add a new TExec object to the list of Execs.
Definition TPad.cxx:564
Double_t fWNDC
Width of pad along X in Normalized Coordinates (NDC)
Definition TPad.h:72
Int_t NextPaletteColor() override
Get the next autocolor in the pad.
Definition TPad.cxx:3021
Int_t VtoPixel(Double_t v) const override
Convert Y NDC to pixel.
Definition TPad.cxx:7414
void PaintBorder(Color_t color, Bool_t tops)
Paint the pad border.
Definition TPad.cxx:3566
Double_t GetPhi() const override
Definition TPad.h:238
std::map< std::string, std::unique_ptr< TPadDrawOperation > > fDrawOperXor
! map of draw operations performed outside of normal paint
Definition TPad.h:39
Bool_t IsEditable() const override
Definition TPad.h:285
void FillCollideGrid(TObject *o)
Initialise the grid used to find empty space when adding a box (Legend) in a pad.
Definition TPad.cxx:3037
void SetView(TView *view=nullptr) override
Set the current TView. Delete previous view if view=0.
Definition TPad.cxx:6121
TVirtualViewer3D * GetViewer3D(Option_t *type="") override
Create/obtain handle to 3D viewer.
Definition TPad.cxx:7078
Double_t fPixeltoYk
Conversion coefficient for pixel to Y World.
Definition TPad.h:65
void PaintHatches(Double_t dy, Double_t angle, Int_t nn, Double_t *xx, Double_t *yy)
This routine draw hatches inclined with the angle "angle" and spaced of "dy" in normalized device coo...
Definition TPad.cxx:4053
void PaintLine3D(Float_t *p1, Float_t *p2) override
Paint 3-D line in the CurrentPad.
Definition TPad.cxx:4234
static Int_t fgMaxPickDistance
Maximum Pick Distance.
Definition TPad.h:121
void ResizePad(Option_t *option="") override
Compute pad conversion coefficients.
Definition TPad.cxx:5609
void PaintMarker3D(Double_t x, Double_t y, Double_t z) override
Paint 3-D marker in the CurrentPad.
Definition TPad.cxx:4270
void PaintPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override
Paint polymarker in CurrentPad World coordinates.
Definition TPad.cxx:4447
Double_t fPhi
phi angle to view as lego/surface
Definition TPad.h:86
Double_t fPixeltoY
yworld = fPixeltoYk + fPixeltoY*ypixel
Definition TPad.h:66
virtual void RecordLatex(const TObject *obj)
Emit RecordLatex() signal.
Definition TPad.cxx:7181
Double_t fAbsXlowNDC
Absolute X top left corner of pad in NDC [0,1].
Definition TPad.h:75
Double_t fVtoPixelk
Conversion coefficient for V NDC to pixel.
Definition TPad.h:58
Bool_t fGridx
Set to true if grid along X.
Definition TPad.h:106
TObject * fPadView3D
! 3D View of this TPad
Definition TPad.h:120
Double_t GetUxmax() const override
Returns the maximum x-coordinate value visible on the pad. If log axis the returned value is in decad...
Definition TPad.h:245
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1361
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitives in this pad on the C++ source file out.
Definition TPad.cxx:5824
void CopyBackgroundPixmaps(TPad *stop, Int_t x, Int_t y)
Copy pixmaps of pads laying below pad "stop" into pad "stop".
Definition TPad.cxx:3895
Double_t fXtoPixel
xpixel = fXtoPixelk + fXtoPixel*xworld
Definition TPad.h:49
TList * fExecs
List of commands to be executed when a pad event occurs.
Definition TPad.h:114
Double_t PadtoY(Double_t y) const override
Convert y from pad to Y.
Definition TPad.cxx:3455
Int_t fTickx
Set to 1 if tick marks along X.
Definition TPad.h:95
void PaintOperations(Bool_t withXor=kFALSE)
Perform buffered paint operations Used for interactivity functionality immediately after normal paint...
Definition TPad.cxx:3797
void SetBBoxY1(const Int_t y) override
Set top of BoundingBox to a value (resize in y direction on top)
Definition TPad.cxx:7290
Int_t fTicky
Set to 1 if tick marks along Y.
Definition TPad.h:96
Int_t GetPixmapID() const override
Definition TPad.h:279
Bool_t GetGridx() const override
Definition TPad.h:248
Double_t fX2
X of upper X coordinate.
Definition TPad.h:44
Bool_t PlaceBox(TObject *o, Double_t w, Double_t h, Double_t &xl, Double_t &yb, Option_t *option="lb") override
Place a box in NDC space.
Definition TPad.cxx:3106
void SetLogz(Int_t value=1) override
Set Lin/Log scale for Z.
Definition TPad.cxx:6037
Bool_t fEmbeddedGL
!
Definition TPad.h:93
Int_t UtoAbsPixel(Double_t u) const override
Convert X NDC to absolute pixel.
Definition TPad.cxx:7422
void Browse(TBrowser *b) override
Browse pad.
Definition TPad.cxx:587
Int_t XtoPixel(Double_t x) const override
Convert X coordinate to pixel.
Definition TPad.cxx:7446
void SetAttFillPS(Color_t color, Style_t style) override
Set postscript fill area attributes.
Definition TPad.cxx:6132
Int_t fCGnx
! Size of the collide grid along x
Definition TPad.h:125
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the center of the Pad.
Definition TPad.cxx:7254
Double_t fPixeltoX
xworld = fPixeltoXk + fPixeltoX*xpixel
Definition TPad.h:63
~TPad() override
Pad destructor.
Definition TPad.cxx:445
Bool_t fCopyGLDevice
!
Definition TPad.h:92
Double_t fYtoPixel
ypixel = fYtoPixelk + fYtoPixel*yworld
Definition TPad.h:52
Double_t GetY2() const override
Definition TPad.h:256
void DeleteToolTip(TObject *tip) override
Delete tool tip object.
Definition TPad.cxx:7028
void Close(Option_t *option="") override
Delete all primitives in pad and pad itself.
Definition TPad.cxx:1147
void AbsPixeltoXY(Double_t xpixel, Double_t ypixel, Double_t &x, Double_t &y) override
Convert absolute pixel into X/Y coordinates.
Definition TPad.cxx:7324
Double_t fAbsWNDC
Absolute Width of pad along X in NDC.
Definition TPad.h:77
TObject * Remove(TObject *obj, Bool_t modified=kTRUE) override
Remove object from list of primitives When.
Definition TPad.cxx:5392
UInt_t GetWw() const override
Get canvas width.
Definition TPad.cxx:2657
void PaintModified() override
Traverse pad hierarchy and (re)paint only modified pads.
Definition TPad.cxx:3701
void SetEditable(Bool_t mode=kTRUE) override
Set pad editable yes/no If a pad is not editable:
Definition TPad.cxx:5981
const char * GetTitle() const override
Returns title of object.
Definition TPad.h:274
void PaintDate()
Paint the current date and time if the option Date is set on via gStyle->SetOptDate() Paint the curre...
Definition TPad.cxx:3639
static void SetMaxPickDistance(Int_t maxPick=5)
static function to set the maximum Pick Distance fgMaxPickDistance This parameter is used in TPad::Pi...
Definition TPad.cxx:6607
void PixeltoXY(Double_t xpixel, Double_t ypixel, Double_t &x, Double_t &y) override
Convert pixel to X/Y coordinates.
Definition TPad.cxx:7352
void SetBBoxX2(const Int_t x) override
Set right hand side of BoundingBox to a value (resize in x direction on right)
Definition TPad.cxx:7279
void SetBBoxX1(const Int_t x) override
Set lefthandside of BoundingBox to a value (resize in x direction on left)
Definition TPad.cxx:7266
virtual Int_t ClippingCode(Double_t x, Double_t y, Double_t xcl1, Double_t ycl1, Double_t xcl2, Double_t ycl2)
Compute the endpoint codes for TPad::Clip.
Definition TPad.cxx:967
Double_t GetUymin() const override
Returns the minimum y-coordinate value visible on the pad. If log axis the returned value is in decad...
Definition TPad.h:243
Double_t fX1
X of lower X coordinate.
Definition TPad.h:42
TList * GetListOfPrimitives() const override
Definition TPad.h:258
void SetFillStyle(Style_t fstyle) override
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition TPad.cxx:6000
Double_t AbsPixeltoY(Double_t py) override
Definition TPad.h:177
TH1F * DrawFrame(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, const char *title="") override
Draw an empty pad frame with X and Y axis.
Definition TPad.cxx:1898
Double_t fVtoPixel
ypixel = fVtoPixelk + fVtoPixel*vndc
Definition TPad.h:59
TCanvasImp * GetCanvasImp() const override
Get canvas implementation pointer if any.
Definition TPad.cxx:2558
Int_t GetEvent() const override
Get Event.
Definition TPad.cxx:2566
Double_t PadtoX(Double_t x) const override
Convert x from pad to X.
Definition TPad.cxx:3446
TInteractive * Interactive(TObject *obj=nullptr, TInteractive *init=nullptr) override
Internal method to create, provide or delete TInteractive instance It is allowed the only instance of...
Definition TPad.cxx:2986
virtual void DrawCrosshair()
Function called to draw a crosshair in the canvas.
Definition TPad.cxx:1819
Double_t YtoPad(Double_t y) const override
Convert y from Y to pad.
Definition TPad.cxx:3476
virtual void RangeChanged()
Definition TPad.h:334
Double_t fUymin
Minimum value on the Y axis.
Definition TPad.h:81
void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1) override
Set all pad parameters.
Definition TPad.cxx:6097
void SetCursor(ECursor cursor) override
Set cursor type.
Definition TPad.cxx:2788
Int_t GetCanvasID() const override
Get canvas identifier.
Definition TPad.cxx:2550
Int_t fLogz
(=0 if Z linear scale, =1 if log scale)
Definition TPad.h:99
Int_t HtoAbsPixel(Double_t y1, Double_t y2) const override
Convert a vertical distance [y1,y2] to pixel.
Definition TPad.cxx:7462
void XYtoPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const override
Convert X/Y into pixel coordinates - integer.
Definition TPad.cxx:7388
Double_t fYtoPixelk
Conversion coefficient for Y World to pixel.
Definition TPad.h:51
void UpdateAsync() override
Asynchronous pad update.
Definition TPad.cxx:2824
TPad()
Pad default constructor.
Definition TPad.cxx:198
void UseCurrentStyle() override
Force a copy of current style for all objects in pad.
Definition TPad.cxx:6854
static Int_t GetMaxPickDistance()
Static function (see also TPad::SetMaxPickDistance)
Definition TPad.cxx:2614
Int_t VtoAbsPixel(Double_t v) const override
Convert Y NDC to absolute pixel.
Definition TPad.cxx:7430
void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Set world coordinate system for the pad.
Definition TPad.cxx:5316
Double_t fUtoPixelk
Conversion coefficient for U NDC to pixel.
Definition TPad.h:55
void XYtoAbsPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const override
Convert X/Y into absolute pixel coordinates - integer.
Definition TPad.cxx:7361
Double_t fPixeltoXk
Conversion coefficient for pixel to X World.
Definition TPad.h:62
Bool_t IsModified() const override
Definition TPad.h:287
Double_t fY1
Y of lower Y coordinate.
Definition TPad.h:43
Int_t GetEventY() const override
Get Y event.
Definition TPad.cxx:2582
Int_t fGLDevice
! OpenGL off-screen pixmap identifier
Definition TPad.h:91
Double_t fYlowNDC
Y bottom left corner of pad in NDC [0,1].
Definition TPad.h:69
TObject * WaitPrimitive(const char *pname="", const char *emode="") override
Loop and sleep until a primitive with name=pname is found in the pad.
Definition TPad.cxx:6974
void SetAttTextPS(Int_t align, Float_t angle, Color_t color, Style_t font, Float_t tsize) override
Set postscript text attributes.
Definition TPad.cxx:6168
Bool_t fModified
Set to true when pad is modified.
Definition TPad.h:105
Double_t PixeltoY(Double_t py) override
Convert pixel to Y coordinate.
Definition TPad.cxx:7343
TLegend * BuildLegend(Double_t x1=0.3, Double_t y1=0.21, Double_t x2=0.3, Double_t y2=0.21, const char *title="", Option_t *option="") override
Build a legend from the graphical objects in the pad.
Definition TPad.cxx:619
virtual TPad * Pick(Int_t px, Int_t py, TObjLink *&pickobj)
Search for an object at pixel position px,py.
Definition TPad.cxx:4648
void Update() override
Update pad.
Definition TPad.cxx:2812
virtual void SetNumber(Int_t number)
Definition TPad.h:360
Int_t fNumber
pad number identifier
Definition TPad.h:94
void PaintFillAreaNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override
Paint fill area in CurrentPad NDC coordinates.
Definition TPad.cxx:3976
Double_t fAbsPixeltoXk
Conversion coefficient for absolute pixel to X World.
Definition TPad.h:61
void Clear(Option_t *option="") override
Delete all pad primitives.
Definition TPad.cxx:786
Int_t YtoPixel(Double_t y) const override
Convert Y coordinate to pixel.
Definition TPad.cxx:7483
Int_t GetTickx() const override
Definition TPad.h:251
void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Paint line in CurrentPad World coordinates.
Definition TPad.cxx:4199
Int_t GetGLDevice() override
Get GL device.
Definition TPad.cxx:7165
Double_t fAspectRatio
ratio of w/h in case of fixed ratio
Definition TPad.h:88
virtual void RecordPave(const TObject *obj)
Emit RecordPave() signal.
Definition TPad.cxx:7173
void PaintBorderPS(Double_t xl, Double_t yl, Double_t xt, Double_t yt, Int_t bmode, Int_t bsize, Int_t dark, Int_t light) override
Paint a frame border with Postscript - no longer used.
Definition TPad.cxx:3629
Double_t fUymax
Maximum value on the Y axis.
Definition TPad.h:83
void SetLogy(Int_t value=1) override
Set Lin/Log scale for Y.
Definition TPad.cxx:6026
virtual Int_t ClipPolygon(Int_t n, Double_t *x, Double_t *y, Int_t nn, Double_t *xc, Double_t *yc, Double_t xclipl, Double_t yclipb, Double_t xclipr, Double_t yclipt)
Clip polygon using the Sutherland-Hodgman algorithm.
Definition TPad.cxx:1016
void ExecuteEventAxis(Int_t event, Int_t px, Int_t py, TAxis *axis) override
Execute action corresponding to one event for a TAxis object (called by TAxis::ExecuteEvent....
Definition TPad.cxx:2256
void HighLight(Color_t col=kRed, Bool_t set=kTRUE) override
Highlight pad.
Definition TPad.cxx:2932
Double_t AbsPixeltoX(Double_t px) override
Definition TPad.h:176
void SetBatch(Bool_t batch=kTRUE) override
Set pad in batch mode.
Definition TPad.cxx:2772
TCanvas * fCanvas
! Pointer to mother canvas
Definition TPad.h:112
TVirtualPad * GetMother() const override
Definition TPad.h:272
TVirtualViewer3D * fViewer3D
! Current 3D viewer
Definition TPad.h:129
virtual void x3d(Option_t *type="")
Deprecated: use TPad::GetViewer3D() instead.
Definition TPad.cxx:7060
Bool_t HasCrosshair() const override
Return kTRUE if the crosshair has been activated (via SetCrosshair).
Definition TPad.cxx:6569
Bool_t IsRetained() const override
Is pad retained ?
Definition TPad.cxx:2741
Bool_t Collide(Int_t i, Int_t j, Int_t w, Int_t h)
Check if a box of size w and h collide some primitives in the pad at position i,j.
Definition TPad.cxx:3082
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a box.
Definition TPad.cxx:1257
Bool_t fFixedAspectRatio
True if fixed aspect ratio.
Definition TPad.h:110
void PaintFillArea(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override
Definition TPad.cxx:3914
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7315
void RecursiveRemove(TObject *obj) override
Recursively remove object from a pad and its sub-pads.
Definition TPad.cxx:5374
void DivideRatios(Int_t nrows, Int_t ncolumns, const std::vector< double > &widthRatios={}, const std::vector< double > &heightRatios={}, const double canvasTopMargin=0., const double canvasLeftMargin=0.)
Divide the canvas according to ratios.
Definition TPad.cxx:1460
Bool_t HasFixedAspectRatio() const override
Definition TPad.h:283
void CloseToolTip(TObject *tip) override
Hide tool tip.
Definition TPad.cxx:7050
Double_t GetUxmin() const override
Returns the minimum x-coordinate value visible on the pad. If log axis the returned value is in decad...
Definition TPad.h:241
void SetToolTipText(const char *text, Long_t delayms=1000) override
Set tool tip text associated with this pad.
Definition TPad.cxx:6617
void PaintPolyLine(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override
Paint polyline in CurrentPad World coordinates.
Definition TPad.cxx:4296
Int_t WtoAbsPixel(Double_t x1, Double_t x2) const override
Convert a horizontal distance [x1,x2] to pixel.
Definition TPad.cxx:7472
void ls(Option_t *option="") const override
List all primitives in pad.
Definition TPad.cxx:2968
TView * GetView() const override
Definition TPad.h:267
void ModifiedUpdate() override
Short cut to call Modified() and Update() in a single call.
Definition TPad.cxx:3434
Double_t fVtoAbsPixelk
Conversion coefficient for V NDC to absolute pixel.
Definition TPad.h:57
UInt_t GetPadHeight() const override
Get pad height.
Definition TPad.cxx:2682
TVirtualPad * GetPadSave() const override
Get save pad.
Definition TPad.cxx:2640
void SetAttLinePS(Color_t color, Style_t style, Width_t lwidth) override
Set postscript line attributes.
Definition TPad.cxx:6144
TClass * IsA() const override
Definition TPad.h:441
virtual void Resized()
Definition TPad.h:341
TVirtualPad * GetVirtCanvas() const override
Get virtual canvas.
Definition TPad.cxx:2590
void DeleteExec(const char *name) override
Remove TExec name from the list of Execs.
Definition TPad.cxx:1241
void PaintSegments(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override
Paint N individual segments Provided arrays should have 2*n elements IMPORTANT! Provided arrays can b...
Definition TPad.cxx:4518
void FeedbackMode(Bool_t set) override
Switch feedback mode for the canvas Only for internal use when implementing special painters.
Definition TPad.cxx:2501
UInt_t GetPadWidth() const override
Get pad width.
Definition TPad.cxx:2665
void Streamer(TBuffer &) override
Stream a class object.
Definition TPad.cxx:6640
void PaintSegmentsNDC(Int_t n, Double_t *u, Double_t *v) override
Paint N individual segments in NDC coordinates Provided arrays should have 2*n elements IMPORTANT!...
Definition TPad.cxx:4559
TString fTitle
Pad title.
Definition TPad.h:116
void CopyPixmaps() override
Copy the sub-pixmaps of the pad to the canvas.
Definition TPad.cxx:1222
void CopyPixmap() override
Copy the pixmap of the pad to the canvas.
Definition TPad.cxx:1206
Double_t GetY1() const override
Definition TPad.h:255
Int_t UtoPixel(Double_t u) const override
Convert X NDC to pixel.
Definition TPad.cxx:7406
TPoint GetBBoxCenter() override
Return the center of the Pad as TPoint in pixels.
Definition TPad.cxx:7215
void FillCollideGridTFrame(TObject *o)
Definition TPad.cxx:3238
Bool_t GetGridy() const override
Definition TPad.h:249
void LineNotFree(Int_t x1, Int_t x2, Int_t y1, Int_t y2)
Mark as "not free" the cells along a line.
Definition TPad.cxx:3178
Double_t fAbsHNDC
Absolute Height of pad along Y in NDC.
Definition TPad.h:78
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TPad.cxx:2004
TObject * fTip
! tool tip associated with box
Definition TPad.h:37
void SetCanvasSize(UInt_t ww, UInt_t wh) override
Set canvas size.
Definition TPad.cxx:2780
Int_t GetLogz() const override
Definition TPad.h:271
virtual void AutoExec()
Execute the list of Execs when a pad event occurs.
Definition TPad.cxx:574
Bool_t fAbsCoord
Use absolute coordinates.
Definition TPad.h:108
Int_t fNumPaletteColor
Number of objects with an automatic color.
Definition TPad.h:122
Int_t fCrosshairPos
Position of crosshair.
Definition TPad.h:102
void FillCollideGridTGraph(TObject *o)
Definition TPad.cxx:3264
void SetFixedAspectRatio(Bool_t fixed=kTRUE) override
Fix pad aspect ratio to current value if fixed is true.
Definition TPad.cxx:5957
Short_t GetBorderSize() const override
Definition TPad.h:210
void RedrawAxis(Option_t *option="") override
Redraw the frame axis.
Definition TPad.cxx:5435
void DrawDist(Rectangle_t aBBox, Rectangle_t bBBox, char mode)
Draw Arrows to indicated equal distances of Objects with given BBoxes.
Definition TPad.cxx:6193
Int_t fLogx
(=0 if X linear scale, =1 if log scale)
Definition TPad.h:97
Double_t GetAbsWNDC() const override
Definition TPad.h:235
Int_t YtoAbsPixel(Double_t y) const override
Convert Y coordinate to absolute pixel.
Definition TPad.cxx:7454
Double_t fUtoPixel
xpixel = fUtoPixelk + fUtoPixel*undc
Definition TPad.h:56
Int_t fCrosshair
Crosshair type (0 if no crosshair requested)
Definition TPad.h:101
void PaintFillAreaHatches(Int_t n, Double_t *x, Double_t *y, Int_t FillStyle)
This function paints hatched fill area according to the FillStyle value The convention for the Hatch ...
Definition TPad.cxx:4019
void RangeAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax) override
Set axis coordinate system for the pad.
Definition TPad.cxx:5354
@ kCannotMove
Fixed position.
Definition TPad.h:166
@ kClearAfterCR
Clear after CR.
Definition TPad.h:167
@ kHori
Pad is horizontal.
Definition TPad.h:163
@ kPrintingPS
PS Printing.
Definition TPad.h:165
@ kFraming
Frame is requested.
Definition TPad.h:162
Double_t fUtoAbsPixelk
Conversion coefficient for U NDC to absolute pixel.
Definition TPad.h:54
void ResetToolTip(TObject *tip) override
Reset tool tip, i.e.
Definition TPad.cxx:7039
Double_t GetTheta() const override
Definition TPad.h:239
TList * fPrimitives
->List of primitives (subpads)
Definition TPad.h:113
UInt_t GetWh() const override
Get canvas height.
Definition TPad.cxx:2649
TCanvas * GetCanvas() const override
Definition TPad.h:275
Short_t fBorderSize
pad bordersize in pixels
Definition TPad.h:103
void Add(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object to list of primitives with specified draw option When.
Definition TPad.cxx:484
TView * fView
! Pointer to 3-D view (if one exists)
Definition TPad.h:118
Rectangle_t GetBBox() override
Return the bounding Box of the Pad.
Definition TPad.cxx:7198
void Paint(Option_t *option="") override
Paint all primitives in pad.
Definition TPad.cxx:3488
void FillCollideGridTBox(TObject *o)
Definition TPad.cxx:3221
Double_t fTheta
theta angle to view as lego/surface
Definition TPad.h:85
void DrawCollideGrid()
This method draws the collide grid on top of the canvas.
Definition TPad.cxx:3377
TString fName
Pad name.
Definition TPad.h:115
void SetVertical(Bool_t vert=kTRUE) override
Set pad vertical (default) or horizontal.
Definition TPad.cxx:6631
void FillCollideGridTH1(TObject *o)
Definition TPad.cxx:3295
void GetPadPar(Double_t &xlow, Double_t &ylow, Double_t &xup, Double_t &yup) override
Return lower and upper bounds of the pad in NDC coordinates.
Definition TPad.cxx:2898
void PaintText(Double_t x, Double_t y, const char *text) override
Paint text in CurrentPad World coordinates.
Definition TPad.cxx:4573
Int_t fPadPaint
Set to 1 while painting the pad.
Definition TPad.h:100
static void DrawColorTable()
Static function to Display Color Table in a pad.
Definition TPad.cxx:1943
Double_t GetXlowNDC() const override
Definition TPad.h:223
void SaveAs(const char *filename="", Option_t *option="") const override
Save the pad content in a file.
Definition TPad.cxx:5769
Int_t fPixmapID
! Off-screen pixmap identifier
Definition TPad.h:90
Bool_t fEditable
True if canvas is editable.
Definition TPad.h:109
Double_t GetYlowNDC() const override
Definition TPad.h:224
TObject * FindObject(const char *name) const override
Search if object named name is inside this pad or in pads inside this pad.
Definition TPad.cxx:2512
Color_t GetHighLightColor() const override
Get highlight color.
Definition TPad.cxx:2606
Bool_t OpaqueResizing() const override
Is pad resizing in opaque mode ?
Definition TPad.cxx:2764
Double_t fXUpNDC
Definition TPad.h:70
std::vector< Bool_t > fCollideGrid
! Grid used to find empty space when adding a box (Legend) in a pad
Definition TPad.h:124
Int_t IsAnyNeedRepaint() const
Check if pad or any subpads need to be repaint Returns flag with following mask: 1 - some pad is modi...
Definition TPad.cxx:2714
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:757
Int_t GetLogy() const override
Definition TPad.h:270
void PaintLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Paint line in normalized coordinates.
Definition TPad.cxx:4221
void Print(const char *filename="") const override
This method is equivalent to SaveAs("filename"). See TPad::SaveAs for details.
Definition TPad.cxx:4789
Int_t GetEventX() const override
Get X event.
Definition TPad.cxx:2574
TFrame * GetFrame() override
Get frame.
Definition TPad.cxx:2832
Double_t fYUpNDC
Definition TPad.h:71
Double_t fYtoAbsPixelk
Conversion coefficient for Y World to absolute pixel.
Definition TPad.h:50
Double_t fXtoPixelk
Conversion coefficient for X World to pixel.
Definition TPad.h:48
Int_t fLogy
(=0 if Y linear scale, =1 if log scale)
Definition TPad.h:98
TFrame * fFrame
! Pointer to 2-D frame (if one exists)
Definition TPad.h:117
TVirtualPadPainter * GetPainter() override
Get pad painter from TCanvas.
Definition TPad.cxx:7189
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1578
virtual void Closed()
Definition TPad.h:192
Double_t fHNDC
Height of pad along Y in Normalized Coordinates (NDC)
Definition TPad.h:73
void ShowGuidelines(TObject *object, const Int_t event, const char mode='i', const bool cling=true) override
Shows lines to indicate if a TAttBBox2D object is aligned to the center or to another object,...
Definition TPad.cxx:6277
Int_t GetCrosshair() const
Return the crosshair type (from the mother canvas) crosshair type = 0 means no crosshair.
Definition TPad.cxx:6578
void GetRangeAxis(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) override
Return pad axis coordinates range.
Definition TPad.cxx:2920
void SetBorderMode(Short_t bordermode) override
Definition TPad.h:343
void PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option="") override
Paint box in CurrentPad World coordinates.
Definition TPad.cxx:3843
void DrawClassObject(const TObject *obj, Option_t *option="") override
Draw class inheritance tree of the class to which obj belongs.
Definition TPad.cxx:1617
Int_t fCGny
! Size of the collide grid along y
Definition TPad.h:126
Double_t fXlowNDC
X bottom left corner of pad in NDC [0,1].
Definition TPad.h:68
TObject * GetPrimitive(const char *name) const override
Get primitive.
Definition TPad.cxx:2860
Double_t fUxmin
Minimum value on the X axis.
Definition TPad.h:80
Double_t GetAbsHNDC() const override
Definition TPad.h:236
Int_t GetDoubleBuffer() const override
Get doublebuffer mode - 1 by default.
Definition TPad.cxx:2598
std::unique_ptr< TInteractive > fInteractive
! current interactive object
Definition TPad.h:38
void SetBBoxCenter(const TPoint &p) override
Set center of the Pad.
Definition TPad.cxx:7230
Bool_t IsWeb() const override
Is web ?
Definition TPad.cxx:2748
void SetSelected(TObject *obj) override
Set selected.
Definition TPad.cxx:2804
TObject * GetSelected() const override
Get selected.
Definition TPad.cxx:2622
void GetRange(Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2) override
Return pad world coordinates range.
Definition TPad.cxx:2909
Double_t PixeltoX(Double_t px) override
Convert pixel to X coordinate.
Definition TPad.cxx:7334
void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override
Paint polyline in CurrentPad NDC coordinates.
Definition TPad.cxx:4411
Bool_t IsVertical() const override
Definition TPad.h:290
void PaintPadFrame(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax) override
Paint histogram/graph frame.
Definition TPad.cxx:3682
Double_t GetAbsYlowNDC() const override
Definition TPad.h:234
Double_t fUxmax
Maximum value on the X axis.
Definition TPad.h:82
void AddFirst(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object as first in list of primitives with specified draw option When.
Definition TPad.cxx:505
Double_t fY2
Y of upper Y coordinate.
Definition TPad.h:45
void PaintTextUrl(Double_t x, Double_t y, const char *text, const char *url) override
Paint text with URL in CurrentPad World coordinates.
Definition TPad.cxx:4599
Double_t fAbsPixeltoYk
Conversion coefficient for absolute pixel to Y World.
Definition TPad.h:64
TVirtualPad * GetSelectedPad() const override
Get selected pad.
Definition TPad.cxx:2631
void PaintPolyLine3D(Int_t n, Double_t *p) override
Paint 3-D polyline in the CurrentPad.
Definition TPad.cxx:4431
TVirtualPad * GetPad(Int_t subpadnumber) const override
Get a pointer to subpadnumber of this pad.
Definition TPad.cxx:2877
Short_t fBorderMode
Bordermode (-1=down, 0 = no border, 1=up)
Definition TPad.h:104
void SetLogx(Int_t value=1) override
Set Lin/Log scale for X.
Definition TPad.cxx:6012
void ReleaseViewer3D(Option_t *type="") override
Release current (external) viewer.
Definition TPad.cxx:7149
void SetCrosshair(Int_t crhair=1) override
Set crosshair active/inactive.
Definition TPad.cxx:6591
void SetDoubleBuffer(Int_t mode=1) override
Set double buffer mode ON or OFF.
Definition TPad.cxx:2796
Int_t fNextPaletteColor
Next automatic color.
Definition TPad.h:123
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the center of the Pad.
Definition TPad.cxx:7243
Int_t GetLogx() const override
Definition TPad.h:269
TObject * fPadPointer
! free pointer
Definition TPad.h:119
Double_t GetX2() const override
Definition TPad.h:254
TObject * CreateToolTip(const TBox *b, const char *text, Long_t delayms) override
Create a tool tip and return its pointer.
Definition TPad.cxx:7018
Double_t GetWNDC() const override
Get width of pad along X in Normalized Coordinates (NDC)
Definition TPad.h:226
void Pop() override
Pop pad to the top of the stack.
Definition TPad.cxx:4767
Double_t GetAbsXlowNDC() const override
Definition TPad.h:233
Int_t IncrementPaletteColor(Int_t i, const TString &opt) override
Increment (i==1) or set (i>1) the number of autocolor in the pad.
Definition TPad.cxx:3004
Double_t GetX1() const override
Definition TPad.h:253
Double_t GetHNDC() const override
Get height of pad along Y in Normalized Coordinates (NDC)
Definition TPad.h:228
TPad * fMother
! pointer to mother of the list
Definition TPad.h:111
const char * GetName() const override
Returns name of object.
Definition TPad.h:273
Int_t XtoAbsPixel(Double_t x) const override
Convert X coordinate to absolute pixel.
Definition TPad.cxx:7438
Bool_t fGridy
Set to true if grid along Y.
Definition TPad.h:107
void SetBBoxY2(const Int_t y) override
Set bottom of BoundingBox to a value (resize in y direction on bottom)
Definition TPad.cxx:7302
Double_t XtoPad(Double_t x) const override
Convert x from X to pad.
Definition TPad.cxx:3464
The histogram statistics painter class.
Definition TPaveStats.h:18
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
virtual TLine * AddLine(Double_t x1=0, Double_t y1=0, Double_t x2=0, Double_t y2=0)
Add a new graphics line to this pavetext.
virtual TBox * AddBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Add a new graphics box to this pavetext.
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
Int_t GetBorderSize() const
Definition TPave.h:56
virtual void SetBorderSize(Int_t bordersize=4)
Sets the border size of the TPave box and shadow.
Definition TPave.h:79
static TClass * Class()
TPluginHandler * FindHandler(const char *base, const char *uri=nullptr)
Returns the handler if there exists a handler for the specified URI.
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
SCoord_t GetY() const
Definition TPoint.h:47
SCoord_t GetX() const
Definition TPoint.h:46
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition TROOT.cxx:3060
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:3068
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2917
Basic string class.
Definition TString.h:137
Ssiz_t Length() const
Definition TString.h:426
void ToLower()
Change string to lower-case.
Definition TString.cxx:1190
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2325
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1122
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:704
const char * Data() const
Definition TString.h:385
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:714
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1160
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:633
TString & Prepend(const char *cs)
Definition TString.h:683
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1493
TString & Append(const char *cs)
Definition TString.h:582
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:2460
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2438
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:661
Int_t GetOptLogy() const
Definition TStyle.h:250
void SetPadBorderMode(Int_t mode=1)
Definition TStyle.h:361
void SetPadTopMargin(Float_t margin=0.1)
Definition TStyle.h:363
void SetOptLogx(Int_t logx=1)
Definition TStyle.h:333
void SetPadBottomMargin(Float_t margin=0.1)
Definition TStyle.h:362
Int_t GetOptTitle() const
Definition TStyle.h:248
Int_t GetPadTickX() const
Definition TStyle.h:219
Bool_t IsReading() const
Definition TStyle.h:300
Color_t GetPadColor() const
Definition TStyle.h:210
void SetPadRightMargin(Float_t margin=0.1)
Definition TStyle.h:365
void SetTitleFont(Style_t font=62, Option_t *axis="X")
Definition TStyle.cxx:1776
Float_t GetPadRightMargin() const
Definition TStyle.h:216
void SetTitleBorderSize(Width_t size=2)
Definition TStyle.h:412
Float_t GetDateX() const
Definition TStyle.h:199
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition TStyle.cxx:1217
void SetPadTickY(Int_t ticky)
Definition TStyle.h:369
Color_t GetTitleFillColor() const
Definition TStyle.h:273
void SetPadTickX(Int_t tickx)
Definition TStyle.h:368
Int_t GetOptDate() const
Definition TStyle.h:244
Bool_t GetPadGridY() const
Definition TStyle.h:218
void SetPadGridX(Bool_t gridx)
Definition TStyle.h:366
void SetTitleTextColor(Color_t color=1)
Definition TStyle.h:409
Float_t GetPadLeftMargin() const
Definition TStyle.h:215
Double_t GetHatchesSpacing() const
Definition TStyle.h:203
Bool_t GetPadGridX() const
Definition TStyle.h:217
void SetPadLeftMargin(Float_t margin=0.1)
Definition TStyle.h:364
void SetPadGridY(Bool_t gridy)
Definition TStyle.h:367
void SetOptLogy(Int_t logy=1)
Definition TStyle.h:334
Int_t GetOptFile() const
Definition TStyle.h:245
TAttText * GetAttDate()
Definition TStyle.h:170
Int_t GetPadTickY() const
Definition TStyle.h:220
Width_t GetPadBorderSize() const
Definition TStyle.h:211
Width_t GetTitleBorderSize() const
Definition TStyle.h:277
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition TStyle.cxx:1102
void SetTitleFillColor(Color_t color=1)
Definition TStyle.h:408
Float_t GetPadBottomMargin() const
Definition TStyle.h:213
void SetOptLogz(Int_t logz=1)
Definition TStyle.h:335
void SetPadColor(Color_t color=19)
Definition TStyle.h:359
Color_t GetTitleTextColor() const
Definition TStyle.h:274
Int_t GetOptLogx() const
Definition TStyle.h:249
Float_t GetDateY() const
Definition TStyle.h:200
Int_t GetPadBorderMode() const
Definition TStyle.h:212
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition TStyle.cxx:1176
Int_t GetOptLogz() const
Definition TStyle.h:251
void SetPadBorderSize(Width_t size=1)
Definition TStyle.h:360
Int_t GetHatchesLineWidth() const
Definition TStyle.h:202
Float_t GetPadTopMargin() const
Definition TStyle.h:214
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1296
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:656
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1318
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition TSystem.cxx:1372
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:440
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:419
Base class for several text objects.
Definition TText.h:22
void Paint(Option_t *option="") override
Paint this text with its current attributes.
Definition TText.cxx:662
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:796
See TView3D.
Definition TView.h:25
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
virtual Int_t GetDistancetoAxis(Int_t axis, Int_t px, Int_t py, Double_t &ratio)=0
virtual void ResizePad()=0
virtual void GetRange(Float_t *min, Float_t *max)=0
Provides 3D viewer interface (TVirtualViewer3D) support on a pad.
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition TVirtualPS.h:32
virtual void NewPage()=0
virtual void Open(const char *filename, Int_t type=-111)=0
virtual void DrawFrame(Double_t xl, Double_t yl, Double_t xt, Double_t yt, Int_t mode, Int_t border, Int_t dark, Int_t light)=0
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
virtual void SetAttFill(const TAttFill &att)
Set fill attributes.
virtual void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y)=0
virtual void DestroyDrawable(Int_t device)=0
virtual void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y)=0
virtual void SetAttLine(const TAttLine &att)
Set line attributes.
virtual void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v)=0
virtual void SelectDrawable(Int_t device)=0
virtual void InvalidateCS()
Empty definition.
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:58
void PadDeleted(TVirtualPad *pad)
Inform context that pad deleted or will be deleted soon Reference on that pad should be cleared.
Helper class to store interactive parameters for individual objects Should be used via MakeInteractiv...
Definition TVirtualPad.h:72
void SetObject(TObject *obj)
Definition TVirtualPad.h:78
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:53
virtual Int_t YtoAbsPixel(Double_t y) const =0
virtual Double_t GetX2() const =0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual Int_t XtoAbsPixel(Double_t x) const =0
virtual Double_t GetY1() const =0
virtual Int_t GetNumber() const =0
T * GetInteractive(TObject *obj)
void Streamer(TBuffer &) override
Stream an object of class TVirtualPad.
static TClass * Class()
T * MakeInteractive(TObject *obj, Rest &&... rest)
virtual void ShowGuidelines(TObject *object, const Int_t event, const char mode='i', const bool cling=true)=0
virtual void RangeAxisChanged()
virtual Double_t GetY2() const =0
virtual void GetRange(Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2)=0
Bool_t fResizing
!true when resizing the pad
Definition TVirtualPad.h:84
virtual Bool_t IsEditable() const =0
void FreeInteractive(TObject *obj)
Release interactive instance for specified object.
virtual Double_t GetX1() const =0
Abstract 3D shapes viewer.
virtual Bool_t BuildingScene() const =0
virtual void EndScene()=0
static TVirtualViewer3D * Viewer3D(TVirtualPad *pad=nullptr, Option_t *type="")
Create a Viewer 3D of specified type.
virtual void PadPaint(TVirtualPad *)
virtual void BeginScene()=0
virtual Bool_t CanLoopOnPrimitives() const
A TBox with a bordersize and a bordermode.
Definition TWbox.h:20
Short_t GetBorderSize() const
Definition TWbox.h:41
Short_t GetBorderMode() const
Definition TWbox.h:40
virtual void SetBorderMode(Short_t bordermode)
Definition TWbox.h:54
virtual void SetBorderSize(Short_t bordersize)
Definition TWbox.h:55
TPaveText * pt
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
Double_t ex[n]
Definition legend1.C:17
TH1F * h1
Definition legend1.C:5
leg
Definition legend1.C:34
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
Definition TObject.h:409
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.
Definition TROOT.h:406
Bool_t IsNaN(Double_t x)
Definition TMath.h:905
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:706
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition TMath.h:722
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:693
Double_t Ceil(Double_t x)
Rounds x upward, returning the smallest integral value that is not less than x.
Definition TMath.h:681
Int_t Finite(Double_t x)
Check if it is finite with a mask in order to be consistent in presence of fast math.
Definition TMath.h:783
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:769
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:675
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:734
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:607
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:601
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.
Definition TMath.h:775
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122
Rectangle structure (maps to the X11 XRectangle structure)
Definition GuiTypes.h:362
Short_t fX
Definition GuiTypes.h:363
UShort_t fHeight
Definition GuiTypes.h:364
Short_t fY
Definition GuiTypes.h:363
UShort_t fWidth
Definition GuiTypes.h:364
struct used by ShowGuidelines to store the distance Field between objects in the canvas.
Definition TPad.cxx:6246
TAttBBox2D * fb
Definition TPad.cxx:6248
dField()
Definition TPad.cxx:6253
char fdir
Definition TPad.cxx:6250
dField(TAttBBox2D *a, TAttBBox2D *b, Int_t dist, char direction)
Definition TPad.cxx:6257
TAttBBox2D * fa
Definition TPad.cxx:6247
Int_t fdist
Definition TPad.cxx:6249
TMarker m
Definition textangle.C:8