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)
2019 parent.FreeInteractive(this); // delete any interactive object
2020 switch (newcode) {
2021 case kPad:
2023 break;
2024 case kMarker:
2025 case kText:
2026 TCreatePrimitives::Text(event,px,py,newcode);
2027 break;
2028 case kLine:
2030 break;
2031 case kArrow:
2033 break;
2034 case kCurlyLine:
2036 break;
2037 case kCurlyArc:
2039 break;
2040 case kPolyLine:
2042 break;
2043 case kCutG:
2045 break;
2046 case kArc:
2048 break;
2049 case kEllipse:
2051 break;
2052 case kButton:
2053 case kPave:
2054 case kPaveLabel:
2055 case kPaveText:
2056 case kPavesText:
2057 case kDiamond:
2058 TCreatePrimitives::Pave(event,px,py,newcode);
2059 return;
2060 default:
2061 break;
2062 }
2063 if (newcode)
2064 return;
2065
2066 auto inter = parent.GetInteractive<TBoxInteractive>(this);
2067
2068 auto setNewValues = [&inter, &parent, this]() {
2069 // Get parent corners pixels coordinates
2070 Int_t parentpx1 = parent.XtoAbsPixel(parent.GetX1());
2071 Int_t parentpx2 = parent.XtoAbsPixel(parent.GetX2());
2072 Int_t parentpy1 = parent.YtoAbsPixel(parent.GetY1());
2073 Int_t parentpy2 = parent.YtoAbsPixel(parent.GetY2());
2074
2075 // Get pad new corners pixels coordinates
2076 Int_t apx1 = TMath::Max(inter->px1, parentpx1);
2077 Int_t apx2 = TMath::Min(inter->px2, parentpx2);
2078 Int_t apy1 = TMath::Min(inter->py1, parentpy1);
2079 Int_t apy2 = TMath::Max(inter->py2, parentpy2);
2080
2081 // Compute new pad positions in the NDC space of parent
2082 fXlowNDC = Double_t(apx1 - parentpx1)/Double_t(parentpx2 - parentpx1);
2083 fYlowNDC = Double_t(apy1 - parentpy1)/Double_t(parentpy2 - parentpy1);
2084 fWNDC = Double_t(apx2 - apx1)/Double_t(parentpx2 - parentpx1);
2085 fHNDC = Double_t(apy2 - apy1)/Double_t(parentpy2 - parentpy1);
2086 };
2087
2088
2089 switch (event) {
2090
2091 case kMouseEnter:
2092 if (fTip)
2094 break;
2095
2096 case kArrowKeyPress:
2097 case kButton1Down:
2101 // No break !!!
2102
2103 case kMouseMotion: {
2104 TBoxInteractive dummy(kFALSE);
2105 if (!inter) inter = &dummy;
2106 // use pad itself to calculate its pixel coordinates
2107 inter->CalcPixelCoord(*this, GetX1(), GetY1(), GetX2(), GetY2());
2108
2109 if (TestBit(kCannotMove) || !inter->SelectCorner(px, py)) {
2110 // refuse interactive changes
2111 parent.FreeInteractive(this);
2112 } else {
2113 inter->SetCursor(parent, event == kButton1Down);
2114 fResizing = inter->IsResizing() && (event != kMouseMotion);
2115 }
2116
2117 break;
2118 }
2119
2120 case kArrowKeyRelease:
2121 case kButton1Motion: {
2122 if (!inter)
2123 return;
2124
2125 Double_t ratio = HasFixedAspectRatio() ? fAspectRatio : 0.;
2126
2127 if (!inter->ProcessMouseMove(parent, px, py, kTRUE, kTRUE, ratio))
2128 return;
2129
2130 // paint if necessary
2131 inter->ApplyChanges(parent);
2132
2133 if (inter->IsOpaque(parent)) {
2134 setNewValues();
2135 ResizePad();
2136 parent.ShowGuidelines(this, event, inter->GetGuideChar(), true);
2137 Modified(kTRUE);
2138 }
2139
2140 break;
2141 }
2142
2143 case kButton1Up:
2144 if (inter && inter->IsOpaque(parent))
2145 parent.ShowGuidelines(this, event);
2146
2147 if (gROOT->IsEscaped()) {
2148 gROOT->SetEscape(kFALSE);
2149 if (inter && inter->IsOpaque(parent)) {
2150 fXlowNDC = inter->oldX1;
2151 fYlowNDC = inter->oldY1;
2152 fWNDC = inter->oldX2;
2153 fHNDC = inter->oldY2;
2154 ResizePad();
2155 Modified(kTRUE);
2156
2157 }
2158 } else if (inter && !inter->IsOpaque(parent) && (inter->newX1 != inter->newX2)) {
2159 setNewValues();
2160 ResizePad();
2161 Modified(kTRUE);
2162 }
2163
2164 RangeChanged();
2165
2166 fResizing = kFALSE;
2167 parent.FreeInteractive(this);
2168
2169 break;
2170
2171 case kButton1Locate:
2172
2173 ExecuteEvent(kButton1Down, px, py);
2174
2175 while (true) {
2176 px = py = 0;
2177 event = GetCanvasImp()->RequestLocator(px, py);
2178
2180
2181 if (event != -1) { // button is released
2182 ExecuteEvent(kButton1Up, px, py);
2183 return;
2184 }
2185 }
2186
2187 case kButton2Down:
2188
2189 Pop();
2190 break;
2191
2192 }
2193}
2194
2196 public:
2197
2200 Double_t px1old = 0, py1old = 0, px2old = 0, py2old = 0;
2201
2203 {
2204 Double_t zbx1 = pad.GetUxmin();
2205 Double_t zbx2 = pad.GetUxmax();
2206 Double_t zby1 = pad.GetUymin();
2207 Double_t zby2 = pad.GetUymax();
2208 if (axisNumber == 1) {
2209 zbx1 = px1old;
2210 zbx2 = px2old;
2211 } else {
2212 zby1 = py1old;
2213 zby2 = py2old;
2214 }
2215
2216 if (pad.OpaqueMoving()) {
2217 TAttLine{kBlack, 1, 1}.ModifyOn(pad);
2218 Double_t xx[4], yy[4];
2219
2220 if (axisNumber == 1) {
2221 xx[0] = xx[1] = zbx1;
2222 xx[2] = xx[3] = zbx2;
2223 yy[0] = yy[2] = zby1;
2224 yy[1] = yy[3] = zby2;
2225 } else {
2226 xx[0] = xx[2] = zbx1;
2227 xx[1] = xx[3] = zbx2;
2228 yy[0] = yy[1] = zby1;
2229 yy[2] = yy[3] = zby2;
2230 }
2231 pad.PaintPolyLine(2, xx, yy, "iaxiszoom1");
2232 pad.PaintPolyLine(2, xx+2, yy+2, "iaxiszoom2");
2233 } else {
2234 pad.PaintBox(zbx1, zby1, zbx2, zby2, "iaxiszoom");
2235 }
2236 pad.UpdateAsync();
2237 }
2238};
2239
2240
2241////////////////////////////////////////////////////////////////////////////////
2242/// Execute action corresponding to one event for a TAxis object
2243/// (called by TAxis::ExecuteEvent.)
2244/// This member function is called when an axis is clicked with the locator
2245///
2246/// The axis range is set between the position where the mouse is pressed
2247/// and the position where it is released.
2248///
2249/// If the mouse position is outside the current axis range when it is released
2250/// the axis is unzoomed with the corresponding proportions.
2251///
2252/// Note that the mouse does not need to be in the pad or even canvas
2253/// when it is released.
2254
2256{
2257 if (!IsEditable() || !axis)
2258 return;
2260
2261 TView *view = GetView();
2262
2263 // The CONT4 option, used to paint TH2, is a special case; it uses a 3D
2264 // drawing technique to paint a 2D plot.
2265 TString opt = axis->GetParent()->GetDrawOption();
2266 opt.ToLower();
2267 Bool_t kCont4 = kFALSE;
2268 if (strstr(opt,"cont4")) {
2269 view = nullptr;
2270 kCont4 = kTRUE;
2271 }
2272
2273 auto inter = dynamic_cast<TAxisInteractive *>(Interactive(axis));
2274
2275 switch (event) {
2276
2277 case kButton1Down:
2278 inter = new TAxisInteractive();
2279 Interactive(axis, inter);
2280
2281 inter->axisNumber = 1;
2282 if (!strcmp(axis->GetName(), "xaxis"))
2283 inter->axisNumber = IsVertical() ? 1 : 2;
2284 else if (!strcmp(axis->GetName(), "yaxis"))
2285 inter->axisNumber = IsVertical() ? 2 : 1;
2286 else if (!strcmp(axis->GetName(), "zaxis"))
2287 inter->axisNumber = 3;
2288 if (view) {
2289 view->GetDistancetoAxis(inter->axisNumber, px, py, inter->ratio1);
2290 } else if (inter->axisNumber == 1) {
2291 inter->ratio1 = (AbsPixeltoX(px) - GetUxmin()) / (GetUxmax() - GetUxmin());
2292 inter->px1old = GetUxmin() + inter->ratio1 * (GetUxmax() - GetUxmin());
2293 inter->py1old = GetUymin();
2294 inter->px2old = inter->px1old;
2295 inter->py2old = GetUymax();
2296 } else {
2297 inter->ratio1 = (AbsPixeltoY(py) - GetUymin()) / (GetUymax() - GetUymin());
2298 inter->px1old = GetUxmin();
2299 inter->py1old = GetUymin() + inter->ratio1 * (GetUymax() - GetUymin());
2300 inter->px2old = GetUxmax();
2301 inter->py2old = inter->py1old;
2302 }
2303 // No break !!!
2304
2305 case kButton1Motion:
2306 if (!inter)
2307 break;
2308 if (view) {
2309 view->GetDistancetoAxis(inter->axisNumber, px, py, inter->ratio2);
2310 } else if (inter->axisNumber == 1) {
2311 inter->ratio2 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
2312 inter->px2old = GetUxmin() + inter->ratio2 * (GetUxmax() - GetUxmin());
2313 } else {
2314 inter->ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
2315 inter->py2old = GetUymin() + inter->ratio2 * (GetUymax() - GetUymin());
2316 }
2317 inter->PaintZoomBox(*this);
2318 break;
2319
2320 case kWheelUp: {
2321 Int_t nbd = (axis->GetLast()-axis->GetFirst());
2322 Int_t inc = TMath::Max(nbd/100,1);
2323 Int_t bin1 = TMath::Max(1, axis->GetFirst() + inc);
2324 Int_t bin2 = TMath::Min(axis->GetNbins(), axis->GetLast() - inc);
2325 if (bin2 > bin1) {
2326 axis->SetRange(bin1, bin2);
2327 Modified();
2328 UpdateAsync();
2329 }
2330 break;
2331 }
2332
2333 case kWheelDown: {
2334 Int_t nbd = (axis->GetLast()-axis->GetFirst());
2335 Int_t inc = TMath::Max(nbd/100,1);
2336 Int_t bin1 = TMath::Max(1, axis->GetFirst()-inc);
2337 Int_t bin2 = TMath::Min(axis->GetNbins(), axis->GetLast()+inc);
2338 Bool_t resetAxisRange = (bin1 == 1 && axis->GetFirst() == 1 && bin2 == axis->GetNbins() && axis->GetLast() == axis->GetNbins());
2339 if (bin2 > bin1)
2340 axis->SetRange(bin1,bin2);
2341 if (resetAxisRange)
2343 if (bin2 > bin1) {
2344 Modified();
2345 UpdateAsync();
2346 }
2347 break;
2348 }
2349
2350 case kButton1Up:
2351 if (gROOT->IsEscaped()) {
2352 gROOT->SetEscape(kFALSE);
2353 break;
2354 }
2355
2356 if (view && inter) {
2357 view->GetDistancetoAxis(inter->axisNumber, px, py, inter->ratio2);
2358 if (inter->ratio1 > inter->ratio2)
2359 std::swap(inter->ratio1, inter->ratio2);
2360 if (inter->ratio2 - inter->ratio1 > 0.05) {
2361 auto hobj = static_cast<TH1 *>(axis->GetParent());
2362 if (inter->axisNumber == 3 && hobj && hobj->GetDimension() != 3) {
2363 Float_t zmin = hobj->GetMinimum();
2364 Float_t zmax = hobj->GetMaximum();
2365 if (GetLogz()) {
2366 if (zmin <= 0 && zmax > 0)
2367 zmin = TMath::Min((Double_t)1, (Double_t)0.001 * zmax);
2368 zmin = TMath::Log10(zmin);
2369 zmax = TMath::Log10(zmax);
2370 }
2371 Float_t newmin = zmin + (zmax - zmin) * inter->ratio1;
2372 Float_t newmax = zmin + (zmax - zmin) * inter->ratio2;
2373 if (newmin < zmin)
2374 newmin = hobj->GetBinContent(hobj->GetMinimumBin());
2375 if (newmax > zmax)
2376 newmax = hobj->GetBinContent(hobj->GetMaximumBin());
2377 if (GetLogz()){
2378 newmin = TMath::Exp(2.302585092994*newmin);
2379 newmax = TMath::Exp(2.302585092994*newmax);
2380 }
2381 hobj->SetMinimum(newmin);
2382 hobj->SetMaximum(newmax);
2383 hobj->SetBit(TH1::kIsZoomed);
2384 } else {
2385 Int_t first = axis->GetFirst();
2386 Int_t last = axis->GetLast();
2387 Int_t bin1 = TMath::Max(1, first + Int_t((last-first+1) * inter->ratio1));
2388 Int_t bin2 = TMath::Min(axis->GetNbins(), first + Int_t((last-first+1) * inter->ratio2));
2389 axis->SetRange(bin1, bin2);
2390 }
2391 delete view;
2392 SetView(nullptr);
2393 Modified();
2394 }
2395 } else if (inter) {
2397 if (inter->axisNumber == 1) {
2398 inter->ratio2 = (AbsPixeltoX(px) - GetUxmin()) / (GetUxmax() - GetUxmin());
2399 xmin = GetUxmin() + inter->ratio1 * (GetUxmax() - GetUxmin());
2400 xmax = GetUxmin() + inter->ratio2 * (GetUxmax() - GetUxmin());
2401 if (GetLogx() && !kCont4) {
2402 xmin = PadtoX(xmin);
2403 xmax = PadtoX(xmax);
2404 }
2405 } else if (inter->axisNumber == 2) {
2406 inter->ratio2 = (AbsPixeltoY(py) - GetUymin()) / (GetUymax() - GetUymin());
2407 xmin = GetUymin() + inter->ratio1 * (GetUymax() - GetUymin());
2408 xmax = GetUymin() + inter->ratio2 * (GetUymax() - GetUymin());
2409 if (GetLogy() && !kCont4) {
2410 xmin = PadtoY(xmin);
2411 xmax = PadtoY(xmax);
2412 }
2413 } else {
2414 inter->ratio2 = (AbsPixeltoY(py) - GetUymin()) / (GetUymax() - GetUymin());
2415 xmin = inter->ratio1;
2416 xmax = inter->ratio2;
2417 }
2418 if (xmin > xmax) {
2419 std::swap(xmin, xmax);
2420 std::swap(inter->ratio1, inter->ratio2);
2421 }
2422
2423 // xmin and xmax need to be adjusted in case of CONT4.
2424 if (kCont4) {
2425 Double_t low = axis->GetBinLowEdge(axis->GetFirst());
2426 Double_t up = axis->GetBinUpEdge(axis->GetLast());
2427 Double_t xmi = GetUxmin();
2428 Double_t xma = GetUxmax();
2429 xmin = ((xmin - xmi) / (xma - xmi)) * (up - low) + low;
2430 xmax = ((xmax - xmi) / (xma - xmi)) * (up - low) + low;
2431 }
2432
2433 if (!strcmp(axis->GetName(),"xaxis"))
2434 inter->axisNumber = 1;
2435 if (!strcmp(axis->GetName(),"yaxis"))
2436 inter->axisNumber = 2;
2437 if (inter->ratio2 - inter->ratio1 > 0.05) {
2438 //update object owning this axis
2439 TH1 *hobj1 = static_cast<TH1 *>(axis->GetParent());
2440 Int_t bin1 = TMath::Max(1, axis->FindFixBin(xmin));
2441 Int_t bin2 = TMath::Min(axis->GetNbins(), axis->FindFixBin(xmax));
2442 if (inter->axisNumber == 1)
2443 axis->SetRange(bin1,bin2);
2444 if (inter->axisNumber == 2 && hobj1) {
2445 if (hobj1->GetDimension() == 1) {
2446 if (hobj1->GetNormFactor() != 0) {
2447 Double_t norm = hobj1->GetSumOfWeights()/hobj1->GetNormFactor();
2448 xmin *= norm;
2449 xmax *= norm;
2450 }
2451 hobj1->SetMinimum(xmin);
2452 hobj1->SetMaximum(xmax);
2453 hobj1->SetBit(TH1::kIsZoomed);
2454 } else {
2455 axis->SetRange(bin1,bin2);
2456 }
2457 }
2458 //update all histograms in the pad
2459 TIter next(GetListOfPrimitives());
2460 while (auto obj = next()) {
2461 if (auto hobj = dynamic_cast<TH1 *> (obj)) {
2462 if (hobj == hobj1)
2463 continue;
2464 bin1 = hobj->GetXaxis()->FindFixBin(xmin);
2465 bin2 = hobj->GetXaxis()->FindFixBin(xmax);
2466 if (inter->axisNumber == 1) {
2467 hobj->GetXaxis()->SetRange(bin1,bin2);
2468 } else if (inter->axisNumber == 2) {
2469 if (hobj->GetDimension() == 1) {
2470 Double_t xxmin = xmin;
2471 Double_t xxmax = xmax;
2472 if (hobj->GetNormFactor() != 0) {
2473 Double_t norm = hobj->GetSumOfWeights()/hobj->GetNormFactor();
2474 xxmin *= norm;
2475 xxmax *= norm;
2476 }
2477 hobj->SetMinimum(xxmin);
2478 hobj->SetMaximum(xxmax);
2479 hobj->SetBit(TH1::kIsZoomed);
2480 } else {
2481 bin1 = hobj->GetYaxis()->FindFixBin(xmin);
2482 bin2 = hobj->GetYaxis()->FindFixBin(xmax);
2483 hobj->GetYaxis()->SetRange(bin1,bin2);
2484 }
2485 }
2486 }
2487 }
2488 Modified();
2489 }
2490 }
2491 Interactive(); // remove interactive object
2492 break;
2493 }
2494}
2495
2496////////////////////////////////////////////////////////////////////////////////
2497/// Switch feedback mode for the canvas
2498/// Only for internal use when implementing special painters
2499
2501{
2502 if (fCanvas)
2503 fCanvas->FeedbackMode(set);
2504}
2505
2506////////////////////////////////////////////////////////////////////////////////
2507/// Search if object named name is inside this pad or in pads inside this pad.
2508///
2509/// In case name is in several sub-pads the first one is returned.
2510
2511TObject *TPad::FindObject(const char *name) const
2512{
2513 if (!fPrimitives) return nullptr;
2515 if (found) return found;
2516 TIter next(GetListOfPrimitives());
2517 while (auto cur = next()) {
2518 if (cur->InheritsFrom(TPad::Class())) {
2519 found = ((TPad*)cur)->FindObject(name);
2520 if (found) return found;
2521 }
2522 }
2523 return nullptr;
2524}
2525
2526////////////////////////////////////////////////////////////////////////////////
2527/// Search if obj is in pad or in pads inside this pad.
2528///
2529/// In case obj is in several sub-pads the first one is returned.
2530
2532{
2533 if (!fPrimitives) return nullptr;
2534 TObject *found = fPrimitives->FindObject(obj);
2535 if (found) return found;
2536 TIter next(GetListOfPrimitives());
2537 while (auto cur = next()) {
2538 if (cur->InheritsFrom(TPad::Class())) {
2539 found = ((TPad*)cur)->FindObject(obj);
2540 if (found) return found;
2541 }
2542 }
2543 return nullptr;
2544}
2545
2546////////////////////////////////////////////////////////////////////////////////
2547/// Get canvas identifier.
2548
2550{
2551 return fCanvas ? fCanvas->GetCanvasID() : -1;
2552}
2553
2554////////////////////////////////////////////////////////////////////////////////
2555/// Get canvas implementation pointer if any
2556
2558{
2559 return fCanvas ? fCanvas->GetCanvasImp() : nullptr;
2560}
2561
2562////////////////////////////////////////////////////////////////////////////////
2563/// Get Event.
2564
2566{
2567 return fCanvas ? fCanvas->GetEvent() : 0;
2568}
2569
2570////////////////////////////////////////////////////////////////////////////////
2571/// Get X event.
2572
2574{
2575 return fCanvas ? fCanvas->GetEventX() : 0;
2576}
2577
2578////////////////////////////////////////////////////////////////////////////////
2579/// Get Y event.
2580
2582{
2583 return fCanvas ? fCanvas->GetEventY() : 0;
2584}
2585
2586////////////////////////////////////////////////////////////////////////////////
2587/// Get virtual canvas.
2588
2590{
2591 return fCanvas ? (TVirtualPad*) fCanvas : nullptr;
2592}
2593
2594////////////////////////////////////////////////////////////////////////////////
2595/// Get doublebuffer mode - 1 by default.
2596
2598{
2599 return fCanvas ? fCanvas->GetDoubleBuffer() : 1;
2600}
2601
2602////////////////////////////////////////////////////////////////////////////////
2603/// Get highlight color.
2604
2606{
2607 return fCanvas ? fCanvas->GetHighLightColor() : 0;
2608}
2609
2610////////////////////////////////////////////////////////////////////////////////
2611/// Static function (see also TPad::SetMaxPickDistance)
2612
2617
2618////////////////////////////////////////////////////////////////////////////////
2619/// Get selected.
2620
2622{
2623 if (fCanvas == this) return nullptr;
2624 return fCanvas ? fCanvas->GetSelected() : nullptr;
2625}
2626
2627////////////////////////////////////////////////////////////////////////////////
2628/// Get selected pad.
2629
2631{
2632 if (fCanvas == this) return nullptr;
2633 return fCanvas ? fCanvas->GetSelectedPad() : nullptr;
2634}
2635
2636////////////////////////////////////////////////////////////////////////////////
2637/// Get save pad.
2638
2640{
2641 if (fCanvas == this) return nullptr;
2642 return fCanvas ? fCanvas->GetPadSave() : nullptr;
2643}
2644
2645////////////////////////////////////////////////////////////////////////////////
2646/// Get canvas height
2647
2649{
2650 return fCanvas ? fCanvas->GetWh() : 0;
2651}
2652
2653////////////////////////////////////////////////////////////////////////////////
2654/// Get canvas width
2655
2657{
2658 return fCanvas ? fCanvas->GetWw() : 0;
2659}
2660
2661////////////////////////////////////////////////////////////////////////////////
2662/// Get pad width
2663
2665{
2666 // Very often pad width was calculated as XtoPixel(GetX2());
2667 // But if coordinate system broken such transformation fail.
2668 // Therefore use canvas width multiplied by absolute NDC width value
2669 // Keep fallback solution only when canvas width cannot be defined
2670
2671 auto cw = GetWw();
2672 if (!cw)
2673 return XtoPixel(GetX2());
2674
2675 return static_cast<UInt_t>(std::lround(cw * GetAbsWNDC()));
2676}
2677
2678////////////////////////////////////////////////////////////////////////////////
2679/// Get pad height
2680
2682{
2683 // Very often pad height was calculated as YtoPixel(GetY1())
2684 // But if coordinate system broken such transformation fail.
2685 // Therefore use canvas height multiplied by absolute NDC height value
2686 // Keep fallback solution only when canvas height cannot be defined
2687
2688 auto ch = GetWh();
2689 if (!ch)
2690 return YtoPixel(GetY1());
2691
2692 return static_cast<UInt_t>(std::lround(GetWh() * GetAbsHNDC()));
2693}
2694
2695////////////////////////////////////////////////////////////////////////////////
2696/// Hide tool tip depending on the event type. Typically tool tips
2697/// are hidden when event is not a kMouseEnter and not a kMouseMotion
2698/// event.
2699
2701{
2702 if (event != kMouseEnter && event != kMouseMotion && fTip)
2703 gPad->CloseToolTip(fTip);
2704}
2705
2706////////////////////////////////////////////////////////////////////////////////
2707/// Check if pad or any subpads need to be repaint
2708/// Returns flag with following mask:
2709/// 1 - some pad is modified
2710/// 2 - some pad is transparent (also trigger repaint in modified)
2711/// 4 - some pad has interactive XOR draw operations
2712
2714{
2715 Int_t mask = IsModified() ? 1 : 0;
2716 if (IsTransparent())
2717 mask |= 2;
2718 if (fDrawOper.size())
2719 mask |= 4;
2720
2721 TIter next(GetListOfPrimitives());
2722 while (auto obj = next())
2723 if (auto p = dynamic_cast<TPad *>(obj))
2724 mask |= p->IsAnyNeedRepaint();
2725
2726 return mask;
2727}
2728
2729////////////////////////////////////////////////////////////////////////////////
2730/// Is pad in batch mode ?
2731
2733{
2734 return fCanvas ? fCanvas->IsBatch() : kFALSE;
2735}
2736
2737////////////////////////////////////////////////////////////////////////////////
2738/// Is pad retained ?
2739
2741{
2742 return fCanvas ? fCanvas->IsRetained() : kFALSE;
2743}
2744
2745////////////////////////////////////////////////////////////////////////////////
2746/// Is web ?
2748{
2749 return fCanvas ? fCanvas->IsWeb() : kFALSE;
2750}
2751
2752////////////////////////////////////////////////////////////////////////////////
2753/// Is pad moving in opaque mode ?
2754
2756{
2757 return fCanvas ? fCanvas->OpaqueMoving() : kFALSE;
2758}
2759
2760////////////////////////////////////////////////////////////////////////////////
2761/// Is pad resizing in opaque mode ?
2762
2764{
2765 return fCanvas ? fCanvas->OpaqueResizing() : kFALSE;
2766}
2767
2768////////////////////////////////////////////////////////////////////////////////
2769/// Set pad in batch mode.
2770
2772{
2773 if (fCanvas) fCanvas->SetBatch(batch);
2774}
2775
2776////////////////////////////////////////////////////////////////////////////////
2777/// Set canvas size.
2778
2780{
2781 if (fCanvas) fCanvas->SetCanvasSize(ww,wh);
2782}
2783
2784////////////////////////////////////////////////////////////////////////////////
2785/// Set cursor type.
2786
2791
2792////////////////////////////////////////////////////////////////////////////////
2793/// Set double buffer mode ON or OFF.
2794
2799
2800////////////////////////////////////////////////////////////////////////////////
2801/// Set selected.
2802
2804{
2805 if (fCanvas) fCanvas->SetSelected(obj);
2806}
2807
2808////////////////////////////////////////////////////////////////////////////////
2809/// Update pad.
2810
2812{
2813 if (fCanvas) fCanvas->Update();
2814}
2815
2816////////////////////////////////////////////////////////////////////////////////
2817/// Asynchronous pad update.
2818/// In case of web-based canvas triggers update of the canvas on the client side,
2819/// but does not wait that real update is completed. Avoids blocking of caller thread.
2820/// Have to be used if called from other web-based widget to avoid logical dead-locks.
2821/// In case of normal canvas just canvas->Update() is performed.
2822
2824{
2825 if (fCanvas) fCanvas->UpdateAsync();
2826}
2827
2828////////////////////////////////////////////////////////////////////////////////
2829/// Get frame.
2830
2832{
2833 if (!fPrimitives) fPrimitives = new TList;
2835 if (!frame) frame = (TFrame*)GetListOfPrimitives()->FindObject("TFrame");
2836 fFrame = frame;
2837 if (!fFrame) {
2838 if (!frame) fFrame = new TFrame(0,0,1,1);
2839 Int_t framecolor = GetFrameFillColor();
2840 if (!framecolor) framecolor = GetFillColor();
2841 fFrame->SetFillColor(framecolor);
2848 } else {
2849 // Preexisting and now assigned to fFrame, let's make sure it is not
2850 // deleted twice (the bit might have been set in TPad::Streamer)
2852 }
2853 return fFrame;
2854}
2855
2856////////////////////////////////////////////////////////////////////////////////
2857/// Get primitive.
2858
2860{
2861 if (!fPrimitives) return nullptr;
2862 TIter next(fPrimitives);
2863 TObject *found, *obj;
2864 while ((obj=next())) {
2865 if (!strcmp(name, obj->GetName())) return obj;
2866 if (obj->InheritsFrom(TPad::Class())) continue;
2867 found = obj->FindObject(name);
2868 if (found) return found;
2869 }
2870 return nullptr;
2871}
2872
2873////////////////////////////////////////////////////////////////////////////////
2874/// Get a pointer to subpadnumber of this pad.
2875
2876TVirtualPad *TPad::GetPad(Int_t subpadnumber) const
2877{
2878 if (!subpadnumber) {
2879 return (TVirtualPad*)this;
2880 }
2881
2882 TObject *obj;
2883 if (!fPrimitives) return nullptr;
2884 TIter next(GetListOfPrimitives());
2885 while ((obj = next())) {
2886 if (obj->InheritsFrom(TVirtualPad::Class())) {
2887 TVirtualPad *pad = (TVirtualPad*)obj;
2888 if (pad->GetNumber() == subpadnumber) return pad;
2889 }
2890 }
2891 return nullptr;
2892}
2893
2894////////////////////////////////////////////////////////////////////////////////
2895/// Return lower and upper bounds of the pad in NDC coordinates.
2896
2897void TPad::GetPadPar(Double_t &xlow, Double_t &ylow, Double_t &xup, Double_t &yup)
2898{
2899 xlow = fXlowNDC;
2900 ylow = fYlowNDC;
2901 xup = fXlowNDC+fWNDC;
2902 yup = fYlowNDC+fHNDC;
2903}
2904
2905////////////////////////////////////////////////////////////////////////////////
2906/// Return pad world coordinates range.
2907
2909{
2910 x1 = fX1;
2911 y1 = fY1;
2912 x2 = fX2;
2913 y2 = fY2;
2914}
2915
2916////////////////////////////////////////////////////////////////////////////////
2917/// Return pad axis coordinates range.
2918
2920{
2921 xmin = fUxmin;
2922 ymin = fUymin;
2923 xmax = fUxmax;
2924 ymax = fUymax;
2925}
2926
2927////////////////////////////////////////////////////////////////////////////////
2928/// Highlight pad.
2929/// do not highlight when printing on Postscript
2930
2932{
2933 if (auto pp = GetPainter())
2934 if(!pp->IsNative())
2935 return;
2936
2937 if (color <= 0)
2938 return;
2939
2941
2942 // We do not want to have active(executable) buttons, etc highlighted
2943 // in this manner, unless we want to edit'em
2945 //When doing a DrawClone from the GUI you would do
2946 // - select an empty pad -
2947 // - right click on object -
2948 // - select DrawClone on menu -
2949 //
2950 // Without the SetSelectedPad(); in the HighLight function, the
2951 // above instruction lead to the clone to be drawn in the
2952 // same canvas as the original object. This is because the
2953 // 'right clicking' (via TCanvas::HandleInput) changes gPad
2954 // momentarily such that when DrawClone is called, it is
2955 // not the right value (for DrawClone). Should be FIXED.
2956 gROOT->SetSelectedPad(this);
2957 if (GetBorderMode() > 0)
2958 PaintBorder(set ? -color : -GetFillColor(), kFALSE);
2959 }
2960
2962}
2963
2964////////////////////////////////////////////////////////////////////////////////
2965/// List all primitives in pad.
2966
2968{
2970 std::cout <<IsA()->GetName()<<" fXlowNDC=" <<fXlowNDC<<" fYlowNDC="<<fYlowNDC<<" fWNDC="<<GetWNDC()<<" fHNDC="<<GetHNDC()
2971 <<" Name= "<<GetName()<<" Title= "<<GetTitle()<<" Option="<<option<<std::endl;
2973 if (!fPrimitives) return;
2976}
2977
2978////////////////////////////////////////////////////////////////////////////////
2979/// Internal method to create, provide or delete TInteractive instance
2980/// It is allowed the only instance of TInteractive object per pad
2981/// It can be assigned for the object when @param init is provided
2982/// Otherwise returns existing instance for the @param obj
2983/// If none of parameters are specified - existing instance will be deleted
2984
2986{
2987 if (obj && init) {
2988 init->SetObject(obj);
2989 fInteractive.reset(init);
2990 } else if (!obj)
2991 fInteractive.reset(nullptr);
2992
2993 if (!fInteractive || (fInteractive->GetObject() != obj))
2994 return nullptr;
2995
2996 return fInteractive.get();
2997}
2998
2999
3000////////////////////////////////////////////////////////////////////////////////
3001/// Increment (i==1) or set (i>1) the number of autocolor in the pad.
3002
3004{
3005 TString opt1 = opt;
3006 opt1.ToLower();
3007
3008 if (opt1.Contains("pfc") || opt1.Contains("plc") || opt1.Contains("pmc")) {
3009 if (i == 1) fNumPaletteColor++;
3010 else fNumPaletteColor = i;
3011 return fNumPaletteColor;
3012 }
3013
3014 return 0;
3015}
3016
3017////////////////////////////////////////////////////////////////////////////////
3018/// Get the next autocolor in the pad.
3019
3021{
3022 Int_t i = 0;
3023 Int_t ncolors = gStyle->GetNumberOfColors();
3024 if (fNumPaletteColor>1) {
3025 i = fNextPaletteColor*(ncolors/(fNumPaletteColor-1));
3026 if (i>=ncolors) i = ncolors-1;
3027 }
3030 return gStyle->GetColorPalette(i);
3031}
3032
3033////////////////////////////////////////////////////////////////////////////////
3034/// Initialise the grid used to find empty space when adding a box (Legend) in a pad
3035
3037{
3038 Int_t const cellSize = 10; // Size of an individual grid cell in pixels.
3039
3040 fCGnx = GetWw()/cellSize;
3041 fCGny = GetWh()/cellSize;
3042
3043 // Initialise the collide grid
3044 fCollideGrid.resize(fCGnx*fCGny);
3045 for (int i = 0; i < fCGnx; i++)
3046 for (int j = 0; j < fCGny; j++)
3047 fCollideGrid[i + j * fCGnx] = kTRUE;
3048
3049 // Fill the collide grid
3050 TIter iter(GetListOfPrimitives());
3051
3052 while(auto o = iter()) {
3053 if (o == oi)
3054 continue;
3055 if (o->InheritsFrom(TFrame::Class()))
3057 else if (o->InheritsFrom(TBox::Class()))
3059 else if (o->InheritsFrom(TH1::Class()))
3061 else if (o->InheritsFrom(TGraph::Class()))
3063 else if (o->InheritsFrom(TMultiGraph::Class())) {
3064 TIter nextgraph(((TMultiGraph *)o)->GetListOfGraphs());
3065 while (auto og = nextgraph())
3067 } else if (o->InheritsFrom(THStack::Class())) {
3068 TIter nexthist(((THStack *)o)->GetHists());
3069 while (auto oh = nexthist()) {
3070 if (oh->InheritsFrom(TH1::Class()))
3072 }
3073 }
3074 }
3075}
3076
3077////////////////////////////////////////////////////////////////////////////////
3078/// Check if a box of size w and h collide some primitives in the pad at
3079/// position i,j
3080
3082{
3083 for (int r = i; r < w + i; r++) {
3084 for (int c = j; c < h + j; c++) {
3085 if (!fCollideGrid[r + c * fCGnx])
3086 return kTRUE;
3087 }
3088 }
3089 return kFALSE;
3090}
3091
3092////////////////////////////////////////////////////////////////////////////////
3093/// Place a box in NDC space
3094///
3095/// \return `true` if the box could be placed, `false` if not.
3096///
3097/// \param[in] o pointer to the box to be placed
3098/// \param[in] w box width to be placed
3099/// \param[in] h box height to be placed
3100/// \param[out] xl x position of the bottom left corner of the placed box
3101/// \param[out] yb y position of the bottom left corner of the placed box
3102/// \param[in] option l=left, r=right, t=top, b=bottom, w=within margins. Order determines
3103/// priority for placement. Default is "lb" (prioritises horizontal over vertical)
3104
3106{
3107 FillCollideGrid(o);
3108
3109 Int_t iw = (int)(fCGnx*w);
3110 Int_t ih = (int)(fCGny*h);
3111
3112 Int_t nxbeg = 0;
3113 Int_t nybeg = 0;
3114 Int_t nxend = fCGnx-iw-1;
3115 Int_t nyend = fCGny-ih-1;
3116 Int_t dx = 1;
3117 Int_t dy = 1;
3118
3119 bool isFirstVertical = false;
3120 bool isFirstHorizontal = false;
3121
3122 for (std::size_t i = 0; option[i] != '\0'; ++i) {
3123 char letter = std::tolower(option[i]);
3124 if (letter == 'w') {
3125 nxbeg += fCGnx*GetLeftMargin();
3126 nybeg += fCGny*GetBottomMargin();
3127 nxend -= fCGnx*GetRightMargin();
3128 nyend -= fCGny*GetTopMargin();
3129 } else if (letter == 't' || letter == 'b') {
3130 isFirstVertical = !isFirstHorizontal;
3131 // go from top to bottom instead of bottom to top
3132 dy = letter == 't' ? -1 : 1;
3133 } else if (letter == 'l' || letter == 'r') {
3134 isFirstHorizontal = !isFirstVertical;
3135 // go from right to left instead of left to right
3136 dx = letter == 'r' ? -1 : 1;
3137 }
3138 }
3139
3140 if(dx < 0) std::swap(nxbeg, nxend);
3141 if(dy < 0) std::swap(nybeg, nyend);
3142
3143 auto attemptPlacement = [&](Int_t i, Int_t j) {
3144 if (Collide(i, j, iw, ih)) {
3145 return false;
3146 } else {
3147 xl = (Double_t)(i) / (Double_t)(fCGnx);
3148 yb = (Double_t)(j) / (Double_t)(fCGny);
3149 return true;
3150 }
3151 };
3152
3153 if(!isFirstVertical) {
3154 for (Int_t i = nxbeg; i != nxend; i += dx) {
3155 for (Int_t j = nybeg; j != nyend; j += dy) {
3156 if (attemptPlacement(i, j)) return true;
3157 }
3158 }
3159 } else {
3160 // prioritizing vertical over horizontal
3161 for (Int_t j = nybeg; j != nyend; j += dy) {
3162 for (Int_t i = nxbeg; i != nxend; i += dx) {
3163 if (attemptPlacement(i, j)) return true;
3164 }
3165 }
3166 }
3167
3168 return kFALSE;
3169}
3170
3171// Set the specific cell element in the grid to false, clamp to (fCGnx*fCGny) - 1 to avoid going out of bounds
3172#define NotFree(i, j) fCollideGrid[TMath::Max(TMath::Min(i + j * fCGnx, (fCGnx * fCGny) - 1), 0)] = kFALSE;
3173
3174////////////////////////////////////////////////////////////////////////////////
3175/// Mark as "not free" the cells along a line.
3176
3178{
3179 NotFree(x1, y1);
3180 NotFree(x2, y2);
3181 Int_t i, j, xt, yt;
3182
3183 // horizontal lines
3184 if (y1==y2) {
3185 for (i=x1+1; i<x2; i++) NotFree(i,y1);
3186 return;
3187 }
3188
3189 // vertical lines
3190 if (x1==x2) {
3191 for (i=y1+1; i<y2; i++) NotFree(x1,i);
3192 return;
3193 }
3194
3195 // other lines
3196 if (TMath::Abs(x2-x1)>TMath::Abs(y2-y1)) {
3197 if (x1>x2) {
3198 xt = x1; x1 = x2; x2 = xt;
3199 yt = y1; y1 = y2; y2 = yt;
3200 }
3201 for (i=x1+1; i<x2; i++) {
3202 j = (Int_t)((Double_t)(y2-y1)*(Double_t)((i-x1)/(Double_t)(x2-x1))+y1);
3203 NotFree(i,j);
3204 NotFree(i,(j+1));
3205 }
3206 } else {
3207 if (y1>y2) {
3208 yt = y1; y1 = y2; y2 = yt;
3209 xt = x1; x1 = x2; x2 = xt;
3210 }
3211 for (j=y1+1; j<y2; j++) {
3212 i = (Int_t)((Double_t)(x2-x1)*(Double_t)((j-y1)/(Double_t)(y2-y1))+x1);
3213 NotFree(i,j);
3214 NotFree((i+1),j);
3215 }
3216 }
3217}
3218
3219////////////////////////////////////////////////////////////////////////////////
3221{
3222 TBox *b = (TBox *)o;
3223 if (fCGnx==0||fCGny==0) return;
3224 Double_t xs = (fX2-fX1)/fCGnx;
3225 Double_t ys = (fY2-fY1)/fCGny;
3226
3227 Int_t x1 = (Int_t)((b->GetX1()-fX1)/xs);
3228 Int_t x2 = (Int_t)((b->GetX2()-fX1)/xs);
3229 Int_t y1 = (Int_t)((b->GetY1()-fY1)/ys);
3230 Int_t y2 = (Int_t)((b->GetY2()-fY1)/ys);
3231 for (int i = x1; i<=x2; i++) {
3232 for (int j = y1; j<=y2; j++) NotFree(i, j);
3233 }
3234}
3235
3236////////////////////////////////////////////////////////////////////////////////
3238{
3239 TFrame *f = (TFrame *)o;
3240 if (fCGnx==0||fCGny==0) return;
3241 Double_t xs = (fX2-fX1)/fCGnx;
3242 Double_t ys = (fY2-fY1)/fCGny;
3243
3244 Int_t x1 = (Int_t)((f->GetX1()-fX1)/xs);
3245 Int_t x2 = (Int_t)((f->GetX2()-fX1)/xs);
3246 Int_t y1 = (Int_t)((f->GetY1()-fY1)/ys);
3247 Int_t y2 = (Int_t)((f->GetY2()-fY1)/ys);
3248 Int_t i;
3249
3250 for (i = x1; i<=x2; i++) {
3251 NotFree(i, y1);
3252 NotFree(i, (y1-1));
3253 NotFree(i, (y1-2));
3254 }
3255 for (i = y1; i<=y2; i++) {
3256 NotFree(x1, i);
3257 NotFree((x1-1), i);
3258 NotFree((x1-2), i);
3259 }
3260}
3261
3262////////////////////////////////////////////////////////////////////////////////
3264{
3265 TGraph *g = (TGraph *)o;
3266 if (fCGnx==0||fCGny==0) return;
3267 Double_t xs = (fX2-fX1)/fCGnx;
3268 Double_t ys = (fY2-fY1)/fCGny;
3269
3270 Int_t n = g->GetN();
3271 Int_t s = TMath::Max(n/10,1);
3272 Double_t x1, x2, y1, y2;
3273 for (Int_t i=s; i<n; i=i+s) {
3274 g->GetPoint(TMath::Max(0,i-s),x1,y1);
3275 g->GetPoint(i ,x2,y2);
3276 if (fLogx) {
3277 if (x1 > 0) x1 = TMath::Log10(x1);
3278 else x1 = fUxmin;
3279 if (x2 > 0) x2 = TMath::Log10(x2);
3280 else x2 = fUxmin;
3281 }
3282 if (fLogy) {
3283 if (y1 > 0) y1 = TMath::Log10(y1);
3284 else y1 = fUymin;
3285 if (y2 > 0) y2 = TMath::Log10(y2);
3286 else y2 = fUymin;
3287 }
3288 LineNotFree((int)((x1-fX1)/xs), (int)((x2-fX1)/xs),
3289 (int)((y1-fY1)/ys), (int)((y2-fY1)/ys));
3290 }
3291}
3292
3293////////////////////////////////////////////////////////////////////////////////
3295{
3296 TH1 *h = (TH1 *)o;
3297 if (fCGnx==0||fCGny==0) return;
3298 if (o->InheritsFrom(TH2::Class())) return;
3299 if (o->InheritsFrom(TH3::Class())) return;
3300
3301 TString name = h->GetName();
3302 if (name.Index("hframe") >= 0) return;
3303
3304 Double_t xs = (fX2-fX1)/fCGnx;
3305 Double_t ys = (fY2-fY1)/fCGny;
3306
3307 bool haserrors = false;
3308 TString drawOption = h->GetDrawOption();
3309 drawOption.ToLower();
3310 drawOption.ReplaceAll("same","");
3311
3312 if (drawOption.Index("hist") < 0) {
3313 if (drawOption.Index("e") >= 0) haserrors = true;
3314 }
3315
3316 Int_t nx = h->GetNbinsX();
3317 Int_t x1, y1, y2;
3318 Int_t i, j;
3319 Double_t x1l, y1l, y2l;
3320
3321 for (i = 1; i<nx; i++) {
3322 if (haserrors) {
3323 x1l = h->GetBinCenter(i);
3324 if (fLogx) {
3325 if (x1l > 0) x1l = TMath::Log10(x1l);
3326 else x1l = fUxmin;
3327 }
3328 x1 = (Int_t)((x1l-fX1)/xs);
3329 y1l = h->GetBinContent(i)-h->GetBinErrorLow(i);
3330 if (fLogy) {
3331 if (y1l > 0) y1l = TMath::Log10(y1l);
3332 else y1l = fUymin;
3333 }
3334 y1 = (Int_t)((y1l-fY1)/ys);
3335 y2l = h->GetBinContent(i)+h->GetBinErrorUp(i);
3336 if (fLogy) {
3337 if (y2l > 0) y2l = TMath::Log10(y2l);
3338 else y2l = fUymin;
3339 }
3340 y2 = (Int_t)((y2l-fY1)/ys);
3341 for (j=y1; j<y2; j++) {
3342 NotFree(x1, j);
3343 }
3344 }
3345 x1l = h->GetBinLowEdge(i);
3346 if (fLogx) {
3347 if (x1l > 0) x1l = TMath::Log10(x1l);
3348 else x1l = fUxmin;
3349 }
3350 x1 = (Int_t)((x1l-fX1)/xs);
3351 y1l = h->GetBinContent(i);
3352 if (fLogy) {
3353 if (y1l > 0) y1l = TMath::Log10(y1l);
3354 else y1l = fUymin;
3355 }
3356 y1 = (Int_t)((y1l-fY1)/ys);
3357 NotFree(x1, y1);
3358 x1l = h->GetBinLowEdge(i)+h->GetBinWidth(i);
3359 if (fLogx) {
3360 if (x1l > 0) x1l = TMath::Log10(x1l);
3361 else x1l = fUxmin;
3362 }
3363 x1 = (int)((x1l-fX1)/xs);
3364 NotFree(x1, y1);
3365 }
3366
3367 // Extra objects in the list of function
3368 TPaveStats *ps = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
3369 if (ps) FillCollideGridTBox(ps);
3370}
3371
3372////////////////////////////////////////////////////////////////////////////////
3373/// This method draws the collide grid on top of the canvas. This is used for
3374/// debugging only. At some point it will be removed.
3375
3377{
3378 if (fCGnx==0||fCGny==0) return;
3379
3380 TContext ctxt(this, kTRUE);
3381
3382 TBox box;
3383 box.SetFillColorAlpha(kRed,0.5);
3384
3385 Double_t xs = (fX2-fX1)/fCGnx;
3386 Double_t ys = (fY2-fY1)/fCGny;
3387
3388 Double_t X1L, X2L, Y1L, Y2L;
3389 Double_t t = 0.15;
3390 Double_t Y1, Y2;
3391 Double_t X1 = fX1;
3392 Double_t X2 = X1+xs;
3393
3394 for (int i = 0; i<fCGnx; i++) {
3395 Y1 = fY1;
3396 Y2 = Y1+ys;
3397 for (int j = 0; j<fCGny; j++) {
3398 if (GetLogx()) {
3399 X1L = TMath::Power(10,X1);
3400 X2L = TMath::Power(10,X2);
3401 } else {
3402 X1L = X1;
3403 X2L = X2;
3404 }
3405 if (GetLogy()) {
3406 Y1L = TMath::Power(10,Y1);
3407 Y2L = TMath::Power(10,Y2);
3408 } else {
3409 Y1L = Y1;
3410 Y2L = Y2;
3411 }
3412 if (!fCollideGrid[i + j*fCGnx]) {
3413 box.SetFillColorAlpha(kBlack,t);
3414 box.DrawBox(X1L, Y1L, X2L, Y2L);
3415 } else {
3416 box.SetFillColorAlpha(kRed,t);
3417 box.DrawBox(X1L, Y1L, X2L, Y2L);
3418 }
3419 Y1 = Y2;
3420 Y2 = Y1+ys;
3421 if (t==0.15) t = 0.1;
3422 else t = 0.15;
3423 }
3424 X1 = X2;
3425 X2 = X1+xs;
3426 }
3427}
3428
3429////////////////////////////////////////////////////////////////////////////////
3430/// Short cut to call Modified() and Update() in a single call.
3431/// On Mac with Cocoa, it performs an additional ProcessEvents().
3432
3434{
3435 Modified();
3436 Update();
3437#ifdef R__HAS_COCOA
3439#endif
3440}
3441
3442////////////////////////////////////////////////////////////////////////////////
3443/// Convert x from pad to X.
3444
3446{
3447 if (fLogx && x < 50) return Double_t(TMath::Exp(2.302585092994*x));
3448 return x;
3449}
3450
3451////////////////////////////////////////////////////////////////////////////////
3452/// Convert y from pad to Y.
3453
3455{
3456 if (fLogy && y < 50) return Double_t(TMath::Exp(2.302585092994*y));
3457 return y;
3458}
3459
3460////////////////////////////////////////////////////////////////////////////////
3461/// Convert x from X to pad.
3462
3464{
3465 if (fLogx) {
3466 if (x > 0) x = TMath::Log10(x);
3467 else x = fUxmin;
3468 }
3469 return x;
3470}
3471
3472////////////////////////////////////////////////////////////////////////////////
3473/// Convert y from Y to pad.
3474
3476{
3477 if (fLogy) {
3478 if (y > 0) y = TMath::Log10(y);
3479 else y = fUymin;
3480 }
3481 return y;
3482}
3483
3484////////////////////////////////////////////////////////////////////////////////
3485/// Paint all primitives in pad.
3486
3487void TPad::Paint(Option_t * /* option */)
3488{
3489 if (!fPrimitives)
3490 fPrimitives = new TList;
3492 fViewer3D->PadPaint(this);
3494 if (GetGLDevice()!=-1 && gVirtualPS) {
3495 TContext ctxt(this, kFALSE);
3496 if (gGLManager) gGLManager->PrintViewer(GetViewer3D());
3497 }
3498 return;
3499 }
3500
3501 TVirtualPadPainter *oldpp = nullptr;
3502 Bool_t replace_pp = kFALSE;
3503
3504 if (fCanvas) {
3505 // check if special PS painter should be assigned to TCanvas
3506 replace_pp = fCanvas->EnsurePSPainter(kTRUE, oldpp);
3508 }
3509
3510 Bool_t began3DScene = kFALSE;
3511 fPadPaint = 1;
3512
3513 {
3514 TContext ctxt(this, kTRUE);
3515
3516 fDrawOperXor.clear();
3518 PaintDate();
3519
3520 auto lnk = GetListOfPrimitives()->FirstLink();
3521
3522 while (lnk) {
3523 TObject *obj = lnk->GetObject();
3524
3525 // Create a pad 3D viewer if none exists and we encounter a 3D shape
3526 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3527 GetViewer3D("pad");
3528 }
3529
3530 // Open a 3D scene if required
3531 if (fViewer3D && !fViewer3D->BuildingScene()) {
3533 began3DScene = kTRUE;
3534 }
3535
3536 obj->Paint(lnk->GetOption());
3537 lnk = lnk->Next();
3538 }
3539
3540 if (fCanvas && (fCanvas->fHilightPadBorder == this)) {
3541 auto col = GetHighLightColor();
3542 if (col > 0) PaintBorder(-col, kTRUE);
3543 }
3544
3545 PaintOperations(); // paint operations only for the pad
3546 }
3547
3548 fPadPaint = 0;
3550
3551 if (replace_pp && fCanvas)
3553
3554 // Close the 3D scene if we opened it. This must be done after modified
3555 // flag is cleared, as some viewers will invoke another paint by marking pad modified again
3556 if (began3DScene) {
3558 }
3559}
3560
3561////////////////////////////////////////////////////////////////////////////////
3562/// Paint the pad border.
3563/// Draw first a box as a normal filled box
3564
3565void TPad::PaintBorder(Color_t color, Bool_t /* tops */)
3566{
3567 auto pp = GetPainter();
3568 if (!pp)
3569 return;
3570
3571 pp->OnPad(this);
3572
3573 if (color >= 0) {
3574
3575 Bool_t do_paint_box = kTRUE;
3576
3578 if (!IsBatch() && (pp->IsCocoa() || (pp->IsNative() && (style > 3000) && (style < 3026))))
3579 pp->ClearDrawable();
3580
3581 // special only for transparent pads in plain X11;
3582 // Cocoa, GL, Web and PS implement transparency different
3583 if ((style >= 4000) && (style <= 4100) && pp->IsNative() && !pp->IsCocoa() && !pp->GetPS() && !(fCanvas && fCanvas->UseGL()) && !IsWeb() && !IsBatch()) {
3584 if (this == fMother) {
3585 style = 1001;
3586 } else {
3587 // copy all pixmaps
3588 do_paint_box = kFALSE;
3589 Int_t px, py;
3590 XYtoAbsPixel(GetX1(), GetY2(), px, py);
3591 if (fMother)
3592 fMother->CopyBackgroundPixmaps(this, px, py);
3593 pp->SetAttFill({color, 1001}); // use fill color producing opacity
3594 pp->SetOpacity(style - 4000);
3595 }
3596 } else if ((style >= 4000) && (style <= 4100) && pp->IsCocoa() && (this == fMother))
3597 style = 1001;
3598 else if ((color == 10) && (style > 3000) && (style < 3100))
3599 color = 1;
3600
3601 if (do_paint_box) {
3602 pp->SetAttFill({color, style});
3603 pp->SetAttLine(*this);
3604 PaintBox(fX1, fY1, fX2, fY2);
3605 }
3606 } else
3607 color = -color;
3608
3609 if (IsTransparent() || (fBorderMode == 0))
3610 return;
3611
3612 // then paint 3d frame (depending on bordermode)
3613 // Paint a 3D frame around the pad.
3614
3615 TWbox box;
3616 box.SetFillColor(color);
3617 box.SetFillStyle(GetFillStyle());
3619
3620 box.PaintBorderOn(this, fX1, fY1, fX2, fY2,
3623}
3624
3625////////////////////////////////////////////////////////////////////////////////
3626/// Paint a frame border with Postscript - no longer used
3627
3629{
3630 if (!gVirtualPS) return;
3631 gVirtualPS->DrawFrame(xl, yl, xt, yt, bmode,bsize,dark,light);
3632}
3633
3634////////////////////////////////////////////////////////////////////////////////
3635/// Paint the current date and time if the option `Date` is set on via `gStyle->SetOptDate()`
3636/// Paint the current file name if the option `File` is set on via `gStyle->SetOptFile()`
3637
3639{
3640 if (fCanvas == this) {
3641 if (gStyle->GetOptDate()) {
3642 TDatime dt;
3643 const char *dates;
3644 char iso[16];
3645 if (gStyle->GetOptDate() < 10) {
3646 //by default use format like "Wed Sep 25 17:10:35 2002"
3647 dates = dt.AsString();
3648 } else if (gStyle->GetOptDate() < 20) {
3649 //use ISO format like 2002-09-25
3650 strlcpy(iso,dt.AsSQLString(),16);
3651 dates = iso;
3652 } else {
3653 //use ISO format like 2002-09-25 17:10:35
3654 dates = dt.AsSQLString();
3655 }
3656 TText tdate(gStyle->GetDateX(),gStyle->GetDateY(),dates);
3662 tdate.SetNDC();
3663 tdate.Paint();
3664 }
3665 if (gStyle->GetOptFile() && gFile) {
3666 TText tfile(1. - gStyle->GetDateX(),gStyle->GetDateY(),gFile->GetName());
3670 tfile.SetTextAlign(31);
3672 tfile.SetNDC();
3673 tfile.Paint();
3674 }
3675 }
3676}
3677
3678////////////////////////////////////////////////////////////////////////////////
3679/// Paint histogram/graph frame.
3680
3682{
3683 if (!fPrimitives) fPrimitives = new TList;
3684 TList *glist = GetListOfPrimitives();
3685 TFrame *frame = GetFrame();
3686 frame->SetX1(xmin);
3687 frame->SetX2(xmax);
3688 frame->SetY1(ymin);
3689 frame->SetY2(ymax);
3690 if (!glist->FindObject(fFrame)) {
3691 glist->AddFirst(frame);
3693 }
3694 frame->Paint();
3695}
3696
3697////////////////////////////////////////////////////////////////////////////////
3698/// Traverse pad hierarchy and (re)paint only modified pads.
3699
3701{
3703 if (IsModified()) {
3704 fViewer3D->PadPaint(this);
3706 }
3707 TList *pList = GetListOfPrimitives();
3708 auto lnk = pList ? pList->FirstLink() : nullptr;
3709 while (lnk) {
3710 auto obj = lnk->GetObject();
3711 if (obj->InheritsFrom(TPad::Class()))
3712 ((TPad*)obj)->PaintModified();
3713 lnk = lnk->Next();
3714 }
3715 return;
3716 }
3717
3718 TVirtualPS *saveps = gVirtualPS;
3720 gVirtualPS = nullptr;
3721
3722 TVirtualPadPainter *oldpp = nullptr;
3723 Bool_t replace_pp = kFALSE;
3724
3725 if (fCanvas) {
3726 // check if special PS painter should be assigned to TCanvas
3727 replace_pp = fCanvas->EnsurePSPainter(kTRUE, oldpp);
3729 }
3730
3731 Bool_t began3DScene = kFALSE;
3732 fPadPaint = 1;
3733 {
3734 TContext ctxt(this, kTRUE);
3735
3736 auto pp = GetPainter();
3737 Bool_t useXor = pp && pp->IsNative() && !pp->IsCocoa();
3738 Bool_t needRepaint = IsModified() || IsTransparent() || (!useXor && fDrawOper.size());
3739
3740 if (needRepaint)
3742
3743 PaintDate();
3744
3745 TList *pList = GetListOfPrimitives();
3746 auto lnk = pList ? pList->FirstLink() : nullptr;
3747
3748 while (lnk) {
3749 TObject *obj = lnk->GetObject();
3750 if (obj->InheritsFrom(TPad::Class())) {
3751 ((TPad*)obj)->PaintModified();
3752 } else if (needRepaint) {
3753
3754 // Create a pad 3D viewer if none exists and we encounter a
3755 // 3D shape
3756 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3757 GetViewer3D("pad");
3758 }
3759
3760 // Open a 3D scene if required
3761 if (fViewer3D && !fViewer3D->BuildingScene()) {
3763 began3DScene = kTRUE;
3764 }
3765
3766 obj->Paint(lnk->GetOption());
3767 }
3768 lnk = lnk->Next();
3769 }
3770
3771 // when XOR is not available - paint operations at the ned
3772 if (!useXor && needRepaint)
3774 }
3775
3776 fPadPaint = 0;
3778
3779 // This must be done after modified flag is cleared, as some
3780 // viewers will invoke another paint by marking pad modified again
3781 if (began3DScene && fViewer3D)
3783
3784 if (replace_pp && fCanvas)
3786
3787 gVirtualPS = saveps;
3788}
3789
3790////////////////////////////////////////////////////////////////////////////////
3791/// Perform buffered paint operations
3792/// Used for interactivity functionality immediately after normal painting is performed
3793/// Only when withXor is specified global window context used to perform
3794/// inversion of window, otherwise only draw operations for the current pad are done
3795
3797{
3798 auto pp = GetPainter();
3799 if (!pp)
3800 return;
3801
3802 // IMPORTANT - only when XOR used change gPad only for coordinates calculation
3803 // selected device should never be changed - therefore not use cd()
3804 auto savepad = gPad;
3805 if (withXor)
3806 gPad = this;
3807
3808 pp->OnPad(this);
3809
3810 if (withXor)
3811 for (auto &oper : fDrawOperXor)
3812 oper.second->Draw(*this, pp, withXor);
3813
3814 fDrawOperXor.clear();
3815
3816 for (auto &oper : fDrawOper)
3817 oper.second->Draw(*this, pp, withXor);
3818
3819 if (withXor)
3820 std::swap(fDrawOperXor, fDrawOper);
3821 else
3822 fDrawOper.clear();
3823
3824 if (withXor) {
3825 gPad = savepad;
3826
3827 TIter next(GetListOfPrimitives());
3828 while (auto obj = next()) {
3829 if (auto pad = dynamic_cast<TPad *>(obj))
3830 pad->PaintOperations(withXor);
3831 }
3832 }
3833}
3834
3835////////////////////////////////////////////////////////////////////////////////
3836/// Paint box in CurrentPad World coordinates.
3837///
3838/// - if option[0] = 's' the box is forced to be paint with style=0
3839/// - if option[0] = 'l' the box contour is drawn
3840/// - if option[0] = 'i' the interactive xor box will be painted
3841
3843{
3844 auto pp = GetPainter();
3845 if (!pp)
3846 return;
3847
3848 if (option && *option == 'i') {
3849 Double_t x[5] = {x1, x2, x2, x1, x1};
3850 Double_t y[5] = {y1, y1, y2, y2, y1};
3852 fDrawOper[option] = std::make_unique<TPadDrawOperation>(5, x, y, drawKind, pp->GetLineWidth());
3853 return;
3854 }
3855
3856 pp->OnPad(this);
3857
3858 Style_t style = pp->GetAttFill().GetFillStyle();
3859 Bool_t draw_border = kFALSE, draw_fill = kFALSE, skip_fill = kFALSE;
3860 if (option && *option == 's')
3861 skip_fill = draw_border = kTRUE;
3862 else if (option && *option == 'l')
3863 draw_border = kTRUE;
3864
3865 if (style >= 3100 && style < 4000) {
3866 Double_t xb[4] = {x1, x1, x2, x2};
3867 Double_t yb[4] = {y1, y2, y2, y1};
3868 PaintFillAreaHatches(4, xb, yb, style);
3869 } else if (style >= 0 && style < 1000) {
3870 draw_border = kTRUE;
3871 } else if (style >= 1000 && style < 2000) {
3872 draw_fill = kTRUE;
3873 } else if (style > 3000 && style < 3100) {
3874 draw_fill = style < 3026;
3875 } else if (style >= 4000 && style <= 4100) {
3876 // transparency styles, supported now by all painters
3877 draw_fill = style > 4000;
3878 } else if (style > 0)
3879 draw_border = kTRUE;
3880
3881 if (draw_fill && !skip_fill)
3882 pp->DrawBox(x1, y1, x2, y2, TVirtualPadPainter::kFilled);
3883
3884 if (draw_border)
3885 pp->DrawBox(x1, y1, x2, y2, TVirtualPadPainter::kHollow);
3886
3887 Modified();
3888}
3889
3890////////////////////////////////////////////////////////////////////////////////
3891/// Copy pixmaps of pads laying below pad "stop" into pad "stop". This
3892/// gives the effect of pad "stop" being transparent.
3893
3895{
3896 Int_t px, py;
3897 XYtoAbsPixel(GetX1(), GetY2(), px, py);
3898 /// Copy pixmap of this pad as background of the current pad.
3899 if (auto pp = GetPainter())
3900 pp->CopyDrawable(GetPixmapID(), px - x, py - y);
3901
3902 TIter next(GetListOfPrimitives());
3903 while (auto obj = next()) {
3904 if (obj == stop)
3905 break;
3906 if (auto pad = dynamic_cast<TPad *>(obj))
3907 pad->CopyBackgroundPixmaps(stop, x, y);
3908 }
3909}
3910
3911////////////////////////////////////////////////////////////////////////////////
3912
3914{
3915 Warning("PaintFillArea", "Float_t signature is obsolete. Use Double_t signature.");
3916}
3917
3918////////////////////////////////////////////////////////////////////////////////
3919/// Paint fill area in CurrentPad World coordinates.
3920///
3921/// If option[0] == 'C' no clipping
3922/// If option[0] == 'i' paint during ExecuteEvent (interactive)
3923
3925{
3926 if (nn < 3)
3927 return;
3929 Bool_t mustClip = kTRUE;
3932 } else {
3933 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
3934 if (option && (*option == 'C')) mustClip = kFALSE;
3935 }
3936
3937 std::vector<Double_t> xclip, yclip;
3938
3939 if (mustClip) {
3940 Int_t nc = 2*nn+1;
3941 xclip.resize(nc, 0.);
3942 yclip.resize(nc, 0.);
3943 Int_t n = ClipPolygon(nn, xx, yy, nc, xclip.data(), yclip.data(), xmin, ymin, xmax, ymax);
3944 if (!n)
3945 return;
3946 nn = n;
3947 xx = xclip.data();
3948 yy = yclip.data();
3949 }
3950
3951 if (option && *option == 'i') {
3952 fDrawOper[option] = std::make_unique<TPadDrawOperation>(nn, xx, yy, TPadDrawOperation::drawFill);
3953 return;
3954 }
3955
3956 auto pp = GetPainter();
3957 if (!pp)
3958 return;
3959
3960 pp->OnPad(this);
3961
3962 // Paint the fill area with hatches
3963 Int_t fillstyle = pp->GetFillStyle();
3964 if (fillstyle >= 3100 && fillstyle < 4000)
3965 PaintFillAreaHatches(nn, xx, yy, fillstyle);
3966 else
3967 pp->DrawFillArea(nn, xx, yy);
3968
3969 Modified();
3970}
3971
3972////////////////////////////////////////////////////////////////////////////////
3973/// Paint fill area in CurrentPad NDC coordinates.
3974
3976{
3977 std::vector<Double_t> xw(n), yw(n);
3978 for (int i=0; i<n; i++) {
3979 xw[i] = fX1 + x[i]*(fX2 - fX1);
3980 yw[i] = fY1 + y[i]*(fY2 - fY1);
3981 }
3982 PaintFillArea(n, xw.data(), yw.data(), option);
3983}
3984
3985////////////////////////////////////////////////////////////////////////////////
3986/// This function paints hatched fill area according to the FillStyle value
3987/// The convention for the Hatch is the following:
3988///
3989/// `FillStyle = 3ijk`
3990///
3991/// - i (1-9) : specify the space between each hatch
3992/// 1 = minimum 9 = maximum
3993/// the final spacing is i*GetHatchesSpacing(). The hatches spacing
3994/// is set by SetHatchesSpacing()
3995/// - j (0-9) : specify angle between 0 and 90 degrees
3996/// * 0 = 0
3997/// * 1 = 10
3998/// * 2 = 20
3999/// * 3 = 30
4000/// * 4 = 45
4001/// * 5 = Not drawn
4002/// * 6 = 60
4003/// * 7 = 70
4004/// * 8 = 80
4005/// * 9 = 90
4006/// - k (0-9) : specify angle between 90 and 180 degrees
4007/// * 0 = 180
4008/// * 1 = 170
4009/// * 2 = 160
4010/// * 3 = 150
4011/// * 4 = 135
4012/// * 5 = Not drawn
4013/// * 6 = 120
4014/// * 7 = 110
4015/// * 8 = 100
4016/// * 9 = 90
4017
4019{
4020 static Double_t ang1[10] = { 0., 10., 20., 30., 45.,5., 60., 70., 80., 89.99};
4021 static Double_t ang2[10] = {180.,170.,160.,150.,135.,5.,120.,110.,100., 89.99};
4022
4023 Int_t fasi = FillStyle % 1000;
4024 Int_t idSPA = fasi / 100;
4025 Int_t iAng2 = (fasi - 100 * idSPA) / 10;
4026 Int_t iAng1 = fasi % 10;
4027 Double_t dy = 0.003 * idSPA * gStyle->GetHatchesSpacing();
4029 auto pp = GetPainter();
4030 if (!pp)
4031 return;
4032
4033 // Save the current line attributes and change to draw hatches
4034 TAttLine saveatt = pp->GetAttLine();
4035
4036 pp->SetAttLine({ pp->GetAttFill().GetFillColor(), 1, lw });
4037
4038 // Draw the hatches
4039 if (ang1[iAng1] != 5.)
4040 PaintHatches(dy, ang1[iAng1], nn, xx, yy);
4041 if (ang2[iAng2] != 5.)
4042 PaintHatches(dy, ang2[iAng2], nn, xx, yy);
4043
4044 pp->SetAttLine(saveatt);
4045}
4046
4047////////////////////////////////////////////////////////////////////////////////
4048/// This routine draw hatches inclined with the
4049/// angle "angle" and spaced of "dy" in normalized device
4050/// coordinates in the surface defined by n,xx,yy.
4051
4053 Int_t nn, Double_t *xx, Double_t *yy)
4054{
4055 Int_t i, i1, i2, nbi;
4056 Double_t ratiox, ratioy, ymin, ymax, yrot, ycur;
4057 const Double_t angr = TMath::Pi()*(180.-angle)/180.;
4058 const Double_t epsil = 0.0001;
4059
4060 std::vector<Double_t> xli;
4061 std::vector<Double_t> yli;
4062
4063 Double_t xt1, xt2, yt1, yt2;
4064 Double_t x, y, x1, x2, y1, y2, a, b, xi, xip, xin, yi, yip;
4065
4066 Double_t rwxmin = gPad->GetX1();
4067 Double_t rwxmax = gPad->GetX2();
4068 Double_t rwymin = gPad->GetY1();
4069 Double_t rwymax = gPad->GetY2();
4070 ratiox = 1./(rwxmax-rwxmin);
4071 ratioy = 1./(rwymax-rwymin);
4072
4073 Double_t sina = TMath::Sin(angr), sinb;
4074 Double_t cosa = TMath::Cos(angr), cosb;
4075 if (TMath::Abs(cosa) <= epsil) cosa=0.;
4076 if (TMath::Abs(sina) <= epsil) sina=0.;
4077 sinb = -sina;
4078 cosb = cosa;
4079
4080 // Values needed to compute the hatches in TRUE normalized space (NDC)
4081 Int_t iw = (Int_t)gPad->GetWw();
4082 Int_t ih = (Int_t)gPad->GetWh();
4083 Double_t x1p,y1p,x2p,y2p;
4084 gPad->GetPadPar(x1p,y1p,x2p,y2p);
4085 iw = (Int_t)(iw*x2p)-(Int_t)(iw*x1p);
4086 ih = (Int_t)(ih*y2p)-(Int_t)(ih*y1p);
4087 Double_t wndc = TMath::Min(1.,(Double_t)iw/(Double_t)ih);
4088 Double_t hndc = TMath::Min(1.,(Double_t)ih/(Double_t)iw);
4089
4090 // Search ymin and ymax
4091 ymin = 1.;
4092 ymax = 0.;
4093 for (i=1; i<=nn; i++) {
4094 x = wndc*ratiox*(xx[i-1]-rwxmin);
4095 y = hndc*ratioy*(yy[i-1]-rwymin);
4096 yrot = sina*x+cosa*y;
4097 if (yrot > ymax) ymax = yrot;
4098 if (yrot < ymin) ymin = yrot;
4099 }
4100
4101 Int_t yindx = (Int_t) (ymax/dy);
4102
4103 while (dy * yindx >= ymin) {
4104 ycur = dy * yindx--;
4105 nbi = 0;
4106
4107 xli.clear();
4108 yli.clear();
4109
4110 for (i=2; i<=nn+1; i++) {
4111 i2 = i;
4112 i1 = i-1;
4113 if (i == nn+1) i2=1;
4114
4115 x1 = wndc*ratiox*(xx[i1-1]-rwxmin);
4116 y1 = hndc*ratioy*(yy[i1-1]-rwymin);
4117 x2 = wndc*ratiox*(xx[i2-1]-rwxmin);
4118 y2 = hndc*ratioy*(yy[i2-1]-rwymin);
4119
4120 xt1 = cosa*x1-sina*y1;
4121 yt1 = sina*x1+cosa*y1;
4122 xt2 = cosa*x2-sina*y2;
4123 yt2 = sina*x2+cosa*y2;
4124
4125 // Line segment parallel to oy
4126 if (xt1 == xt2) {
4127 if (yt1 < yt2) {
4128 yi = yt1;
4129 yip = yt2;
4130 } else {
4131 yi = yt2;
4132 yip = yt1;
4133 }
4134 if ((yi <= ycur) && (ycur < yip)) {
4135 nbi++;
4136 xli.push_back(xt1);
4137 }
4138 continue;
4139 }
4140
4141 // Line segment parallel to ox
4142 if (yt1 == yt2) {
4143 if (yt1 == ycur) {
4144 nbi++;
4145 xli.push_back(xt1);
4146 nbi++;
4147 xli.push_back(xt2);
4148 }
4149 continue;
4150 }
4151
4152 // Other line segment
4153 a = (yt1-yt2)/(xt1-xt2);
4154 b = (yt2*xt1-xt2*yt1)/(xt1-xt2);
4155
4156 if (xt1 < xt2) {
4157 xi = xt1;
4158 xip = xt2;
4159 } else {
4160 xi = xt2;
4161 xip = xt1;
4162 }
4163
4164 xin = (ycur-b)/a;
4165
4166 if ((xi <= xin) && (xin < xip) &&
4167 (TMath::Min(yt1,yt2) <= ycur) &&
4168 (ycur < TMath::Max(yt1,yt2))) {
4169 nbi++;
4170 xli.push_back(xin);
4171 }
4172 }
4173
4174 // Sorting of the x coordinates intersections
4175 std::sort(xli.begin(), xli.end());
4176
4177 // Draw the hatches
4178 if ((nbi%2 != 0) || (nbi == 0))
4179 continue;
4180
4181 for (i=0; i<nbi; ++i) {
4182 // Rotate back the hatches - first calculate y coordinate
4183 Double_t ytmp = sinb*xli[i] + cosb*ycur;
4184 xli[i] = cosb*xli[i] - sinb*ycur;
4185 // Convert hatches' positions from true NDC to WC to handle clipping
4186 xli[i] = (xli[i]/wndc)*(rwxmax-rwxmin)+rwxmin;
4187 ytmp = (ytmp/hndc)*(rwymax-rwymin)+rwymin;
4188 yli.push_back(ytmp);
4189 }
4190
4191 gPad->PaintSegments(nbi/2, xli.data(), yli.data());
4192 }
4193}
4194
4195////////////////////////////////////////////////////////////////////////////////
4196/// Paint line in CurrentPad World coordinates.
4197
4199{
4200 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
4201
4202 //If line is totally clipped, return
4204 if (Clip(x,y,fUxmin,fUymin,fUxmax,fUymax) == 2) return;
4205 } else {
4206 if (Clip(x,y,fX1,fY1,fX2,fY2) == 2) return;
4207 }
4208
4209 if (auto pp = GetPainter()) {
4210 pp->OnPad(this);
4211 pp->DrawLine(x[0], y[0], x[1], y[1]);
4212 }
4213
4214 Modified();
4215}
4216
4217////////////////////////////////////////////////////////////////////////////////
4218/// Paint line in normalized coordinates.
4219
4221{
4222 if (auto pp = GetPainter()) {
4223 pp->OnPad(this);
4224 pp->DrawLineNDC(u1, v1, u2, v2);
4225 }
4226
4227 Modified();
4228}
4229
4230////////////////////////////////////////////////////////////////////////////////
4231/// Paint 3-D line in the CurrentPad.
4232
4234{
4235 if (!fView) return;
4236
4237 // convert from 3-D to 2-D pad coordinate system
4238 Double_t xpad[6];
4239 Double_t temp[3];
4240 Int_t i;
4241 for (i=0;i<3;i++) temp[i] = p1[i];
4242 fView->WCtoNDC(temp, &xpad[0]);
4243 for (i=0;i<3;i++) temp[i] = p2[i];
4244 fView->WCtoNDC(temp, &xpad[3]);
4245 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4246}
4247
4248////////////////////////////////////////////////////////////////////////////////
4249/// Paint 3-D line in the CurrentPad.
4250
4252{
4253 if (!fView) return;
4254
4255 // convert from 3-D to 2-D pad coordinate system
4256 Double_t xpad[6];
4257 Double_t temp[3];
4258 Int_t i;
4259 for (i=0;i<3;i++) temp[i] = p1[i];
4260 fView->WCtoNDC(temp, &xpad[0]);
4261 for (i=0;i<3;i++) temp[i] = p2[i];
4262 fView->WCtoNDC(temp, &xpad[3]);
4263 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4264}
4265
4266////////////////////////////////////////////////////////////////////////////////
4267/// Paint 3-D marker in the CurrentPad.
4268
4270{
4271 if (!fView) return;
4272
4273 Double_t rmin[3], rmax[3];
4274 fView->GetRange(rmin, rmax);
4275
4276 // convert from 3-D to 2-D pad coordinate system
4277 Double_t xpad[3];
4278 Double_t temp[3];
4279 temp[0] = x;
4280 temp[1] = y;
4281 temp[2] = z;
4282 if (x<rmin[0] || x>rmax[0]) return;
4283 if (y<rmin[1] || y>rmax[1]) return;
4284 if (z<rmin[2] || z>rmax[2]) return;
4285 fView->WCtoNDC(temp, &xpad[0]);
4286 PaintPolyMarker(1, &xpad[0], &xpad[1]);
4287}
4288
4289////////////////////////////////////////////////////////////////////////////////
4290/// Paint polyline in CurrentPad World coordinates.
4291///
4292/// If option[0] == 'C' no clipping
4293/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4294
4296{
4297 auto pp = GetPainter();
4298 if ((n < 2) || !pp)
4299 return;
4300
4302 Bool_t mustClip = kTRUE, interactive = option && *option == 'i';
4305 } else {
4306 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4307 if (option && (*option == 'C')) mustClip = kFALSE;
4308 }
4309 Int_t i1 = -1, np = 1, iclip = 0;
4310 for (Int_t i = 0; i < n - 1; i++) {
4311 Double_t x1 = x[i];
4312 Double_t y1 = y[i];
4313 Double_t x2 = x[i+1];
4314 Double_t y2 = y[i+1];
4315 if (mustClip) {
4316 iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4317 if (iclip == 2) {
4318 i1 = -1;
4319 continue;
4320 }
4321 }
4322 np++;
4323 if (i1 < 0)
4324 i1 = i;
4325 if (iclip == 0 && i < n-2)
4326 continue;
4327 if (interactive)
4328 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawLine, pp->GetLineWidth());
4329 else {
4330 pp->OnPad(this);
4331 pp->DrawPolyLine(np, &x[i1], &y[i1]);
4332 }
4333 if (iclip) {
4334 x[i] = x1;
4335 y[i] = y1;
4336 x[i+1] = x2;
4337 y[i+1] = y2;
4338 }
4339 i1 = -1;
4340 np = 1;
4341 }
4342
4343 if (!interactive)
4344 Modified();
4345}
4346
4347////////////////////////////////////////////////////////////////////////////////
4348/// Paint polyline in CurrentPad World coordinates.
4349///
4350/// If option[0] == 'C' no clipping
4351/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4352
4354{
4355 auto pp = GetPainter();
4356 if ((n < 2) || !pp)
4357 return;
4358
4360 Bool_t mustClip = kTRUE, interactive = option && *option == 'i';
4363 } else {
4364 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4365 if (option && (*option == 'C')) mustClip = kFALSE;
4366 }
4367
4368 Int_t i1 = -1, np = 1, iclip = 0;
4369
4370 for (Int_t i = 0; i < n-1; i++) {
4371 Double_t x1 = x[i];
4372 Double_t y1 = y[i];
4373 Double_t x2 = x[i+1];
4374 Double_t y2 = y[i+1];
4375 if (mustClip) {
4376 iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4377 if (iclip == 2) {
4378 i1 = -1;
4379 continue;
4380 }
4381 }
4382 np++;
4383 if (i1 < 0)
4384 i1 = i;
4385 if (iclip == 0 && i < n-2)
4386 continue;
4387 if (interactive)
4388 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawLine, pp->GetLineWidth());
4389 else {
4390 pp->OnPad(this);
4391 pp->DrawPolyLine(np, &x[i1], &y[i1]);
4392 }
4393 if (iclip) {
4394 x[i] = x1;
4395 y[i] = y1;
4396 x[i+1] = x2;
4397 y[i+1] = y2;
4398 }
4399 i1 = -1;
4400 np = 1;
4401 }
4402
4403 if (!interactive)
4404 Modified();
4405}
4406
4407////////////////////////////////////////////////////////////////////////////////
4408/// Paint polyline in CurrentPad NDC coordinates.
4409
4411{
4412 auto pp = GetPainter();
4413 if ((n < 2) || !pp)
4414 return;
4415
4416 if (option && *option == 'i') {
4417 fDrawOper[option] = std::make_unique<TPadDrawOperation>(n, x, y, TPadDrawOperation::drawLine, pp->GetLineWidth(), kTRUE);
4418 return;
4419 }
4420
4421 pp->OnPad(this);
4422 pp->DrawPolyLineNDC(n, x, y);
4423
4424 Modified();
4425}
4426
4427////////////////////////////////////////////////////////////////////////////////
4428/// Paint 3-D polyline in the CurrentPad.
4429
4431{
4432 if (!fView) return;
4433
4434 // Loop on each individual line
4435 for (Int_t i = 1; i < n; i++)
4436 PaintLine3D(&p[3*i-3], &p[3*i]);
4437
4438 Modified();
4439}
4440
4441////////////////////////////////////////////////////////////////////////////////
4442/// Paint polymarker in CurrentPad World coordinates.
4443///
4444/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4445
4447{
4448 Int_t n = TMath::Abs(nn);
4450 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4452 } else {
4453 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4454 }
4455 Int_t i,i1=-1,np=0;
4456 for (i=0; i<n; i++) {
4457 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4458 np++;
4459 if (i1 < 0) i1 = i;
4460 if (i < n-1) continue;
4461 }
4462 if (np == 0)
4463 continue;
4464 if (option && *option == 'i')
4465 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawMarker, option[1] == 'f' ? 0 : 1);
4466 else if (auto pp = GetPainter()) {
4467 pp->OnPad(this);
4468 pp->DrawPolyMarker(np, &x[i1], &y[i1]);
4469 }
4470 i1 = -1;
4471 np = 0;
4472 }
4473 Modified();
4474}
4475
4476////////////////////////////////////////////////////////////////////////////////
4477/// Paint polymarker in CurrentPad World coordinates.
4478///
4479/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4480
4482{
4483 Int_t n = TMath::Abs(nn);
4485 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4487 } else {
4488 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4489 }
4490 Int_t i,i1=-1,np=0;
4491 for (i=0; i<n; i++) {
4492 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4493 np++;
4494 if (i1 < 0) i1 = i;
4495 if (i < n-1) continue;
4496 }
4497 if (np == 0)
4498 continue;
4499
4500 if (option && *option == 'i')
4501 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawMarker, option[1] == 'f' ? 0 : 1);
4502 else if (auto pp = GetPainter()) {
4503 pp->OnPad(this);
4504 pp->DrawPolyMarker(np, &x[i1], &y[i1]);
4505 }
4506 i1 = -1;
4507 np = 0;
4508 }
4509 Modified();
4510}
4511
4512////////////////////////////////////////////////////////////////////////////////
4513/// Paint N individual segments
4514/// Provided arrays should have 2*n elements
4515/// IMPORTANT! Provided arrays can be modified after function call!
4516
4518{
4519 if (n < 1)
4520 return;
4521
4523 Bool_t mustClip = kTRUE, isAny = kFALSE;
4526 } else {
4527 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4528 if (option && *option == 'C') mustClip = kFALSE;
4529 }
4530
4531 if (!mustClip)
4532 isAny = kTRUE;
4533 else {
4534 for (Int_t i = 0; i < 2*n; i+=2) {
4535 Int_t iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4536 if (iclip == 2)
4537 x[i] = y[i] = x[i+1] = y[i+1] = 0;
4538 else
4539 isAny = kTRUE;
4540 }
4541 }
4542
4543 if (isAny)
4544 if (auto pp = GetPainter()) {
4545 pp->OnPad(this);
4546 pp->DrawSegments(n, x, y);
4547 }
4548
4549 Modified();
4550}
4551
4552
4553////////////////////////////////////////////////////////////////////////////////
4554/// Paint N individual segments in NDC coordinates
4555/// Provided arrays should have 2*n elements
4556/// IMPORTANT! Provided arrays can be modified after function call!
4557
4559{
4560 if (auto pp = GetPainter()) {
4561 pp->OnPad(this);
4562 pp->DrawSegmentsNDC(n, u, v);
4563 }
4564
4565 Modified();
4566}
4567
4568
4569////////////////////////////////////////////////////////////////////////////////
4570/// Paint text in CurrentPad World coordinates.
4571
4573{
4574 Modified();
4575
4576 if (auto pp = GetPainter()) {
4577 pp->OnPad(this);
4578 pp->DrawText(x, y, text, TVirtualPadPainter::kClear);
4579 }
4580}
4581
4582////////////////////////////////////////////////////////////////////////////////
4583/// Paint text in CurrentPad World coordinates.
4584
4585void TPad::PaintText(Double_t x, Double_t y, const wchar_t *text)
4586{
4587 Modified();
4588
4589 if (auto pp = GetPainter()) {
4590 pp->OnPad(this);
4591 pp->DrawText(x, y, text, TVirtualPadPainter::kClear);
4592 }
4593}
4594
4595////////////////////////////////////////////////////////////////////////////////
4596/// Paint text with URL in CurrentPad World coordinates.
4597
4598void TPad::PaintTextUrl(Double_t x, Double_t y, const char *text, const char *url)
4599{
4600 Modified();
4601
4602 if (auto pp = GetPainter()) {
4603 pp->OnPad(this);
4604 pp->DrawTextUrl(x, y, text, url);
4605 }
4606}
4607
4608////////////////////////////////////////////////////////////////////////////////
4609/// Paint text in CurrentPad NDC coordinates.
4610
4612{
4613 Modified();
4614
4615 if (auto pp = GetPainter()) {
4616 pp->OnPad(this);
4617 pp->DrawTextNDC(u, v, text, TVirtualPadPainter::kClear);
4618 }
4619}
4620
4621////////////////////////////////////////////////////////////////////////////////
4622/// Paint text in CurrentPad NDC coordinates.
4623
4625{
4626 Modified();
4627
4628 if (auto pp = GetPainter()) {
4629 pp->OnPad(this);
4630 pp->DrawTextNDC(u, v, text, TVirtualPadPainter::kClear);
4631 }
4632}
4633
4634////////////////////////////////////////////////////////////////////////////////
4635/// Search for an object at pixel position px,py.
4636///
4637/// Check if point is in this pad.
4638///
4639/// If yes, check if it is in one of the sub-pads
4640///
4641/// If found in the pad, compute closest distance of approach
4642/// to each primitive.
4643///
4644/// If one distance of approach is found to be within the limit Distancemaximum
4645/// the corresponding primitive is selected and the routine returns.
4646
4648{
4649 //the two following statements are necessary under NT (multithreaded)
4650 //when a TCanvas object is being created and a thread calling TPad::Pick
4651 //before the TPad constructor has completed in the other thread
4652 if (!gPad) return nullptr; //Andy Haas
4653 if (!GetListOfPrimitives()) return nullptr; //Andy Haas
4654
4655 Int_t dist;
4656 // Search if point is in pad itself
4657 Double_t x = AbsPixeltoX(px);
4658 Double_t y = AbsPixeltoY(py);
4659 if (this != gPad->GetCanvas()) {
4660 if (!((x >= fX1 && x <= fX2) && (y >= fY1 && y <= fY2))) return nullptr;
4661 }
4662
4663 // search for a primitive in this pad or its sub-pads
4664 static TObjOptLink dummyLink(nullptr,""); //place holder for when no link available
4665
4666 TContext ctxt(this, kFALSE); // since no drawing will be done, don't use cd() for efficiency reasons
4667
4668 TPad *pick = nullptr;
4669 TPad *picked = this;
4670 pickobj = nullptr;
4672 dummyLink.SetObject(this);
4673 pickobj = &dummyLink;
4674 }
4675
4676 // Loop backwards over the list of primitives. The first non-pad primitive
4677 // found is the selected one. However, we have to keep going down the
4678 // list to see if there is maybe a pad overlaying the primitive. In that
4679 // case look into the pad for a possible primitive. Once a pad has been
4680 // found we can terminate the loop.
4681 Bool_t gotPrim = kFALSE; // true if found a non pad primitive
4683
4684 //We can have 3d stuff in pad. If canvas prefers to draw
4685 //such stuff with OpenGL, the selection of 3d objects is
4686 //a gl viewer business so, in first cycle we do not
4687 //call DistancetoPrimitive for TAtt3D descendants.
4688 //In case of gl we first try to select 2d object first.
4689
4690 while (lnk) {
4691 TObject *obj = lnk->GetObject();
4692
4693 //If canvas prefers GL, all 3d objects must be drawn/selected by
4694 //gl viewer
4695 if (obj->InheritsFrom(TAtt3D::Class()) && fEmbeddedGL) {
4696 lnk = lnk->Prev();
4697 continue;
4698 }
4699
4700 fPadPointer = obj;
4701 if (obj->InheritsFrom(TPad::Class())) {
4702 pick = ((TPad*)obj)->Pick(px, py, pickobj);
4703 if (pick) {
4704 picked = pick;
4705 break;
4706 }
4707 } else if (!gROOT->GetEditorMode()) {
4708 if (!gotPrim) {
4709 if (!obj->TestBit(kCannotPick)) {
4710 dist = obj->DistancetoPrimitive(px, py);
4711 if (dist < fgMaxPickDistance) {
4712 pickobj = lnk;
4713 gotPrim = kTRUE;
4714 if (dist == 0) break;
4715 }
4716 }
4717 }
4718 }
4719
4720 lnk = lnk->Prev();
4721 }
4722
4723 //if no primitive found, check if we have a TView
4724 //if yes, return the view except if you are in the lower or upper X range
4725 //of the pad.
4726 //In case canvas prefers gl, fView existence
4727 //automatically means viewer3d existence. (?)
4728
4729 if (fView && !gotPrim) {
4730 Double_t dx = 0.05*(fUxmax-fUxmin);
4731 if ((x > fUxmin + dx) && (x < fUxmax-dx)) {
4732
4733 if (fEmbeddedGL) {
4734 //No 2d stuff was selected, but we have gl-viewer. Let it select an object in
4735 //scene (or select itself). In any case it'll internally call
4736 //gPad->SetSelected(ptr) as, for example, hist painter does.
4737 py -= Int_t((1 - GetHNDC() - GetYlowNDC()) * GetWh());
4738 px -= Int_t(GetXlowNDC() * GetWw());
4740 }
4741 else
4742 dummyLink.SetObject(fView);
4743 }
4744 }
4745
4746 if (picked->InheritsFrom(TButton::Class())) {
4747 TButton *button = (TButton*)picked;
4748 if (!button->IsEditable()) pickobj = nullptr;
4749 }
4750
4751 if (TestBit(kCannotPick)) {
4752
4753 if (picked == this) {
4754 // cannot pick pad itself!
4755 picked = nullptr;
4756 }
4757
4758 }
4759
4760 return picked;
4761}
4762
4763////////////////////////////////////////////////////////////////////////////////
4764/// Pop pad to the top of the stack.
4765
4767{
4769 return;
4770 if (!fPrimitives)
4771 fPrimitives = new TList;
4772 if (this == fMother->GetListOfPrimitives()->Last())
4773 return;
4774
4776 while (auto obj = next())
4777 if (obj == this) {
4778 TString opt = next.GetOption();
4779 fMother->Remove(this, kFALSE); // do not issue modified
4780 fMother->Add(this, opt.Data());
4781 return;
4782 }
4783}
4784
4785////////////////////////////////////////////////////////////////////////////////
4786/// This method is equivalent to `SaveAs("filename")`. See TPad::SaveAs for details.
4787
4788void TPad::Print(const char *filename) const
4789{
4790 ((TPad*)this)->SaveAs(filename);
4791}
4792
4793////////////////////////////////////////////////////////////////////////////////
4794/// Save Canvas contents in a file in one of various formats.
4795///
4796/// \anchor TPadPrint
4797/// option can be:
4798///
4799/// - `ps`: a Postscript file is produced (default). [See special cases](\ref TPadPrintPS).
4800/// - `Portrait`: Postscript file is produced (Portrait)
4801/// - `Landscape`: Postscript file is produced (Landscape)
4802/// - `eps`: an Encapsulated Postscript file is produced
4803/// - `Preview`: an [Encapsulated Postscript file with preview](\ref TPadPrintPreview) is produced.
4804/// - `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.
4805/// - `Title:`: The character string after `Title:` becomes a table
4806/// of content entry (for PDF files).
4807/// - `EmbedFonts`: a [PDF file with embedded fonts](\ref TPadPrintEmbedFonts) is generated.
4808/// - `svg`: a SVG file is produced
4809/// - `tex`: a TeX file is produced
4810/// - `Standalone`: a [standalone TeX file](\ref TPadPrintStandalone) is produced.
4811/// - `gif`: a GIF file is produced
4812/// - `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
4813/// - `xpm`: a XPM file is produced
4814/// - `png`: a PNG file is produced
4815/// - `jpg`: a JPEG file is produced. NOTE: JPEG's lossy compression will make all sharp edges fuzzy.
4816/// - `tiff`: a TIFF file is produced
4817/// - `cxx`: a C++ macro file is produced
4818/// - `xml`: a XML file
4819/// - `json`: a JSON file
4820/// - `root`: a ROOT binary file
4821///
4822/// `filename` = 0 - filename is defined by `GetName` and its
4823/// extension is defined with the option
4824///
4825/// When Postscript output is selected (`ps`, `eps`), the canvas is saved
4826/// to `filename.ps` or `filename.eps`. The aspect ratio of the canvas is preserved
4827/// on the Postscript file. When the "ps" option is selected, the Postscript
4828/// page will be landscape format if the canvas is in landscape format, otherwise
4829/// portrait format is selected.
4830///
4831/// The physical size of the Postscript page is the one selected in the
4832/// current style. This size can be modified via TStyle::SetPaperSize.
4833///
4834/// Examples:
4835/// ~~~ {.cpp}
4836/// gStyle->SetPaperSize(TStyle::kA4); //default
4837/// gStyle->SetPaperSize(TStyle::kUSLetter);
4838/// ~~~
4839/// where TStyle::kA4 and TStyle::kUSLetter are defined in the enum
4840/// EPaperSize in TStyle.h
4841///
4842/// An alternative is to call:
4843/// ~~~ {.cpp}
4844/// gStyle->SetPaperSize(20,26); same as kA4
4845/// or gStyle->SetPaperSize(20,24); same as kUSLetter
4846/// ~~~
4847/// The above numbers take into account some margins and are in centimeters.
4848///
4849/// \anchor TPadPrintPreview
4850/// ### The "Preview" option
4851///
4852/// The "Preview" option allows to generate a preview (in the TIFF format) within
4853/// the Encapsulated Postscript file. This preview can be used by programs like
4854/// MSWord to visualize the picture on screen. The "Preview" option relies on the
4855/// ["epstool" command](http://www.cs.wisc.edu/~ghost/gsview/epstool.htm).
4856///
4857/// Example:
4858/// ~~~ {.cpp}
4859/// canvas->Print("example.eps","Preview");
4860/// ~~~
4861///
4862/// \anchor TPadPrintEmbedFonts
4863/// ### The "EmbedFonts" option
4864///
4865/// The "EmbedFonts" option allows to embed the fonts used in a PDF file inside
4866/// that file. This option relies on the ["gs" command](https://ghostscript.com).
4867///
4868/// Example:
4869/// ~~~ {.cpp}
4870/// canvas->Print("example.pdf","EmbedFonts");
4871/// ~~~
4872///
4873/// \anchor TPadPrintStandalone
4874/// ### The "Standalone" option
4875/// The "Standalone" option allows to generate a TeX file ready to be processed by
4876/// tools like `pdflatex`.
4877///
4878/// Example:
4879/// ~~~ {.cpp}
4880/// canvas->Print("example.tex","Standalone");
4881/// ~~~
4882///
4883/// \anchor TPadPrintPS
4884/// ### Writing several canvases to the same Postscript or PDF file:
4885///
4886/// - if the Postscript or PDF file name finishes with "(", the file is not closed
4887/// - if the Postscript or PDF file name finishes with ")" and the file has been opened
4888/// with "(", the file is closed.
4889///
4890/// Example:
4891/// ~~~ {.cpp}
4892/// {
4893/// TCanvas c1("c1");
4894/// h1.Draw();
4895/// c1.Print("c1.ps("); //write canvas and keep the ps file open
4896/// h2.Draw();
4897/// c1.Print("c1.ps"); canvas is added to "c1.ps"
4898/// h3.Draw();
4899/// c1.Print("c1.ps)"); canvas is added to "c1.ps" and ps file is closed
4900/// }
4901/// ~~~
4902/// In the previous example replacing "ps" by "pdf" will create a multi-pages PDF file.
4903///
4904/// Note that the following sequence writes the canvas to "c1.ps" and closes the ps file.:
4905/// ~~~ {.cpp}
4906/// TCanvas c1("c1");
4907/// h1.Draw();
4908/// c1.Print("c1.ps");
4909/// ~~~
4910/// The `TCanvas::Print("file.ps(")` mechanism is very useful, but it can be
4911/// a little inconvenient to have the action of opening/closing a file
4912/// being atomic with printing a page. Particularly if pages are being
4913/// generated in some loop one needs to detect the special cases of first
4914/// and last page and then munge the argument to Print() accordingly.
4915///
4916/// The "[" and "]" can be used instead of "(" and ")" to open / close without
4917/// actual printing.
4918///
4919/// Example:
4920/// ~~~ {.cpp}
4921/// c1.Print("file.ps["); // No actual print, just open file.ps
4922/// for (int i=0; i<10; ++i) {
4923/// // fill canvas for context i
4924/// // ...
4925///
4926/// c1.Print("file.ps"); // actually print canvas to file
4927/// }// end loop
4928/// c1.Print("file.ps]"); // No actual print, just close.
4929/// ~~~
4930/// As before, the same macro is valid for PDF files.
4931///
4932/// It is possible to print a canvas into an animated GIF file by specifying the
4933/// file name as "myfile.gif+" or "myfile.gif+NN", where NN*10ms is delay
4934/// between the subimages' display. If NN is omitted the delay between
4935/// subimages is zero. Each picture is added in the animation thanks to a loop
4936/// similar to the following one:
4937/// ~~~ {.cpp}
4938/// for (int i=0; i<10; ++i) {
4939/// // fill canvas for context i
4940/// // ...
4941///
4942/// c1.Print("file.gif+5"); // print canvas to GIF file with 50ms delays
4943/// }// end loop
4944/// ~~~
4945/// The delay between each frame must be specified in each Print() statement.
4946/// If the file "myfile.gif" already exists, the new frame are appended at
4947/// the end of the file. To avoid this, delete it first with `gSystem->Unlink(myfile.gif);`
4948/// If you want the gif file to repeat or loop forever, check TASImage::WriteImage documentation
4949
4951{
4952 auto canv = GetCanvas();
4953 if (!canv)
4954 return;
4955
4956 TString psname, fs1 = filename;
4957
4958 // "[" and "]" are special characters for ExpandPathName. When they are at the end
4959 // of the file name (see help) they must be removed before doing ExpandPathName.
4960 if (fs1.EndsWith("[")) {
4961 fs1.Replace((fs1.Length()-1),1," ");
4962 gSystem->ExpandPathName(fs1);
4963 fs1.Replace((fs1.Length()-1),1,"[");
4964 } else if (fs1.EndsWith("]")) {
4965 fs1.Replace((fs1.Length()-1),1," ");
4966 gSystem->ExpandPathName(fs1);
4967 fs1.Replace((fs1.Length()-1),1,"]");
4968 } else {
4969 gSystem->ExpandPathName(fs1);
4970 }
4971
4972 // Set the default option as "Postscript" (Should be a data member of TPad)
4973 const char *opt_default = "ps";
4974
4975 TString opt = !option ? opt_default : option;
4976 Bool_t image = kFALSE;
4977 Bool_t title = opt.Contains("Title:");
4978
4979 if (!fs1.Length()) {
4980 psname = GetName();
4981 psname += opt;
4982 } else {
4983 psname = fs1;
4984 }
4985
4986 // lines below protected against case like c1->SaveAs( "../ps/cs.ps" );
4987 if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
4988 psname = GetName();
4989 psname.Append(fs1);
4990 psname.Prepend("/");
4991 psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
4992 }
4993
4994 // Save pad/canvas in alternative formats
4996 if (!title && opt.Contains("gif+")) {
4997 gtype = TImage::kAnimGif;
4998 image = kTRUE;
4999 } else if (!title && opt.Contains("gif")) {
5000 gtype = TImage::kGif;
5001 image = kTRUE;
5002 } else if (!title && opt.Contains("png")) {
5003 gtype = TImage::kPng;
5004 image = kTRUE;
5005 } else if (!title && opt.Contains("jpg")) {
5006 gtype = TImage::kJpeg;
5007 image = kTRUE;
5008 } else if (!title && opt.Contains("tiff")) {
5009 gtype = TImage::kTiff;
5010 image = kTRUE;
5011 } else if (!title && opt.Contains("xpm")) {
5012 gtype = TImage::kXpm;
5013 image = kTRUE;
5014 } else if (!title && opt.Contains("bmp")) {
5015 gtype = TImage::kBmp;
5016 image = kTRUE;
5017 } else if (!title && opt.Contains("svg")) {
5018 gtype = TImage::kSvg;
5019 } else if (!title && opt.Contains("pdf")) {
5020 gtype = TImage::kPdf;
5021 } else if (!title && opt.Contains("html")) {
5022 gtype = TImage::kHtml;
5023 }
5024
5025 auto pp = GetPainter();
5026 Bool_t isweb = canv->IsWeb();
5027 Bool_t isbatch = gROOT->IsBatch() || canv->IsBatch();
5028
5029 // for a moment special handling of web canvas - check if can save directly
5030 if (isweb && pp)
5031 if (pp->SaveAsImage(this, psname.Data(), gtype) != TVirtualPadPainter::kSaveNotImplemented)
5032 return;
5033
5034 // to create HTML file web-based canvas functionality is invoked
5035 if (gtype == TImage::kHtml) {
5036 auto cmd = TString::Format("TWebCanvas::ProduceImage((TPad *) 0x%zx, \"%s\");", (size_t) this, psname.Data());
5037 Long_t res = gROOT->ProcessLine(cmd);
5038 if (!res)
5039 Error("Print", "Fail create HTML file %s", psname.Data());
5040 return;
5041 }
5042
5043 if (((!isbatch && image) || isweb) && pp) {
5044 Color_t hc = canv->GetHighLightColor();
5045
5046 if (!isweb) {
5047 canv->SetHighLightColor(-1);
5048 Modified();
5049 }
5050 canv->Update();
5051
5052 auto res = pp->SaveAsImage(this, psname.Data(), gtype);
5053
5054 if (!isweb)
5055 canv->SetHighLightColor(hc);
5056
5058 Warning("Print", "Unsupported image format %s, fallback to TImageDump", psname.Data());
5059 else if ((res == TVirtualPadPainter::kSaveOk) && !gSystem->AccessPathName(psname.Data()))
5060 Info("Print", "file %s has been created", psname.Data());
5061
5063 return;
5064 }
5065
5066 //==============Save pad/canvas as a C++ script==============================
5067 if (!title && opt.Contains("cxx")) {
5068 GetCanvas()->SaveSource(psname, "");
5069 return;
5070 }
5071
5072 //==============Save pad/canvas as a root file===============================
5073 if (!title && opt.Contains("root")) {
5074 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5075 return;
5076 }
5077
5078 //==============Save pad/canvas as a XML file================================
5079 if (!title && opt.Contains("xml")) {
5080 // Plugin XML driver
5081 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5082 return;
5083 }
5084
5085 //==============Save pad/canvas as a JSON file================================
5086 if (!title && opt.Contains("json")) {
5087 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5088 return;
5089 }
5090
5091 //==============Save pad/canvas as a SVG file================================
5092 if (gtype == TImage::kSvg) {
5093 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5094
5095 Bool_t noScreen = kFALSE, wasModified = IsModified();
5096 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5097 noScreen = kTRUE;
5099 }
5100
5101 TContext ctxt(this, kTRUE);
5102
5103 if (!gVirtualPS) {
5104 // Plugin Postscript/SVG driver
5105 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "svg")) {
5106 if (h->LoadPlugin() == -1)
5107 return;
5108 h->ExecPlugin(0);
5109 }
5110 }
5111
5112 // Create a new SVG file
5113 if (gVirtualPS) {
5114 gVirtualPS->SetName(psname);
5115 gVirtualPS->Open(psname);
5118 }
5119
5120 Paint();
5121 if (noScreen)
5123 if (wasModified && !IsBatch())
5124 Modified(kTRUE);
5125
5126 if (!gSystem->AccessPathName(psname))
5127 Info("Print", "SVG file %s has been created", psname.Data());
5128
5129 delete gVirtualPS;
5130 gVirtualPS = nullptr;
5131
5132 return;
5133 }
5134
5135 //==============Save pad/canvas as a TeX file================================
5136 if (!title && (opt.Contains("tex") || opt.Contains("Standalone"))) {
5137 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5138
5139 Bool_t noScreen = kFALSE, wasModified = IsModified();
5140 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5141 noScreen = kTRUE;
5143 }
5144
5145 TContext ctxt(this, kTRUE);
5146
5147 if (!gVirtualPS) {
5148 // Plugin Postscript/SVG driver
5149 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "tex")) {
5150 if (h->LoadPlugin() == -1)
5151 return;
5152 h->ExecPlugin(0);
5153 }
5154 }
5155
5156 Bool_t standalone = kFALSE;
5157 if (strstr(opt,"Standalone")) standalone = kTRUE;
5158
5159 // Create a new TeX file
5160 if (gVirtualPS) {
5161 gVirtualPS->SetName(psname);
5162 if (standalone) gVirtualPS->SetTitle("Standalone");
5163 gVirtualPS->Open(psname);
5166 }
5167 Paint();
5168 if (noScreen)
5170 if (wasModified && !IsBatch())
5171 Modified(kTRUE);
5172
5173 if (!gSystem->AccessPathName(psname)) {
5174 if (standalone) {
5175 Info("Print", "Standalone TeX file %s has been created", psname.Data());
5176 } else{
5177 Info("Print", "TeX file %s has been created", psname.Data());
5178 }
5179 }
5180
5181 delete gVirtualPS;
5182 gVirtualPS = nullptr;
5183
5184 return;
5185 }
5186
5187 //==============Save pad/canvas as a Postscript file=========================
5188
5189 // in case we read directly from a Root file and the canvas
5190 // is not on the screen, set batch mode
5191
5192 Bool_t mustOpen = kTRUE, mustClose = kTRUE,
5193 copen = kFALSE, cclose = kFALSE, copenb = kFALSE, ccloseb = kFALSE;
5194 if (!image) {
5195 // The parenthesis mechanism is only valid for PS and PDF files.
5196 copen = psname.EndsWith("("); if (copen) psname[psname.Length()-1] = 0;
5197 cclose = psname.EndsWith(")"); if (cclose) psname[psname.Length()-1] = 0;
5198 copenb = psname.EndsWith("["); if (copenb) psname[psname.Length()-1] = 0;
5199 ccloseb = psname.EndsWith("]"); if (ccloseb) psname[psname.Length()-1] = 0;
5200 }
5201 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5202 if (gVirtualPS) mustOpen = mustClose = kFALSE;
5203 if (copen || copenb) mustClose = kFALSE;
5204 if (cclose || ccloseb) mustClose = kTRUE;
5205
5206 Bool_t noScreen = kFALSE, wasModified = IsModified();
5207 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5208 noScreen = kTRUE;
5210 }
5211 Int_t pstype = 111;
5212 Double_t xcanvas = GetCanvas()->XtoPixel(GetCanvas()->GetX2());
5213 Double_t ycanvas = GetCanvas()->YtoPixel(GetCanvas()->GetY1());
5214 Double_t ratio = ycanvas/xcanvas;
5215 if (ratio < 1) pstype = 112;
5216 if (strstr(opt,"Portrait")) pstype = 111;
5217 if (strstr(opt,"Landscape")) pstype = 112;
5218 if (strstr(opt,"eps")) pstype = 113;
5219 if (strstr(opt,"Preview")) pstype = 113;
5220
5221 TContext ctxt(this, kTRUE);
5222 TVirtualPS *psave = gVirtualPS;
5223
5224 if (!gVirtualPS || mustOpen) {
5225
5226 const char *pluginName = "ps"; // Plugin Postscript driver
5227 if (opt.Contains("pdf") || title || opt.Contains("EmbedFonts"))
5228 pluginName = "pdf";
5229 else if (image)
5230 pluginName = "image"; // Plugin TImageDump driver
5231
5232 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", pluginName)) {
5233 if (h->LoadPlugin() == -1)
5234 return;
5235 h->ExecPlugin(0);
5236 }
5237
5238 // Create a new Postscript, PDF or image file
5239 if (gVirtualPS)
5240 gVirtualPS->SetName(psname);
5241 const Ssiz_t titlePos = opt.Index("Title:");
5242 if (titlePos != kNPOS) {
5243 if (gVirtualPS)
5244 gVirtualPS->SetTitle(opt.Data()+titlePos+6);
5245 opt.Replace(titlePos,opt.Length(),"pdf");
5246 }
5247 if (gVirtualPS)
5248 gVirtualPS->Open(psname,pstype);
5249 if (gVirtualPS)
5251 if (!copenb) {
5252 if (!opt.Contains("pdf") || image) {
5254 }
5255 Paint();
5256 }
5257 if (noScreen) GetCanvas()->SetBatch(kFALSE);
5258
5259 if (mustClose) {
5260 gROOT->GetListOfSpecials()->Remove(gVirtualPS);
5261 delete gVirtualPS;
5262 gVirtualPS = psave;
5263 } else {
5264 gROOT->GetListOfSpecials()->Add(gVirtualPS);
5265 gVirtualPS = nullptr;
5266 }
5267
5268 if (!gSystem->AccessPathName(psname)) {
5269 if (!copen) Info("Print", "%s file %s has been created", opt.Data(), psname.Data());
5270 else Info("Print", "%s file %s has been created using the current canvas", opt.Data(), psname.Data());
5271 }
5272 } else {
5273 // Append to existing Postscript, PDF or GIF file
5274 if (!ccloseb) {
5276 Paint();
5277 }
5278 const Ssiz_t titlePos = opt.Index("Title:");
5279 if (titlePos != kNPOS) {
5280 gVirtualPS->SetTitle(opt.Data() + titlePos + 6);
5281 opt.Replace(titlePos, opt.Length(), "pdf");
5282 } else if (!ccloseb) {
5283 gVirtualPS->SetTitle("PDF");
5284 }
5285 if (mustClose) {
5286 if (cclose) Info("Print", "Current canvas added to %s file %s and file closed", opt.Data(), psname.Data());
5287 else Info("Print", "%s file %s has been closed", opt.Data(), psname.Data());
5288 gROOT->GetListOfSpecials()->Remove(gVirtualPS);
5289 delete gVirtualPS;
5290 gVirtualPS = nullptr;
5291 } else {
5292 Info("Print", "Current canvas added to %s file %s", opt.Data(), psname.Data());
5293 gVirtualPS = nullptr;
5294 }
5295 }
5296
5297 if (wasModified && !IsBatch())
5298 Modified(kTRUE);
5299
5300 if (opt.Contains("Preview"))
5301 gSystem->Exec(TString::Format("epstool --quiet -t6p %s %s", psname.Data(), psname.Data()).Data());
5302 if (opt.Contains("EmbedFonts")) {
5303 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",
5304 psname.Data()).Data());
5305 gSystem->Rename("pdf_temp.pdf", psname.Data());
5306 }
5307
5308}
5309
5310////////////////////////////////////////////////////////////////////////////////
5311/// Set world coordinate system for the pad.
5312/// Emits signal "RangeChanged()", in the slot get the range
5313/// via GetRange().
5314
5316{
5317 if ((x1 >= x2) || (y1 >= y2)) {
5318 Error("Range", "illegal world coordinates range: x1=%f, y1=%f, x2=%f, y2=%f",x1,y1,x2,y2);
5319 return;
5320 }
5321
5322 fUxmin = x1;
5323 fUxmax = x2;
5324 fUymin = y1;
5325 fUymax = y2;
5326
5327 if (fX1 == x1 && fY1 == y1 && fX2 == x2 && fY2 == y2) return;
5328
5329 fX1 = x1;
5330 fY1 = y1;
5331 fX2 = x2;
5332 fY2 = y2;
5333
5334 // compute pad conversion coefficients
5335 ResizePad();
5336
5337 if (gPad == this && GetPainter())
5339
5340 // emit signal
5341 RangeChanged();
5342}
5343
5344////////////////////////////////////////////////////////////////////////////////
5345/// Set axis coordinate system for the pad.
5346/// The axis coordinate system is a subset of the world coordinate system
5347/// xmin,ymin is the origin of the current coordinate system,
5348/// xmax is the end of the X axis, ymax is the end of the Y axis.
5349/// By default a margin of 10 per cent is left on all sides of the pad
5350/// Emits signal "RangeAxisChanged()", in the slot get the axis range
5351/// via GetRangeAxis().
5352
5354{
5355 if ((xmin >= xmax) || (ymin >= ymax)) {
5356 Error("RangeAxis", "illegal axis coordinates range: xmin=%f, ymin=%f, xmax=%f, ymax=%f",
5357 xmin, ymin, xmax, ymax);
5358 return;
5359 }
5360
5361 fUxmin = xmin;
5362 fUymin = ymin;
5363 fUxmax = xmax;
5364 fUymax = ymax;
5365
5366 // emit signal
5368}
5369
5370////////////////////////////////////////////////////////////////////////////////
5371/// Recursively remove object from a pad and its sub-pads.
5372
5374{
5375 if (fCanvas) {
5376 if (obj == fCanvas->GetSelected()) fCanvas->SetSelected(nullptr);
5377 if (obj == fCanvas->GetClickSelected()) fCanvas->SetClickSelected(nullptr);
5378 }
5379 if (obj == fView) fView = nullptr;
5380 if (!fPrimitives) return;
5381 Int_t nold = fPrimitives->GetSize();
5383 if (nold != fPrimitives->GetSize()) fModified = kTRUE;
5384}
5385
5386////////////////////////////////////////////////////////////////////////////////
5387/// Remove object from list of primitives
5388/// When \par modified set to kTRUE (default) pad will be marked as modified - if object really removed
5389/// Returns result of GetListOfPrimitives()->Remove(obj) or nullptr if list of primitives not exists
5390
5392{
5393 TObject *res = nullptr;
5394 if (fPrimitives)
5395 res = fPrimitives->Remove(obj);
5396 if (res && modified)
5397 Modified();
5398 return res;
5399}
5400
5401////////////////////////////////////////////////////////////////////////////////
5402/// Redraw the frame axis.
5403///
5404/// Redrawing axis may be necessary in case of superimposed histograms
5405/// when one or more histograms have a fill color.
5406///
5407/// Instead of calling this function, it may be more convenient
5408/// to call directly `h1->Draw("sameaxis")` where h1 is the pointer
5409/// to the first histogram drawn in the pad.
5410///
5411/// By default, if the pad has the options gridx or/and gridy activated,
5412/// the grid is not drawn by this function.
5413///
5414/// If option="g" is specified, this will force the drawing of the grid
5415/// on top of the picture
5416///
5417/// To redraw the axis tick marks do:
5418/// ~~~ {.cpp}
5419/// gPad->RedrawAxis();
5420/// ~~~
5421/// To redraw the axis grid do:
5422/// ~~~ {.cpp}
5423/// gPad->RedrawAxis("G");
5424/// ~~~
5425/// To redraw the axis tick marks and the axis grid do:
5426/// ~~~ {.cpp}
5427/// gPad->RedrawAxis();
5428/// gPad->RedrawAxis("G");
5429/// ~~~
5430///
5431/// If option="f" is specified, this will force the drawing of the frame
5432/// around the plot.
5433
5435{
5436 TString opt = option;
5437 opt.ToLower();
5438
5439 TContext ctxt(this, kTRUE);
5440
5441 TH1 *hobj = nullptr;
5442
5443 // Get the first histogram drawing the axis in the list of primitives
5444 if (!fPrimitives) fPrimitives = new TList;
5445 TIter next(fPrimitives);
5446 TObject *obj;
5447 while ((obj = next())) {
5448 if (obj->InheritsFrom(TH1::Class())) {
5449 hobj = (TH1*)obj;
5450 break;
5451 }
5452 if (obj->InheritsFrom(TMultiGraph::Class())) {
5453 TMultiGraph *mg = (TMultiGraph*)obj;
5454 if (mg) hobj = mg->GetHistogram();
5455 break;
5456 }
5457 if (obj->InheritsFrom(TGraph::Class())) {
5458 TGraph *g = (TGraph*)obj;
5459 if (g) hobj = g->GetHistogram();
5460 break;
5461 }
5462 if (obj->InheritsFrom(THStack::Class())) {
5463 THStack *hs = (THStack*)obj;
5464 if (hs) hobj = hs->GetHistogram();
5465 break;
5466 }
5467 }
5468
5469 if (hobj) {
5470 if (opt.Contains("g")) hobj->DrawCopy("sameaxig");
5471 else hobj->DrawCopy("sameaxis");
5472 }
5473
5474 if (opt.Contains("f")) {
5475 auto b = new TBox(gPad->GetUxmin(), gPad->GetUymin(),
5476 gPad->GetUxmax(), gPad->GetUymax());
5477 b->SetFillStyle(0);
5478 b->SetLineStyle(gPad->GetFrameLineStyle());
5479 b->SetLineWidth(gPad->GetFrameLineWidth());
5480 b->SetLineColor(gPad->GetFrameLineColor());
5481 b->Draw();
5482 }
5483}
5484
5485////////////////////////////////////////////////////////////////////////////////
5486/// Compute pad conversion coefficients.
5487///
5488/// ### Conversion from x to px
5489///
5490/// \f[\frac{x-xmin}{xrange} = \frac{px-pxlow}{pxrange}\f]
5491/// with:
5492/// \f[ xrange = xmax-xmin \f]
5493/// \f[ pxrange = pxmax-pxmin \f]
5494///
5495/// \f[
5496/// \Rightarrow px = \frac{pxrange(x-xmin)}{xrange} + pxlow = fXtoPixelk + fXtoPixel \times x
5497/// \f]
5498///
5499/// \f[
5500/// \Rightarrow fXtoPixelk = pxlow - pxrange \frac{xmin}{xrange}
5501/// \f]
5502/// \f[
5503/// fXtoPixel = \frac{pxrange}{xrange}
5504/// \f]
5505/// where:
5506/// \f[
5507/// pxlow = fAbsXlowNDC \times fCw
5508/// \f]
5509/// \f[
5510/// pxrange = fAbsWNDC \times fCw
5511/// \f]
5512///
5513/// ### Conversion from y to py
5514///
5515/// \f[\frac{y-ymin}{yrange} = \frac{py-pylow}{pyrange}\f]
5516/// with:
5517/// \f[ yrange = ymax-ymin \f]
5518/// \f[ pyrange = pymax-pymin \f]
5519///
5520/// \f[
5521/// \Rightarrow py = \frac{pyrange(y-xmin)}{yrange} + pylow = fYtoPixelk + fYtoPixel \times y
5522/// \f]
5523///
5524/// \f[
5525/// \Rightarrow fYtoPixelk = pylow - pyrange \frac{ymin}{yrange}
5526/// \f]
5527/// \f[
5528/// fYtoPixel = \frac{pyrange}{yrange}
5529/// \f]
5530/// where:
5531/// \f[
5532/// pylow = fAbsYlowNDC \times fCh
5533/// \f]
5534/// \f[
5535/// pyrange = fAbsHNDC \times fCh
5536/// \f]
5537///
5538/// ### Conversion from px to x
5539///
5540/// \f[
5541/// \Rightarrow x = \frac{xrange(px-pxlow)}{pxrange}+ xmin = fPixeltoXk + fPixeltoX \times px
5542/// \f]
5543///
5544/// \f[
5545/// \Rightarrow fPixeltoXk = xmin - pxlow \times\frac{xrange}{pxrange}
5546/// \f]
5547/// \f[
5548/// fPixeltoX = \frac{xrange}{pxrange}
5549/// \f]
5550///
5551/// ### Conversion from py to y
5552///
5553/// \f[
5554/// \Rightarrow y = \frac{yrange(py-pylow)}{pyrange}+ ymin = fPixeltoYk + fPixeltoY \times py
5555/// \f]
5556///
5557/// \f[
5558/// \Rightarrow fPixeltoYk = ymin - pylow \times\frac{yrange}{pyrange}
5559/// \f]
5560/// \f[
5561/// fPixeltoY = \frac{yrange}{pyrange}
5562/// \f]
5563///
5564/// ### Computation of the coefficients in case of LOG scales
5565///
5566/// #### Conversion from pixel coordinates to world coordinates
5567///
5568/// \f[
5569/// u = \frac{Log(x) - Log(xmin)}{Log(xmax) - Log(xmin)} = \frac{Log(x/xmin)}{Log(xmax/xmin)} = \frac{px - pxlow}{pxrange}
5570/// \f]
5571///
5572/// \f[ \Rightarrow Log(\frac{x}{xmin}) = u \times Log(\frac{xmax}{xmin}) \f]
5573/// \f[ x = xmin \times e^{(u \times Log(\frac{xmax}{xmin})} \f]
5574/// Let:
5575/// \f[ alfa = \frac{Log(\frac{xmax}{xmin})}{fAbsWNDC} \f]
5576///
5577/// \f[ x = xmin \times e^{(-alfa \times pxlow)} + e^{(alfa \times px)} \f]
5578/// \f[ x = fPixeltoXk \times e^{(fPixeltoX \times px)} \f]
5579/// \f[ ==> fPixeltoXk = xmin \times e^{(-alfa*pxlow)} \f]
5580/// \f[ fPixeltoX = alfa \f]
5581///
5582/// \f[
5583/// v = \frac{Log(y) - Log(ymin)}{Log(ymax) - Log(ymin)} = \frac{Log(y/ymin)}{Log(ymax/ymin)} = \frac{py - pylow}{pyrange}
5584/// \f]
5585/// Let:
5586/// \f[ beta = Log(\frac{ymax}{ymin}) \f]
5587/// \f[ Log(\frac{y}{ymin}) = beta \times pylow - beta \times py \f]
5588/// \f[ \frac{y}{ymin} = e^{(beta \times pylow - beta \times py)} \f]
5589/// \f[ y = ymin \times e^{(beta \times pylow)} \times e^{(-beta \times py)}\f]
5590/// \f[ \Rightarrow y = fPixeltoYk \times e^{(fPixeltoY \times py)} \f]
5591/// \f[ fPixeltoYk = ymin \times e^{(beta \times pylow)} \f]
5592/// \f[ fPixeltoY = -beta \f]
5593///
5594/// #### Conversion from World coordinates to pixel coordinates
5595///
5596/// \f[ px = pxlow + u*pxrange \f]
5597/// \f[ = pxlow + Log(x/xmin)/alfa \f]
5598/// \f[ = pxlow -Log(xmin)/alfa + Log(x)/alfa \f]
5599/// \f[ = fXtoPixelk + fXtoPixel*Log(x) \f]
5600/// \f[ \Rightarrow fXtoPixelk = pxlow -Log(xmin)/alfa \f]
5601/// \f[ \Rightarrow fXtoPixel = 1/alfa \f]
5602///
5603/// \f[ py = pylow - Log(y/ymin)/beta \f]
5604/// \f[ = fYtoPixelk + fYtoPixel*Log(y) \f]
5605/// \f[ \Rightarrow fYtoPixelk = pylow - Log(ymin)/beta \f]
5606/// \f[ fYtoPixel = 1/beta \f]
5607
5609{
5610
5611 if (!gPad) {
5612 Error("ResizePad", "Cannot resize pad. No current pad available.");
5613 return;
5614 }
5615 if (gPad->GetWw()==0.0||gPad->GetWh()==0.0) {
5616 Warning("ResizePad", "gPad has at least one zero dimension.");
5617 return;
5618 }
5619 if (fX1==fX2||fY1==fY2) {
5620 Warning("ResizePad", "The pad has at least one zero dimension.");
5621 return;
5622 }
5623 // Recompute subpad positions in case pad has been moved/resized
5624 TPad *parent = fMother;
5625 if (this == gPad->GetCanvas()) {
5628 fAbsWNDC = fWNDC;
5629 fAbsHNDC = fHNDC;
5630 }
5631 else {
5632 if (parent->GetAbsHNDC()==0.0||parent->GetAbsWNDC()==0.0||fHNDC==0.0||fWNDC==0.0) {
5633 Warning("ResizePad", "The parent pad has at least one zero dimension.");
5634 return;
5635 }
5636 fAbsXlowNDC = fXlowNDC*parent->GetAbsWNDC() + parent->GetAbsXlowNDC();
5637 fAbsYlowNDC = fYlowNDC*parent->GetAbsHNDC() + parent->GetAbsYlowNDC();
5638 fAbsWNDC = fWNDC*parent->GetAbsWNDC();
5639 fAbsHNDC = fHNDC*parent->GetAbsHNDC();
5640 }
5641
5642 Double_t ww = (Double_t)gPad->GetWw();
5643 Double_t wh = (Double_t)gPad->GetWh();
5644 Double_t pxlow = fAbsXlowNDC*ww;
5645 Double_t pylow = (1-fAbsYlowNDC)*wh;
5646 Double_t pxrange = fAbsWNDC*ww;
5647 Double_t pyrange = -fAbsHNDC*wh;
5648
5649 // Linear X axis
5650 Double_t rounding = 0.; // was used before to adjust somehow wrong int truncation by coordinates transformation
5651 Double_t xrange = fX2 - fX1;
5652 fXtoAbsPixelk = rounding + pxlow - pxrange*fX1/xrange; //origin at left
5653 fXtoPixelk = rounding + -pxrange*fX1/xrange;
5654 fXtoPixel = pxrange/xrange;
5655 fAbsPixeltoXk = fX1 - pxlow*xrange/pxrange;
5656 fPixeltoXk = fX1;
5657 fPixeltoX = xrange/pxrange;
5658 // Linear Y axis
5659 Double_t yrange = fY2 - fY1;
5660 fYtoAbsPixelk = rounding + pylow - pyrange*fY1/yrange; //origin at top
5661 fYtoPixelk = rounding + -pyrange - pyrange*fY1/yrange;
5662 fYtoPixel = pyrange/yrange;
5663 fAbsPixeltoYk = fY1 - pylow*yrange/pyrange;
5664 fPixeltoYk = fY1;
5665 fPixeltoY = yrange/pyrange;
5666
5667 // Coefficients to convert from pad NDC coordinates to pixel coordinates
5668
5669 fUtoAbsPixelk = rounding + pxlow;
5670 fUtoPixelk = rounding;
5671 fUtoPixel = pxrange;
5672 fVtoAbsPixelk = rounding + pylow;
5673 fVtoPixelk = -pyrange;
5674 fVtoPixel = pyrange;
5675
5676 // Coefficients to convert from canvas pixels to pad world coordinates
5677
5678 // Resize all sub-pads
5679 if (!fPrimitives)
5680 fPrimitives = new TList;
5681 TIter next(GetListOfPrimitives());
5682 while (auto obj = next()) {
5683 if (obj->InheritsFrom(TPad::Class()))
5684 ((TPad *)obj)->ResizePad(option);
5685 }
5686
5687 // Reset all current sizes
5688 if (gPad->IsBatch())
5689 fPixmapID = 0;
5690 else if (auto pp = GetPainter()) {
5691 if (pp->IsNative()) {
5692 // TODO: check if this is necessary
5693 auto attl = pp->GetAttLine();
5694 attl.SetLineColor(-1);
5695 pp->SetAttLine(attl);
5696 auto attt = pp->GetAttText();
5697 attt.SetTextSize(-1);
5698 pp->OnPad(this);
5699 pp->SetAttText(attt);
5700 // create or re-create off-screen pixmap
5701 if (fPixmapID) {
5702 int w = TMath::Abs(XtoPixel(fX2) - XtoPixel(fX1));
5703 int h = TMath::Abs(YtoPixel(fY2) - YtoPixel(fY1));
5704 //protection in case of wrong pad parameters.
5705 //without this protection, the OpenPixmap or ResizePixmap crashes with
5706 //the message "Error in <RootX11ErrorHandler>: BadValue (integer parameter out of range for operation)"
5707 //resulting in a frozen xterm
5710 Warning("ResizePad", "Inf/NaN propagated to the pad. Check drawn objects.");
5711 if (w <= 0 || w > 10000) {
5712 Warning("ResizePad", "%s width changed from %d to %d\n",GetName(),w,10);
5713 w = 10;
5714 }
5715 if (h <= 0 || h > 10000) {
5716 Warning("ResizePad", "%s height changed from %d to %d\n",GetName(),h,10);
5717 h = 10;
5718 }
5719 if (fPixmapID == -1) // this case is handled via the ctor
5720 fPixmapID = pp->CreateDrawable(w, h);
5721 else if (pp->ResizeDrawable(fPixmapID, w, h)) {
5722 Resized();
5723 Modified(kTRUE);
5724 }
5725 }
5726 }
5727 }
5728 if (fView) {
5729 if (gPad == this) {
5730 fView->ResizePad();
5731 } else {
5732 TContext ctxt(this, kTRUE);
5733 fView->ResizePad();
5734 }
5735 }
5736}
5737
5738////////////////////////////////////////////////////////////////////////////////
5739/// Save the pad content in a file.
5740///
5741/// The file's format used to save the pad is determined by the `filename` extension:
5742///
5743/// - if `filename` is empty, the file produced is `padname.ps`
5744/// - if `filename` starts with a dot, the padname is added in front
5745/// - if `filename` ends with `.ps`, a Postscript file is produced
5746/// - if `filename` ends with `.eps`, an Encapsulated Postscript file is produced
5747/// - 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.
5748/// - if `filename` ends with `.svg`, a SVG file is produced
5749/// - if `filename` ends with `.tex`, a TeX file is produced
5750/// - if `filename` ends with `.gif`, a GIF file is produced
5751/// - 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
5752/// - if `filename` ends with `.xpm`, a XPM file is produced
5753/// - if `filename` ends with `.png`, a PNG file is produced
5754/// - if `filename` ends with `.bmp`, a BMP file is produced
5755/// - if `filename` ends with `.jpg` or `.jpeg` a JPEG file is produced NOTE: JPEG's lossy compression will make all sharp edges fuzzy.
5756/// - if `filename` ends with `.tiff`, a TIFF file is produced
5757/// - if `filename` ends with `.C`, `.cxx`,`.cpp` or `.cc`, a C++ macro file is produced
5758/// - if `filename` ends with `.root`, a Root file is produced
5759/// - if `filename` ends with `.xml`, a XML file is produced
5760/// - if `filename` ends with `.json`, a JSON file is produced
5761///
5762/// \remarks
5763/// - The parameter `option` is not used.
5764/// - This method calls [TPad::Print(const char *filename, Option_t *option)](\ref TPadPrint)
5765/// the value of `option` is determined by the `filename` extension.
5766/// - Postscript and PDF formats allow to have [several pictures in one file](\ref TPadPrintPS).
5767
5768void TPad::SaveAs(const char *filename, Option_t * /*option*/) const
5769{
5770 TString psname;
5771 Int_t lenfil = filename ? strlen(filename) : 0;
5772
5773 if (!lenfil) { psname = GetName(); psname.Append(".ps"); }
5774 else psname = filename;
5775
5776 // lines below protected against case like c1->SaveAs( "../ps/cs.ps" );
5777 if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
5778 psname = GetName();
5779 psname.Append(filename);
5780 psname.Prepend("/");
5781 psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
5782 }
5783
5784 if (psname.EndsWith(".gif"))
5785 ((TPad*)this)->Print(psname,"gif");
5786 else if (psname.Contains(".gif+"))
5787 ((TPad*)this)->Print(psname,"gif+");
5788 else if (psname.EndsWith(".C") || psname.EndsWith(".cxx") || psname.EndsWith(".cpp") || psname.EndsWith(".cc"))
5789 ((TPad*)this)->Print(psname,"cxx");
5790 else if (psname.EndsWith(".root"))
5791 ((TPad*)this)->Print(psname,"root");
5792 else if (psname.EndsWith(".xml"))
5793 ((TPad*)this)->Print(psname,"xml");
5794 else if (psname.EndsWith(".json"))
5795 ((TPad*)this)->Print(psname,"json");
5796 else if (psname.EndsWith(".html"))
5797 ((TPad*)this)->Print(psname,"html");
5798 else if (psname.EndsWith(".eps"))
5799 ((TPad*)this)->Print(psname,"eps");
5800 else if (psname.EndsWith(".pdf") || psname.EndsWith(".pdf[") || psname.EndsWith(".pdf]") || psname.EndsWith(".pdf("))
5801 ((TPad*)this)->Print(psname,"pdf");
5802 else if (psname.EndsWith(".svg"))
5803 ((TPad*)this)->Print(psname,"svg");
5804 else if (psname.EndsWith(".tex"))
5805 ((TPad*)this)->Print(psname,"tex");
5806 else if (psname.EndsWith(".xpm"))
5807 ((TPad*)this)->Print(psname,"xpm");
5808 else if (psname.EndsWith(".png"))
5809 ((TPad*)this)->Print(psname,"png");
5810 else if (psname.EndsWith(".jpg") || psname.EndsWith(".jpeg"))
5811 ((TPad*)this)->Print(psname,"jpg");
5812 else if (psname.EndsWith(".bmp"))
5813 ((TPad*)this)->Print(psname,"bmp");
5814 else if (psname.EndsWith(".tiff"))
5815 ((TPad*)this)->Print(psname,"tiff");
5816 else
5817 ((TPad*)this)->Print(psname,"ps");
5818}
5819
5820////////////////////////////////////////////////////////////////////////////////
5821/// Save primitives in this pad on the C++ source file out.
5822
5823void TPad::SavePrimitive(std::ostream &out, Option_t * option /*= ""*/)
5824{
5825 TContext ctxt(this, kFALSE); // not interactive
5826
5827 TString padName = GetName();
5828
5829 // check for space in the pad name
5830 auto p = padName.Index(" ");
5831 if (p != kNPOS)
5832 padName.Resize(p);
5833
5834 TString opt = option;
5835 if (!opt.Contains("toplevel")) {
5836 static Int_t pcounter = 0;
5837 padName += TString::Format("__%d", pcounter++);
5838 padName = gInterpreter->MapCppName(padName);
5839 }
5840
5841 const char *pname = padName.Data();
5842 const char *cname = padName.Data();
5843
5844 if (padName.Length() == 0) {
5845 pname = "unnamed";
5846 if (this == gPad->GetCanvas())
5847 cname = "c1";
5848 else
5849 cname = "pad";
5850 }
5851
5852 // Write pad parameters
5853 if (this != gPad->GetCanvas()) {
5854 out << " \n";
5855 out << "// ------------>Primitives in pad: " << GetName() << "\n";
5856 out << " TPad *" << cname << " = new TPad(\"" << GetName() << "\", \""
5857 << TString(GetTitle()).ReplaceSpecialCppChars() << "\", " << fXlowNDC << ", " << fYlowNDC << ", "
5858 << fXlowNDC + fWNDC << ", " << fYlowNDC + fHNDC << ");\n";
5859 out << " " << cname << "->Draw();\n";
5860 out << " " << cname << "->cd();\n";
5861 }
5862 out << " " << cname << "->Range(" << fX1 << "," << fY1 << "," << fX2 << "," << fY2 << ");\n";
5863 TView *view = GetView();
5864 if (view) {
5865 Double_t rmin[3], rmax[3];
5866 view->GetRange(rmin, rmax);
5867 out << " TView::CreateView(1)->SetRange(" << rmin[0] << ", " << rmin[1] << ", " << rmin[2] << ", " << rmax[0]
5868 << ", " << rmax[1] << ", " << rmax[2] << ");\n";
5869 }
5870
5871 SaveFillAttributes(out, cname, -1, -1);
5872
5873 if (GetBorderMode() != 1)
5874 out << " " << cname << "->SetBorderMode(" << GetBorderMode() << ");\n";
5875 if (GetBorderSize() != 4)
5876 out << " " << cname << "->SetBorderSize(" << GetBorderSize() << ");\n";
5877 if (GetLogx())
5878 out << " " << cname << "->SetLogx();\n";
5879 if (GetLogy())
5880 out << " " << cname << "->SetLogy();\n";
5881 if (GetLogz())
5882 out << " " << cname << "->SetLogz();\n";
5883 if (GetGridx())
5884 out << " " << cname << "->SetGridx();\n";
5885 if (GetGridy())
5886 out << " " << cname << "->SetGridy();\n";
5887 if (GetTickx())
5888 out << " " << cname << "->SetTickx(" << GetTickx() << ");\n";
5889 if (GetTicky())
5890 out << " " << cname << "->SetTicky(" << GetTicky() << ");\n";
5891 if (GetTheta() != 30)
5892 out << " " << cname << "->SetTheta(" << GetTheta() << ");\n";
5893 if (GetPhi() != 30)
5894 out << " " << cname << "->SetPhi(" << GetPhi() << ");\n";
5895 if (TMath::Abs(fLeftMargin - 0.1) > 0.01)
5896 out << " " << cname << "->SetLeftMargin(" << GetLeftMargin() << ");\n";
5897 if (TMath::Abs(fRightMargin - 0.1) > 0.01)
5898 out << " " << cname << "->SetRightMargin(" << GetRightMargin() << ");\n";
5899 if (TMath::Abs(fTopMargin - 0.1) > 0.01)
5900 out << " " << cname << "->SetTopMargin(" << GetTopMargin() << ");\n";
5901 if (TMath::Abs(fBottomMargin - 0.1) > 0.01)
5902 out << " " << cname << "->SetBottomMargin(" << GetBottomMargin() << ");\n";
5903
5905 out << " " << cname << "->SetFrameFillColor(" << TColor::SavePrimitiveColor(GetFrameFillColor()) << ");\n";
5906 if (GetFrameFillStyle() != 1001)
5907 out << " " << cname << "->SetFrameFillStyle(" << GetFrameFillStyle() << ");\n";
5908 if (GetFrameLineStyle() != 1)
5909 out << " " << cname << "->SetFrameLineStyle(" << GetFrameLineStyle() << ");\n";
5910 if (GetFrameLineColor() != 1)
5911 out << " " << cname << "->SetFrameLineColor(" << TColor::SavePrimitiveColor(GetFrameLineColor()) << ");\n";
5912 if (GetFrameLineWidth() != 1)
5913 out << " " << cname << "->SetFrameLineWidth(" << GetFrameLineWidth() << ");\n";
5914 if (GetFrameBorderMode() != 0)
5915 out << " " << cname << "->SetFrameBorderMode(" << GetFrameBorderMode() << ");\n";
5916 if (GetFrameBorderSize() != 1)
5917 out << " " << cname << "->SetFrameBorderSize(" << GetFrameBorderSize() << ");\n";
5918
5919 TFrame *frame = fFrame;
5920 if (!frame)
5921 frame = (TFrame *)GetPrimitive("TFrame");
5922 if (frame) {
5923 if (frame->GetFillColor() != GetFillColor())
5924 out << " " << cname << "->SetFrameFillColor(" << TColor::SavePrimitiveColor(frame->GetFillColor()) << ");\n";
5925 if (frame->GetFillStyle() != 1001)
5926 out << " " << cname << "->SetFrameFillStyle(" << frame->GetFillStyle() << ");\n";
5927 if (frame->GetLineStyle() != 1)
5928 out << " " << cname << "->SetFrameLineStyle(" << frame->GetLineStyle() << ");\n";
5929 if (frame->GetLineColor() != 1)
5930 out << " " << cname << "->SetFrameLineColor(" << TColor::SavePrimitiveColor(frame->GetLineColor()) << ");\n";
5931 if (frame->GetLineWidth() != 1)
5932 out << " " << cname << "->SetFrameLineWidth(" << frame->GetLineWidth() << ");\n";
5933 if (frame->GetBorderMode() != 0)
5934 out << " " << cname << "->SetFrameBorderMode(" << frame->GetBorderMode() << ");\n";
5935 if (frame->GetBorderSize() != 1)
5936 out << " " << cname << "->SetFrameBorderSize(" << frame->GetBorderSize() << ");\n";
5937 }
5938
5939 TIter next(GetListOfPrimitives());
5940
5941 while (auto obj = next()) {
5942 obj->SavePrimitive(out, (Option_t *)next.GetOption());
5943 if (obj->InheritsFrom(TPad::Class())) {
5944 if (opt.Contains("toplevel"))
5945 out << " " << pname << "->cd();\n";
5946 else
5947 out << " " << cname << "->cd();\n";
5948 }
5949 }
5950 out << " " << cname << "->Modified();\n";
5951}
5952
5953////////////////////////////////////////////////////////////////////////////////
5954/// Fix pad aspect ratio to current value if fixed is true.
5955
5957{
5958 if (fixed) {
5959 if (!fFixedAspectRatio) {
5960 if (fHNDC != 0.)
5962 else {
5963 Error("SetAspectRatio", "cannot fix aspect ratio, height of pad is 0");
5964 return;
5965 }
5967 }
5968 } else {
5970 fAspectRatio = 0;
5971 }
5972}
5973
5974////////////////////////////////////////////////////////////////////////////////
5975/// Set pad editable yes/no
5976/// If a pad is not editable:
5977/// - one cannot modify the pad and its objects via the mouse.
5978/// - one cannot add new objects to the pad
5979
5981{
5982 fEditable = mode;
5983
5984 TObject *obj;
5985 if (!fPrimitives) fPrimitives = new TList;
5986 TIter next(GetListOfPrimitives());
5987 while ((obj = next())) {
5988 if (obj->InheritsFrom(TPad::Class())) {
5989 TPad *pad = (TPad*)obj;
5990 pad->SetEditable(mode);
5991 }
5992 }
5993}
5994
5995////////////////////////////////////////////////////////////////////////////////
5996/// Override TAttFill::FillStyle for TPad because we want to handle style=0
5997/// as style 4000.
5998
6000{
6001 if (fstyle == 0) fstyle = 4000;
6002 TAttFill::SetFillStyle(fstyle);
6003}
6004
6005////////////////////////////////////////////////////////////////////////////////
6006/// Set Lin/Log scale for X
6007/// - value = 0 X scale will be linear
6008/// - value = 1 X scale will be logarithmic (base 10)
6009/// - value > 1 reserved for possible support of base e or other
6010
6012{
6013 fLogx = value;
6014 delete fView; fView = nullptr;
6015 Modified();
6017}
6018
6019////////////////////////////////////////////////////////////////////////////////
6020/// Set Lin/Log scale for Y
6021/// - value = 0 Y scale will be linear
6022/// - value = 1 Y scale will be logarithmic (base 10)
6023/// - value > 1 reserved for possible support of base e or other
6024
6026{
6027 fLogy = value;
6028 delete fView; fView = nullptr;
6029 Modified();
6031}
6032
6033////////////////////////////////////////////////////////////////////////////////
6034/// Set Lin/Log scale for Z
6035
6037{
6038 fLogz = value;
6039 delete fView; fView = nullptr;
6040 Modified();
6042}
6043
6044////////////////////////////////////////////////////////////////////////////////
6045/// Set canvas range for pad and resize the pad. If the aspect ratio
6046/// was fixed before the call it will be un-fixed.
6047
6049{
6050 // Reorder points to make sure xlow,ylow is bottom left point and
6051 // xup,yup is top right point.
6052 if (xup < xlow) {
6053 Double_t x = xlow;
6054 xlow = xup;
6055 xup = x;
6056 }
6057 if (yup < ylow) {
6058 Double_t y = ylow;
6059 ylow = yup;
6060 yup = y;
6061 }
6062
6063 // Check if the new pad position is valid.
6064 if ((xlow < 0) || (xlow > 1) || (ylow < 0) || (ylow > 1)) {
6065 Error("TPad", "illegal bottom left position: x=%f, y=%f", xlow, ylow);
6066 return;
6067 }
6068 if ((xup < 0) || (xup > 1) || (yup < 0) || (yup > 1)) {
6069 Error("TPad", "illegal top right position: x=%f, y=%f", xup, yup);
6070 return;
6071 }
6072 if (xup-xlow <= 0) {
6073 Error("TPad", "illegal width: %f", xup-xlow);
6074 return;
6075 }
6076 if (yup-ylow <= 0) {
6077 Error("TPad", "illegal height: %f", yup-ylow);
6078 return;
6079 }
6080
6081 fXlowNDC = xlow;
6082 fYlowNDC = ylow;
6083 fXUpNDC = xup;
6084 fYUpNDC = yup;
6085 fWNDC = xup - xlow;
6086 fHNDC = yup - ylow;
6087
6089
6090 ResizePad();
6091}
6092
6093////////////////////////////////////////////////////////////////////////////////
6094/// Set all pad parameters.
6095
6096void TPad::SetPad(const char *name, const char *title,
6097 Double_t xlow, Double_t ylow, Double_t xup, Double_t yup,
6098 Color_t color, Short_t bordersize, Short_t bordermode)
6099{
6100 fName = name;
6101 fTitle = title;
6102 SetFillStyle(1001);
6107 if (color >= 0) SetFillColor(color);
6109 if (bordersize < 0) fBorderSize = gStyle->GetPadBorderSize();
6110 else fBorderSize = bordersize;
6111 if (bordermode < -1) fBorderMode = gStyle->GetPadBorderMode();
6112 else fBorderMode = bordermode;
6113
6114 SetPad(xlow, ylow, xup, yup);
6115}
6116
6117////////////////////////////////////////////////////////////////////////////////
6118/// Set the current TView. Delete previous view if view=0
6119
6121{
6122 if (!view) delete fView;
6123 fView = view;
6124}
6125
6126////////////////////////////////////////////////////////////////////////////////
6127/// Set postscript fill area attributes.
6128///
6129/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6130
6132{
6133 if (auto pp = GetPainter())
6134 if (pp->GetPS())
6135 pp->SetAttFill({color, style});
6136}
6137
6138////////////////////////////////////////////////////////////////////////////////
6139/// Set postscript line attributes.
6140///
6141/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6142
6144{
6145 if (auto pp = GetPainter())
6146 if (pp->GetPS())
6147 pp->SetAttLine({color, style, lwidth});
6148}
6149
6150////////////////////////////////////////////////////////////////////////////////
6151/// Set postscript marker attributes.
6152///
6153/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6154
6156{
6157 if (auto pp = GetPainter())
6158 if (pp->GetPS())
6159 pp->SetAttMarker({color, style, msize});
6160}
6161
6162////////////////////////////////////////////////////////////////////////////////
6163/// Set postscript text attributes.
6164///
6165/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6166
6168{
6169 if (auto pp = GetPainter())
6170 if (pp->GetPS()) {
6171 if (font % 10 > 2) {
6172 Float_t wh = (Float_t) XtoPixel(GetX2());
6173 Float_t hh = (Float_t) YtoPixel(GetY1());
6174 Float_t dy;
6175 if (wh < hh) {
6176 dy = AbsPixeltoX(Int_t(tsize)) - AbsPixeltoX(0);
6177 tsize = dy/(GetX2()-GetX1());
6178 } else {
6179 dy = AbsPixeltoY(0) - AbsPixeltoY(Int_t(tsize));
6180 tsize = dy/(GetY2()-GetY1());
6181 }
6182 }
6183 pp->OnPad(this);
6184 pp->SetAttText({align, angle, color, font, tsize});
6185 }
6186}
6187
6188////////////////////////////////////////////////////////////////////////////////
6189/// Draw Arrows to indicated equal distances of Objects with given BBoxes.
6190/// Used by ShowGuidelines
6191
6193{
6194 Int_t lineColor = TColor::GetColor(239, 202, 0);
6195 Int_t x1,x2,y1,y2;
6196 x1 = x2 = y1 = y2 = 0;
6197 if (mode == 'x') {
6198 if (aBBox.fX<bBBox.fX) {
6199 x1 = aBBox.fX+aBBox.fWidth;
6200 x2 = bBBox.fX;
6201 }
6202 else {
6203 x1 = bBBox.fX+bBBox.fWidth;
6204 x2 = aBBox.fX;
6205 }
6206
6207 if ((aBBox.fY > bBBox.fY) && (aBBox.fY + aBBox.fHeight < bBBox.fY + bBBox.fHeight))
6208 y1 = y2 = aBBox.fY + TMath::Nint(0.5*(Double_t)(aBBox.fHeight))+1;
6209 else if ((bBBox.fY > aBBox.fY) && (bBBox.fY + bBBox.fHeight < aBBox.fY + aBBox.fHeight))
6210 y1 = y2 = bBBox.fY + TMath::Nint(0.5*(Double_t)(bBBox.fHeight))+1;
6211 else if (aBBox.fY>bBBox.fY) y1 = y2 = aBBox.fY-TMath::Nint(0.5*(Double_t)(aBBox.fY-(bBBox.fY+bBBox.fHeight)));
6212 else y1 = y2 = bBBox.fY-TMath::Nint(0.5*(Double_t)(bBBox.fY-(aBBox.fY+aBBox.fHeight)));
6213 }
6214 else if (mode == 'y') {
6215 if (aBBox.fY<bBBox.fY) {
6216 y1 = aBBox.fY+aBBox.fHeight;
6217 y2 = bBBox.fY;
6218 }
6219 else {
6220 y1 = bBBox.fY+bBBox.fHeight;
6221 y2 = aBBox.fY;
6222 }
6223 if ((aBBox.fX > bBBox.fX) && (aBBox.fX + aBBox.fWidth < bBBox.fX + bBBox.fWidth))
6224 x1 = x2 = aBBox.fX + TMath::Nint(0.5*(Double_t)(aBBox.fWidth))+1;
6225 else if ((bBBox.fX > aBBox.fX) && (bBBox.fX + bBBox.fWidth < aBBox.fX + aBBox.fWidth))
6226 x1 = x2 = bBBox.fX + TMath::Nint(0.5*(Double_t)(bBBox.fWidth))+1;
6227 else if (aBBox.fX>bBBox.fX) x1 = x2 = aBBox.fX+TMath::Nint(0.5*(Double_t)(bBBox.fX+bBBox.fWidth-aBBox.fX));
6228 else x1 = x2 = bBBox.fX+TMath::Nint(0.5*(Double_t)(aBBox.fX+aBBox.fWidth-bBBox.fX));
6229 }
6230
6231 TArrow *A = new TArrow(gPad->PixeltoX(x1), gPad->PixeltoY(y1-gPad->VtoPixel(0)), gPad->PixeltoX(x2), gPad->PixeltoY(y2-gPad->VtoPixel(0)), 0.01, "<|>");
6232 A->SetBit(kCanDelete);
6233 A->SetFillColor(lineColor);
6234 A->SetLineWidth(1);
6235 A->SetLineColor(lineColor);
6236 A->Draw();
6237
6238 return;
6239}
6240
6241////////////////////////////////////////////////////////////////////////////////
6242/// struct used by ShowGuidelines to store the distance Field between objects
6243/// in the canvas.
6244
6245struct dField {
6249 char fdir;
6250
6251
6253 : fa(nullptr), fb(nullptr), fdist(0), fdir(' ')
6254 {}
6255
6256 dField(TAttBBox2D *a, TAttBBox2D *b, Int_t dist, char direction)
6257 : fa(a), fb(b), fdist(dist), fdir(direction)
6258 {}
6259};
6260
6261////////////////////////////////////////////////////////////////////////////////
6262/// Shows lines to indicate if a TAttBBox2D object is aligned to
6263/// the center or to another object, shows distance arrows if two
6264/// objects on screen have the same distance to another object
6265/// Call from primitive in Execute Event, in ButtonMotion after
6266/// the new coordinates have been set, to 'stick'
6267/// once when button is up to delete lines
6268///
6269/// modes: t (Top), b (bottom), l (left), r (right), i (inside)
6270/// in resize modes (t,b,l,r) only size arrows are sticky
6271///
6272/// in mode, the function gets the point on the element that is clicked to
6273/// move (i) or resize (all others). The expected values are:
6274/// \image html gpad_pad5.png
6275
6276void TPad::ShowGuidelines(TObject *object, const Int_t event, const char mode, const bool cling )
6277{
6278 // When the object is moved with arrow or when the ShowGuideLines flag
6279 // is off we do show guide lines.
6280 if ((event == kArrowKeyRelease) || (event == kArrowKeyPress) ||
6281 !gEnv->GetValue("Canvas.ShowGuideLines", 0)) return;
6282
6283 std::vector<dField> curDist;
6284 std::vector<dField> otherDist;
6285 Int_t pMX, pMY;
6286 Double_t MX, MY;
6287 Int_t threshold;
6288 TList *prims;
6289 UInt_t n;
6290 Rectangle_t aBBox, bBBox;
6291 aBBox = bBBox = Rectangle_t();
6292 TLine *L;
6293 TArrow *A;
6294 Int_t dSizeArrow = 12; // distance of arrows indicating same size from BBox in px
6295 Bool_t movedX, movedY; // make sure the current object is moved just once
6296 movedX = movedY = false;
6297 Bool_t resize = false; // indicates resize mode
6298 Bool_t log = gPad->GetLogx() || gPad->GetLogy();
6299 if (mode != 'i') resize = true;
6300
6301 TPad *is_pad = dynamic_cast<TPad *>( object );
6302
6303 TContext ctxt(kTRUE);
6304
6305 if (is_pad && is_pad->GetMother())
6306 is_pad->GetMother()->cd();
6307
6308 static TPad *tmpGuideLinePad = nullptr;
6309
6310 //delete all existing Guidelines and create new invisible pad
6311 if (tmpGuideLinePad) {
6312 ctxt.PadDeleted(tmpGuideLinePad);
6313 auto guidePadClicked = (object == tmpGuideLinePad); // in case of funny button click combination.
6314 tmpGuideLinePad->Delete();
6315 tmpGuideLinePad = nullptr;
6316 if (guidePadClicked) return;
6317 }
6318
6319 // Get Primitives
6320 prims = gPad->GetListOfPrimitives();
6321 n = TMath::Min(15,prims->GetSize());
6322 Int_t lineColor = TColor::GetColor(239, 202, 0);
6323
6324 TAttBBox2D *cur = dynamic_cast<TAttBBox2D *>( object );
6325 if (cur) {
6326 //create invisible TPad above gPad
6327 if (!tmpGuideLinePad){
6328 tmpGuideLinePad = new TPad("tmpGuideLinePad", "tmpGuideLinePad", 0, 0, 1, 1);
6329 Double_t x1, y1, x2, y2;
6330 gPad->GetRange(x1, y1, x2, y2);
6331 tmpGuideLinePad->Range(x1, y1, x2, y2);
6332 tmpGuideLinePad->SetFillStyle(0);
6333 tmpGuideLinePad->SetFillColor(0);
6334 tmpGuideLinePad->Draw();
6335 tmpGuideLinePad->cd();
6336 gPad->GetRange(x1, y1, x2, y2);
6337 }
6338 if (cling && !log) threshold = 7;
6339 else threshold = 1;
6340
6341 Rectangle_t BBox = cur->GetBBox();
6342 TPoint center = cur->GetBBoxCenter();
6343
6344 otherDist.clear();
6345 curDist.clear();
6346
6347 switch (event) {
6348
6349 case kButton1Down:
6350 case kButton1Motion:
6351 MX = gPad->GetX1() + 0.5 * (gPad->GetX2()-gPad->GetX1());
6352 MY = gPad->GetY1() + 0.5 * (gPad->GetY2()-gPad->GetY1());
6353 pMX = gPad->XtoPixel(MX);
6354 pMY = gPad->YtoPixel(MY);
6355 // Middlelines
6356 if (TMath::Abs(pMX-center.GetX())<threshold) {
6357 if (cling && (!resize)) {
6358 cur->SetBBoxCenterX(pMX);
6359 center = cur->GetBBoxCenter();
6360 BBox = cur->GetBBox();
6361 center = cur->GetBBoxCenter();
6362 }
6363 L = new TLine(MX, gPad->GetY1(), MX, gPad->GetY2());
6364 L->SetBit(kCanDelete);
6365 L->SetLineColor(lineColor);
6366 L->Draw();
6367 }
6368 if (TMath::Abs(pMY-center.GetY())<threshold) {
6369 if (cling && (!resize)) {
6370 cur->SetBBoxCenterY(pMY);
6371 center = cur->GetBBoxCenter();
6372 BBox = cur->GetBBox();
6373 center = cur->GetBBoxCenter();
6374 }
6375 L = new TLine(gPad->GetX1(), MY, gPad->GetX2(), MY);
6376 L->SetBit(kCanDelete);
6377 L->SetLineColor(lineColor);
6378 L->Draw();
6379 }
6380 // Alignment to other objects
6381 for (UInt_t i = 0; i<n; i++) {
6382 TAttBBox2D *other = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6383 if (other) {
6384 if (other != cur) {
6385 TPoint centerOther = other->GetBBoxCenter();
6386 if (TMath::Abs(center.GetX()-centerOther.GetX())<threshold) {
6387 if (cling && (!resize)) {
6388 cur->SetBBoxCenterX(centerOther.GetX());
6389 BBox = cur->GetBBox();
6390 center = cur->GetBBoxCenter();
6391 }
6392 L = new TLine(gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(center.GetY()-gPad->VtoPixel(0)),
6393 gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)));
6394 L->SetLineColor(lineColor);
6395 L->Draw();
6396 L->SetBit(kCanDelete);
6397 }
6398 if (TMath::Abs(center.GetY()-centerOther.GetY())<threshold) {
6399 if (cling && (!resize)) {
6400 cur->SetBBoxCenterY(centerOther.GetY());
6401 BBox = cur->GetBBox();
6402 center = cur->GetBBoxCenter();
6403 }
6404 L = new TLine(gPad->PixeltoX(center.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)),
6405 gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)));
6406 L->SetBit(kCanDelete);
6407 L->SetLineColor(lineColor);
6408 L->Draw();
6409 }
6410 }
6411 }
6412 }
6413 // Get Distances between objects
6414 for (UInt_t i = 0; i<n; i++) {
6415 TAttBBox2D *a = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6416 if (a) {
6417 aBBox = a->GetBBox();
6418 for (UInt_t j = i+1; j<n; j++) {
6419 TAttBBox2D *b = dynamic_cast<TAttBBox2D *>( prims->At(j) );
6420 if (b) {
6421 bBBox = b->GetBBox();
6422
6423 //only when bounding boxes overlap in x or y direction
6424 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
6425 if ((aBBox.fY+aBBox.fHeight<bBBox.fY)||(bBBox.fY+bBBox.fHeight<aBBox.fY)) {//No overlap in Y-direction required
6426 dField abDist = dField();
6427 if (aBBox.fY>bBBox.fY) abDist = dField(a, b, TMath::Abs(aBBox.fY-(bBBox.fY+bBBox.fHeight)), 'y');
6428 else abDist = dField(a, b, TMath::Abs(bBBox.fY-(aBBox.fY+aBBox.fHeight)), 'y');
6429 if ((b != cur)&&(a != cur)) otherDist.push_back(abDist);
6430 else curDist.push_back(abDist);
6431 }
6432 } 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
6433 if ((aBBox.fX+aBBox.fWidth<bBBox.fX)||(bBBox.fX+bBBox.fWidth<aBBox.fX)) {//No overlap in x-direction required
6434 dField abDist = dField();
6435 if (aBBox.fX>bBBox.fX) abDist = dField(a, b, TMath::Abs(aBBox.fX-(bBBox.fX+bBBox.fWidth)), 'x');
6436 else abDist = dField(a, b, TMath::Abs(bBBox.fX-(aBBox.fX+aBBox.fWidth)), 'x');
6437 if ((b != cur)&&(a != cur)) otherDist.push_back(abDist);
6438 else curDist.push_back(abDist);
6439 }
6440 }
6441 }
6442 }
6443 }
6444 }
6445 // Show equal distances
6446 for (UInt_t i = 0; i<curDist.size(); i++) {
6447 for (UInt_t j = 0; j<otherDist.size(); j++) {
6448 if ((curDist[i].fdir == otherDist[j].fdir) && (otherDist[j].fdir=='x') && (TMath::Abs(curDist[i].fdist-otherDist[j].fdist)<threshold)) {
6449 if (cling && (!movedX) && (!resize)) {
6450 if ((cur->GetBBoxCenter().fX < curDist[i].fb->GetBBoxCenter().fX)||(cur->GetBBoxCenter().fX < curDist[i].fa->GetBBoxCenter().fX))
6451 cur->SetBBoxCenterX(cur->GetBBoxCenter().fX - otherDist[j].fdist + curDist[i].fdist);
6452 else cur->SetBBoxCenterX(cur->GetBBoxCenter().fX + otherDist[j].fdist - curDist[i].fdist);
6453 movedX = true;
6454 }
6455 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'x');
6456 DrawDist(otherDist[j].fa->GetBBox(), otherDist[j].fb->GetBBox(), 'x');
6457 }
6458 if ((curDist[i].fdir == otherDist[j].fdir) && (otherDist[j].fdir=='y') && (TMath::Abs(curDist[i].fdist-otherDist[j].fdist)<threshold)) {
6459 if (cling && (!movedY) && (!resize)) {
6460 if ((cur->GetBBoxCenter().fY < curDist[i].fb->GetBBoxCenter().fY)||(cur->GetBBoxCenter().fY < curDist[i].fa->GetBBoxCenter().fY))
6461 cur->SetBBoxCenterY(cur->GetBBoxCenter().fY - otherDist[j].fdist + curDist[i].fdist);
6462 else cur->SetBBoxCenterY(cur->GetBBoxCenter().fY + otherDist[j].fdist - curDist[i].fdist);
6463 movedY = true;
6464 }
6465 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'y');
6466 DrawDist(otherDist[j].fa->GetBBox(), otherDist[j].fb->GetBBox(), 'y');
6467 }
6468 }
6469 for (UInt_t j = i; j<curDist.size(); j++) {
6470 if (i!=j) {
6471 if ((curDist[i].fdir == curDist[j].fdir) && (curDist[j].fdir=='x') && (TMath::Abs(curDist[i].fdist-curDist[j].fdist)<threshold)) {
6472 if (cling && (!movedX) && (!resize)) {
6473 if ((cur->GetBBoxCenter().fX < curDist[i].fb->GetBBoxCenter().fX)||(cur->GetBBoxCenter().fX < curDist[i].fa->GetBBoxCenter().fX))
6474 cur->SetBBoxCenterX(cur->GetBBoxCenter().fX - floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6475 else cur->SetBBoxCenterX(cur->GetBBoxCenter().fX + floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6476 }
6477 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'x');
6478 DrawDist(curDist[j].fa->GetBBox(), curDist[j].fb->GetBBox(), 'x');
6479 }
6480
6481 if ((curDist[i].fdir == curDist[j].fdir) && (curDist[j].fdir=='y') && (TMath::Abs(curDist[i].fdist-curDist[j].fdist)<threshold)) {
6482 if (cling && (!movedY) && (!resize)) {
6483 if ((cur->GetBBoxCenter().fY < curDist[i].fb->GetBBoxCenter().fY)||(cur->GetBBoxCenter().fY < curDist[i].fa->GetBBoxCenter().fY))
6484 cur->SetBBoxCenterY(cur->GetBBoxCenter().fY - floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6485 else cur->SetBBoxCenterY(cur->GetBBoxCenter().fY + floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6486 }
6487 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'y');
6488 DrawDist(curDist[j].fa->GetBBox(), curDist[j].fb->GetBBox(), 'y');
6489 }
6490 }
6491 }
6492 }
6493 if (resize) {
6494 // Show equal Sizes
6495 for (UInt_t i = 0; i<n; i++) {
6496 TAttBBox2D *a = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6497 if (a && (cur != a)) {
6498 aBBox = a->GetBBox();
6499
6500 if ((TMath::Abs(aBBox.fWidth - BBox.fWidth)<threshold) && (mode != 't') && (mode != 'b')) {
6501 if (cling) {
6502 if (mode == 'l') cur->SetBBoxX1(BBox.fX + BBox.fWidth - aBBox.fWidth);
6503 if (mode == 'r') cur->SetBBoxX2(BBox.fX + aBBox.fWidth);
6504 if ((mode == '1')||(mode == '4')) cur->SetBBoxX1(BBox.fX + BBox.fWidth - aBBox.fWidth);
6505 if ((mode == '2')||(mode == '3')) cur->SetBBoxX2(BBox.fX + aBBox.fWidth);
6506 BBox = cur->GetBBox();
6507 }
6508
6509 A = new TArrow(gPad->PixeltoX(aBBox.fX), gPad->PixeltoY(aBBox.fY-dSizeArrow-gPad->VtoPixel(0)),
6510 gPad->PixeltoX(aBBox.fX+aBBox.fWidth), gPad->PixeltoY(aBBox.fY-dSizeArrow-gPad->VtoPixel(0)), 0.01, "<|>");
6511 A->SetBit(kCanDelete);
6512 A->SetLineColor(lineColor);
6513 A->SetFillColor(lineColor);
6514 A->Draw();
6515
6516 A = new TArrow(gPad->PixeltoX(BBox.fX), gPad->PixeltoY(BBox.fY-dSizeArrow-gPad->VtoPixel(0)),
6517 gPad->PixeltoX(BBox.fX+BBox.fWidth), gPad->PixeltoY(BBox.fY-dSizeArrow-gPad->VtoPixel(0)), 0.01, "<|>");
6518 A->SetBit(kCanDelete);
6519 A->SetLineColor(lineColor);
6520 A->SetFillColor(lineColor);
6521 A->Draw();
6522 }
6523 if ((TMath::Abs(aBBox.fHeight - BBox.fHeight)<threshold) && (mode != 'r') && (mode != 'l')) {
6524 if (cling) {
6525 if (mode == 't') cur->SetBBoxY1(BBox.fY + BBox.fHeight - aBBox.fHeight);
6526 if (mode == 'b') cur->SetBBoxY2(BBox.fY + aBBox.fHeight);
6527 if ((mode == '1')||(mode == '2')) cur->SetBBoxY1(BBox.fY + BBox.fHeight - aBBox.fHeight);
6528 if ((mode == '3')||(mode == '4')) cur->SetBBoxY2(BBox.fY + aBBox.fHeight);
6529 BBox = cur->GetBBox();
6530 }
6531 A = new TArrow(gPad->PixeltoX(aBBox.fX-dSizeArrow), gPad->PixeltoY(aBBox.fY-gPad->VtoPixel(0)),
6532 gPad->PixeltoX(aBBox.fX-dSizeArrow), gPad->PixeltoY(aBBox.fY+aBBox.fHeight-gPad->VtoPixel(0)), 0.01, "<|>");
6533 A->SetBit(kCanDelete);
6534 A->SetLineColor(lineColor);
6535 A->SetFillColor(lineColor);
6536 A->Draw();
6537
6538 A = new TArrow(gPad->PixeltoX(BBox.fX-dSizeArrow), gPad->PixeltoY(BBox.fY-gPad->VtoPixel(0)),
6539 gPad->PixeltoX(BBox.fX-dSizeArrow), gPad->PixeltoY(BBox.fY+BBox.fHeight-gPad->VtoPixel(0)), 0.01, "<|>");
6540 A->SetBit(kCanDelete);
6541 A->SetLineColor(lineColor);
6542 A->SetFillColor(lineColor);
6543 A->Draw();
6544 }
6545 }
6546 }
6547 }
6548
6549 break;
6550
6551 case kButton1Up:
6552 if (tmpGuideLinePad) {
6553 // All the arrows and lines in that pad are also deleted because
6554 // they all have the bit kCanDelete on.
6555 tmpGuideLinePad->Delete();
6556 tmpGuideLinePad = nullptr;
6557 }
6558 break;
6559 }
6560 }
6561
6563}
6564
6565////////////////////////////////////////////////////////////////////////////////
6566/// Return kTRUE if the crosshair has been activated (via SetCrosshair).
6567
6569{
6570 return (Bool_t)GetCrosshair();
6571}
6572
6573////////////////////////////////////////////////////////////////////////////////
6574/// Return the crosshair type (from the mother canvas)
6575/// crosshair type = 0 means no crosshair.
6576
6578{
6579 if (this == (TPad*)fCanvas)
6580 return fCrosshair;
6581 return fCanvas ? fCanvas->GetCrosshair() : 0;
6582}
6583
6584////////////////////////////////////////////////////////////////////////////////
6585/// Set crosshair active/inactive.
6586/// - If crhair != 0, a crosshair will be drawn in the pad and its sub-pads.
6587/// - If the canvas crhair = 1 , the crosshair spans the full canvas.
6588/// - If the canvas crhair > 1 , the crosshair spans only the pad.
6589
6591{
6592 if (!fCanvas) return;
6593 fCrosshair = crhair;
6594 fCrosshairPos = 0;
6595
6596 if (this != (TPad*)fCanvas) fCanvas->SetCrosshair(crhair);
6597}
6598
6599////////////////////////////////////////////////////////////////////////////////
6600/// static function to set the maximum Pick Distance fgMaxPickDistance
6601/// This parameter is used in TPad::Pick to select an object if
6602/// its DistancetoPrimitive returns a value < fgMaxPickDistance
6603/// The default value is 5 pixels. Setting a smaller value will make
6604/// picking more precise but also more difficult
6605
6607{
6608 fgMaxPickDistance = maxPick;
6609}
6610
6611////////////////////////////////////////////////////////////////////////////////
6612/// Set tool tip text associated with this pad. The delay is in
6613/// milliseconds (minimum 250). To remove tool tip call method with
6614/// text = 0.
6615
6616void TPad::SetToolTipText(const char *text, Long_t delayms)
6617{
6618 if (fTip) {
6620 fTip = nullptr;
6621 }
6622
6623 if (text && strlen(text))
6624 fTip = CreateToolTip((TBox*)nullptr, text, delayms);
6625}
6626
6627////////////////////////////////////////////////////////////////////////////////
6628/// Set pad vertical (default) or horizontal
6629
6631{
6632 if (vert) ResetBit(kHori);
6633 else SetBit(kHori);
6634}
6635
6636////////////////////////////////////////////////////////////////////////////////
6637/// Stream a class object.
6638
6640{
6641 UInt_t R__s, R__c;
6642 Int_t nch, nobjects;
6643 Float_t single;
6644 TObject *obj;
6645 if (b.IsReading()) {
6646 Version_t v = b.ReadVersion(&R__s, &R__c);
6647 if (v > 5) {
6648 if (!gPad)
6649 gPad = new TCanvas(GetName());
6650 fMother = (TPad*)gPad;
6652 TContext ctxt(this, kFALSE);
6653 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
6654 gReadLevel++;
6655 gROOT->SetReadingObject(kTRUE);
6656
6657 b.ReadClassBuffer(TPad::Class(), this, v, R__s, R__c);
6658
6659 //Set the kCanDelete bit in all objects in the pad such that when the pad
6660 //is deleted all objects in the pad are deleted too.
6661 //Also set must cleanup bit which normally set for all primitives add to pad,
6662 // but may be reset in IO like TH1::Streamer does
6663 TIter next(fPrimitives);
6664 while ((obj = next())) {
6665 obj->SetBit(kCanDelete);
6666 obj->SetBit(kMustCleanup);
6667 }
6668
6669 fModified = kTRUE;
6670 fPadPointer = nullptr;
6671 gReadLevel--;
6672 if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
6673 gROOT->SetReadingObject(kFALSE);
6674 return;
6675 }
6676
6677 //====process old versions before automatic schema evolution
6678 if (v < 5) { //old TPad in single precision
6679 if (v < 3) { //old TPad derived from TWbox
6680 b.ReadVersion(); // TVirtualPad::Streamer(b)
6681 b.ReadVersion(); // TWbox::Streamer(b)
6682 b.ReadVersion(); // TBox::Streamer(b)
6686 b >> single; fX1 = single;
6687 b >> single; fY1 = single;
6688 b >> single; fX2 = single;
6689 b >> single; fY2 = single;
6690 b >> fBorderSize;
6691 b >> fBorderMode;
6693 } else { //new TPad
6696 b >> single; fX1 = single;
6697 b >> single; fY1 = single;
6698 b >> single; fX2 = single;
6699 b >> single; fY2 = single;
6700 b >> fBorderSize;
6701 b >> fBorderMode;
6702 }
6703 b >> fLogx;
6704 b >> fLogy;
6705 b >> fLogz;
6706 b >> single; fXtoAbsPixelk = single;
6707 b >> single; fXtoPixelk = single;
6708 b >> single; fXtoPixel = single;
6709 b >> single; fYtoAbsPixelk = single;
6710 b >> single; fYtoPixelk = single;
6711 b >> single; fYtoPixel = single;
6712 b >> single; fUtoAbsPixelk = single;
6713 b >> single; fUtoPixelk = single;
6714 b >> single; fUtoPixel = single;
6715 b >> single; fVtoAbsPixelk = single;
6716 b >> single; fVtoPixelk = single;
6717 b >> single; fVtoPixel = single;
6718 b >> single; fAbsPixeltoXk = single;
6719 b >> single; fPixeltoXk = single;
6720 b >> single; fPixeltoX = single;
6721 b >> single; fAbsPixeltoYk = single;
6722 b >> single; fPixeltoYk = single;
6723 b >> single; fPixeltoY = single;
6724 b >> single; fXlowNDC = single;
6725 b >> single; fYlowNDC = single;
6726 b >> single; fWNDC = single;
6727 b >> single; fHNDC = single;
6728 b >> single; fAbsXlowNDC = single;
6729 b >> single; fAbsYlowNDC = single;
6730 b >> single; fAbsWNDC = single;
6731 b >> single; fAbsHNDC = single;
6732 b >> single; fUxmin = single;
6733 b >> single; fUymin = single;
6734 b >> single; fUxmax = single;
6735 b >> single; fUymax = single;
6736 } else {
6739 b >> fX1;
6740 b >> fY1;
6741 b >> fX2;
6742 b >> fY2;
6743 b >> fBorderSize;
6744 b >> fBorderMode;
6745 b >> fLogx;
6746 b >> fLogy;
6747 b >> fLogz;
6748 b >> fXtoAbsPixelk;
6749 b >> fXtoPixelk;
6750 b >> fXtoPixel;
6751 b >> fYtoAbsPixelk;
6752 b >> fYtoPixelk;
6753 b >> fYtoPixel;
6754 b >> fUtoAbsPixelk;
6755 b >> fUtoPixelk;
6756 b >> fUtoPixel;
6757 b >> fVtoAbsPixelk;
6758 b >> fVtoPixelk;
6759 b >> fVtoPixel;
6760 b >> fAbsPixeltoXk;
6761 b >> fPixeltoXk;
6762 b >> fPixeltoX;
6763 b >> fAbsPixeltoYk;
6764 b >> fPixeltoYk;
6765 b >> fPixeltoY;
6766 b >> fXlowNDC;
6767 b >> fYlowNDC;
6768 b >> fWNDC;
6769 b >> fHNDC;
6770 b >> fAbsXlowNDC;
6771 b >> fAbsYlowNDC;
6772 b >> fAbsWNDC;
6773 b >> fAbsHNDC;
6774 b >> fUxmin;
6775 b >> fUymin;
6776 b >> fUxmax;
6777 b >> fUymax;
6778 }
6779
6780 if (!gPad)
6781 gPad = new TCanvas(GetName());
6782 if (gReadLevel == 0)
6784 else
6785 fMother = (TPad *)gPad;
6786 if (!fMother)
6787 fMother = (TPad *)gPad;
6788 if (fMother)
6790 gPad = fMother;
6791 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
6792 //-------------------------
6793 // read objects and their drawing options
6794 // b >> fPrimitives;
6795 gReadLevel++;
6796 gROOT->SetReadingObject(kTRUE);
6797 fPrimitives = new TList;
6798 b >> nobjects;
6799 if (nobjects > 0) {
6800 TContext ctxt(this, kFALSE);
6801 char drawoption[64];
6802 for (Int_t i = 0; i < nobjects; i++) {
6803 b >> obj;
6804 b >> nch;
6805 b.ReadFastArray(drawoption,nch);
6806 fPrimitives->AddLast(obj, drawoption);
6807 gPad = this; // gPad may be modified in b >> obj if obj is a pad
6808 }
6809 }
6810 gReadLevel--;
6811 gROOT->SetReadingObject(kFALSE);
6812 //////////////////////////////////////////////////////////////////////////
6813
6814 if (v > 3) {
6815 b >> fExecs;
6816 }
6817 fName.Streamer(b);
6818 fTitle.Streamer(b);
6819 b >> fPadPaint;
6820 fModified = kTRUE;
6821 b >> fGridx;
6822 b >> fGridy;
6823 b >> fFrame;
6824 b >> fView;
6825 if (v < 5) {
6826 b >> single; fTheta = single;
6827 b >> single; fPhi = single;
6828 } else {
6829 b >> fTheta;
6830 b >> fPhi;
6831 }
6832 fPadPointer = nullptr;
6833 b >> fNumber;
6834 b >> fAbsCoord;
6835 if (v > 1) {
6836 b >> fTickx;
6837 b >> fTicky;
6838 } else {
6839 fTickx = fTicky = 0;
6840 }
6841 if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
6842 b.CheckByteCount(R__s, R__c, TPad::IsA());
6843 //====end of old versions
6844
6845 } else {
6846 b.WriteClassBuffer(TPad::Class(),this);
6847 }
6848}
6849
6850////////////////////////////////////////////////////////////////////////////////
6851/// Force a copy of current style for all objects in pad.
6852
6854{
6855 if (gStyle->IsReading()) {
6867 fLogx = gStyle->GetOptLogx();
6868 fLogy = gStyle->GetOptLogy();
6869 fLogz = gStyle->GetOptLogz();
6870 } else {
6885 }
6886
6887 if (!fPrimitives) fPrimitives = new TList;
6888 TIter next(GetListOfPrimitives());
6889 TObject *obj;
6890
6891 while ((obj = next())) {
6892 obj->UseCurrentStyle();
6893 }
6894
6895 TPaveText *title = (TPaveText*)FindObject("title");
6896 if (title) {
6897 if (gStyle->IsReading()) {
6899 title->SetTextFont(gStyle->GetTitleFont(""));
6902 if (!gStyle->GetOptTitle()) delete title;
6903 } else {
6905 gStyle->SetTitleFont(title->GetTextFont());
6908 }
6909 }
6911
6912 if (gStyle->IsReading()) Modified();
6913}
6914
6915////////////////////////////////////////////////////////////////////////////////
6916/// Loop and sleep until a primitive with name=pname is found in the pad.
6917///
6918/// If emode is given, the editor is automatically set to emode, ie
6919/// it is not required to have the editor control bar.
6920///
6921/// The possible values for emode are:
6922/// - emode = "" (default). User will select the mode via the editor bar
6923/// - emode = "Arc", "Line", "Arrow", "Button", "Diamond", "Ellipse",
6924/// - emode = "Pad","pave", "PaveLabel","PaveText", "PavesText",
6925/// - emode = "PolyLine", "CurlyLine", "CurlyArc", "Text", "Marker", "CutG"
6926///
6927/// If emode is specified and it is not valid, "PolyLine" is assumed. If emode
6928/// is not specified or ="", an attempt is to use pname[1...]
6929///
6930/// for example if pname="TArc", emode="Arc" will be assumed.
6931/// When this function is called within a macro, the macro execution
6932/// is suspended until a primitive corresponding to the arguments
6933/// is found in the pad.
6934///
6935/// If CRTL/C is typed in the pad, the function returns 0.
6936///
6937/// While this function is executing, one can use the mouse, interact
6938/// with the graphics pads, use the Inspector, Browser, TreeViewer, etc.
6939///
6940/// Examples:
6941/// ~~~ {.cpp}
6942/// c1.WaitPrimitive(); // Return the first created primitive
6943/// // whatever it is.
6944/// // If a double-click with the mouse is executed
6945/// // in the pad or any key pressed, the function
6946/// // returns 0.
6947/// c1.WaitPrimitive("ggg"); // Set the editor in mode "PolyLine/Graph"
6948/// // Create a polyline, then using the context
6949/// // menu item "SetName", change the name
6950/// // of the created TGraph to "ggg"
6951/// c1.WaitPrimitive("TArc");// Set the editor in mode "Arc". Returns
6952/// // as soon as a TArc object is created.
6953/// c1.WaitPrimitive("lat","Text"); // Set the editor in Text/Latex mode.
6954/// // Create a text object, then Set its name to "lat"
6955/// ~~~
6956/// The following macro waits for 10 primitives of any type to be created.
6957///
6958/// ~~~ {.cpp}
6959///{
6960/// TCanvas c1("c1");
6961/// TObject *obj;
6962/// for (Int_t i=0;i<10;i++) {
6963/// obj = gPad->WaitPrimitive();
6964/// if (!obj) break;
6965/// printf("Loop i=%d, found objIsA=%s, name=%s\n",
6966/// i,obj->ClassName(),obj->GetName());
6967/// }
6968///}
6969/// ~~~
6970///
6971/// If ROOT runs in batch mode a call to this method does nothing.
6972
6973TObject *TPad::WaitPrimitive(const char *pname, const char *emode)
6974{
6975 if (!gPad || IsWeb())
6976 return nullptr;
6977
6978 if (emode && strlen(emode)) gROOT->SetEditorMode(emode);
6979 if (gROOT->GetEditorMode() == 0 && pname && strlen(pname) > 2) gROOT->SetEditorMode(&pname[1]);
6980
6981 if (!fPrimitives) fPrimitives = new TList;
6983 TObject *oldlast = gPad->GetListOfPrimitives() ? gPad->GetListOfPrimitives()->Last() : nullptr;
6984 TObject *obj = nullptr;
6985 Bool_t testlast = kFALSE;
6986 Bool_t hasname = pname && (strlen(pname) > 0);
6987 if ((!pname || !pname[0]) && (!emode || !emode[0])) testlast = kTRUE;
6988 if (testlast) gROOT->SetEditorMode();
6989 while (!gSystem->ProcessEvents() && gROOT->GetSelectedPad() && gPad) {
6990 if (gROOT->GetEditorMode() == 0) {
6991 if (hasname) {
6992 obj = FindObject(pname);
6993 if (obj) return obj;
6994 }
6995 if (testlast) {
6996 if (!gPad->GetListOfPrimitives()) return nullptr;
6997 obj = gPad->GetListOfPrimitives()->Last();
6998 if (obj != oldlast) return obj;
6999 Int_t event = GetEvent();
7000 if (event == kButton1Double || event == kKeyPress) {
7001 //the following statement is required against other loop executions
7002 //before returning
7003 fCanvas->HandleInput((EEventType)-1,0,0);
7004 return nullptr;
7005 }
7006 }
7007 }
7008 gSystem->Sleep(10);
7009 }
7010
7011 return nullptr;
7012}
7013
7014////////////////////////////////////////////////////////////////////////////////
7015/// Create a tool tip and return its pointer.
7016
7017TObject *TPad::CreateToolTip(const TBox *box, const char *text, Long_t delayms)
7018{
7019 if (gPad->IsBatch()) return nullptr;
7020 return (TObject*)gROOT->ProcessLineFast(TString::Format("new TGToolTip((TBox*)0x%zx,\"%s\",%d)",
7021 (size_t)box,text,(Int_t)delayms).Data());
7022}
7023
7024////////////////////////////////////////////////////////////////////////////////
7025/// Delete tool tip object.
7026
7028{
7029 // delete tip;
7030 if (!tip) return;
7031 gROOT->ProcessLineFast(TString::Format("delete (TGToolTip*)0x%zx", (size_t)tip).Data());
7032}
7033
7034////////////////////////////////////////////////////////////////////////////////
7035/// Reset tool tip, i.e. within time specified in CreateToolTip the
7036/// tool tip will pop up.
7037
7039{
7040 if (!tip) return;
7041 // tip->Reset(this);
7042 gROOT->ProcessLineFast(TString::Format("((TGToolTip*)0x%zx)->Reset((TPad*)0x%zx)",
7043 (size_t)tip,(size_t)this).Data());
7044}
7045
7046////////////////////////////////////////////////////////////////////////////////
7047/// Hide tool tip.
7048
7050{
7051 if (!tip) return;
7052 // tip->Hide();
7053 gROOT->ProcessLineFast(TString::Format("((TGToolTip*)0x%zx)->Hide()", (size_t)tip).Data());
7054}
7055
7056////////////////////////////////////////////////////////////////////////////////
7057/// Deprecated: use TPad::GetViewer3D() instead
7058
7060{
7061 ::Info("TPad::x3d()", "This function is deprecated. Use %s->GetViewer3D(\"x3d\") instead",this->GetName());
7062
7063 // Default on GetViewer3D is pad - for x3d it was x3d...
7064 if (!type || !type[0]) {
7065 type = "x3d";
7066 }
7068}
7069
7070////////////////////////////////////////////////////////////////////////////////
7071/// Create/obtain handle to 3D viewer. Valid types are:
7072/// - 'pad' - pad drawing via TViewer3DPad
7073/// any others registered with plugin manager supporting TVirtualViewer3D
7074/// If an invalid/null type is requested then the current viewer is returned
7075/// (if any), otherwise a default 'pad' type is returned
7076
7078{
7079 Bool_t validType = kFALSE;
7080
7081 if ((!type || !*type || (strstr(type, "gl") && !strstr(type, "ogl"))) && (!fCanvas || !fCanvas->UseGL()))
7082 type = "pad";
7083
7084 if (type && *type) {
7085 if (gPluginMgr->FindHandler("TVirtualViewer3D", type))
7086 validType = kTRUE;
7087 }
7088
7089 // Invalid/null type requested?
7090 if (!validType) {
7091 // Return current viewer if there is one
7092 if (fViewer3D)
7093 return fViewer3D;
7094 // otherwise default to the pad
7095 else
7096 type = "pad";
7097 }
7098
7099 // Ensure we can create the new viewer before removing any existing one
7100 TVirtualViewer3D *newViewer = nullptr;
7101
7102 Bool_t createdExternal = kFALSE;
7103
7104 // External viewers need to be created via plugin manager via interface...
7105 if (!strstr(type,"pad")) {
7106 newViewer = TVirtualViewer3D::Viewer3D(this, type);
7107
7108 if (!newViewer) {
7109 Warning("GetViewer3D", "Cannot create 3D viewer of type: %s", type);
7110 // Return the existing viewer
7111 return fViewer3D;
7112 }
7113
7114 if (strstr(type, "gl") && !strstr(type, "ogl")) {
7117 Modified();
7118 } else {
7119 createdExternal = kTRUE;
7120 }
7121
7122 } else {
7123 newViewer = new TViewer3DPad(*this);
7124 }
7125
7126 // If we had a previous viewer destroy it now
7127 // In this case we do take responsibility for destroying viewer
7128 // c.f. ReleaseViewer3D
7129 delete fViewer3D;
7130
7131 // Set and return new viewer
7132 fViewer3D = newViewer;
7133
7134 // Ensure any new external viewer is painted
7135 // For internal TViewer3DPad type we assume this is being
7136 // create on demand due to a paint - so this is not required
7137 if (createdExternal) {
7138 Modified();
7139 Update();
7140 }
7141
7142 return fViewer3D;
7143}
7144
7145////////////////////////////////////////////////////////////////////////////////
7146/// Release current (external) viewer
7147
7149{
7150 fViewer3D = nullptr;
7151
7152 // We would like to ensure the pad is repainted
7153 // when external viewer is closed down. However
7154 // a modify/paint call here will repaint the pad
7155 // before the external viewer window actually closes.
7156 // So the pad would have to be redraw twice over.
7157 // Currently we just have to live with the pad staying blank
7158 // any click in pad will refresh.
7159}
7160
7161////////////////////////////////////////////////////////////////////////////////
7162/// Get GL device.
7163
7165{
7166 return fGLDevice;
7167}
7168
7169////////////////////////////////////////////////////////////////////////////////
7170/// Emit RecordPave() signal.
7171
7173{
7174 Emit("RecordPave(const TObject*)", (Longptr_t)obj);
7175}
7176
7177////////////////////////////////////////////////////////////////////////////////
7178/// Emit RecordLatex() signal.
7179
7181{
7182 Emit("RecordLatex(const TObject*)", (Longptr_t)obj);
7183}
7184
7185////////////////////////////////////////////////////////////////////////////////
7186/// Get pad painter from TCanvas.
7187
7189{
7190 if (!fCanvas) return nullptr;
7191 return fCanvas->GetCanvasPainter();
7192}
7193
7194////////////////////////////////////////////////////////////////////////////////
7195/// Return the bounding Box of the Pad
7196
7198{
7199 Rectangle_t BBox{0, 0, 0, 0};
7200 if (gPad) {
7201 BBox.fX = gPad->XtoPixel(fXlowNDC * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1());
7202 BBox.fY = gPad->YtoPixel((fYlowNDC + fHNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1());
7203 BBox.fWidth = gPad->XtoPixel((fXlowNDC + fWNDC) * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1()) -
7204 gPad->XtoPixel(fXlowNDC * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1());
7205 BBox.fHeight = gPad->YtoPixel((fYlowNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1()) -
7206 gPad->YtoPixel((fYlowNDC + fHNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1());
7207 }
7208 return BBox;
7209}
7210
7211////////////////////////////////////////////////////////////////////////////////
7212/// Return the center of the Pad as TPoint in pixels
7213
7215{
7216 TPoint p(0, 0);
7217 if (gPad) {
7218 Double_t x = ((fXlowNDC + 0.5 * fWNDC) * (gPad->GetX2() - gPad->GetX1())) + gPad->GetX1();
7219 Double_t y = ((fYlowNDC + 0.5 * fHNDC) * (gPad->GetY2() - gPad->GetY1())) + gPad->GetY1();
7220 p.SetX(gPad->XtoPixel(x));
7221 p.SetY(gPad->YtoPixel(y));
7222 }
7223 return p;
7224}
7225
7226////////////////////////////////////////////////////////////////////////////////
7227/// Set center of the Pad
7228
7230{
7231 if (!gPad)
7232 return;
7233 fXlowNDC = (gPad->PixeltoX(p.GetX()) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1()) - 0.5 * fWNDC;
7234 fYlowNDC =
7235 (gPad->PixeltoY(p.GetY() - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - 0.5 * fHNDC;
7236 ResizePad();
7237}
7238
7239////////////////////////////////////////////////////////////////////////////////
7240/// Set X coordinate of the center of the Pad
7241
7243{
7244 if (!gPad)
7245 return;
7246 fXlowNDC = (gPad->PixeltoX(x) - gPad->GetX1())/(gPad->GetX2()-gPad->GetX1())-0.5*fWNDC;
7247 ResizePad();
7248}
7249
7250////////////////////////////////////////////////////////////////////////////////
7251/// Set Y coordinate of the center of the Pad
7252
7254{
7255 if (!gPad)
7256 return;
7257 fYlowNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - 0.5 * fHNDC;
7258 ResizePad();
7259}
7260
7261////////////////////////////////////////////////////////////////////////////////
7262/// Set lefthandside of BoundingBox to a value
7263/// (resize in x direction on left)
7264
7266{
7267 if (!gPad)
7268 return;
7269 fXlowNDC = (gPad->PixeltoX(x) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1());
7271 ResizePad();
7272}
7273
7274////////////////////////////////////////////////////////////////////////////////
7275/// Set right hand side of BoundingBox to a value
7276/// (resize in x direction on right)
7277
7279{
7280 if (!gPad)
7281 return;
7282 fWNDC = (gPad->PixeltoX(x) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1()) - fXlowNDC;
7283 ResizePad();
7284}
7285
7286////////////////////////////////////////////////////////////////////////////////
7287/// Set top of BoundingBox to a value (resize in y direction on top)
7288
7290{
7291 if (!gPad)
7292 return;
7293 fHNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - fYlowNDC;
7294 ResizePad();
7295}
7296
7297////////////////////////////////////////////////////////////////////////////////
7298/// Set bottom of BoundingBox to a value
7299/// (resize in y direction on bottom)
7300
7302{
7303 if (!gPad)
7304 return;
7305 fYlowNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1());
7307 ResizePad();
7308}
7309
7310////////////////////////////////////////////////////////////////////////////////
7311/// Mark pad modified
7312/// Will be repainted when TCanvas::Update() will be called next time
7313
7315{
7316 if (!fModified && flag) Emit("Modified()");
7317 fModified = flag;
7318}
7319
7320////////////////////////////////////////////////////////////////////////////////
7321/// Convert absolute pixel into X/Y coordinates
7322
7324{
7325 x = AbsPixeltoX(xpixel);
7326 y = AbsPixeltoY(ypixel);
7327}
7328
7329
7330////////////////////////////////////////////////////////////////////////////////
7331/// Convert pixel to X coordinate
7332
7334{
7335 if (fAbsCoord) return fAbsPixeltoXk + px*fPixeltoX;
7336 else return fPixeltoXk + px*fPixeltoX;
7337}
7338
7339////////////////////////////////////////////////////////////////////////////////
7340/// Convert pixel to Y coordinate
7341
7343{
7344 if (fAbsCoord) return fAbsPixeltoYk + py*fPixeltoY;
7345 else return fPixeltoYk + py*fPixeltoY;
7346}
7347
7348////////////////////////////////////////////////////////////////////////////////
7349/// Convert pixel to X/Y coordinates
7350
7352{
7353 x = PixeltoX(xpixel);
7354 y = PixeltoY(ypixel);
7355}
7356
7357////////////////////////////////////////////////////////////////////////////////
7358/// Convert X/Y into absolute pixel coordinates - integer
7359
7360void TPad::XYtoAbsPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const
7361{
7362 xpixel = XtoAbsPixel(x);
7363 ypixel = YtoAbsPixel(y);
7364}
7365
7366////////////////////////////////////////////////////////////////////////////////
7367/// Check value for valid range for pixel values
7368
7370{
7371 return v < -kMaxPixel ? -kMaxPixel : (v > kMaxPixel ? kMaxPixel : v);
7372}
7373
7374////////////////////////////////////////////////////////////////////////////////
7375/// Convert X/Y into absolute pixel coordinates - doble
7376/// Introduced to avoid pixel rounding problems
7377
7379{
7382}
7383
7384////////////////////////////////////////////////////////////////////////////////
7385/// Convert X/Y into pixel coordinates - integer
7386
7387void TPad::XYtoPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const
7388{
7389 xpixel = XtoPixel(x);
7390 ypixel = YtoPixel(y);
7391}
7392
7393////////////////////////////////////////////////////////////////////////////////
7394/// Convert X/Y into pixel coordinates - double
7395
7401
7402////////////////////////////////////////////////////////////////////////////////
7403/// Convert X NDC to pixel
7404
7409
7410////////////////////////////////////////////////////////////////////////////////
7411/// Convert Y NDC to pixel
7412
7417
7418////////////////////////////////////////////////////////////////////////////////
7419/// Convert X NDC to absolute pixel
7420
7425
7426////////////////////////////////////////////////////////////////////////////////
7427/// Convert Y NDC to absolute pixel
7428
7433
7434////////////////////////////////////////////////////////////////////////////////
7435/// Convert X coordinate to absolute pixel
7436
7441
7442////////////////////////////////////////////////////////////////////////////////
7443/// Convert X coordinate to pixel
7444
7449
7450////////////////////////////////////////////////////////////////////////////////
7451/// Convert Y coordinate to absolute pixel
7452
7457
7458////////////////////////////////////////////////////////////////////////////////
7459/// Convert a vertical distance [y1,y2] to pixel
7460
7462{
7463 double h1 = fYtoAbsPixelk + y1 * fYtoPixel;
7464 double h2 = fYtoAbsPixelk + y2 * fYtoPixel;
7465 return TMath::Nint(pixel_boundary(std::abs(h1 - h2)));
7466}
7467
7468////////////////////////////////////////////////////////////////////////////////
7469/// Convert a horizontal distance [x1,x2] to pixel
7470
7472{
7473 double w1 = fXtoAbsPixelk + x1 * fXtoPixel;
7474 double w2 = fXtoAbsPixelk + x2 * fXtoPixel;
7475 return TMath::Nint(pixel_boundary(std::abs(w1 - w2)));
7476}
7477
7478
7479////////////////////////////////////////////////////////////////////////////////
7480/// Convert Y coordinate to pixel
7481
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
@ 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:7369
static Int_t gReadLevel
Definition TPad.cxx:70
#define NotFree(i, j)
Definition TPad.cxx:3172
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:2202
Double_t px1old
Definition TPad.cxx:2200
Double_t py1old
Definition TPad.cxx:2200
Double_t px2old
Definition TPad.cxx:2200
Double_t ratio2
Definition TPad.cxx:2199
Double_t py2old
Definition TPad.cxx:2200
Double_t ratio1
Definition TPad.cxx:2199
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:2755
void PaintTextNDC(Double_t u, Double_t v, const char *text) override
Paint text in CurrentPad NDC coordinates.
Definition TPad.cxx:4611
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:2700
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:6155
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:2732
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:3020
Int_t VtoPixel(Double_t v) const override
Convert Y NDC to pixel.
Definition TPad.cxx:7413
void PaintBorder(Color_t color, Bool_t tops)
Paint the pad border.
Definition TPad.cxx:3565
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:3036
void SetView(TView *view=nullptr) override
Set the current TView. Delete previous view if view=0.
Definition TPad.cxx:6120
TVirtualViewer3D * GetViewer3D(Option_t *type="") override
Create/obtain handle to 3D viewer.
Definition TPad.cxx:7077
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:4052
void PaintLine3D(Float_t *p1, Float_t *p2) override
Paint 3-D line in the CurrentPad.
Definition TPad.cxx:4233
static Int_t fgMaxPickDistance
Maximum Pick Distance.
Definition TPad.h:121
void ResizePad(Option_t *option="") override
Compute pad conversion coefficients.
Definition TPad.cxx:5608
void PaintMarker3D(Double_t x, Double_t y, Double_t z) override
Paint 3-D marker in the CurrentPad.
Definition TPad.cxx:4269
void PaintPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override
Paint polymarker in CurrentPad World coordinates.
Definition TPad.cxx:4446
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:7180
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:5823
void CopyBackgroundPixmaps(TPad *stop, Int_t x, Int_t y)
Copy pixmaps of pads laying below pad "stop" into pad "stop".
Definition TPad.cxx:3894
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:3454
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:3796
void SetBBoxY1(const Int_t y) override
Set top of BoundingBox to a value (resize in y direction on top)
Definition TPad.cxx:7289
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:3105
void SetLogz(Int_t value=1) override
Set Lin/Log scale for Z.
Definition TPad.cxx:6036
Bool_t fEmbeddedGL
!
Definition TPad.h:93
Int_t UtoAbsPixel(Double_t u) const override
Convert X NDC to absolute pixel.
Definition TPad.cxx:7421
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:7445
void SetAttFillPS(Color_t color, Style_t style) override
Set postscript fill area attributes.
Definition TPad.cxx:6131
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:7253
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:7027
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:7323
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:5391
UInt_t GetWw() const override
Get canvas width.
Definition TPad.cxx:2656
void PaintModified() override
Traverse pad hierarchy and (re)paint only modified pads.
Definition TPad.cxx:3700
void SetEditable(Bool_t mode=kTRUE) override
Set pad editable yes/no If a pad is not editable:
Definition TPad.cxx:5980
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:3638
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:6606
void PixeltoXY(Double_t xpixel, Double_t ypixel, Double_t &x, Double_t &y) override
Convert pixel to X/Y coordinates.
Definition TPad.cxx:7351
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:7278
void SetBBoxX1(const Int_t x) override
Set lefthandside of BoundingBox to a value (resize in x direction on left)
Definition TPad.cxx:7265
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:5999
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:2557
Int_t GetEvent() const override
Get Event.
Definition TPad.cxx:2565
Double_t PadtoX(Double_t x) const override
Convert x from pad to X.
Definition TPad.cxx:3445
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:2985
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:3475
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:6096
void SetCursor(ECursor cursor) override
Set cursor type.
Definition TPad.cxx:2787
Int_t GetCanvasID() const override
Get canvas identifier.
Definition TPad.cxx:2549
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:7461
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:7387
Double_t fYtoPixelk
Conversion coefficient for Y World to pixel.
Definition TPad.h:51
void UpdateAsync() override
Asynchronous pad update.
Definition TPad.cxx:2823
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:6853
static Int_t GetMaxPickDistance()
Static function (see also TPad::SetMaxPickDistance)
Definition TPad.cxx:2613
Int_t VtoAbsPixel(Double_t v) const override
Convert Y NDC to absolute pixel.
Definition TPad.cxx:7429
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:5315
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:7360
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:2581
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:6973
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:6167
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:7342
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:4647
void Update() override
Update pad.
Definition TPad.cxx:2811
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:3975
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:7482
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:4198
Int_t GetGLDevice() override
Get GL device.
Definition TPad.cxx:7164
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:7172
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:3628
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:6025
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:2255
void HighLight(Color_t col=kRed, Bool_t set=kTRUE) override
Highlight pad.
Definition TPad.cxx:2931
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:2771
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:7059
Bool_t HasCrosshair() const override
Return kTRUE if the crosshair has been activated (via SetCrosshair).
Definition TPad.cxx:6568
Bool_t IsRetained() const override
Is pad retained ?
Definition TPad.cxx:2740
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:3081
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:3913
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7314
void RecursiveRemove(TObject *obj) override
Recursively remove object from a pad and its sub-pads.
Definition TPad.cxx:5373
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:7049
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:6616
void PaintPolyLine(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override
Paint polyline in CurrentPad World coordinates.
Definition TPad.cxx:4295
Int_t WtoAbsPixel(Double_t x1, Double_t x2) const override
Convert a horizontal distance [x1,x2] to pixel.
Definition TPad.cxx:7471
void ls(Option_t *option="") const override
List all primitives in pad.
Definition TPad.cxx:2967
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:3433
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:2681
TVirtualPad * GetPadSave() const override
Get save pad.
Definition TPad.cxx:2639
void SetAttLinePS(Color_t color, Style_t style, Width_t lwidth) override
Set postscript line attributes.
Definition TPad.cxx:6143
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:2589
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:4517
void FeedbackMode(Bool_t set) override
Switch feedback mode for the canvas Only for internal use when implementing special painters.
Definition TPad.cxx:2500
UInt_t GetPadWidth() const override
Get pad width.
Definition TPad.cxx:2664
void Streamer(TBuffer &) override
Stream a class object.
Definition TPad.cxx:6639
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:4558
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:7405
TPoint GetBBoxCenter() override
Return the center of the Pad as TPoint in pixels.
Definition TPad.cxx:7214
void FillCollideGridTFrame(TObject *o)
Definition TPad.cxx:3237
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:3177
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:2779
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:3263
void SetFixedAspectRatio(Bool_t fixed=kTRUE) override
Fix pad aspect ratio to current value if fixed is true.
Definition TPad.cxx:5956
Short_t GetBorderSize() const override
Definition TPad.h:210
void RedrawAxis(Option_t *option="") override
Redraw the frame axis.
Definition TPad.cxx:5434
void DrawDist(Rectangle_t aBBox, Rectangle_t bBBox, char mode)
Draw Arrows to indicated equal distances of Objects with given BBoxes.
Definition TPad.cxx:6192
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:7453
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:4018
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:5353
@ 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:7038
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:2648
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:7197
void Paint(Option_t *option="") override
Paint all primitives in pad.
Definition TPad.cxx:3487
void FillCollideGridTBox(TObject *o)
Definition TPad.cxx:3220
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:3376
TString fName
Pad name.
Definition TPad.h:115
void SetVertical(Bool_t vert=kTRUE) override
Set pad vertical (default) or horizontal.
Definition TPad.cxx:6630
void FillCollideGridTH1(TObject *o)
Definition TPad.cxx:3294
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:2897
void PaintText(Double_t x, Double_t y, const char *text) override
Paint text in CurrentPad World coordinates.
Definition TPad.cxx:4572
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:5768
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:2511
Color_t GetHighLightColor() const override
Get highlight color.
Definition TPad.cxx:2605
Bool_t OpaqueResizing() const override
Is pad resizing in opaque mode ?
Definition TPad.cxx:2763
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:2713
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:4220
void Print(const char *filename="") const override
This method is equivalent to SaveAs("filename"). See TPad::SaveAs for details.
Definition TPad.cxx:4788
Int_t GetEventX() const override
Get X event.
Definition TPad.cxx:2573
TFrame * GetFrame() override
Get frame.
Definition TPad.cxx:2831
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:7188
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:6276
Int_t GetCrosshair() const
Return the crosshair type (from the mother canvas) crosshair type = 0 means no crosshair.
Definition TPad.cxx:6577
void GetRangeAxis(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) override
Return pad axis coordinates range.
Definition TPad.cxx:2919
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:3842
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:2859
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:2597
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:7229
Bool_t IsWeb() const override
Is web ?
Definition TPad.cxx:2747
void SetSelected(TObject *obj) override
Set selected.
Definition TPad.cxx:2803
TObject * GetSelected() const override
Get selected.
Definition TPad.cxx:2621
void GetRange(Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2) override
Return pad world coordinates range.
Definition TPad.cxx:2908
Double_t PixeltoX(Double_t px) override
Convert pixel to X coordinate.
Definition TPad.cxx:7333
void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override
Paint polyline in CurrentPad NDC coordinates.
Definition TPad.cxx:4410
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:3681
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:4598
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:2630
void PaintPolyLine3D(Int_t n, Double_t *p) override
Paint 3-D polyline in the CurrentPad.
Definition TPad.cxx:4430
TVirtualPad * GetPad(Int_t subpadnumber) const override
Get a pointer to subpadnumber of this pad.
Definition TPad.cxx:2876
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:6011
void ReleaseViewer3D(Option_t *type="") override
Release current (external) viewer.
Definition TPad.cxx:7148
void SetCrosshair(Int_t crhair=1) override
Set crosshair active/inactive.
Definition TPad.cxx:6590
void SetDoubleBuffer(Int_t mode=1) override
Set double buffer mode ON or OFF.
Definition TPad.cxx:2795
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:7242
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:7017
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:4766
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:3003
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:7437
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:7301
Double_t XtoPad(Double_t x) const override
Convert x from X to pad.
Definition TPad.cxx:3463
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:3059
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:3067
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2916
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:6245
TAttBBox2D * fb
Definition TPad.cxx:6247
dField()
Definition TPad.cxx:6252
char fdir
Definition TPad.cxx:6249
dField(TAttBBox2D *a, TAttBBox2D *b, Int_t dist, char direction)
Definition TPad.cxx:6256
TAttBBox2D * fa
Definition TPad.cxx:6246
Int_t fdist
Definition TPad.cxx:6248
TMarker m
Definition textangle.C:8