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#define NotFree(i, j) fCollideGrid[TMath::Max(TMath::Min(i+j*fCGnx,fCGnx*fCGny),0)] = kFALSE;
3172
3173////////////////////////////////////////////////////////////////////////////////
3174/// Mark as "not free" the cells along a line.
3175
3177{
3178 NotFree(x1, y1);
3179 NotFree(x2, y2);
3180 Int_t i, j, xt, yt;
3181
3182 // horizontal lines
3183 if (y1==y2) {
3184 for (i=x1+1; i<x2; i++) NotFree(i,y1);
3185 return;
3186 }
3187
3188 // vertical lines
3189 if (x1==x2) {
3190 for (i=y1+1; i<y2; i++) NotFree(x1,i);
3191 return;
3192 }
3193
3194 // other lines
3195 if (TMath::Abs(x2-x1)>TMath::Abs(y2-y1)) {
3196 if (x1>x2) {
3197 xt = x1; x1 = x2; x2 = xt;
3198 yt = y1; y1 = y2; y2 = yt;
3199 }
3200 for (i=x1+1; i<x2; i++) {
3201 j = (Int_t)((Double_t)(y2-y1)*(Double_t)((i-x1)/(Double_t)(x2-x1))+y1);
3202 NotFree(i,j);
3203 NotFree(i,(j+1));
3204 }
3205 } else {
3206 if (y1>y2) {
3207 yt = y1; y1 = y2; y2 = yt;
3208 xt = x1; x1 = x2; x2 = xt;
3209 }
3210 for (j=y1+1; j<y2; j++) {
3211 i = (Int_t)((Double_t)(x2-x1)*(Double_t)((j-y1)/(Double_t)(y2-y1))+x1);
3212 NotFree(i,j);
3213 NotFree((i+1),j);
3214 }
3215 }
3216}
3217
3218////////////////////////////////////////////////////////////////////////////////
3220{
3221 TBox *b = (TBox *)o;
3222 if (fCGnx==0||fCGny==0) return;
3223 Double_t xs = (fX2-fX1)/fCGnx;
3224 Double_t ys = (fY2-fY1)/fCGny;
3225
3226 Int_t x1 = (Int_t)((b->GetX1()-fX1)/xs);
3227 Int_t x2 = (Int_t)((b->GetX2()-fX1)/xs);
3228 Int_t y1 = (Int_t)((b->GetY1()-fY1)/ys);
3229 Int_t y2 = (Int_t)((b->GetY2()-fY1)/ys);
3230 for (int i = x1; i<=x2; i++) {
3231 for (int j = y1; j<=y2; j++) NotFree(i, j);
3232 }
3233}
3234
3235////////////////////////////////////////////////////////////////////////////////
3237{
3238 TFrame *f = (TFrame *)o;
3239 if (fCGnx==0||fCGny==0) return;
3240 Double_t xs = (fX2-fX1)/fCGnx;
3241 Double_t ys = (fY2-fY1)/fCGny;
3242
3243 Int_t x1 = (Int_t)((f->GetX1()-fX1)/xs);
3244 Int_t x2 = (Int_t)((f->GetX2()-fX1)/xs);
3245 Int_t y1 = (Int_t)((f->GetY1()-fY1)/ys);
3246 Int_t y2 = (Int_t)((f->GetY2()-fY1)/ys);
3247 Int_t i;
3248
3249 for (i = x1; i<=x2; i++) {
3250 NotFree(i, y1);
3251 NotFree(i, (y1-1));
3252 NotFree(i, (y1-2));
3253 }
3254 for (i = y1; i<=y2; i++) {
3255 NotFree(x1, i);
3256 NotFree((x1-1), i);
3257 NotFree((x1-2), i);
3258 }
3259}
3260
3261////////////////////////////////////////////////////////////////////////////////
3263{
3264 TGraph *g = (TGraph *)o;
3265 if (fCGnx==0||fCGny==0) return;
3266 Double_t xs = (fX2-fX1)/fCGnx;
3267 Double_t ys = (fY2-fY1)/fCGny;
3268
3269 Int_t n = g->GetN();
3270 Int_t s = TMath::Max(n/10,1);
3271 Double_t x1, x2, y1, y2;
3272 for (Int_t i=s; i<n; i=i+s) {
3273 g->GetPoint(TMath::Max(0,i-s),x1,y1);
3274 g->GetPoint(i ,x2,y2);
3275 if (fLogx) {
3276 if (x1 > 0) x1 = TMath::Log10(x1);
3277 else x1 = fUxmin;
3278 if (x2 > 0) x2 = TMath::Log10(x2);
3279 else x2 = fUxmin;
3280 }
3281 if (fLogy) {
3282 if (y1 > 0) y1 = TMath::Log10(y1);
3283 else y1 = fUymin;
3284 if (y2 > 0) y2 = TMath::Log10(y2);
3285 else y2 = fUymin;
3286 }
3287 LineNotFree((int)((x1-fX1)/xs), (int)((x2-fX1)/xs),
3288 (int)((y1-fY1)/ys), (int)((y2-fY1)/ys));
3289 }
3290}
3291
3292////////////////////////////////////////////////////////////////////////////////
3294{
3295 TH1 *h = (TH1 *)o;
3296 if (fCGnx==0||fCGny==0) return;
3297 if (o->InheritsFrom(TH2::Class())) return;
3298 if (o->InheritsFrom(TH3::Class())) return;
3299
3300 TString name = h->GetName();
3301 if (name.Index("hframe") >= 0) return;
3302
3303 Double_t xs = (fX2-fX1)/fCGnx;
3304 Double_t ys = (fY2-fY1)/fCGny;
3305
3306 bool haserrors = false;
3307 TString drawOption = h->GetDrawOption();
3308 drawOption.ToLower();
3309 drawOption.ReplaceAll("same","");
3310
3311 if (drawOption.Index("hist") < 0) {
3312 if (drawOption.Index("e") >= 0) haserrors = true;
3313 }
3314
3315 Int_t nx = h->GetNbinsX();
3316 Int_t x1, y1, y2;
3317 Int_t i, j;
3318 Double_t x1l, y1l, y2l;
3319
3320 for (i = 1; i<nx; i++) {
3321 if (haserrors) {
3322 x1l = h->GetBinCenter(i);
3323 if (fLogx) {
3324 if (x1l > 0) x1l = TMath::Log10(x1l);
3325 else x1l = fUxmin;
3326 }
3327 x1 = (Int_t)((x1l-fX1)/xs);
3328 y1l = h->GetBinContent(i)-h->GetBinErrorLow(i);
3329 if (fLogy) {
3330 if (y1l > 0) y1l = TMath::Log10(y1l);
3331 else y1l = fUymin;
3332 }
3333 y1 = (Int_t)((y1l-fY1)/ys);
3334 y2l = h->GetBinContent(i)+h->GetBinErrorUp(i);
3335 if (fLogy) {
3336 if (y2l > 0) y2l = TMath::Log10(y2l);
3337 else y2l = fUymin;
3338 }
3339 y2 = (Int_t)((y2l-fY1)/ys);
3340 for (j=y1; j<y2; j++) {
3341 NotFree(x1, j);
3342 }
3343 }
3344 x1l = h->GetBinLowEdge(i);
3345 if (fLogx) {
3346 if (x1l > 0) x1l = TMath::Log10(x1l);
3347 else x1l = fUxmin;
3348 }
3349 x1 = (Int_t)((x1l-fX1)/xs);
3350 y1l = h->GetBinContent(i);
3351 if (fLogy) {
3352 if (y1l > 0) y1l = TMath::Log10(y1l);
3353 else y1l = fUymin;
3354 }
3355 y1 = (Int_t)((y1l-fY1)/ys);
3356 NotFree(x1, y1);
3357 x1l = h->GetBinLowEdge(i)+h->GetBinWidth(i);
3358 if (fLogx) {
3359 if (x1l > 0) x1l = TMath::Log10(x1l);
3360 else x1l = fUxmin;
3361 }
3362 x1 = (int)((x1l-fX1)/xs);
3363 NotFree(x1, y1);
3364 }
3365
3366 // Extra objects in the list of function
3367 TPaveStats *ps = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
3368 if (ps) FillCollideGridTBox(ps);
3369}
3370
3371////////////////////////////////////////////////////////////////////////////////
3372/// This method draws the collide grid on top of the canvas. This is used for
3373/// debugging only. At some point it will be removed.
3374
3376{
3377 if (fCGnx==0||fCGny==0) return;
3378
3379 TContext ctxt(this, kTRUE);
3380
3381 TBox box;
3382 box.SetFillColorAlpha(kRed,0.5);
3383
3384 Double_t xs = (fX2-fX1)/fCGnx;
3385 Double_t ys = (fY2-fY1)/fCGny;
3386
3387 Double_t X1L, X2L, Y1L, Y2L;
3388 Double_t t = 0.15;
3389 Double_t Y1, Y2;
3390 Double_t X1 = fX1;
3391 Double_t X2 = X1+xs;
3392
3393 for (int i = 0; i<fCGnx; i++) {
3394 Y1 = fY1;
3395 Y2 = Y1+ys;
3396 for (int j = 0; j<fCGny; j++) {
3397 if (GetLogx()) {
3398 X1L = TMath::Power(10,X1);
3399 X2L = TMath::Power(10,X2);
3400 } else {
3401 X1L = X1;
3402 X2L = X2;
3403 }
3404 if (GetLogy()) {
3405 Y1L = TMath::Power(10,Y1);
3406 Y2L = TMath::Power(10,Y2);
3407 } else {
3408 Y1L = Y1;
3409 Y2L = Y2;
3410 }
3411 if (!fCollideGrid[i + j*fCGnx]) {
3412 box.SetFillColorAlpha(kBlack,t);
3413 box.DrawBox(X1L, Y1L, X2L, Y2L);
3414 } else {
3415 box.SetFillColorAlpha(kRed,t);
3416 box.DrawBox(X1L, Y1L, X2L, Y2L);
3417 }
3418 Y1 = Y2;
3419 Y2 = Y1+ys;
3420 if (t==0.15) t = 0.1;
3421 else t = 0.15;
3422 }
3423 X1 = X2;
3424 X2 = X1+xs;
3425 }
3426}
3427
3428////////////////////////////////////////////////////////////////////////////////
3429/// Short cut to call Modified() and Update() in a single call.
3430/// On Mac with Cocoa, it performs an additional ProcessEvents().
3431
3433{
3434 Modified();
3435 Update();
3436#ifdef R__HAS_COCOA
3438#endif
3439}
3440
3441////////////////////////////////////////////////////////////////////////////////
3442/// Convert x from pad to X.
3443
3445{
3446 if (fLogx && x < 50) return Double_t(TMath::Exp(2.302585092994*x));
3447 return x;
3448}
3449
3450////////////////////////////////////////////////////////////////////////////////
3451/// Convert y from pad to Y.
3452
3454{
3455 if (fLogy && y < 50) return Double_t(TMath::Exp(2.302585092994*y));
3456 return y;
3457}
3458
3459////////////////////////////////////////////////////////////////////////////////
3460/// Convert x from X to pad.
3461
3463{
3464 if (fLogx) {
3465 if (x > 0) x = TMath::Log10(x);
3466 else x = fUxmin;
3467 }
3468 return x;
3469}
3470
3471////////////////////////////////////////////////////////////////////////////////
3472/// Convert y from Y to pad.
3473
3475{
3476 if (fLogy) {
3477 if (y > 0) y = TMath::Log10(y);
3478 else y = fUymin;
3479 }
3480 return y;
3481}
3482
3483////////////////////////////////////////////////////////////////////////////////
3484/// Paint all primitives in pad.
3485
3486void TPad::Paint(Option_t * /* option */)
3487{
3488 if (!fPrimitives)
3489 fPrimitives = new TList;
3491 fViewer3D->PadPaint(this);
3493 if (GetGLDevice()!=-1 && gVirtualPS) {
3494 TContext ctxt(this, kFALSE);
3495 if (gGLManager) gGLManager->PrintViewer(GetViewer3D());
3496 }
3497 return;
3498 }
3499
3500 TVirtualPadPainter *oldpp = nullptr;
3501 Bool_t replace_pp = kFALSE;
3502
3503 if (fCanvas) {
3504 // check if special PS painter should be assigned to TCanvas
3505 replace_pp = fCanvas->EnsurePSPainter(kTRUE, oldpp);
3507 }
3508
3509 Bool_t began3DScene = kFALSE;
3510 fPadPaint = 1;
3511
3512 {
3513 TContext ctxt(this, kTRUE);
3514
3515 fDrawOperXor.clear();
3517 PaintDate();
3518
3519 auto lnk = GetListOfPrimitives()->FirstLink();
3520
3521 while (lnk) {
3522 TObject *obj = lnk->GetObject();
3523
3524 // Create a pad 3D viewer if none exists and we encounter a 3D shape
3525 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3526 GetViewer3D("pad");
3527 }
3528
3529 // Open a 3D scene if required
3530 if (fViewer3D && !fViewer3D->BuildingScene()) {
3532 began3DScene = kTRUE;
3533 }
3534
3535 obj->Paint(lnk->GetOption());
3536 lnk = lnk->Next();
3537 }
3538
3539 if (fCanvas && (fCanvas->fHilightPadBorder == this)) {
3540 auto col = GetHighLightColor();
3541 if (col > 0) PaintBorder(-col, kTRUE);
3542 }
3543
3544 PaintOperations(); // paint operations only for the pad
3545 }
3546
3547 fPadPaint = 0;
3549
3550 if (replace_pp && fCanvas)
3552
3553 // Close the 3D scene if we opened it. This must be done after modified
3554 // flag is cleared, as some viewers will invoke another paint by marking pad modified again
3555 if (began3DScene) {
3557 }
3558}
3559
3560////////////////////////////////////////////////////////////////////////////////
3561/// Paint the pad border.
3562/// Draw first a box as a normal filled box
3563
3564void TPad::PaintBorder(Color_t color, Bool_t /* tops */)
3565{
3566 auto pp = GetPainter();
3567 if (!pp)
3568 return;
3569
3570 pp->OnPad(this);
3571
3572 if (color >= 0) {
3573
3574 Bool_t do_paint_box = kTRUE;
3575
3577 if (!IsBatch() && (pp->IsCocoa() || (pp->IsNative() && (style > 3000) && (style < 3026))))
3578 pp->ClearDrawable();
3579
3580 // special only for transparent pads in plain X11;
3581 // Cocoa, GL, Web and PS implement transparency different
3582 if ((style >= 4000) && (style <= 4100) && pp->IsNative() && !pp->IsCocoa() && !pp->GetPS() && !(fCanvas && fCanvas->UseGL()) && !IsWeb() && !IsBatch()) {
3583 if (this == fMother) {
3584 style = 1001;
3585 } else {
3586 // copy all pixmaps
3587 do_paint_box = kFALSE;
3588 Int_t px, py;
3589 XYtoAbsPixel(GetX1(), GetY2(), px, py);
3590 if (fMother)
3591 fMother->CopyBackgroundPixmaps(this, px, py);
3592 pp->SetAttFill({color, 1001}); // use fill color producing opacity
3593 pp->SetOpacity(style - 4000);
3594 }
3595 } else if ((style >= 4000) && (style <= 4100) && pp->IsCocoa() && (this == fMother))
3596 style = 1001;
3597 else if ((color == 10) && (style > 3000) && (style < 3100))
3598 color = 1;
3599
3600 if (do_paint_box) {
3601 pp->SetAttFill({color, style});
3602 pp->SetAttLine(*this);
3603 PaintBox(fX1, fY1, fX2, fY2);
3604 }
3605 } else
3606 color = -color;
3607
3608 if (IsTransparent() || (fBorderMode == 0))
3609 return;
3610
3611 // then paint 3d frame (depending on bordermode)
3612 // Paint a 3D frame around the pad.
3613
3614 TWbox box;
3615 box.SetFillColor(color);
3616 box.SetFillStyle(GetFillStyle());
3618
3619 box.PaintBorderOn(this, fX1, fY1, fX2, fY2,
3622}
3623
3624////////////////////////////////////////////////////////////////////////////////
3625/// Paint a frame border with Postscript - no longer used
3626
3628{
3629 if (!gVirtualPS) return;
3630 gVirtualPS->DrawFrame(xl, yl, xt, yt, bmode,bsize,dark,light);
3631}
3632
3633////////////////////////////////////////////////////////////////////////////////
3634/// Paint the current date and time if the option `Date` is set on via `gStyle->SetOptDate()`
3635/// Paint the current file name if the option `File` is set on via `gStyle->SetOptFile()`
3636
3638{
3639 if (fCanvas == this) {
3640 if (gStyle->GetOptDate()) {
3641 TDatime dt;
3642 const char *dates;
3643 char iso[16];
3644 if (gStyle->GetOptDate() < 10) {
3645 //by default use format like "Wed Sep 25 17:10:35 2002"
3646 dates = dt.AsString();
3647 } else if (gStyle->GetOptDate() < 20) {
3648 //use ISO format like 2002-09-25
3649 strlcpy(iso,dt.AsSQLString(),16);
3650 dates = iso;
3651 } else {
3652 //use ISO format like 2002-09-25 17:10:35
3653 dates = dt.AsSQLString();
3654 }
3655 TText tdate(gStyle->GetDateX(),gStyle->GetDateY(),dates);
3661 tdate.SetNDC();
3662 tdate.Paint();
3663 }
3664 if (gStyle->GetOptFile() && gFile) {
3665 TText tfile(1. - gStyle->GetDateX(),gStyle->GetDateY(),gFile->GetName());
3669 tfile.SetTextAlign(31);
3671 tfile.SetNDC();
3672 tfile.Paint();
3673 }
3674 }
3675}
3676
3677////////////////////////////////////////////////////////////////////////////////
3678/// Paint histogram/graph frame.
3679
3681{
3682 if (!fPrimitives) fPrimitives = new TList;
3683 TList *glist = GetListOfPrimitives();
3684 TFrame *frame = GetFrame();
3685 frame->SetX1(xmin);
3686 frame->SetX2(xmax);
3687 frame->SetY1(ymin);
3688 frame->SetY2(ymax);
3689 if (!glist->FindObject(fFrame)) {
3690 glist->AddFirst(frame);
3692 }
3693 frame->Paint();
3694}
3695
3696////////////////////////////////////////////////////////////////////////////////
3697/// Traverse pad hierarchy and (re)paint only modified pads.
3698
3700{
3702 if (IsModified()) {
3703 fViewer3D->PadPaint(this);
3705 }
3706 TList *pList = GetListOfPrimitives();
3707 auto lnk = pList ? pList->FirstLink() : nullptr;
3708 while (lnk) {
3709 auto obj = lnk->GetObject();
3710 if (obj->InheritsFrom(TPad::Class()))
3711 ((TPad*)obj)->PaintModified();
3712 lnk = lnk->Next();
3713 }
3714 return;
3715 }
3716
3717 TVirtualPS *saveps = gVirtualPS;
3719 gVirtualPS = nullptr;
3720
3721 TVirtualPadPainter *oldpp = nullptr;
3722 Bool_t replace_pp = kFALSE;
3723
3724 if (fCanvas) {
3725 // check if special PS painter should be assigned to TCanvas
3726 replace_pp = fCanvas->EnsurePSPainter(kTRUE, oldpp);
3728 }
3729
3730 Bool_t began3DScene = kFALSE;
3731 fPadPaint = 1;
3732 {
3733 TContext ctxt(this, kTRUE);
3734
3735 auto pp = GetPainter();
3736 Bool_t useXor = pp && pp->IsNative() && !pp->IsCocoa();
3737 Bool_t needRepaint = IsModified() || IsTransparent() || (!useXor && fDrawOper.size());
3738
3739 if (needRepaint)
3741
3742 PaintDate();
3743
3744 TList *pList = GetListOfPrimitives();
3745 auto lnk = pList ? pList->FirstLink() : nullptr;
3746
3747 while (lnk) {
3748 TObject *obj = lnk->GetObject();
3749 if (obj->InheritsFrom(TPad::Class())) {
3750 ((TPad*)obj)->PaintModified();
3751 } else if (needRepaint) {
3752
3753 // Create a pad 3D viewer if none exists and we encounter a
3754 // 3D shape
3755 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3756 GetViewer3D("pad");
3757 }
3758
3759 // Open a 3D scene if required
3760 if (fViewer3D && !fViewer3D->BuildingScene()) {
3762 began3DScene = kTRUE;
3763 }
3764
3765 obj->Paint(lnk->GetOption());
3766 }
3767 lnk = lnk->Next();
3768 }
3769
3770 // when XOR is not available - paint operations at the ned
3771 if (!useXor && needRepaint)
3773 }
3774
3775 fPadPaint = 0;
3777
3778 // This must be done after modified flag is cleared, as some
3779 // viewers will invoke another paint by marking pad modified again
3780 if (began3DScene && fViewer3D)
3782
3783 if (replace_pp && fCanvas)
3785
3786 gVirtualPS = saveps;
3787}
3788
3789////////////////////////////////////////////////////////////////////////////////
3790/// Perform buffered paint operations
3791/// Used for interactivity functionality immediately after normal painting is performed
3792/// Only when withXor is specified global window context used to perform
3793/// inversion of window, otherwise only draw operations for the current pad are done
3794
3796{
3797 auto pp = GetPainter();
3798 if (!pp)
3799 return;
3800
3801 // IMPORTANT - only when XOR used change gPad only for coordinates calculation
3802 // selected device should never be changed - therefore not use cd()
3803 auto savepad = gPad;
3804 if (withXor)
3805 gPad = this;
3806
3807 pp->OnPad(this);
3808
3809 if (withXor)
3810 for (auto &oper : fDrawOperXor)
3811 oper.second->Draw(*this, pp, withXor);
3812
3813 fDrawOperXor.clear();
3814
3815 for (auto &oper : fDrawOper)
3816 oper.second->Draw(*this, pp, withXor);
3817
3818 if (withXor)
3819 std::swap(fDrawOperXor, fDrawOper);
3820 else
3821 fDrawOper.clear();
3822
3823 if (withXor) {
3824 gPad = savepad;
3825
3826 TIter next(GetListOfPrimitives());
3827 while (auto obj = next()) {
3828 if (auto pad = dynamic_cast<TPad *>(obj))
3829 pad->PaintOperations(withXor);
3830 }
3831 }
3832}
3833
3834////////////////////////////////////////////////////////////////////////////////
3835/// Paint box in CurrentPad World coordinates.
3836///
3837/// - if option[0] = 's' the box is forced to be paint with style=0
3838/// - if option[0] = 'l' the box contour is drawn
3839/// - if option[0] = 'i' the interactive xor box will be painted
3840
3842{
3843 auto pp = GetPainter();
3844 if (!pp)
3845 return;
3846
3847 if (option && *option == 'i') {
3848 Double_t x[5] = {x1, x2, x2, x1, x1};
3849 Double_t y[5] = {y1, y1, y2, y2, y1};
3851 fDrawOper[option] = std::make_unique<TPadDrawOperation>(5, x, y, drawKind, pp->GetLineWidth());
3852 return;
3853 }
3854
3855 pp->OnPad(this);
3856
3857 Style_t style = pp->GetAttFill().GetFillStyle();
3858 Bool_t draw_border = kFALSE, draw_fill = kFALSE, skip_fill = kFALSE;
3859 if (option && *option == 's')
3860 skip_fill = draw_border = kTRUE;
3861 else if (option && *option == 'l')
3862 draw_border = kTRUE;
3863
3864 if (style >= 3100 && style < 4000) {
3865 Double_t xb[4] = {x1, x1, x2, x2};
3866 Double_t yb[4] = {y1, y2, y2, y1};
3867 PaintFillAreaHatches(4, xb, yb, style);
3868 } else if (style >= 0 && style < 1000) {
3869 draw_border = kTRUE;
3870 } else if (style >= 1000 && style < 2000) {
3871 draw_fill = kTRUE;
3872 } else if (style > 3000 && style < 3100) {
3873 draw_fill = style < 3026;
3874 } else if (style >= 4000 && style <= 4100) {
3875 // transparency styles, supported now by all painters
3876 draw_fill = style > 4000;
3877 } else if (style > 0)
3878 draw_border = kTRUE;
3879
3880 if (draw_fill && !skip_fill)
3881 pp->DrawBox(x1, y1, x2, y2, TVirtualPadPainter::kFilled);
3882
3883 if (draw_border)
3884 pp->DrawBox(x1, y1, x2, y2, TVirtualPadPainter::kHollow);
3885
3886 Modified();
3887}
3888
3889////////////////////////////////////////////////////////////////////////////////
3890/// Copy pixmaps of pads laying below pad "stop" into pad "stop". This
3891/// gives the effect of pad "stop" being transparent.
3892
3894{
3895 Int_t px, py;
3896 XYtoAbsPixel(GetX1(), GetY2(), px, py);
3897 /// Copy pixmap of this pad as background of the current pad.
3898 if (auto pp = GetPainter())
3899 pp->CopyDrawable(GetPixmapID(), px - x, py - y);
3900
3901 TIter next(GetListOfPrimitives());
3902 while (auto obj = next()) {
3903 if (obj == stop)
3904 break;
3905 if (auto pad = dynamic_cast<TPad *>(obj))
3906 pad->CopyBackgroundPixmaps(stop, x, y);
3907 }
3908}
3909
3910////////////////////////////////////////////////////////////////////////////////
3911
3913{
3914 Warning("PaintFillArea", "Float_t signature is obsolete. Use Double_t signature.");
3915}
3916
3917////////////////////////////////////////////////////////////////////////////////
3918/// Paint fill area in CurrentPad World coordinates.
3919///
3920/// If option[0] == 'C' no clipping
3921/// If option[0] == 'i' paint during ExecuteEvent (interactive)
3922
3924{
3925 if (nn < 3)
3926 return;
3928 Bool_t mustClip = kTRUE;
3931 } else {
3932 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
3933 if (option && (*option == 'C')) mustClip = kFALSE;
3934 }
3935
3936 std::vector<Double_t> xclip, yclip;
3937
3938 if (mustClip) {
3939 Int_t nc = 2*nn+1;
3940 xclip.resize(nc, 0.);
3941 yclip.resize(nc, 0.);
3942 Int_t n = ClipPolygon(nn, xx, yy, nc, xclip.data(), yclip.data(), xmin, ymin, xmax, ymax);
3943 if (!n)
3944 return;
3945 nn = n;
3946 xx = xclip.data();
3947 yy = yclip.data();
3948 }
3949
3950 if (option && *option == 'i') {
3951 fDrawOper[option] = std::make_unique<TPadDrawOperation>(nn, xx, yy, TPadDrawOperation::drawFill);
3952 return;
3953 }
3954
3955 auto pp = GetPainter();
3956 if (!pp)
3957 return;
3958
3959 pp->OnPad(this);
3960
3961 // Paint the fill area with hatches
3962 Int_t fillstyle = pp->GetFillStyle();
3963 if (fillstyle >= 3100 && fillstyle < 4000)
3964 PaintFillAreaHatches(nn, xx, yy, fillstyle);
3965 else
3966 pp->DrawFillArea(nn, xx, yy);
3967
3968 Modified();
3969}
3970
3971////////////////////////////////////////////////////////////////////////////////
3972/// Paint fill area in CurrentPad NDC coordinates.
3973
3975{
3976 std::vector<Double_t> xw(n), yw(n);
3977 for (int i=0; i<n; i++) {
3978 xw[i] = fX1 + x[i]*(fX2 - fX1);
3979 yw[i] = fY1 + y[i]*(fY2 - fY1);
3980 }
3981 PaintFillArea(n, xw.data(), yw.data(), option);
3982}
3983
3984////////////////////////////////////////////////////////////////////////////////
3985/// This function paints hatched fill area according to the FillStyle value
3986/// The convention for the Hatch is the following:
3987///
3988/// `FillStyle = 3ijk`
3989///
3990/// - i (1-9) : specify the space between each hatch
3991/// 1 = minimum 9 = maximum
3992/// the final spacing is i*GetHatchesSpacing(). The hatches spacing
3993/// is set by SetHatchesSpacing()
3994/// - j (0-9) : specify angle between 0 and 90 degrees
3995/// * 0 = 0
3996/// * 1 = 10
3997/// * 2 = 20
3998/// * 3 = 30
3999/// * 4 = 45
4000/// * 5 = Not drawn
4001/// * 6 = 60
4002/// * 7 = 70
4003/// * 8 = 80
4004/// * 9 = 90
4005/// - k (0-9) : specify angle between 90 and 180 degrees
4006/// * 0 = 180
4007/// * 1 = 170
4008/// * 2 = 160
4009/// * 3 = 150
4010/// * 4 = 135
4011/// * 5 = Not drawn
4012/// * 6 = 120
4013/// * 7 = 110
4014/// * 8 = 100
4015/// * 9 = 90
4016
4018{
4019 static Double_t ang1[10] = { 0., 10., 20., 30., 45.,5., 60., 70., 80., 89.99};
4020 static Double_t ang2[10] = {180.,170.,160.,150.,135.,5.,120.,110.,100., 89.99};
4021
4022 Int_t fasi = FillStyle % 1000;
4023 Int_t idSPA = fasi / 100;
4024 Int_t iAng2 = (fasi - 100 * idSPA) / 10;
4025 Int_t iAng1 = fasi % 10;
4026 Double_t dy = 0.003 * idSPA * gStyle->GetHatchesSpacing();
4028 auto pp = GetPainter();
4029 if (!pp)
4030 return;
4031
4032 // Save the current line attributes and change to draw hatches
4033 TAttLine saveatt = pp->GetAttLine();
4034
4035 pp->SetAttLine({ pp->GetAttFill().GetFillColor(), 1, lw });
4036
4037 // Draw the hatches
4038 if (ang1[iAng1] != 5.)
4039 PaintHatches(dy, ang1[iAng1], nn, xx, yy);
4040 if (ang2[iAng2] != 5.)
4041 PaintHatches(dy, ang2[iAng2], nn, xx, yy);
4042
4043 pp->SetAttLine(saveatt);
4044}
4045
4046////////////////////////////////////////////////////////////////////////////////
4047/// This routine draw hatches inclined with the
4048/// angle "angle" and spaced of "dy" in normalized device
4049/// coordinates in the surface defined by n,xx,yy.
4050
4052 Int_t nn, Double_t *xx, Double_t *yy)
4053{
4054 Int_t i, i1, i2, nbi;
4055 Double_t ratiox, ratioy, ymin, ymax, yrot, ycur;
4056 const Double_t angr = TMath::Pi()*(180.-angle)/180.;
4057 const Double_t epsil = 0.0001;
4058
4059 std::vector<Double_t> xli;
4060 std::vector<Double_t> yli;
4061
4062 Double_t xt1, xt2, yt1, yt2;
4063 Double_t x, y, x1, x2, y1, y2, a, b, xi, xip, xin, yi, yip;
4064
4065 Double_t rwxmin = gPad->GetX1();
4066 Double_t rwxmax = gPad->GetX2();
4067 Double_t rwymin = gPad->GetY1();
4068 Double_t rwymax = gPad->GetY2();
4069 ratiox = 1./(rwxmax-rwxmin);
4070 ratioy = 1./(rwymax-rwymin);
4071
4072 Double_t sina = TMath::Sin(angr), sinb;
4073 Double_t cosa = TMath::Cos(angr), cosb;
4074 if (TMath::Abs(cosa) <= epsil) cosa=0.;
4075 if (TMath::Abs(sina) <= epsil) sina=0.;
4076 sinb = -sina;
4077 cosb = cosa;
4078
4079 // Values needed to compute the hatches in TRUE normalized space (NDC)
4080 Int_t iw = (Int_t)gPad->GetWw();
4081 Int_t ih = (Int_t)gPad->GetWh();
4082 Double_t x1p,y1p,x2p,y2p;
4083 gPad->GetPadPar(x1p,y1p,x2p,y2p);
4084 iw = (Int_t)(iw*x2p)-(Int_t)(iw*x1p);
4085 ih = (Int_t)(ih*y2p)-(Int_t)(ih*y1p);
4086 Double_t wndc = TMath::Min(1.,(Double_t)iw/(Double_t)ih);
4087 Double_t hndc = TMath::Min(1.,(Double_t)ih/(Double_t)iw);
4088
4089 // Search ymin and ymax
4090 ymin = 1.;
4091 ymax = 0.;
4092 for (i=1; i<=nn; i++) {
4093 x = wndc*ratiox*(xx[i-1]-rwxmin);
4094 y = hndc*ratioy*(yy[i-1]-rwymin);
4095 yrot = sina*x+cosa*y;
4096 if (yrot > ymax) ymax = yrot;
4097 if (yrot < ymin) ymin = yrot;
4098 }
4099
4100 Int_t yindx = (Int_t) (ymax/dy);
4101
4102 while (dy * yindx >= ymin) {
4103 ycur = dy * yindx--;
4104 nbi = 0;
4105
4106 xli.clear();
4107 yli.clear();
4108
4109 for (i=2; i<=nn+1; i++) {
4110 i2 = i;
4111 i1 = i-1;
4112 if (i == nn+1) i2=1;
4113
4114 x1 = wndc*ratiox*(xx[i1-1]-rwxmin);
4115 y1 = hndc*ratioy*(yy[i1-1]-rwymin);
4116 x2 = wndc*ratiox*(xx[i2-1]-rwxmin);
4117 y2 = hndc*ratioy*(yy[i2-1]-rwymin);
4118
4119 xt1 = cosa*x1-sina*y1;
4120 yt1 = sina*x1+cosa*y1;
4121 xt2 = cosa*x2-sina*y2;
4122 yt2 = sina*x2+cosa*y2;
4123
4124 // Line segment parallel to oy
4125 if (xt1 == xt2) {
4126 if (yt1 < yt2) {
4127 yi = yt1;
4128 yip = yt2;
4129 } else {
4130 yi = yt2;
4131 yip = yt1;
4132 }
4133 if ((yi <= ycur) && (ycur < yip)) {
4134 nbi++;
4135 xli.push_back(xt1);
4136 }
4137 continue;
4138 }
4139
4140 // Line segment parallel to ox
4141 if (yt1 == yt2) {
4142 if (yt1 == ycur) {
4143 nbi++;
4144 xli.push_back(xt1);
4145 nbi++;
4146 xli.push_back(xt2);
4147 }
4148 continue;
4149 }
4150
4151 // Other line segment
4152 a = (yt1-yt2)/(xt1-xt2);
4153 b = (yt2*xt1-xt2*yt1)/(xt1-xt2);
4154
4155 if (xt1 < xt2) {
4156 xi = xt1;
4157 xip = xt2;
4158 } else {
4159 xi = xt2;
4160 xip = xt1;
4161 }
4162
4163 xin = (ycur-b)/a;
4164
4165 if ((xi <= xin) && (xin < xip) &&
4166 (TMath::Min(yt1,yt2) <= ycur) &&
4167 (ycur < TMath::Max(yt1,yt2))) {
4168 nbi++;
4169 xli.push_back(xin);
4170 }
4171 }
4172
4173 // Sorting of the x coordinates intersections
4174 std::sort(xli.begin(), xli.end());
4175
4176 // Draw the hatches
4177 if ((nbi%2 != 0) || (nbi == 0))
4178 continue;
4179
4180 for (i=0; i<nbi; ++i) {
4181 // Rotate back the hatches - first calculate y coordinate
4182 Double_t ytmp = sinb*xli[i] + cosb*ycur;
4183 xli[i] = cosb*xli[i] - sinb*ycur;
4184 // Convert hatches' positions from true NDC to WC to handle clipping
4185 xli[i] = (xli[i]/wndc)*(rwxmax-rwxmin)+rwxmin;
4186 ytmp = (ytmp/hndc)*(rwymax-rwymin)+rwymin;
4187 yli.push_back(ytmp);
4188 }
4189
4190 gPad->PaintSegments(nbi/2, xli.data(), yli.data());
4191 }
4192}
4193
4194////////////////////////////////////////////////////////////////////////////////
4195/// Paint line in CurrentPad World coordinates.
4196
4198{
4199 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
4200
4201 //If line is totally clipped, return
4203 if (Clip(x,y,fUxmin,fUymin,fUxmax,fUymax) == 2) return;
4204 } else {
4205 if (Clip(x,y,fX1,fY1,fX2,fY2) == 2) return;
4206 }
4207
4208 if (auto pp = GetPainter()) {
4209 pp->OnPad(this);
4210 pp->DrawLine(x[0], y[0], x[1], y[1]);
4211 }
4212
4213 Modified();
4214}
4215
4216////////////////////////////////////////////////////////////////////////////////
4217/// Paint line in normalized coordinates.
4218
4220{
4221 if (auto pp = GetPainter()) {
4222 pp->OnPad(this);
4223 pp->DrawLineNDC(u1, v1, u2, v2);
4224 }
4225
4226 Modified();
4227}
4228
4229////////////////////////////////////////////////////////////////////////////////
4230/// Paint 3-D line in the CurrentPad.
4231
4233{
4234 if (!fView) return;
4235
4236 // convert from 3-D to 2-D pad coordinate system
4237 Double_t xpad[6];
4238 Double_t temp[3];
4239 Int_t i;
4240 for (i=0;i<3;i++) temp[i] = p1[i];
4241 fView->WCtoNDC(temp, &xpad[0]);
4242 for (i=0;i<3;i++) temp[i] = p2[i];
4243 fView->WCtoNDC(temp, &xpad[3]);
4244 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4245}
4246
4247////////////////////////////////////////////////////////////////////////////////
4248/// Paint 3-D line in the CurrentPad.
4249
4251{
4252 if (!fView) return;
4253
4254 // convert from 3-D to 2-D pad coordinate system
4255 Double_t xpad[6];
4256 Double_t temp[3];
4257 Int_t i;
4258 for (i=0;i<3;i++) temp[i] = p1[i];
4259 fView->WCtoNDC(temp, &xpad[0]);
4260 for (i=0;i<3;i++) temp[i] = p2[i];
4261 fView->WCtoNDC(temp, &xpad[3]);
4262 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4263}
4264
4265////////////////////////////////////////////////////////////////////////////////
4266/// Paint 3-D marker in the CurrentPad.
4267
4269{
4270 if (!fView) return;
4271
4272 Double_t rmin[3], rmax[3];
4273 fView->GetRange(rmin, rmax);
4274
4275 // convert from 3-D to 2-D pad coordinate system
4276 Double_t xpad[3];
4277 Double_t temp[3];
4278 temp[0] = x;
4279 temp[1] = y;
4280 temp[2] = z;
4281 if (x<rmin[0] || x>rmax[0]) return;
4282 if (y<rmin[1] || y>rmax[1]) return;
4283 if (z<rmin[2] || z>rmax[2]) return;
4284 fView->WCtoNDC(temp, &xpad[0]);
4285 PaintPolyMarker(1, &xpad[0], &xpad[1]);
4286}
4287
4288////////////////////////////////////////////////////////////////////////////////
4289/// Paint polyline in CurrentPad World coordinates.
4290///
4291/// If option[0] == 'C' no clipping
4292/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4293
4295{
4296 auto pp = GetPainter();
4297 if ((n < 2) || !pp)
4298 return;
4299
4301 Bool_t mustClip = kTRUE, interactive = option && *option == 'i';
4304 } else {
4305 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4306 if (option && (*option == 'C')) mustClip = kFALSE;
4307 }
4308 Int_t i1 = -1, np = 1, iclip = 0;
4309 for (Int_t i = 0; i < n - 1; i++) {
4310 Double_t x1 = x[i];
4311 Double_t y1 = y[i];
4312 Double_t x2 = x[i+1];
4313 Double_t y2 = y[i+1];
4314 if (mustClip) {
4315 iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4316 if (iclip == 2) {
4317 i1 = -1;
4318 continue;
4319 }
4320 }
4321 np++;
4322 if (i1 < 0)
4323 i1 = i;
4324 if (iclip == 0 && i < n-2)
4325 continue;
4326 if (interactive)
4327 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawLine, pp->GetLineWidth());
4328 else {
4329 pp->OnPad(this);
4330 pp->DrawPolyLine(np, &x[i1], &y[i1]);
4331 }
4332 if (iclip) {
4333 x[i] = x1;
4334 y[i] = y1;
4335 x[i+1] = x2;
4336 y[i+1] = y2;
4337 }
4338 i1 = -1;
4339 np = 1;
4340 }
4341
4342 if (!interactive)
4343 Modified();
4344}
4345
4346////////////////////////////////////////////////////////////////////////////////
4347/// Paint polyline in CurrentPad World coordinates.
4348///
4349/// If option[0] == 'C' no clipping
4350/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4351
4353{
4354 auto pp = GetPainter();
4355 if ((n < 2) || !pp)
4356 return;
4357
4359 Bool_t mustClip = kTRUE, interactive = option && *option == 'i';
4362 } else {
4363 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4364 if (option && (*option == 'C')) mustClip = kFALSE;
4365 }
4366
4367 Int_t i1 = -1, np = 1, iclip = 0;
4368
4369 for (Int_t i = 0; i < n-1; i++) {
4370 Double_t x1 = x[i];
4371 Double_t y1 = y[i];
4372 Double_t x2 = x[i+1];
4373 Double_t y2 = y[i+1];
4374 if (mustClip) {
4375 iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4376 if (iclip == 2) {
4377 i1 = -1;
4378 continue;
4379 }
4380 }
4381 np++;
4382 if (i1 < 0)
4383 i1 = i;
4384 if (iclip == 0 && i < n-2)
4385 continue;
4386 if (interactive)
4387 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawLine, pp->GetLineWidth());
4388 else {
4389 pp->OnPad(this);
4390 pp->DrawPolyLine(np, &x[i1], &y[i1]);
4391 }
4392 if (iclip) {
4393 x[i] = x1;
4394 y[i] = y1;
4395 x[i+1] = x2;
4396 y[i+1] = y2;
4397 }
4398 i1 = -1;
4399 np = 1;
4400 }
4401
4402 if (!interactive)
4403 Modified();
4404}
4405
4406////////////////////////////////////////////////////////////////////////////////
4407/// Paint polyline in CurrentPad NDC coordinates.
4408
4410{
4411 auto pp = GetPainter();
4412 if ((n < 2) || !pp)
4413 return;
4414
4415 if (option && *option == 'i') {
4416 fDrawOper[option] = std::make_unique<TPadDrawOperation>(n, x, y, TPadDrawOperation::drawLine, pp->GetLineWidth(), kTRUE);
4417 return;
4418 }
4419
4420 pp->OnPad(this);
4421 pp->DrawPolyLineNDC(n, x, y);
4422
4423 Modified();
4424}
4425
4426////////////////////////////////////////////////////////////////////////////////
4427/// Paint 3-D polyline in the CurrentPad.
4428
4430{
4431 if (!fView) return;
4432
4433 // Loop on each individual line
4434 for (Int_t i = 1; i < n; i++)
4435 PaintLine3D(&p[3*i-3], &p[3*i]);
4436
4437 Modified();
4438}
4439
4440////////////////////////////////////////////////////////////////////////////////
4441/// Paint polymarker in CurrentPad World coordinates.
4442///
4443/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4444
4446{
4447 Int_t n = TMath::Abs(nn);
4449 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4451 } else {
4452 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4453 }
4454 Int_t i,i1=-1,np=0;
4455 for (i=0; i<n; i++) {
4456 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4457 np++;
4458 if (i1 < 0) i1 = i;
4459 if (i < n-1) continue;
4460 }
4461 if (np == 0)
4462 continue;
4463 if (option && *option == 'i')
4464 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawMarker, option[1] == 'f' ? 0 : 1);
4465 else if (auto pp = GetPainter()) {
4466 pp->OnPad(this);
4467 pp->DrawPolyMarker(np, &x[i1], &y[i1]);
4468 }
4469 i1 = -1;
4470 np = 0;
4471 }
4472 Modified();
4473}
4474
4475////////////////////////////////////////////////////////////////////////////////
4476/// Paint polymarker in CurrentPad World coordinates.
4477///
4478/// If option[0] == 'i' paint during ExecuteEvent (interactive)
4479
4481{
4482 Int_t n = TMath::Abs(nn);
4484 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4486 } else {
4487 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4488 }
4489 Int_t i,i1=-1,np=0;
4490 for (i=0; i<n; i++) {
4491 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4492 np++;
4493 if (i1 < 0) i1 = i;
4494 if (i < n-1) continue;
4495 }
4496 if (np == 0)
4497 continue;
4498
4499 if (option && *option == 'i')
4500 fDrawOper[option] = std::make_unique<TPadDrawOperation>(np, &x[i1], &y[i1], TPadDrawOperation::drawMarker, option[1] == 'f' ? 0 : 1);
4501 else if (auto pp = GetPainter()) {
4502 pp->OnPad(this);
4503 pp->DrawPolyMarker(np, &x[i1], &y[i1]);
4504 }
4505 i1 = -1;
4506 np = 0;
4507 }
4508 Modified();
4509}
4510
4511////////////////////////////////////////////////////////////////////////////////
4512/// Paint N individual segments
4513/// Provided arrays should have 2*n elements
4514/// IMPORTANT! Provided arrays can be modified after function call!
4515
4517{
4518 if (n < 1)
4519 return;
4520
4522 Bool_t mustClip = kTRUE, isAny = kFALSE;
4525 } else {
4526 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4527 if (option && *option == 'C') mustClip = kFALSE;
4528 }
4529
4530 if (!mustClip)
4531 isAny = kTRUE;
4532 else {
4533 for (Int_t i = 0; i < 2*n; i+=2) {
4534 Int_t iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4535 if (iclip == 2)
4536 x[i] = y[i] = x[i+1] = y[i+1] = 0;
4537 else
4538 isAny = kTRUE;
4539 }
4540 }
4541
4542 if (isAny)
4543 if (auto pp = GetPainter()) {
4544 pp->OnPad(this);
4545 pp->DrawSegments(n, x, y);
4546 }
4547
4548 Modified();
4549}
4550
4551
4552////////////////////////////////////////////////////////////////////////////////
4553/// Paint N individual segments in NDC coordinates
4554/// Provided arrays should have 2*n elements
4555/// IMPORTANT! Provided arrays can be modified after function call!
4556
4558{
4559 if (auto pp = GetPainter()) {
4560 pp->OnPad(this);
4561 pp->DrawSegmentsNDC(n, u, v);
4562 }
4563
4564 Modified();
4565}
4566
4567
4568////////////////////////////////////////////////////////////////////////////////
4569/// Paint text in CurrentPad World coordinates.
4570
4572{
4573 Modified();
4574
4575 if (auto pp = GetPainter()) {
4576 pp->OnPad(this);
4577 pp->DrawText(x, y, text, TVirtualPadPainter::kClear);
4578 }
4579}
4580
4581////////////////////////////////////////////////////////////////////////////////
4582/// Paint text in CurrentPad World coordinates.
4583
4584void TPad::PaintText(Double_t x, Double_t y, const wchar_t *text)
4585{
4586 Modified();
4587
4588 if (auto pp = GetPainter()) {
4589 pp->OnPad(this);
4590 pp->DrawText(x, y, text, TVirtualPadPainter::kClear);
4591 }
4592}
4593
4594////////////////////////////////////////////////////////////////////////////////
4595/// Paint text with URL in CurrentPad World coordinates.
4596
4597void TPad::PaintTextUrl(Double_t x, Double_t y, const char *text, const char *url)
4598{
4599 Modified();
4600
4601 if (auto pp = GetPainter()) {
4602 pp->OnPad(this);
4603 pp->DrawTextUrl(x, y, text, url);
4604 }
4605}
4606
4607////////////////////////////////////////////////////////////////////////////////
4608/// Paint text in CurrentPad NDC coordinates.
4609
4611{
4612 Modified();
4613
4614 if (auto pp = GetPainter()) {
4615 pp->OnPad(this);
4616 pp->DrawTextNDC(u, v, text, TVirtualPadPainter::kClear);
4617 }
4618}
4619
4620////////////////////////////////////////////////////////////////////////////////
4621/// Paint text in CurrentPad NDC coordinates.
4622
4624{
4625 Modified();
4626
4627 if (auto pp = GetPainter()) {
4628 pp->OnPad(this);
4629 pp->DrawTextNDC(u, v, text, TVirtualPadPainter::kClear);
4630 }
4631}
4632
4633////////////////////////////////////////////////////////////////////////////////
4634/// Search for an object at pixel position px,py.
4635///
4636/// Check if point is in this pad.
4637///
4638/// If yes, check if it is in one of the sub-pads
4639///
4640/// If found in the pad, compute closest distance of approach
4641/// to each primitive.
4642///
4643/// If one distance of approach is found to be within the limit Distancemaximum
4644/// the corresponding primitive is selected and the routine returns.
4645
4647{
4648 //the two following statements are necessary under NT (multithreaded)
4649 //when a TCanvas object is being created and a thread calling TPad::Pick
4650 //before the TPad constructor has completed in the other thread
4651 if (!gPad) return nullptr; //Andy Haas
4652 if (!GetListOfPrimitives()) return nullptr; //Andy Haas
4653
4654 Int_t dist;
4655 // Search if point is in pad itself
4656 Double_t x = AbsPixeltoX(px);
4657 Double_t y = AbsPixeltoY(py);
4658 if (this != gPad->GetCanvas()) {
4659 if (!((x >= fX1 && x <= fX2) && (y >= fY1 && y <= fY2))) return nullptr;
4660 }
4661
4662 // search for a primitive in this pad or its sub-pads
4663 static TObjOptLink dummyLink(nullptr,""); //place holder for when no link available
4664
4665 TContext ctxt(this, kFALSE); // since no drawing will be done, don't use cd() for efficiency reasons
4666
4667 TPad *pick = nullptr;
4668 TPad *picked = this;
4669 pickobj = nullptr;
4671 dummyLink.SetObject(this);
4672 pickobj = &dummyLink;
4673 }
4674
4675 // Loop backwards over the list of primitives. The first non-pad primitive
4676 // found is the selected one. However, we have to keep going down the
4677 // list to see if there is maybe a pad overlaying the primitive. In that
4678 // case look into the pad for a possible primitive. Once a pad has been
4679 // found we can terminate the loop.
4680 Bool_t gotPrim = kFALSE; // true if found a non pad primitive
4682
4683 //We can have 3d stuff in pad. If canvas prefers to draw
4684 //such stuff with OpenGL, the selection of 3d objects is
4685 //a gl viewer business so, in first cycle we do not
4686 //call DistancetoPrimitive for TAtt3D descendants.
4687 //In case of gl we first try to select 2d object first.
4688
4689 while (lnk) {
4690 TObject *obj = lnk->GetObject();
4691
4692 //If canvas prefers GL, all 3d objects must be drawn/selected by
4693 //gl viewer
4694 if (obj->InheritsFrom(TAtt3D::Class()) && fEmbeddedGL) {
4695 lnk = lnk->Prev();
4696 continue;
4697 }
4698
4699 fPadPointer = obj;
4700 if (obj->InheritsFrom(TPad::Class())) {
4701 pick = ((TPad*)obj)->Pick(px, py, pickobj);
4702 if (pick) {
4703 picked = pick;
4704 break;
4705 }
4706 } else if (!gROOT->GetEditorMode()) {
4707 if (!gotPrim) {
4708 if (!obj->TestBit(kCannotPick)) {
4709 dist = obj->DistancetoPrimitive(px, py);
4710 if (dist < fgMaxPickDistance) {
4711 pickobj = lnk;
4712 gotPrim = kTRUE;
4713 if (dist == 0) break;
4714 }
4715 }
4716 }
4717 }
4718
4719 lnk = lnk->Prev();
4720 }
4721
4722 //if no primitive found, check if we have a TView
4723 //if yes, return the view except if you are in the lower or upper X range
4724 //of the pad.
4725 //In case canvas prefers gl, fView existence
4726 //automatically means viewer3d existence. (?)
4727
4728 if (fView && !gotPrim) {
4729 Double_t dx = 0.05*(fUxmax-fUxmin);
4730 if ((x > fUxmin + dx) && (x < fUxmax-dx)) {
4731
4732 if (fEmbeddedGL) {
4733 //No 2d stuff was selected, but we have gl-viewer. Let it select an object in
4734 //scene (or select itself). In any case it'll internally call
4735 //gPad->SetSelected(ptr) as, for example, hist painter does.
4736 py -= Int_t((1 - GetHNDC() - GetYlowNDC()) * GetWh());
4737 px -= Int_t(GetXlowNDC() * GetWw());
4739 }
4740 else
4741 dummyLink.SetObject(fView);
4742 }
4743 }
4744
4745 if (picked->InheritsFrom(TButton::Class())) {
4746 TButton *button = (TButton*)picked;
4747 if (!button->IsEditable()) pickobj = nullptr;
4748 }
4749
4750 if (TestBit(kCannotPick)) {
4751
4752 if (picked == this) {
4753 // cannot pick pad itself!
4754 picked = nullptr;
4755 }
4756
4757 }
4758
4759 return picked;
4760}
4761
4762////////////////////////////////////////////////////////////////////////////////
4763/// Pop pad to the top of the stack.
4764
4766{
4768 return;
4769 if (!fPrimitives)
4770 fPrimitives = new TList;
4771 if (this == fMother->GetListOfPrimitives()->Last())
4772 return;
4773
4775 while (auto obj = next())
4776 if (obj == this) {
4777 TString opt = next.GetOption();
4778 fMother->Remove(this, kFALSE); // do not issue modified
4779 fMother->Add(this, opt.Data());
4780 return;
4781 }
4782}
4783
4784////////////////////////////////////////////////////////////////////////////////
4785/// This method is equivalent to `SaveAs("filename")`. See TPad::SaveAs for details.
4786
4787void TPad::Print(const char *filename) const
4788{
4789 ((TPad*)this)->SaveAs(filename);
4790}
4791
4792////////////////////////////////////////////////////////////////////////////////
4793/// Save Canvas contents in a file in one of various formats.
4794///
4795/// \anchor TPadPrint
4796/// option can be:
4797///
4798/// - `ps`: a Postscript file is produced (default). [See special cases](\ref TPadPrintPS).
4799/// - `Portrait`: Postscript file is produced (Portrait)
4800/// - `Landscape`: Postscript file is produced (Landscape)
4801/// - `eps`: an Encapsulated Postscript file is produced
4802/// - `Preview`: an [Encapsulated Postscript file with preview](\ref TPadPrintPreview) is produced.
4803/// - `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.
4804/// - `Title:`: The character string after `Title:` becomes a table
4805/// of content entry (for PDF files).
4806/// - `EmbedFonts`: a [PDF file with embedded fonts](\ref TPadPrintEmbedFonts) is generated.
4807/// - `svg`: a SVG file is produced
4808/// - `tex`: a TeX file is produced
4809/// - `Standalone`: a [standalone TeX file](\ref TPadPrintStandalone) is produced.
4810/// - `gif`: a GIF file is produced
4811/// - `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
4812/// - `xpm`: a XPM file is produced
4813/// - `png`: a PNG file is produced
4814/// - `jpg`: a JPEG file is produced. NOTE: JPEG's lossy compression will make all sharp edges fuzzy.
4815/// - `tiff`: a TIFF file is produced
4816/// - `cxx`: a C++ macro file is produced
4817/// - `xml`: a XML file
4818/// - `json`: a JSON file
4819/// - `root`: a ROOT binary file
4820///
4821/// `filename` = 0 - filename is defined by `GetName` and its
4822/// extension is defined with the option
4823///
4824/// When Postscript output is selected (`ps`, `eps`), the canvas is saved
4825/// to `filename.ps` or `filename.eps`. The aspect ratio of the canvas is preserved
4826/// on the Postscript file. When the "ps" option is selected, the Postscript
4827/// page will be landscape format if the canvas is in landscape format, otherwise
4828/// portrait format is selected.
4829///
4830/// The physical size of the Postscript page is the one selected in the
4831/// current style. This size can be modified via TStyle::SetPaperSize.
4832///
4833/// Examples:
4834/// ~~~ {.cpp}
4835/// gStyle->SetPaperSize(TStyle::kA4); //default
4836/// gStyle->SetPaperSize(TStyle::kUSLetter);
4837/// ~~~
4838/// where TStyle::kA4 and TStyle::kUSLetter are defined in the enum
4839/// EPaperSize in TStyle.h
4840///
4841/// An alternative is to call:
4842/// ~~~ {.cpp}
4843/// gStyle->SetPaperSize(20,26); same as kA4
4844/// or gStyle->SetPaperSize(20,24); same as kUSLetter
4845/// ~~~
4846/// The above numbers take into account some margins and are in centimeters.
4847///
4848/// \anchor TPadPrintPreview
4849/// ### The "Preview" option
4850///
4851/// The "Preview" option allows to generate a preview (in the TIFF format) within
4852/// the Encapsulated Postscript file. This preview can be used by programs like
4853/// MSWord to visualize the picture on screen. The "Preview" option relies on the
4854/// ["epstool" command](http://www.cs.wisc.edu/~ghost/gsview/epstool.htm).
4855///
4856/// Example:
4857/// ~~~ {.cpp}
4858/// canvas->Print("example.eps","Preview");
4859/// ~~~
4860///
4861/// \anchor TPadPrintEmbedFonts
4862/// ### The "EmbedFonts" option
4863///
4864/// The "EmbedFonts" option allows to embed the fonts used in a PDF file inside
4865/// that file. This option relies on the ["gs" command](https://ghostscript.com).
4866///
4867/// Example:
4868/// ~~~ {.cpp}
4869/// canvas->Print("example.pdf","EmbedFonts");
4870/// ~~~
4871///
4872/// \anchor TPadPrintStandalone
4873/// ### The "Standalone" option
4874/// The "Standalone" option allows to generate a TeX file ready to be processed by
4875/// tools like `pdflatex`.
4876///
4877/// Example:
4878/// ~~~ {.cpp}
4879/// canvas->Print("example.tex","Standalone");
4880/// ~~~
4881///
4882/// \anchor TPadPrintPS
4883/// ### Writing several canvases to the same Postscript or PDF file:
4884///
4885/// - if the Postscript or PDF file name finishes with "(", the file is not closed
4886/// - if the Postscript or PDF file name finishes with ")" and the file has been opened
4887/// with "(", the file is closed.
4888///
4889/// Example:
4890/// ~~~ {.cpp}
4891/// {
4892/// TCanvas c1("c1");
4893/// h1.Draw();
4894/// c1.Print("c1.ps("); //write canvas and keep the ps file open
4895/// h2.Draw();
4896/// c1.Print("c1.ps"); canvas is added to "c1.ps"
4897/// h3.Draw();
4898/// c1.Print("c1.ps)"); canvas is added to "c1.ps" and ps file is closed
4899/// }
4900/// ~~~
4901/// In the previous example replacing "ps" by "pdf" will create a multi-pages PDF file.
4902///
4903/// Note that the following sequence writes the canvas to "c1.ps" and closes the ps file.:
4904/// ~~~ {.cpp}
4905/// TCanvas c1("c1");
4906/// h1.Draw();
4907/// c1.Print("c1.ps");
4908/// ~~~
4909/// The `TCanvas::Print("file.ps(")` mechanism is very useful, but it can be
4910/// a little inconvenient to have the action of opening/closing a file
4911/// being atomic with printing a page. Particularly if pages are being
4912/// generated in some loop one needs to detect the special cases of first
4913/// and last page and then munge the argument to Print() accordingly.
4914///
4915/// The "[" and "]" can be used instead of "(" and ")" to open / close without
4916/// actual printing.
4917///
4918/// Example:
4919/// ~~~ {.cpp}
4920/// c1.Print("file.ps["); // No actual print, just open file.ps
4921/// for (int i=0; i<10; ++i) {
4922/// // fill canvas for context i
4923/// // ...
4924///
4925/// c1.Print("file.ps"); // actually print canvas to file
4926/// }// end loop
4927/// c1.Print("file.ps]"); // No actual print, just close.
4928/// ~~~
4929/// As before, the same macro is valid for PDF files.
4930///
4931/// It is possible to print a canvas into an animated GIF file by specifying the
4932/// file name as "myfile.gif+" or "myfile.gif+NN", where NN*10ms is delay
4933/// between the subimages' display. If NN is omitted the delay between
4934/// subimages is zero. Each picture is added in the animation thanks to a loop
4935/// similar to the following one:
4936/// ~~~ {.cpp}
4937/// for (int i=0; i<10; ++i) {
4938/// // fill canvas for context i
4939/// // ...
4940///
4941/// c1.Print("file.gif+5"); // print canvas to GIF file with 50ms delays
4942/// }// end loop
4943/// ~~~
4944/// The delay between each frame must be specified in each Print() statement.
4945/// If the file "myfile.gif" already exists, the new frame are appended at
4946/// the end of the file. To avoid this, delete it first with `gSystem->Unlink(myfile.gif);`
4947/// If you want the gif file to repeat or loop forever, check TASImage::WriteImage documentation
4948
4950{
4951 auto canv = GetCanvas();
4952 if (!canv)
4953 return;
4954
4955 TString psname, fs1 = filename;
4956
4957 // "[" and "]" are special characters for ExpandPathName. When they are at the end
4958 // of the file name (see help) they must be removed before doing ExpandPathName.
4959 if (fs1.EndsWith("[")) {
4960 fs1.Replace((fs1.Length()-1),1," ");
4961 gSystem->ExpandPathName(fs1);
4962 fs1.Replace((fs1.Length()-1),1,"[");
4963 } else if (fs1.EndsWith("]")) {
4964 fs1.Replace((fs1.Length()-1),1," ");
4965 gSystem->ExpandPathName(fs1);
4966 fs1.Replace((fs1.Length()-1),1,"]");
4967 } else {
4968 gSystem->ExpandPathName(fs1);
4969 }
4970
4971 // Set the default option as "Postscript" (Should be a data member of TPad)
4972 const char *opt_default = "ps";
4973
4974 TString opt = !option ? opt_default : option;
4975 Bool_t image = kFALSE;
4976 Bool_t title = opt.Contains("Title:");
4977
4978 if (!fs1.Length()) {
4979 psname = GetName();
4980 psname += opt;
4981 } else {
4982 psname = fs1;
4983 }
4984
4985 // lines below protected against case like c1->SaveAs( "../ps/cs.ps" );
4986 if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
4987 psname = GetName();
4988 psname.Append(fs1);
4989 psname.Prepend("/");
4990 psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
4991 }
4992
4993 // Save pad/canvas in alternative formats
4995 if (!title && opt.Contains("gif+")) {
4996 gtype = TImage::kAnimGif;
4997 image = kTRUE;
4998 } else if (!title && opt.Contains("gif")) {
4999 gtype = TImage::kGif;
5000 image = kTRUE;
5001 } else if (!title && opt.Contains("png")) {
5002 gtype = TImage::kPng;
5003 image = kTRUE;
5004 } else if (!title && opt.Contains("jpg")) {
5005 gtype = TImage::kJpeg;
5006 image = kTRUE;
5007 } else if (!title && opt.Contains("tiff")) {
5008 gtype = TImage::kTiff;
5009 image = kTRUE;
5010 } else if (!title && opt.Contains("xpm")) {
5011 gtype = TImage::kXpm;
5012 image = kTRUE;
5013 } else if (!title && opt.Contains("bmp")) {
5014 gtype = TImage::kBmp;
5015 image = kTRUE;
5016 } else if (!title && opt.Contains("svg")) {
5017 gtype = TImage::kSvg;
5018 } else if (!title && opt.Contains("pdf")) {
5019 gtype = TImage::kPdf;
5020 } else if (!title && opt.Contains("html")) {
5021 gtype = TImage::kHtml;
5022 }
5023
5024 auto pp = GetPainter();
5025 Bool_t isweb = canv->IsWeb();
5026 Bool_t isbatch = gROOT->IsBatch() || canv->IsBatch();
5027
5028 // for a moment special handling of web canvas - check if can save directly
5029 if (isweb && pp)
5030 if (pp->SaveAsImage(this, psname.Data(), gtype) != TVirtualPadPainter::kSaveNotImplemented)
5031 return;
5032
5033 // to create HTML file web-based canvas functionality is invoked
5034 if (gtype == TImage::kHtml) {
5035 auto cmd = TString::Format("TWebCanvas::ProduceImage((TPad *) 0x%zx, \"%s\");", (size_t) this, psname.Data());
5036 Long_t res = gROOT->ProcessLine(cmd);
5037 if (!res)
5038 Error("Print", "Fail create HTML file %s", psname.Data());
5039 return;
5040 }
5041
5042 if (((!isbatch && image) || isweb) && pp) {
5043 Color_t hc = canv->GetHighLightColor();
5044
5045 if (!isweb) {
5046 canv->SetHighLightColor(-1);
5047 Modified();
5048 }
5049 canv->Update();
5050
5051 auto res = pp->SaveAsImage(this, psname.Data(), gtype);
5052
5053 if (!isweb)
5054 canv->SetHighLightColor(hc);
5055
5057 Warning("Print", "Unsupported image format %s, fallback to TImageDump", psname.Data());
5058 else if ((res == TVirtualPadPainter::kSaveOk) && !gSystem->AccessPathName(psname.Data()))
5059 Info("Print", "file %s has been created", psname.Data());
5060
5062 return;
5063 }
5064
5065 //==============Save pad/canvas as a C++ script==============================
5066 if (!title && opt.Contains("cxx")) {
5067 GetCanvas()->SaveSource(psname, "");
5068 return;
5069 }
5070
5071 //==============Save pad/canvas as a root file===============================
5072 if (!title && opt.Contains("root")) {
5073 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5074 return;
5075 }
5076
5077 //==============Save pad/canvas as a XML file================================
5078 if (!title && opt.Contains("xml")) {
5079 // Plugin XML driver
5080 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5081 return;
5082 }
5083
5084 //==============Save pad/canvas as a JSON file================================
5085 if (!title && opt.Contains("json")) {
5086 if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
5087 return;
5088 }
5089
5090 //==============Save pad/canvas as a SVG file================================
5091 if (gtype == TImage::kSvg) {
5092 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5093
5094 Bool_t noScreen = kFALSE, wasModified = IsModified();
5095 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5096 noScreen = kTRUE;
5098 }
5099
5100 TContext ctxt(this, kTRUE);
5101
5102 if (!gVirtualPS) {
5103 // Plugin Postscript/SVG driver
5104 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "svg")) {
5105 if (h->LoadPlugin() == -1)
5106 return;
5107 h->ExecPlugin(0);
5108 }
5109 }
5110
5111 // Create a new SVG file
5112 if (gVirtualPS) {
5113 gVirtualPS->SetName(psname);
5114 gVirtualPS->Open(psname);
5117 }
5118
5119 Paint();
5120 if (noScreen)
5122 if (wasModified && !IsBatch())
5123 Modified(kTRUE);
5124
5125 if (!gSystem->AccessPathName(psname))
5126 Info("Print", "SVG file %s has been created", psname.Data());
5127
5128 delete gVirtualPS;
5129 gVirtualPS = nullptr;
5130
5131 return;
5132 }
5133
5134 //==============Save pad/canvas as a TeX file================================
5135 if (!title && (opt.Contains("tex") || opt.Contains("Standalone"))) {
5136 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5137
5138 Bool_t noScreen = kFALSE, wasModified = IsModified();
5139 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5140 noScreen = kTRUE;
5142 }
5143
5144 TContext ctxt(this, kTRUE);
5145
5146 if (!gVirtualPS) {
5147 // Plugin Postscript/SVG driver
5148 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "tex")) {
5149 if (h->LoadPlugin() == -1)
5150 return;
5151 h->ExecPlugin(0);
5152 }
5153 }
5154
5155 Bool_t standalone = kFALSE;
5156 if (strstr(opt,"Standalone")) standalone = kTRUE;
5157
5158 // Create a new TeX file
5159 if (gVirtualPS) {
5160 gVirtualPS->SetName(psname);
5161 if (standalone) gVirtualPS->SetTitle("Standalone");
5162 gVirtualPS->Open(psname);
5165 }
5166 Paint();
5167 if (noScreen)
5169 if (wasModified && !IsBatch())
5170 Modified(kTRUE);
5171
5172 if (!gSystem->AccessPathName(psname)) {
5173 if (standalone) {
5174 Info("Print", "Standalone TeX file %s has been created", psname.Data());
5175 } else{
5176 Info("Print", "TeX file %s has been created", psname.Data());
5177 }
5178 }
5179
5180 delete gVirtualPS;
5181 gVirtualPS = nullptr;
5182
5183 return;
5184 }
5185
5186 //==============Save pad/canvas as a Postscript file=========================
5187
5188 // in case we read directly from a Root file and the canvas
5189 // is not on the screen, set batch mode
5190
5191 Bool_t mustOpen = kTRUE, mustClose = kTRUE,
5192 copen = kFALSE, cclose = kFALSE, copenb = kFALSE, ccloseb = kFALSE;
5193 if (!image) {
5194 // The parenthesis mechanism is only valid for PS and PDF files.
5195 copen = psname.EndsWith("("); if (copen) psname[psname.Length()-1] = 0;
5196 cclose = psname.EndsWith(")"); if (cclose) psname[psname.Length()-1] = 0;
5197 copenb = psname.EndsWith("["); if (copenb) psname[psname.Length()-1] = 0;
5198 ccloseb = psname.EndsWith("]"); if (ccloseb) psname[psname.Length()-1] = 0;
5199 }
5200 gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
5201 if (gVirtualPS) mustOpen = mustClose = kFALSE;
5202 if (copen || copenb) mustClose = kFALSE;
5203 if (cclose || ccloseb) mustClose = kTRUE;
5204
5205 Bool_t noScreen = kFALSE, wasModified = IsModified();
5206 if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
5207 noScreen = kTRUE;
5209 }
5210 Int_t pstype = 111;
5211 Double_t xcanvas = GetCanvas()->XtoPixel(GetCanvas()->GetX2());
5212 Double_t ycanvas = GetCanvas()->YtoPixel(GetCanvas()->GetY1());
5213 Double_t ratio = ycanvas/xcanvas;
5214 if (ratio < 1) pstype = 112;
5215 if (strstr(opt,"Portrait")) pstype = 111;
5216 if (strstr(opt,"Landscape")) pstype = 112;
5217 if (strstr(opt,"eps")) pstype = 113;
5218 if (strstr(opt,"Preview")) pstype = 113;
5219
5220 TContext ctxt(this, kTRUE);
5221 TVirtualPS *psave = gVirtualPS;
5222
5223 if (!gVirtualPS || mustOpen) {
5224
5225 const char *pluginName = "ps"; // Plugin Postscript driver
5226 if (opt.Contains("pdf") || title || opt.Contains("EmbedFonts"))
5227 pluginName = "pdf";
5228 else if (image)
5229 pluginName = "image"; // Plugin TImageDump driver
5230
5231 if (auto h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", pluginName)) {
5232 if (h->LoadPlugin() == -1)
5233 return;
5234 h->ExecPlugin(0);
5235 }
5236
5237 // Create a new Postscript, PDF or image file
5238 if (gVirtualPS)
5239 gVirtualPS->SetName(psname);
5240 const Ssiz_t titlePos = opt.Index("Title:");
5241 if (titlePos != kNPOS) {
5242 if (gVirtualPS)
5243 gVirtualPS->SetTitle(opt.Data()+titlePos+6);
5244 opt.Replace(titlePos,opt.Length(),"pdf");
5245 }
5246 if (gVirtualPS)
5247 gVirtualPS->Open(psname,pstype);
5248 if (gVirtualPS)
5250 if (!copenb) {
5251 if (!opt.Contains("pdf") || image) {
5253 }
5254 Paint();
5255 }
5256 if (noScreen) GetCanvas()->SetBatch(kFALSE);
5257
5258 if (mustClose) {
5259 gROOT->GetListOfSpecials()->Remove(gVirtualPS);
5260 delete gVirtualPS;
5261 gVirtualPS = psave;
5262 } else {
5263 gROOT->GetListOfSpecials()->Add(gVirtualPS);
5264 gVirtualPS = nullptr;
5265 }
5266
5267 if (!gSystem->AccessPathName(psname)) {
5268 if (!copen) Info("Print", "%s file %s has been created", opt.Data(), psname.Data());
5269 else Info("Print", "%s file %s has been created using the current canvas", opt.Data(), psname.Data());
5270 }
5271 } else {
5272 // Append to existing Postscript, PDF or GIF file
5273 if (!ccloseb) {
5275 Paint();
5276 }
5277 const Ssiz_t titlePos = opt.Index("Title:");
5278 if (titlePos != kNPOS) {
5279 gVirtualPS->SetTitle(opt.Data() + titlePos + 6);
5280 opt.Replace(titlePos, opt.Length(), "pdf");
5281 } else if (!ccloseb) {
5282 gVirtualPS->SetTitle("PDF");
5283 }
5284 if (mustClose) {
5285 if (cclose) Info("Print", "Current canvas added to %s file %s and file closed", opt.Data(), psname.Data());
5286 else Info("Print", "%s file %s has been closed", opt.Data(), psname.Data());
5287 gROOT->GetListOfSpecials()->Remove(gVirtualPS);
5288 delete gVirtualPS;
5289 gVirtualPS = nullptr;
5290 } else {
5291 Info("Print", "Current canvas added to %s file %s", opt.Data(), psname.Data());
5292 gVirtualPS = nullptr;
5293 }
5294 }
5295
5296 if (wasModified && !IsBatch())
5297 Modified(kTRUE);
5298
5299 if (opt.Contains("Preview"))
5300 gSystem->Exec(TString::Format("epstool --quiet -t6p %s %s", psname.Data(), psname.Data()).Data());
5301 if (opt.Contains("EmbedFonts")) {
5302 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",
5303 psname.Data()).Data());
5304 gSystem->Rename("pdf_temp.pdf", psname.Data());
5305 }
5306
5307}
5308
5309////////////////////////////////////////////////////////////////////////////////
5310/// Set world coordinate system for the pad.
5311/// Emits signal "RangeChanged()", in the slot get the range
5312/// via GetRange().
5313
5315{
5316 if ((x1 >= x2) || (y1 >= y2)) {
5317 Error("Range", "illegal world coordinates range: x1=%f, y1=%f, x2=%f, y2=%f",x1,y1,x2,y2);
5318 return;
5319 }
5320
5321 fUxmin = x1;
5322 fUxmax = x2;
5323 fUymin = y1;
5324 fUymax = y2;
5325
5326 if (fX1 == x1 && fY1 == y1 && fX2 == x2 && fY2 == y2) return;
5327
5328 fX1 = x1;
5329 fY1 = y1;
5330 fX2 = x2;
5331 fY2 = y2;
5332
5333 // compute pad conversion coefficients
5334 ResizePad();
5335
5336 if (gPad == this && GetPainter())
5338
5339 // emit signal
5340 RangeChanged();
5341}
5342
5343////////////////////////////////////////////////////////////////////////////////
5344/// Set axis coordinate system for the pad.
5345/// The axis coordinate system is a subset of the world coordinate system
5346/// xmin,ymin is the origin of the current coordinate system,
5347/// xmax is the end of the X axis, ymax is the end of the Y axis.
5348/// By default a margin of 10 per cent is left on all sides of the pad
5349/// Emits signal "RangeAxisChanged()", in the slot get the axis range
5350/// via GetRangeAxis().
5351
5353{
5354 if ((xmin >= xmax) || (ymin >= ymax)) {
5355 Error("RangeAxis", "illegal axis coordinates range: xmin=%f, ymin=%f, xmax=%f, ymax=%f",
5356 xmin, ymin, xmax, ymax);
5357 return;
5358 }
5359
5360 fUxmin = xmin;
5361 fUymin = ymin;
5362 fUxmax = xmax;
5363 fUymax = ymax;
5364
5365 // emit signal
5367}
5368
5369////////////////////////////////////////////////////////////////////////////////
5370/// Recursively remove object from a pad and its sub-pads.
5371
5373{
5374 if (fCanvas) {
5375 if (obj == fCanvas->GetSelected()) fCanvas->SetSelected(nullptr);
5376 if (obj == fCanvas->GetClickSelected()) fCanvas->SetClickSelected(nullptr);
5377 }
5378 if (obj == fView) fView = nullptr;
5379 if (!fPrimitives) return;
5380 Int_t nold = fPrimitives->GetSize();
5382 if (nold != fPrimitives->GetSize()) fModified = kTRUE;
5383}
5384
5385////////////////////////////////////////////////////////////////////////////////
5386/// Remove object from list of primitives
5387/// When \par modified set to kTRUE (default) pad will be marked as modified - if object really removed
5388/// Returns result of GetListOfPrimitives()->Remove(obj) or nullptr if list of primitives not exists
5389
5391{
5392 TObject *res = nullptr;
5393 if (fPrimitives)
5394 res = fPrimitives->Remove(obj);
5395 if (res && modified)
5396 Modified();
5397 return res;
5398}
5399
5400////////////////////////////////////////////////////////////////////////////////
5401/// Redraw the frame axis.
5402///
5403/// Redrawing axis may be necessary in case of superimposed histograms
5404/// when one or more histograms have a fill color.
5405///
5406/// Instead of calling this function, it may be more convenient
5407/// to call directly `h1->Draw("sameaxis")` where h1 is the pointer
5408/// to the first histogram drawn in the pad.
5409///
5410/// By default, if the pad has the options gridx or/and gridy activated,
5411/// the grid is not drawn by this function.
5412///
5413/// If option="g" is specified, this will force the drawing of the grid
5414/// on top of the picture
5415///
5416/// To redraw the axis tick marks do:
5417/// ~~~ {.cpp}
5418/// gPad->RedrawAxis();
5419/// ~~~
5420/// To redraw the axis grid do:
5421/// ~~~ {.cpp}
5422/// gPad->RedrawAxis("G");
5423/// ~~~
5424/// To redraw the axis tick marks and the axis grid do:
5425/// ~~~ {.cpp}
5426/// gPad->RedrawAxis();
5427/// gPad->RedrawAxis("G");
5428/// ~~~
5429///
5430/// If option="f" is specified, this will force the drawing of the frame
5431/// around the plot.
5432
5434{
5435 TString opt = option;
5436 opt.ToLower();
5437
5438 TContext ctxt(this, kTRUE);
5439
5440 TH1 *hobj = nullptr;
5441
5442 // Get the first histogram drawing the axis in the list of primitives
5443 if (!fPrimitives) fPrimitives = new TList;
5444 TIter next(fPrimitives);
5445 TObject *obj;
5446 while ((obj = next())) {
5447 if (obj->InheritsFrom(TH1::Class())) {
5448 hobj = (TH1*)obj;
5449 break;
5450 }
5451 if (obj->InheritsFrom(TMultiGraph::Class())) {
5452 TMultiGraph *mg = (TMultiGraph*)obj;
5453 if (mg) hobj = mg->GetHistogram();
5454 break;
5455 }
5456 if (obj->InheritsFrom(TGraph::Class())) {
5457 TGraph *g = (TGraph*)obj;
5458 if (g) hobj = g->GetHistogram();
5459 break;
5460 }
5461 if (obj->InheritsFrom(THStack::Class())) {
5462 THStack *hs = (THStack*)obj;
5463 if (hs) hobj = hs->GetHistogram();
5464 break;
5465 }
5466 }
5467
5468 if (hobj) {
5469 if (opt.Contains("g")) hobj->DrawCopy("sameaxig");
5470 else hobj->DrawCopy("sameaxis");
5471 }
5472
5473 if (opt.Contains("f")) {
5474 auto b = new TBox(gPad->GetUxmin(), gPad->GetUymin(),
5475 gPad->GetUxmax(), gPad->GetUymax());
5476 b->SetFillStyle(0);
5477 b->SetLineStyle(gPad->GetFrameLineStyle());
5478 b->SetLineWidth(gPad->GetFrameLineWidth());
5479 b->SetLineColor(gPad->GetFrameLineColor());
5480 b->Draw();
5481 }
5482}
5483
5484////////////////////////////////////////////////////////////////////////////////
5485/// Compute pad conversion coefficients.
5486///
5487/// ### Conversion from x to px
5488///
5489/// \f[\frac{x-xmin}{xrange} = \frac{px-pxlow}{pxrange}\f]
5490/// with:
5491/// \f[ xrange = xmax-xmin \f]
5492/// \f[ pxrange = pxmax-pxmin \f]
5493///
5494/// \f[
5495/// \Rightarrow px = \frac{pxrange(x-xmin)}{xrange} + pxlow = fXtoPixelk + fXtoPixel \times x
5496/// \f]
5497///
5498/// \f[
5499/// \Rightarrow fXtoPixelk = pxlow - pxrange \frac{xmin}{xrange}
5500/// \f]
5501/// \f[
5502/// fXtoPixel = \frac{pxrange}{xrange}
5503/// \f]
5504/// where:
5505/// \f[
5506/// pxlow = fAbsXlowNDC \times fCw
5507/// \f]
5508/// \f[
5509/// pxrange = fAbsWNDC \times fCw
5510/// \f]
5511///
5512/// ### Conversion from y to py
5513///
5514/// \f[\frac{y-ymin}{yrange} = \frac{py-pylow}{pyrange}\f]
5515/// with:
5516/// \f[ yrange = ymax-ymin \f]
5517/// \f[ pyrange = pymax-pymin \f]
5518///
5519/// \f[
5520/// \Rightarrow py = \frac{pyrange(y-xmin)}{yrange} + pylow = fYtoPixelk + fYtoPixel \times y
5521/// \f]
5522///
5523/// \f[
5524/// \Rightarrow fYtoPixelk = pylow - pyrange \frac{ymin}{yrange}
5525/// \f]
5526/// \f[
5527/// fYtoPixel = \frac{pyrange}{yrange}
5528/// \f]
5529/// where:
5530/// \f[
5531/// pylow = fAbsYlowNDC \times fCh
5532/// \f]
5533/// \f[
5534/// pyrange = fAbsHNDC \times fCh
5535/// \f]
5536///
5537/// ### Conversion from px to x
5538///
5539/// \f[
5540/// \Rightarrow x = \frac{xrange(px-pxlow)}{pxrange}+ xmin = fPixeltoXk + fPixeltoX \times px
5541/// \f]
5542///
5543/// \f[
5544/// \Rightarrow fPixeltoXk = xmin - pxlow \times\frac{xrange}{pxrange}
5545/// \f]
5546/// \f[
5547/// fPixeltoX = \frac{xrange}{pxrange}
5548/// \f]
5549///
5550/// ### Conversion from py to y
5551///
5552/// \f[
5553/// \Rightarrow y = \frac{yrange(py-pylow)}{pyrange}+ ymin = fPixeltoYk + fPixeltoY \times py
5554/// \f]
5555///
5556/// \f[
5557/// \Rightarrow fPixeltoYk = ymin - pylow \times\frac{yrange}{pyrange}
5558/// \f]
5559/// \f[
5560/// fPixeltoY = \frac{yrange}{pyrange}
5561/// \f]
5562///
5563/// ### Computation of the coefficients in case of LOG scales
5564///
5565/// #### Conversion from pixel coordinates to world coordinates
5566///
5567/// \f[
5568/// u = \frac{Log(x) - Log(xmin)}{Log(xmax) - Log(xmin)} = \frac{Log(x/xmin)}{Log(xmax/xmin)} = \frac{px - pxlow}{pxrange}
5569/// \f]
5570///
5571/// \f[ \Rightarrow Log(\frac{x}{xmin}) = u \times Log(\frac{xmax}{xmin}) \f]
5572/// \f[ x = xmin \times e^{(u \times Log(\frac{xmax}{xmin})} \f]
5573/// Let:
5574/// \f[ alfa = \frac{Log(\frac{xmax}{xmin})}{fAbsWNDC} \f]
5575///
5576/// \f[ x = xmin \times e^{(-alfa \times pxlow)} + e^{(alfa \times px)} \f]
5577/// \f[ x = fPixeltoXk \times e^{(fPixeltoX \times px)} \f]
5578/// \f[ ==> fPixeltoXk = xmin \times e^{(-alfa*pxlow)} \f]
5579/// \f[ fPixeltoX = alfa \f]
5580///
5581/// \f[
5582/// v = \frac{Log(y) - Log(ymin)}{Log(ymax) - Log(ymin)} = \frac{Log(y/ymin)}{Log(ymax/ymin)} = \frac{py - pylow}{pyrange}
5583/// \f]
5584/// Let:
5585/// \f[ beta = Log(\frac{ymax}{ymin}) \f]
5586/// \f[ Log(\frac{y}{ymin}) = beta \times pylow - beta \times py \f]
5587/// \f[ \frac{y}{ymin} = e^{(beta \times pylow - beta \times py)} \f]
5588/// \f[ y = ymin \times e^{(beta \times pylow)} \times e^{(-beta \times py)}\f]
5589/// \f[ \Rightarrow y = fPixeltoYk \times e^{(fPixeltoY \times py)} \f]
5590/// \f[ fPixeltoYk = ymin \times e^{(beta \times pylow)} \f]
5591/// \f[ fPixeltoY = -beta \f]
5592///
5593/// #### Conversion from World coordinates to pixel coordinates
5594///
5595/// \f[ px = pxlow + u*pxrange \f]
5596/// \f[ = pxlow + Log(x/xmin)/alfa \f]
5597/// \f[ = pxlow -Log(xmin)/alfa + Log(x)/alfa \f]
5598/// \f[ = fXtoPixelk + fXtoPixel*Log(x) \f]
5599/// \f[ \Rightarrow fXtoPixelk = pxlow -Log(xmin)/alfa \f]
5600/// \f[ \Rightarrow fXtoPixel = 1/alfa \f]
5601///
5602/// \f[ py = pylow - Log(y/ymin)/beta \f]
5603/// \f[ = fYtoPixelk + fYtoPixel*Log(y) \f]
5604/// \f[ \Rightarrow fYtoPixelk = pylow - Log(ymin)/beta \f]
5605/// \f[ fYtoPixel = 1/beta \f]
5606
5608{
5609
5610 if (!gPad) {
5611 Error("ResizePad", "Cannot resize pad. No current pad available.");
5612 return;
5613 }
5614 if (gPad->GetWw()==0.0||gPad->GetWh()==0.0) {
5615 Warning("ResizePad", "gPad has at least one zero dimension.");
5616 return;
5617 }
5618 if (fX1==fX2||fY1==fY2) {
5619 Warning("ResizePad", "The pad has at least one zero dimension.");
5620 return;
5621 }
5622 // Recompute subpad positions in case pad has been moved/resized
5623 TPad *parent = fMother;
5624 if (this == gPad->GetCanvas()) {
5627 fAbsWNDC = fWNDC;
5628 fAbsHNDC = fHNDC;
5629 }
5630 else {
5631 if (parent->GetAbsHNDC()==0.0||parent->GetAbsWNDC()==0.0||fHNDC==0.0||fWNDC==0.0) {
5632 Warning("ResizePad", "The parent pad has at least one zero dimension.");
5633 return;
5634 }
5635 fAbsXlowNDC = fXlowNDC*parent->GetAbsWNDC() + parent->GetAbsXlowNDC();
5636 fAbsYlowNDC = fYlowNDC*parent->GetAbsHNDC() + parent->GetAbsYlowNDC();
5637 fAbsWNDC = fWNDC*parent->GetAbsWNDC();
5638 fAbsHNDC = fHNDC*parent->GetAbsHNDC();
5639 }
5640
5641 Double_t ww = (Double_t)gPad->GetWw();
5642 Double_t wh = (Double_t)gPad->GetWh();
5643 Double_t pxlow = fAbsXlowNDC*ww;
5644 Double_t pylow = (1-fAbsYlowNDC)*wh;
5645 Double_t pxrange = fAbsWNDC*ww;
5646 Double_t pyrange = -fAbsHNDC*wh;
5647
5648 // Linear X axis
5649 Double_t rounding = 0.; // was used before to adjust somehow wrong int truncation by coordinates transformation
5650 Double_t xrange = fX2 - fX1;
5651 fXtoAbsPixelk = rounding + pxlow - pxrange*fX1/xrange; //origin at left
5652 fXtoPixelk = rounding + -pxrange*fX1/xrange;
5653 fXtoPixel = pxrange/xrange;
5654 fAbsPixeltoXk = fX1 - pxlow*xrange/pxrange;
5655 fPixeltoXk = fX1;
5656 fPixeltoX = xrange/pxrange;
5657 // Linear Y axis
5658 Double_t yrange = fY2 - fY1;
5659 fYtoAbsPixelk = rounding + pylow - pyrange*fY1/yrange; //origin at top
5660 fYtoPixelk = rounding + -pyrange - pyrange*fY1/yrange;
5661 fYtoPixel = pyrange/yrange;
5662 fAbsPixeltoYk = fY1 - pylow*yrange/pyrange;
5663 fPixeltoYk = fY1;
5664 fPixeltoY = yrange/pyrange;
5665
5666 // Coefficients to convert from pad NDC coordinates to pixel coordinates
5667
5668 fUtoAbsPixelk = rounding + pxlow;
5669 fUtoPixelk = rounding;
5670 fUtoPixel = pxrange;
5671 fVtoAbsPixelk = rounding + pylow;
5672 fVtoPixelk = -pyrange;
5673 fVtoPixel = pyrange;
5674
5675 // Coefficients to convert from canvas pixels to pad world coordinates
5676
5677 // Resize all sub-pads
5678 if (!fPrimitives)
5679 fPrimitives = new TList;
5680 TIter next(GetListOfPrimitives());
5681 while (auto obj = next()) {
5682 if (obj->InheritsFrom(TPad::Class()))
5683 ((TPad *)obj)->ResizePad(option);
5684 }
5685
5686 // Reset all current sizes
5687 if (gPad->IsBatch())
5688 fPixmapID = 0;
5689 else if (auto pp = GetPainter()) {
5690 if (pp->IsNative()) {
5691 // TODO: check if this is necessary
5692 auto attl = pp->GetAttLine();
5693 attl.SetLineColor(-1);
5694 pp->SetAttLine(attl);
5695 auto attt = pp->GetAttText();
5696 attt.SetTextSize(-1);
5697 pp->OnPad(this);
5698 pp->SetAttText(attt);
5699 // create or re-create off-screen pixmap
5700 if (fPixmapID) {
5701 int w = TMath::Abs(XtoPixel(fX2) - XtoPixel(fX1));
5702 int h = TMath::Abs(YtoPixel(fY2) - YtoPixel(fY1));
5703 //protection in case of wrong pad parameters.
5704 //without this protection, the OpenPixmap or ResizePixmap crashes with
5705 //the message "Error in <RootX11ErrorHandler>: BadValue (integer parameter out of range for operation)"
5706 //resulting in a frozen xterm
5709 Warning("ResizePad", "Inf/NaN propagated to the pad. Check drawn objects.");
5710 if (w <= 0 || w > 10000) {
5711 Warning("ResizePad", "%s width changed from %d to %d\n",GetName(),w,10);
5712 w = 10;
5713 }
5714 if (h <= 0 || h > 10000) {
5715 Warning("ResizePad", "%s height changed from %d to %d\n",GetName(),h,10);
5716 h = 10;
5717 }
5718 if (fPixmapID == -1) // this case is handled via the ctor
5719 fPixmapID = pp->CreateDrawable(w, h);
5720 else if (pp->ResizeDrawable(fPixmapID, w, h)) {
5721 Resized();
5722 Modified(kTRUE);
5723 }
5724 }
5725 }
5726 }
5727 if (fView) {
5728 if (gPad == this) {
5729 fView->ResizePad();
5730 } else {
5731 TContext ctxt(this, kTRUE);
5732 fView->ResizePad();
5733 }
5734 }
5735}
5736
5737////////////////////////////////////////////////////////////////////////////////
5738/// Save the pad content in a file.
5739///
5740/// The file's format used to save the pad is determined by the `filename` extension:
5741///
5742/// - if `filename` is empty, the file produced is `padname.ps`
5743/// - if `filename` starts with a dot, the padname is added in front
5744/// - if `filename` ends with `.ps`, a Postscript file is produced
5745/// - if `filename` ends with `.eps`, an Encapsulated Postscript file is produced
5746/// - 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.
5747/// - if `filename` ends with `.svg`, a SVG file is produced
5748/// - if `filename` ends with `.tex`, a TeX file is produced
5749/// - if `filename` ends with `.gif`, a GIF file is produced
5750/// - 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
5751/// - if `filename` ends with `.xpm`, a XPM file is produced
5752/// - if `filename` ends with `.png`, a PNG file is produced
5753/// - if `filename` ends with `.bmp`, a BMP file is produced
5754/// - if `filename` ends with `.jpg` or `.jpeg` a JPEG file is produced NOTE: JPEG's lossy compression will make all sharp edges fuzzy.
5755/// - if `filename` ends with `.tiff`, a TIFF file is produced
5756/// - if `filename` ends with `.C`, `.cxx`,`.cpp` or `.cc`, a C++ macro file is produced
5757/// - if `filename` ends with `.root`, a Root file is produced
5758/// - if `filename` ends with `.xml`, a XML file is produced
5759/// - if `filename` ends with `.json`, a JSON file is produced
5760///
5761/// \remarks
5762/// - The parameter `option` is not used.
5763/// - This method calls [TPad::Print(const char *filename, Option_t *option)](\ref TPadPrint)
5764/// the value of `option` is determined by the `filename` extension.
5765/// - Postscript and PDF formats allow to have [several pictures in one file](\ref TPadPrintPS).
5766
5767void TPad::SaveAs(const char *filename, Option_t * /*option*/) const
5768{
5769 TString psname;
5770 Int_t lenfil = filename ? strlen(filename) : 0;
5771
5772 if (!lenfil) { psname = GetName(); psname.Append(".ps"); }
5773 else psname = filename;
5774
5775 // lines below protected against case like c1->SaveAs( "../ps/cs.ps" );
5776 if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
5777 psname = GetName();
5778 psname.Append(filename);
5779 psname.Prepend("/");
5780 psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
5781 }
5782
5783 if (psname.EndsWith(".gif"))
5784 ((TPad*)this)->Print(psname,"gif");
5785 else if (psname.Contains(".gif+"))
5786 ((TPad*)this)->Print(psname,"gif+");
5787 else if (psname.EndsWith(".C") || psname.EndsWith(".cxx") || psname.EndsWith(".cpp") || psname.EndsWith(".cc"))
5788 ((TPad*)this)->Print(psname,"cxx");
5789 else if (psname.EndsWith(".root"))
5790 ((TPad*)this)->Print(psname,"root");
5791 else if (psname.EndsWith(".xml"))
5792 ((TPad*)this)->Print(psname,"xml");
5793 else if (psname.EndsWith(".json"))
5794 ((TPad*)this)->Print(psname,"json");
5795 else if (psname.EndsWith(".html"))
5796 ((TPad*)this)->Print(psname,"html");
5797 else if (psname.EndsWith(".eps"))
5798 ((TPad*)this)->Print(psname,"eps");
5799 else if (psname.EndsWith(".pdf") || psname.EndsWith(".pdf[") || psname.EndsWith(".pdf]") || psname.EndsWith(".pdf("))
5800 ((TPad*)this)->Print(psname,"pdf");
5801 else if (psname.EndsWith(".svg"))
5802 ((TPad*)this)->Print(psname,"svg");
5803 else if (psname.EndsWith(".tex"))
5804 ((TPad*)this)->Print(psname,"tex");
5805 else if (psname.EndsWith(".xpm"))
5806 ((TPad*)this)->Print(psname,"xpm");
5807 else if (psname.EndsWith(".png"))
5808 ((TPad*)this)->Print(psname,"png");
5809 else if (psname.EndsWith(".jpg") || psname.EndsWith(".jpeg"))
5810 ((TPad*)this)->Print(psname,"jpg");
5811 else if (psname.EndsWith(".bmp"))
5812 ((TPad*)this)->Print(psname,"bmp");
5813 else if (psname.EndsWith(".tiff"))
5814 ((TPad*)this)->Print(psname,"tiff");
5815 else
5816 ((TPad*)this)->Print(psname,"ps");
5817}
5818
5819////////////////////////////////////////////////////////////////////////////////
5820/// Save primitives in this pad on the C++ source file out.
5821
5822void TPad::SavePrimitive(std::ostream &out, Option_t * option /*= ""*/)
5823{
5824 TContext ctxt(this, kFALSE); // not interactive
5825
5826 TString padName = GetName();
5827
5828 // check for space in the pad name
5829 auto p = padName.Index(" ");
5830 if (p != kNPOS)
5831 padName.Resize(p);
5832
5833 TString opt = option;
5834 if (!opt.Contains("toplevel")) {
5835 static Int_t pcounter = 0;
5836 padName += TString::Format("__%d", pcounter++);
5837 padName = gInterpreter->MapCppName(padName);
5838 }
5839
5840 const char *pname = padName.Data();
5841 const char *cname = padName.Data();
5842
5843 if (padName.Length() == 0) {
5844 pname = "unnamed";
5845 if (this == gPad->GetCanvas())
5846 cname = "c1";
5847 else
5848 cname = "pad";
5849 }
5850
5851 // Write pad parameters
5852 if (this != gPad->GetCanvas()) {
5853 out << " \n";
5854 out << "// ------------>Primitives in pad: " << GetName() << "\n";
5855 out << " TPad *" << cname << " = new TPad(\"" << GetName() << "\", \""
5856 << TString(GetTitle()).ReplaceSpecialCppChars() << "\", " << fXlowNDC << ", " << fYlowNDC << ", "
5857 << fXlowNDC + fWNDC << ", " << fYlowNDC + fHNDC << ");\n";
5858 out << " " << cname << "->Draw();\n";
5859 out << " " << cname << "->cd();\n";
5860 }
5861 out << " " << cname << "->Range(" << fX1 << "," << fY1 << "," << fX2 << "," << fY2 << ");\n";
5862 TView *view = GetView();
5863 if (view) {
5864 Double_t rmin[3], rmax[3];
5865 view->GetRange(rmin, rmax);
5866 out << " TView::CreateView(1)->SetRange(" << rmin[0] << ", " << rmin[1] << ", " << rmin[2] << ", " << rmax[0]
5867 << ", " << rmax[1] << ", " << rmax[2] << ");\n";
5868 }
5869
5870 SaveFillAttributes(out, cname, -1, -1);
5871
5872 if (GetBorderMode() != 1)
5873 out << " " << cname << "->SetBorderMode(" << GetBorderMode() << ");\n";
5874 if (GetBorderSize() != 4)
5875 out << " " << cname << "->SetBorderSize(" << GetBorderSize() << ");\n";
5876 if (GetLogx())
5877 out << " " << cname << "->SetLogx();\n";
5878 if (GetLogy())
5879 out << " " << cname << "->SetLogy();\n";
5880 if (GetLogz())
5881 out << " " << cname << "->SetLogz();\n";
5882 if (GetGridx())
5883 out << " " << cname << "->SetGridx();\n";
5884 if (GetGridy())
5885 out << " " << cname << "->SetGridy();\n";
5886 if (GetTickx())
5887 out << " " << cname << "->SetTickx(" << GetTickx() << ");\n";
5888 if (GetTicky())
5889 out << " " << cname << "->SetTicky(" << GetTicky() << ");\n";
5890 if (GetTheta() != 30)
5891 out << " " << cname << "->SetTheta(" << GetTheta() << ");\n";
5892 if (GetPhi() != 30)
5893 out << " " << cname << "->SetPhi(" << GetPhi() << ");\n";
5894 if (TMath::Abs(fLeftMargin - 0.1) > 0.01)
5895 out << " " << cname << "->SetLeftMargin(" << GetLeftMargin() << ");\n";
5896 if (TMath::Abs(fRightMargin - 0.1) > 0.01)
5897 out << " " << cname << "->SetRightMargin(" << GetRightMargin() << ");\n";
5898 if (TMath::Abs(fTopMargin - 0.1) > 0.01)
5899 out << " " << cname << "->SetTopMargin(" << GetTopMargin() << ");\n";
5900 if (TMath::Abs(fBottomMargin - 0.1) > 0.01)
5901 out << " " << cname << "->SetBottomMargin(" << GetBottomMargin() << ");\n";
5902
5904 out << " " << cname << "->SetFrameFillColor(" << TColor::SavePrimitiveColor(GetFrameFillColor()) << ");\n";
5905 if (GetFrameFillStyle() != 1001)
5906 out << " " << cname << "->SetFrameFillStyle(" << GetFrameFillStyle() << ");\n";
5907 if (GetFrameLineStyle() != 1)
5908 out << " " << cname << "->SetFrameLineStyle(" << GetFrameLineStyle() << ");\n";
5909 if (GetFrameLineColor() != 1)
5910 out << " " << cname << "->SetFrameLineColor(" << TColor::SavePrimitiveColor(GetFrameLineColor()) << ");\n";
5911 if (GetFrameLineWidth() != 1)
5912 out << " " << cname << "->SetFrameLineWidth(" << GetFrameLineWidth() << ");\n";
5913 if (GetFrameBorderMode() != 0)
5914 out << " " << cname << "->SetFrameBorderMode(" << GetFrameBorderMode() << ");\n";
5915 if (GetFrameBorderSize() != 1)
5916 out << " " << cname << "->SetFrameBorderSize(" << GetFrameBorderSize() << ");\n";
5917
5918 TFrame *frame = fFrame;
5919 if (!frame)
5920 frame = (TFrame *)GetPrimitive("TFrame");
5921 if (frame) {
5922 if (frame->GetFillColor() != GetFillColor())
5923 out << " " << cname << "->SetFrameFillColor(" << TColor::SavePrimitiveColor(frame->GetFillColor()) << ");\n";
5924 if (frame->GetFillStyle() != 1001)
5925 out << " " << cname << "->SetFrameFillStyle(" << frame->GetFillStyle() << ");\n";
5926 if (frame->GetLineStyle() != 1)
5927 out << " " << cname << "->SetFrameLineStyle(" << frame->GetLineStyle() << ");\n";
5928 if (frame->GetLineColor() != 1)
5929 out << " " << cname << "->SetFrameLineColor(" << TColor::SavePrimitiveColor(frame->GetLineColor()) << ");\n";
5930 if (frame->GetLineWidth() != 1)
5931 out << " " << cname << "->SetFrameLineWidth(" << frame->GetLineWidth() << ");\n";
5932 if (frame->GetBorderMode() != 0)
5933 out << " " << cname << "->SetFrameBorderMode(" << frame->GetBorderMode() << ");\n";
5934 if (frame->GetBorderSize() != 1)
5935 out << " " << cname << "->SetFrameBorderSize(" << frame->GetBorderSize() << ");\n";
5936 }
5937
5938 TIter next(GetListOfPrimitives());
5939
5940 while (auto obj = next()) {
5941 obj->SavePrimitive(out, (Option_t *)next.GetOption());
5942 if (obj->InheritsFrom(TPad::Class())) {
5943 if (opt.Contains("toplevel"))
5944 out << " " << pname << "->cd();\n";
5945 else
5946 out << " " << cname << "->cd();\n";
5947 }
5948 }
5949 out << " " << cname << "->Modified();\n";
5950}
5951
5952////////////////////////////////////////////////////////////////////////////////
5953/// Fix pad aspect ratio to current value if fixed is true.
5954
5956{
5957 if (fixed) {
5958 if (!fFixedAspectRatio) {
5959 if (fHNDC != 0.)
5961 else {
5962 Error("SetAspectRatio", "cannot fix aspect ratio, height of pad is 0");
5963 return;
5964 }
5966 }
5967 } else {
5969 fAspectRatio = 0;
5970 }
5971}
5972
5973////////////////////////////////////////////////////////////////////////////////
5974/// Set pad editable yes/no
5975/// If a pad is not editable:
5976/// - one cannot modify the pad and its objects via the mouse.
5977/// - one cannot add new objects to the pad
5978
5980{
5981 fEditable = mode;
5982
5983 TObject *obj;
5984 if (!fPrimitives) fPrimitives = new TList;
5985 TIter next(GetListOfPrimitives());
5986 while ((obj = next())) {
5987 if (obj->InheritsFrom(TPad::Class())) {
5988 TPad *pad = (TPad*)obj;
5989 pad->SetEditable(mode);
5990 }
5991 }
5992}
5993
5994////////////////////////////////////////////////////////////////////////////////
5995/// Override TAttFill::FillStyle for TPad because we want to handle style=0
5996/// as style 4000.
5997
5999{
6000 if (fstyle == 0) fstyle = 4000;
6001 TAttFill::SetFillStyle(fstyle);
6002}
6003
6004////////////////////////////////////////////////////////////////////////////////
6005/// Set Lin/Log scale for X
6006/// - value = 0 X scale will be linear
6007/// - value = 1 X scale will be logarithmic (base 10)
6008/// - value > 1 reserved for possible support of base e or other
6009
6011{
6012 fLogx = value;
6013 delete fView; fView = nullptr;
6014 Modified();
6016}
6017
6018////////////////////////////////////////////////////////////////////////////////
6019/// Set Lin/Log scale for Y
6020/// - value = 0 Y scale will be linear
6021/// - value = 1 Y scale will be logarithmic (base 10)
6022/// - value > 1 reserved for possible support of base e or other
6023
6025{
6026 fLogy = value;
6027 delete fView; fView = nullptr;
6028 Modified();
6030}
6031
6032////////////////////////////////////////////////////////////////////////////////
6033/// Set Lin/Log scale for Z
6034
6036{
6037 fLogz = value;
6038 delete fView; fView = nullptr;
6039 Modified();
6041}
6042
6043////////////////////////////////////////////////////////////////////////////////
6044/// Set canvas range for pad and resize the pad. If the aspect ratio
6045/// was fixed before the call it will be un-fixed.
6046
6048{
6049 // Reorder points to make sure xlow,ylow is bottom left point and
6050 // xup,yup is top right point.
6051 if (xup < xlow) {
6052 Double_t x = xlow;
6053 xlow = xup;
6054 xup = x;
6055 }
6056 if (yup < ylow) {
6057 Double_t y = ylow;
6058 ylow = yup;
6059 yup = y;
6060 }
6061
6062 // Check if the new pad position is valid.
6063 if ((xlow < 0) || (xlow > 1) || (ylow < 0) || (ylow > 1)) {
6064 Error("TPad", "illegal bottom left position: x=%f, y=%f", xlow, ylow);
6065 return;
6066 }
6067 if ((xup < 0) || (xup > 1) || (yup < 0) || (yup > 1)) {
6068 Error("TPad", "illegal top right position: x=%f, y=%f", xup, yup);
6069 return;
6070 }
6071 if (xup-xlow <= 0) {
6072 Error("TPad", "illegal width: %f", xup-xlow);
6073 return;
6074 }
6075 if (yup-ylow <= 0) {
6076 Error("TPad", "illegal height: %f", yup-ylow);
6077 return;
6078 }
6079
6080 fXlowNDC = xlow;
6081 fYlowNDC = ylow;
6082 fXUpNDC = xup;
6083 fYUpNDC = yup;
6084 fWNDC = xup - xlow;
6085 fHNDC = yup - ylow;
6086
6088
6089 ResizePad();
6090}
6091
6092////////////////////////////////////////////////////////////////////////////////
6093/// Set all pad parameters.
6094
6095void TPad::SetPad(const char *name, const char *title,
6096 Double_t xlow, Double_t ylow, Double_t xup, Double_t yup,
6097 Color_t color, Short_t bordersize, Short_t bordermode)
6098{
6099 fName = name;
6100 fTitle = title;
6101 SetFillStyle(1001);
6106 if (color >= 0) SetFillColor(color);
6108 if (bordersize < 0) fBorderSize = gStyle->GetPadBorderSize();
6109 else fBorderSize = bordersize;
6110 if (bordermode < -1) fBorderMode = gStyle->GetPadBorderMode();
6111 else fBorderMode = bordermode;
6112
6113 SetPad(xlow, ylow, xup, yup);
6114}
6115
6116////////////////////////////////////////////////////////////////////////////////
6117/// Set the current TView. Delete previous view if view=0
6118
6120{
6121 if (!view) delete fView;
6122 fView = view;
6123}
6124
6125////////////////////////////////////////////////////////////////////////////////
6126/// Set postscript fill area attributes.
6127///
6128/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6129
6131{
6132 if (auto pp = GetPainter())
6133 if (pp->GetPS())
6134 pp->SetAttFill({color, style});
6135}
6136
6137////////////////////////////////////////////////////////////////////////////////
6138/// Set postscript line attributes.
6139///
6140/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6141
6143{
6144 if (auto pp = GetPainter())
6145 if (pp->GetPS())
6146 pp->SetAttLine({color, style, lwidth});
6147}
6148
6149////////////////////////////////////////////////////////////////////////////////
6150/// Set postscript marker attributes.
6151///
6152/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6153
6155{
6156 if (auto pp = GetPainter())
6157 if (pp->GetPS())
6158 pp->SetAttMarker({color, style, msize});
6159}
6160
6161////////////////////////////////////////////////////////////////////////////////
6162/// Set postscript text attributes.
6163///
6164/// DEPRECATED!!! No longer used by ROOT, kept only for backward compatibility
6165
6167{
6168 if (auto pp = GetPainter())
6169 if (pp->GetPS()) {
6170 if (font % 10 > 2) {
6171 Float_t wh = (Float_t) XtoPixel(GetX2());
6172 Float_t hh = (Float_t) YtoPixel(GetY1());
6173 Float_t dy;
6174 if (wh < hh) {
6175 dy = AbsPixeltoX(Int_t(tsize)) - AbsPixeltoX(0);
6176 tsize = dy/(GetX2()-GetX1());
6177 } else {
6178 dy = AbsPixeltoY(0) - AbsPixeltoY(Int_t(tsize));
6179 tsize = dy/(GetY2()-GetY1());
6180 }
6181 }
6182 pp->OnPad(this);
6183 pp->SetAttText({align, angle, color, font, tsize});
6184 }
6185}
6186
6187////////////////////////////////////////////////////////////////////////////////
6188/// Draw Arrows to indicated equal distances of Objects with given BBoxes.
6189/// Used by ShowGuidelines
6190
6192{
6193 Int_t lineColor = TColor::GetColor(239, 202, 0);
6194 Int_t x1,x2,y1,y2;
6195 x1 = x2 = y1 = y2 = 0;
6196 if (mode == 'x') {
6197 if (aBBox.fX<bBBox.fX) {
6198 x1 = aBBox.fX+aBBox.fWidth;
6199 x2 = bBBox.fX;
6200 }
6201 else {
6202 x1 = bBBox.fX+bBBox.fWidth;
6203 x2 = aBBox.fX;
6204 }
6205
6206 if ((aBBox.fY > bBBox.fY) && (aBBox.fY + aBBox.fHeight < bBBox.fY + bBBox.fHeight))
6207 y1 = y2 = aBBox.fY + TMath::Nint(0.5*(Double_t)(aBBox.fHeight))+1;
6208 else if ((bBBox.fY > aBBox.fY) && (bBBox.fY + bBBox.fHeight < aBBox.fY + aBBox.fHeight))
6209 y1 = y2 = bBBox.fY + TMath::Nint(0.5*(Double_t)(bBBox.fHeight))+1;
6210 else if (aBBox.fY>bBBox.fY) y1 = y2 = aBBox.fY-TMath::Nint(0.5*(Double_t)(aBBox.fY-(bBBox.fY+bBBox.fHeight)));
6211 else y1 = y2 = bBBox.fY-TMath::Nint(0.5*(Double_t)(bBBox.fY-(aBBox.fY+aBBox.fHeight)));
6212 }
6213 else if (mode == 'y') {
6214 if (aBBox.fY<bBBox.fY) {
6215 y1 = aBBox.fY+aBBox.fHeight;
6216 y2 = bBBox.fY;
6217 }
6218 else {
6219 y1 = bBBox.fY+bBBox.fHeight;
6220 y2 = aBBox.fY;
6221 }
6222 if ((aBBox.fX > bBBox.fX) && (aBBox.fX + aBBox.fWidth < bBBox.fX + bBBox.fWidth))
6223 x1 = x2 = aBBox.fX + TMath::Nint(0.5*(Double_t)(aBBox.fWidth))+1;
6224 else if ((bBBox.fX > aBBox.fX) && (bBBox.fX + bBBox.fWidth < aBBox.fX + aBBox.fWidth))
6225 x1 = x2 = bBBox.fX + TMath::Nint(0.5*(Double_t)(bBBox.fWidth))+1;
6226 else if (aBBox.fX>bBBox.fX) x1 = x2 = aBBox.fX+TMath::Nint(0.5*(Double_t)(bBBox.fX+bBBox.fWidth-aBBox.fX));
6227 else x1 = x2 = bBBox.fX+TMath::Nint(0.5*(Double_t)(aBBox.fX+aBBox.fWidth-bBBox.fX));
6228 }
6229
6230 TArrow *A = new TArrow(gPad->PixeltoX(x1), gPad->PixeltoY(y1-gPad->VtoPixel(0)), gPad->PixeltoX(x2), gPad->PixeltoY(y2-gPad->VtoPixel(0)), 0.01, "<|>");
6231 A->SetBit(kCanDelete);
6232 A->SetFillColor(lineColor);
6233 A->SetLineWidth(1);
6234 A->SetLineColor(lineColor);
6235 A->Draw();
6236
6237 return;
6238}
6239
6240////////////////////////////////////////////////////////////////////////////////
6241/// struct used by ShowGuidelines to store the distance Field between objects
6242/// in the canvas.
6243
6244struct dField {
6248 char fdir;
6249
6250
6252 : fa(nullptr), fb(nullptr), fdist(0), fdir(' ')
6253 {}
6254
6255 dField(TAttBBox2D *a, TAttBBox2D *b, Int_t dist, char direction)
6256 : fa(a), fb(b), fdist(dist), fdir(direction)
6257 {}
6258};
6259
6260////////////////////////////////////////////////////////////////////////////////
6261/// Shows lines to indicate if a TAttBBox2D object is aligned to
6262/// the center or to another object, shows distance arrows if two
6263/// objects on screen have the same distance to another object
6264/// Call from primitive in Execute Event, in ButtonMotion after
6265/// the new coordinates have been set, to 'stick'
6266/// once when button is up to delete lines
6267///
6268/// modes: t (Top), b (bottom), l (left), r (right), i (inside)
6269/// in resize modes (t,b,l,r) only size arrows are sticky
6270///
6271/// in mode, the function gets the point on the element that is clicked to
6272/// move (i) or resize (all others). The expected values are:
6273/// \image html gpad_pad5.png
6274
6275void TPad::ShowGuidelines(TObject *object, const Int_t event, const char mode, const bool cling )
6276{
6277 // When the object is moved with arrow or when the ShowGuideLines flag
6278 // is off we do show guide lines.
6279 if ((event == kArrowKeyRelease) || (event == kArrowKeyPress) ||
6280 !gEnv->GetValue("Canvas.ShowGuideLines", 0)) return;
6281
6282 std::vector<dField> curDist;
6283 std::vector<dField> otherDist;
6284 Int_t pMX, pMY;
6285 Double_t MX, MY;
6286 Int_t threshold;
6287 TList *prims;
6288 UInt_t n;
6289 Rectangle_t aBBox, bBBox;
6290 aBBox = bBBox = Rectangle_t();
6291 TLine *L;
6292 TArrow *A;
6293 Int_t dSizeArrow = 12; // distance of arrows indicating same size from BBox in px
6294 Bool_t movedX, movedY; // make sure the current object is moved just once
6295 movedX = movedY = false;
6296 Bool_t resize = false; // indicates resize mode
6297 Bool_t log = gPad->GetLogx() || gPad->GetLogy();
6298 if (mode != 'i') resize = true;
6299
6300 TPad *is_pad = dynamic_cast<TPad *>( object );
6301
6302 TContext ctxt(kTRUE);
6303
6304 if (is_pad && is_pad->GetMother())
6305 is_pad->GetMother()->cd();
6306
6307 static TPad *tmpGuideLinePad = nullptr;
6308
6309 //delete all existing Guidelines and create new invisible pad
6310 if (tmpGuideLinePad) {
6311 ctxt.PadDeleted(tmpGuideLinePad);
6312 auto guidePadClicked = (object == tmpGuideLinePad); // in case of funny button click combination.
6313 tmpGuideLinePad->Delete();
6314 tmpGuideLinePad = nullptr;
6315 if (guidePadClicked) return;
6316 }
6317
6318 // Get Primitives
6319 prims = gPad->GetListOfPrimitives();
6320 n = TMath::Min(15,prims->GetSize());
6321 Int_t lineColor = TColor::GetColor(239, 202, 0);
6322
6323 TAttBBox2D *cur = dynamic_cast<TAttBBox2D *>( object );
6324 if (cur) {
6325 //create invisible TPad above gPad
6326 if (!tmpGuideLinePad){
6327 tmpGuideLinePad = new TPad("tmpGuideLinePad", "tmpGuideLinePad", 0, 0, 1, 1);
6328 Double_t x1, y1, x2, y2;
6329 gPad->GetRange(x1, y1, x2, y2);
6330 tmpGuideLinePad->Range(x1, y1, x2, y2);
6331 tmpGuideLinePad->SetFillStyle(0);
6332 tmpGuideLinePad->SetFillColor(0);
6333 tmpGuideLinePad->Draw();
6334 tmpGuideLinePad->cd();
6335 gPad->GetRange(x1, y1, x2, y2);
6336 }
6337 if (cling && !log) threshold = 7;
6338 else threshold = 1;
6339
6340 Rectangle_t BBox = cur->GetBBox();
6341 TPoint center = cur->GetBBoxCenter();
6342
6343 otherDist.clear();
6344 curDist.clear();
6345
6346 switch (event) {
6347
6348 case kButton1Down:
6349 case kButton1Motion:
6350 MX = gPad->GetX1() + 0.5 * (gPad->GetX2()-gPad->GetX1());
6351 MY = gPad->GetY1() + 0.5 * (gPad->GetY2()-gPad->GetY1());
6352 pMX = gPad->XtoPixel(MX);
6353 pMY = gPad->YtoPixel(MY);
6354 // Middlelines
6355 if (TMath::Abs(pMX-center.GetX())<threshold) {
6356 if (cling && (!resize)) {
6357 cur->SetBBoxCenterX(pMX);
6358 center = cur->GetBBoxCenter();
6359 BBox = cur->GetBBox();
6360 center = cur->GetBBoxCenter();
6361 }
6362 L = new TLine(MX, gPad->GetY1(), MX, gPad->GetY2());
6363 L->SetBit(kCanDelete);
6364 L->SetLineColor(lineColor);
6365 L->Draw();
6366 }
6367 if (TMath::Abs(pMY-center.GetY())<threshold) {
6368 if (cling && (!resize)) {
6369 cur->SetBBoxCenterY(pMY);
6370 center = cur->GetBBoxCenter();
6371 BBox = cur->GetBBox();
6372 center = cur->GetBBoxCenter();
6373 }
6374 L = new TLine(gPad->GetX1(), MY, gPad->GetX2(), MY);
6375 L->SetBit(kCanDelete);
6376 L->SetLineColor(lineColor);
6377 L->Draw();
6378 }
6379 // Alignment to other objects
6380 for (UInt_t i = 0; i<n; i++) {
6381 TAttBBox2D *other = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6382 if (other) {
6383 if (other != cur) {
6384 TPoint centerOther = other->GetBBoxCenter();
6385 if (TMath::Abs(center.GetX()-centerOther.GetX())<threshold) {
6386 if (cling && (!resize)) {
6387 cur->SetBBoxCenterX(centerOther.GetX());
6388 BBox = cur->GetBBox();
6389 center = cur->GetBBoxCenter();
6390 }
6391 L = new TLine(gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(center.GetY()-gPad->VtoPixel(0)),
6392 gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)));
6393 L->SetLineColor(lineColor);
6394 L->Draw();
6395 L->SetBit(kCanDelete);
6396 }
6397 if (TMath::Abs(center.GetY()-centerOther.GetY())<threshold) {
6398 if (cling && (!resize)) {
6399 cur->SetBBoxCenterY(centerOther.GetY());
6400 BBox = cur->GetBBox();
6401 center = cur->GetBBoxCenter();
6402 }
6403 L = new TLine(gPad->PixeltoX(center.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)),
6404 gPad->PixeltoX(centerOther.GetX()), gPad->PixeltoY(centerOther.GetY()-gPad->VtoPixel(0)));
6405 L->SetBit(kCanDelete);
6406 L->SetLineColor(lineColor);
6407 L->Draw();
6408 }
6409 }
6410 }
6411 }
6412 // Get Distances between objects
6413 for (UInt_t i = 0; i<n; i++) {
6414 TAttBBox2D *a = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6415 if (a) {
6416 aBBox = a->GetBBox();
6417 for (UInt_t j = i+1; j<n; j++) {
6418 TAttBBox2D *b = dynamic_cast<TAttBBox2D *>( prims->At(j) );
6419 if (b) {
6420 bBBox = b->GetBBox();
6421
6422 //only when bounding boxes overlap in x or y direction
6423 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
6424 if ((aBBox.fY+aBBox.fHeight<bBBox.fY)||(bBBox.fY+bBBox.fHeight<aBBox.fY)) {//No overlap in Y-direction required
6425 dField abDist = dField();
6426 if (aBBox.fY>bBBox.fY) abDist = dField(a, b, TMath::Abs(aBBox.fY-(bBBox.fY+bBBox.fHeight)), 'y');
6427 else abDist = dField(a, b, TMath::Abs(bBBox.fY-(aBBox.fY+aBBox.fHeight)), 'y');
6428 if ((b != cur)&&(a != cur)) otherDist.push_back(abDist);
6429 else curDist.push_back(abDist);
6430 }
6431 } 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
6432 if ((aBBox.fX+aBBox.fWidth<bBBox.fX)||(bBBox.fX+bBBox.fWidth<aBBox.fX)) {//No overlap in x-direction required
6433 dField abDist = dField();
6434 if (aBBox.fX>bBBox.fX) abDist = dField(a, b, TMath::Abs(aBBox.fX-(bBBox.fX+bBBox.fWidth)), 'x');
6435 else abDist = dField(a, b, TMath::Abs(bBBox.fX-(aBBox.fX+aBBox.fWidth)), 'x');
6436 if ((b != cur)&&(a != cur)) otherDist.push_back(abDist);
6437 else curDist.push_back(abDist);
6438 }
6439 }
6440 }
6441 }
6442 }
6443 }
6444 // Show equal distances
6445 for (UInt_t i = 0; i<curDist.size(); i++) {
6446 for (UInt_t j = 0; j<otherDist.size(); j++) {
6447 if ((curDist[i].fdir == otherDist[j].fdir) && (otherDist[j].fdir=='x') && (TMath::Abs(curDist[i].fdist-otherDist[j].fdist)<threshold)) {
6448 if (cling && (!movedX) && (!resize)) {
6449 if ((cur->GetBBoxCenter().fX < curDist[i].fb->GetBBoxCenter().fX)||(cur->GetBBoxCenter().fX < curDist[i].fa->GetBBoxCenter().fX))
6450 cur->SetBBoxCenterX(cur->GetBBoxCenter().fX - otherDist[j].fdist + curDist[i].fdist);
6451 else cur->SetBBoxCenterX(cur->GetBBoxCenter().fX + otherDist[j].fdist - curDist[i].fdist);
6452 movedX = true;
6453 }
6454 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'x');
6455 DrawDist(otherDist[j].fa->GetBBox(), otherDist[j].fb->GetBBox(), 'x');
6456 }
6457 if ((curDist[i].fdir == otherDist[j].fdir) && (otherDist[j].fdir=='y') && (TMath::Abs(curDist[i].fdist-otherDist[j].fdist)<threshold)) {
6458 if (cling && (!movedY) && (!resize)) {
6459 if ((cur->GetBBoxCenter().fY < curDist[i].fb->GetBBoxCenter().fY)||(cur->GetBBoxCenter().fY < curDist[i].fa->GetBBoxCenter().fY))
6460 cur->SetBBoxCenterY(cur->GetBBoxCenter().fY - otherDist[j].fdist + curDist[i].fdist);
6461 else cur->SetBBoxCenterY(cur->GetBBoxCenter().fY + otherDist[j].fdist - curDist[i].fdist);
6462 movedY = true;
6463 }
6464 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'y');
6465 DrawDist(otherDist[j].fa->GetBBox(), otherDist[j].fb->GetBBox(), 'y');
6466 }
6467 }
6468 for (UInt_t j = i; j<curDist.size(); j++) {
6469 if (i!=j) {
6470 if ((curDist[i].fdir == curDist[j].fdir) && (curDist[j].fdir=='x') && (TMath::Abs(curDist[i].fdist-curDist[j].fdist)<threshold)) {
6471 if (cling && (!movedX) && (!resize)) {
6472 if ((cur->GetBBoxCenter().fX < curDist[i].fb->GetBBoxCenter().fX)||(cur->GetBBoxCenter().fX < curDist[i].fa->GetBBoxCenter().fX))
6473 cur->SetBBoxCenterX(cur->GetBBoxCenter().fX - floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6474 else cur->SetBBoxCenterX(cur->GetBBoxCenter().fX + floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6475 }
6476 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'x');
6477 DrawDist(curDist[j].fa->GetBBox(), curDist[j].fb->GetBBox(), 'x');
6478 }
6479
6480 if ((curDist[i].fdir == curDist[j].fdir) && (curDist[j].fdir=='y') && (TMath::Abs(curDist[i].fdist-curDist[j].fdist)<threshold)) {
6481 if (cling && (!movedY) && (!resize)) {
6482 if ((cur->GetBBoxCenter().fY < curDist[i].fb->GetBBoxCenter().fY)||(cur->GetBBoxCenter().fY < curDist[i].fa->GetBBoxCenter().fY))
6483 cur->SetBBoxCenterY(cur->GetBBoxCenter().fY - floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6484 else cur->SetBBoxCenterY(cur->GetBBoxCenter().fY + floor(0.5*(curDist[j].fdist - curDist[i].fdist)));
6485 }
6486 DrawDist(curDist[i].fa->GetBBox(), curDist[i].fb->GetBBox(), 'y');
6487 DrawDist(curDist[j].fa->GetBBox(), curDist[j].fb->GetBBox(), 'y');
6488 }
6489 }
6490 }
6491 }
6492 if (resize) {
6493 // Show equal Sizes
6494 for (UInt_t i = 0; i<n; i++) {
6495 TAttBBox2D *a = dynamic_cast<TAttBBox2D *>( prims->At(i) );
6496 if (a && (cur != a)) {
6497 aBBox = a->GetBBox();
6498
6499 if ((TMath::Abs(aBBox.fWidth - BBox.fWidth)<threshold) && (mode != 't') && (mode != 'b')) {
6500 if (cling) {
6501 if (mode == 'l') cur->SetBBoxX1(BBox.fX + BBox.fWidth - aBBox.fWidth);
6502 if (mode == 'r') cur->SetBBoxX2(BBox.fX + aBBox.fWidth);
6503 if ((mode == '1')||(mode == '4')) cur->SetBBoxX1(BBox.fX + BBox.fWidth - aBBox.fWidth);
6504 if ((mode == '2')||(mode == '3')) cur->SetBBoxX2(BBox.fX + aBBox.fWidth);
6505 BBox = cur->GetBBox();
6506 }
6507
6508 A = new TArrow(gPad->PixeltoX(aBBox.fX), gPad->PixeltoY(aBBox.fY-dSizeArrow-gPad->VtoPixel(0)),
6509 gPad->PixeltoX(aBBox.fX+aBBox.fWidth), gPad->PixeltoY(aBBox.fY-dSizeArrow-gPad->VtoPixel(0)), 0.01, "<|>");
6510 A->SetBit(kCanDelete);
6511 A->SetLineColor(lineColor);
6512 A->SetFillColor(lineColor);
6513 A->Draw();
6514
6515 A = new TArrow(gPad->PixeltoX(BBox.fX), gPad->PixeltoY(BBox.fY-dSizeArrow-gPad->VtoPixel(0)),
6516 gPad->PixeltoX(BBox.fX+BBox.fWidth), gPad->PixeltoY(BBox.fY-dSizeArrow-gPad->VtoPixel(0)), 0.01, "<|>");
6517 A->SetBit(kCanDelete);
6518 A->SetLineColor(lineColor);
6519 A->SetFillColor(lineColor);
6520 A->Draw();
6521 }
6522 if ((TMath::Abs(aBBox.fHeight - BBox.fHeight)<threshold) && (mode != 'r') && (mode != 'l')) {
6523 if (cling) {
6524 if (mode == 't') cur->SetBBoxY1(BBox.fY + BBox.fHeight - aBBox.fHeight);
6525 if (mode == 'b') cur->SetBBoxY2(BBox.fY + aBBox.fHeight);
6526 if ((mode == '1')||(mode == '2')) cur->SetBBoxY1(BBox.fY + BBox.fHeight - aBBox.fHeight);
6527 if ((mode == '3')||(mode == '4')) cur->SetBBoxY2(BBox.fY + aBBox.fHeight);
6528 BBox = cur->GetBBox();
6529 }
6530 A = new TArrow(gPad->PixeltoX(aBBox.fX-dSizeArrow), gPad->PixeltoY(aBBox.fY-gPad->VtoPixel(0)),
6531 gPad->PixeltoX(aBBox.fX-dSizeArrow), gPad->PixeltoY(aBBox.fY+aBBox.fHeight-gPad->VtoPixel(0)), 0.01, "<|>");
6532 A->SetBit(kCanDelete);
6533 A->SetLineColor(lineColor);
6534 A->SetFillColor(lineColor);
6535 A->Draw();
6536
6537 A = new TArrow(gPad->PixeltoX(BBox.fX-dSizeArrow), gPad->PixeltoY(BBox.fY-gPad->VtoPixel(0)),
6538 gPad->PixeltoX(BBox.fX-dSizeArrow), gPad->PixeltoY(BBox.fY+BBox.fHeight-gPad->VtoPixel(0)), 0.01, "<|>");
6539 A->SetBit(kCanDelete);
6540 A->SetLineColor(lineColor);
6541 A->SetFillColor(lineColor);
6542 A->Draw();
6543 }
6544 }
6545 }
6546 }
6547
6548 break;
6549
6550 case kButton1Up:
6551 if (tmpGuideLinePad) {
6552 // All the arrows and lines in that pad are also deleted because
6553 // they all have the bit kCanDelete on.
6554 tmpGuideLinePad->Delete();
6555 tmpGuideLinePad = nullptr;
6556 }
6557 break;
6558 }
6559 }
6560
6562}
6563
6564////////////////////////////////////////////////////////////////////////////////
6565/// Return kTRUE if the crosshair has been activated (via SetCrosshair).
6566
6568{
6569 return (Bool_t)GetCrosshair();
6570}
6571
6572////////////////////////////////////////////////////////////////////////////////
6573/// Return the crosshair type (from the mother canvas)
6574/// crosshair type = 0 means no crosshair.
6575
6577{
6578 if (this == (TPad*)fCanvas)
6579 return fCrosshair;
6580 return fCanvas ? fCanvas->GetCrosshair() : 0;
6581}
6582
6583////////////////////////////////////////////////////////////////////////////////
6584/// Set crosshair active/inactive.
6585/// - If crhair != 0, a crosshair will be drawn in the pad and its sub-pads.
6586/// - If the canvas crhair = 1 , the crosshair spans the full canvas.
6587/// - If the canvas crhair > 1 , the crosshair spans only the pad.
6588
6590{
6591 if (!fCanvas) return;
6592 fCrosshair = crhair;
6593 fCrosshairPos = 0;
6594
6595 if (this != (TPad*)fCanvas) fCanvas->SetCrosshair(crhair);
6596}
6597
6598////////////////////////////////////////////////////////////////////////////////
6599/// static function to set the maximum Pick Distance fgMaxPickDistance
6600/// This parameter is used in TPad::Pick to select an object if
6601/// its DistancetoPrimitive returns a value < fgMaxPickDistance
6602/// The default value is 5 pixels. Setting a smaller value will make
6603/// picking more precise but also more difficult
6604
6606{
6607 fgMaxPickDistance = maxPick;
6608}
6609
6610////////////////////////////////////////////////////////////////////////////////
6611/// Set tool tip text associated with this pad. The delay is in
6612/// milliseconds (minimum 250). To remove tool tip call method with
6613/// text = 0.
6614
6615void TPad::SetToolTipText(const char *text, Long_t delayms)
6616{
6617 if (fTip) {
6619 fTip = nullptr;
6620 }
6621
6622 if (text && strlen(text))
6623 fTip = CreateToolTip((TBox*)nullptr, text, delayms);
6624}
6625
6626////////////////////////////////////////////////////////////////////////////////
6627/// Set pad vertical (default) or horizontal
6628
6630{
6631 if (vert) ResetBit(kHori);
6632 else SetBit(kHori);
6633}
6634
6635////////////////////////////////////////////////////////////////////////////////
6636/// Stream a class object.
6637
6639{
6640 UInt_t R__s, R__c;
6641 Int_t nch, nobjects;
6642 Float_t single;
6643 TObject *obj;
6644 if (b.IsReading()) {
6645 Version_t v = b.ReadVersion(&R__s, &R__c);
6646 if (v > 5) {
6647 if (!gPad)
6648 gPad = new TCanvas(GetName());
6649 fMother = (TPad*)gPad;
6651 TContext ctxt(this, kFALSE);
6652 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
6653 gReadLevel++;
6654 gROOT->SetReadingObject(kTRUE);
6655
6656 b.ReadClassBuffer(TPad::Class(), this, v, R__s, R__c);
6657
6658 //Set the kCanDelete bit in all objects in the pad such that when the pad
6659 //is deleted all objects in the pad are deleted too.
6660 //Also set must cleanup bit which normally set for all primitives add to pad,
6661 // but may be reset in IO like TH1::Streamer does
6662 TIter next(fPrimitives);
6663 while ((obj = next())) {
6664 obj->SetBit(kCanDelete);
6665 obj->SetBit(kMustCleanup);
6666 }
6667
6668 fModified = kTRUE;
6669 fPadPointer = nullptr;
6670 gReadLevel--;
6671 if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
6672 gROOT->SetReadingObject(kFALSE);
6673 return;
6674 }
6675
6676 //====process old versions before automatic schema evolution
6677 if (v < 5) { //old TPad in single precision
6678 if (v < 3) { //old TPad derived from TWbox
6679 b.ReadVersion(); // TVirtualPad::Streamer(b)
6680 b.ReadVersion(); // TWbox::Streamer(b)
6681 b.ReadVersion(); // TBox::Streamer(b)
6685 b >> single; fX1 = single;
6686 b >> single; fY1 = single;
6687 b >> single; fX2 = single;
6688 b >> single; fY2 = single;
6689 b >> fBorderSize;
6690 b >> fBorderMode;
6692 } else { //new TPad
6695 b >> single; fX1 = single;
6696 b >> single; fY1 = single;
6697 b >> single; fX2 = single;
6698 b >> single; fY2 = single;
6699 b >> fBorderSize;
6700 b >> fBorderMode;
6701 }
6702 b >> fLogx;
6703 b >> fLogy;
6704 b >> fLogz;
6705 b >> single; fXtoAbsPixelk = single;
6706 b >> single; fXtoPixelk = single;
6707 b >> single; fXtoPixel = single;
6708 b >> single; fYtoAbsPixelk = single;
6709 b >> single; fYtoPixelk = single;
6710 b >> single; fYtoPixel = single;
6711 b >> single; fUtoAbsPixelk = single;
6712 b >> single; fUtoPixelk = single;
6713 b >> single; fUtoPixel = single;
6714 b >> single; fVtoAbsPixelk = single;
6715 b >> single; fVtoPixelk = single;
6716 b >> single; fVtoPixel = single;
6717 b >> single; fAbsPixeltoXk = single;
6718 b >> single; fPixeltoXk = single;
6719 b >> single; fPixeltoX = single;
6720 b >> single; fAbsPixeltoYk = single;
6721 b >> single; fPixeltoYk = single;
6722 b >> single; fPixeltoY = single;
6723 b >> single; fXlowNDC = single;
6724 b >> single; fYlowNDC = single;
6725 b >> single; fWNDC = single;
6726 b >> single; fHNDC = single;
6727 b >> single; fAbsXlowNDC = single;
6728 b >> single; fAbsYlowNDC = single;
6729 b >> single; fAbsWNDC = single;
6730 b >> single; fAbsHNDC = single;
6731 b >> single; fUxmin = single;
6732 b >> single; fUymin = single;
6733 b >> single; fUxmax = single;
6734 b >> single; fUymax = single;
6735 } else {
6738 b >> fX1;
6739 b >> fY1;
6740 b >> fX2;
6741 b >> fY2;
6742 b >> fBorderSize;
6743 b >> fBorderMode;
6744 b >> fLogx;
6745 b >> fLogy;
6746 b >> fLogz;
6747 b >> fXtoAbsPixelk;
6748 b >> fXtoPixelk;
6749 b >> fXtoPixel;
6750 b >> fYtoAbsPixelk;
6751 b >> fYtoPixelk;
6752 b >> fYtoPixel;
6753 b >> fUtoAbsPixelk;
6754 b >> fUtoPixelk;
6755 b >> fUtoPixel;
6756 b >> fVtoAbsPixelk;
6757 b >> fVtoPixelk;
6758 b >> fVtoPixel;
6759 b >> fAbsPixeltoXk;
6760 b >> fPixeltoXk;
6761 b >> fPixeltoX;
6762 b >> fAbsPixeltoYk;
6763 b >> fPixeltoYk;
6764 b >> fPixeltoY;
6765 b >> fXlowNDC;
6766 b >> fYlowNDC;
6767 b >> fWNDC;
6768 b >> fHNDC;
6769 b >> fAbsXlowNDC;
6770 b >> fAbsYlowNDC;
6771 b >> fAbsWNDC;
6772 b >> fAbsHNDC;
6773 b >> fUxmin;
6774 b >> fUymin;
6775 b >> fUxmax;
6776 b >> fUymax;
6777 }
6778
6779 if (!gPad)
6780 gPad = new TCanvas(GetName());
6781 if (gReadLevel == 0)
6783 else
6784 fMother = (TPad *)gPad;
6785 if (!fMother)
6786 fMother = (TPad *)gPad;
6787 if (fMother)
6789 gPad = fMother;
6790 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
6791 //-------------------------
6792 // read objects and their drawing options
6793 // b >> fPrimitives;
6794 gReadLevel++;
6795 gROOT->SetReadingObject(kTRUE);
6796 fPrimitives = new TList;
6797 b >> nobjects;
6798 if (nobjects > 0) {
6799 TContext ctxt(this, kFALSE);
6800 char drawoption[64];
6801 for (Int_t i = 0; i < nobjects; i++) {
6802 b >> obj;
6803 b >> nch;
6804 b.ReadFastArray(drawoption,nch);
6805 fPrimitives->AddLast(obj, drawoption);
6806 gPad = this; // gPad may be modified in b >> obj if obj is a pad
6807 }
6808 }
6809 gReadLevel--;
6810 gROOT->SetReadingObject(kFALSE);
6811 //////////////////////////////////////////////////////////////////////////
6812
6813 if (v > 3) {
6814 b >> fExecs;
6815 }
6816 fName.Streamer(b);
6817 fTitle.Streamer(b);
6818 b >> fPadPaint;
6819 fModified = kTRUE;
6820 b >> fGridx;
6821 b >> fGridy;
6822 b >> fFrame;
6823 b >> fView;
6824 if (v < 5) {
6825 b >> single; fTheta = single;
6826 b >> single; fPhi = single;
6827 } else {
6828 b >> fTheta;
6829 b >> fPhi;
6830 }
6831 fPadPointer = nullptr;
6832 b >> fNumber;
6833 b >> fAbsCoord;
6834 if (v > 1) {
6835 b >> fTickx;
6836 b >> fTicky;
6837 } else {
6838 fTickx = fTicky = 0;
6839 }
6840 if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
6841 b.CheckByteCount(R__s, R__c, TPad::IsA());
6842 //====end of old versions
6843
6844 } else {
6845 b.WriteClassBuffer(TPad::Class(),this);
6846 }
6847}
6848
6849////////////////////////////////////////////////////////////////////////////////
6850/// Force a copy of current style for all objects in pad.
6851
6853{
6854 if (gStyle->IsReading()) {
6866 fLogx = gStyle->GetOptLogx();
6867 fLogy = gStyle->GetOptLogy();
6868 fLogz = gStyle->GetOptLogz();
6869 } else {
6884 }
6885
6886 if (!fPrimitives) fPrimitives = new TList;
6887 TIter next(GetListOfPrimitives());
6888 TObject *obj;
6889
6890 while ((obj = next())) {
6891 obj->UseCurrentStyle();
6892 }
6893
6894 TPaveText *title = (TPaveText*)FindObject("title");
6895 if (title) {
6896 if (gStyle->IsReading()) {
6898 title->SetTextFont(gStyle->GetTitleFont(""));
6901 if (!gStyle->GetOptTitle()) delete title;
6902 } else {
6904 gStyle->SetTitleFont(title->GetTextFont());
6907 }
6908 }
6910
6911 if (gStyle->IsReading()) Modified();
6912}
6913
6914////////////////////////////////////////////////////////////////////////////////
6915/// Loop and sleep until a primitive with name=pname is found in the pad.
6916///
6917/// If emode is given, the editor is automatically set to emode, ie
6918/// it is not required to have the editor control bar.
6919///
6920/// The possible values for emode are:
6921/// - emode = "" (default). User will select the mode via the editor bar
6922/// - emode = "Arc", "Line", "Arrow", "Button", "Diamond", "Ellipse",
6923/// - emode = "Pad","pave", "PaveLabel","PaveText", "PavesText",
6924/// - emode = "PolyLine", "CurlyLine", "CurlyArc", "Text", "Marker", "CutG"
6925///
6926/// If emode is specified and it is not valid, "PolyLine" is assumed. If emode
6927/// is not specified or ="", an attempt is to use pname[1...]
6928///
6929/// for example if pname="TArc", emode="Arc" will be assumed.
6930/// When this function is called within a macro, the macro execution
6931/// is suspended until a primitive corresponding to the arguments
6932/// is found in the pad.
6933///
6934/// If CRTL/C is typed in the pad, the function returns 0.
6935///
6936/// While this function is executing, one can use the mouse, interact
6937/// with the graphics pads, use the Inspector, Browser, TreeViewer, etc.
6938///
6939/// Examples:
6940/// ~~~ {.cpp}
6941/// c1.WaitPrimitive(); // Return the first created primitive
6942/// // whatever it is.
6943/// // If a double-click with the mouse is executed
6944/// // in the pad or any key pressed, the function
6945/// // returns 0.
6946/// c1.WaitPrimitive("ggg"); // Set the editor in mode "PolyLine/Graph"
6947/// // Create a polyline, then using the context
6948/// // menu item "SetName", change the name
6949/// // of the created TGraph to "ggg"
6950/// c1.WaitPrimitive("TArc");// Set the editor in mode "Arc". Returns
6951/// // as soon as a TArc object is created.
6952/// c1.WaitPrimitive("lat","Text"); // Set the editor in Text/Latex mode.
6953/// // Create a text object, then Set its name to "lat"
6954/// ~~~
6955/// The following macro waits for 10 primitives of any type to be created.
6956///
6957/// ~~~ {.cpp}
6958///{
6959/// TCanvas c1("c1");
6960/// TObject *obj;
6961/// for (Int_t i=0;i<10;i++) {
6962/// obj = gPad->WaitPrimitive();
6963/// if (!obj) break;
6964/// printf("Loop i=%d, found objIsA=%s, name=%s\n",
6965/// i,obj->ClassName(),obj->GetName());
6966/// }
6967///}
6968/// ~~~
6969///
6970/// If ROOT runs in batch mode a call to this method does nothing.
6971
6972TObject *TPad::WaitPrimitive(const char *pname, const char *emode)
6973{
6974 if (!gPad || IsWeb())
6975 return nullptr;
6976
6977 if (emode && strlen(emode)) gROOT->SetEditorMode(emode);
6978 if (gROOT->GetEditorMode() == 0 && pname && strlen(pname) > 2) gROOT->SetEditorMode(&pname[1]);
6979
6980 if (!fPrimitives) fPrimitives = new TList;
6982 TObject *oldlast = gPad->GetListOfPrimitives() ? gPad->GetListOfPrimitives()->Last() : nullptr;
6983 TObject *obj = nullptr;
6984 Bool_t testlast = kFALSE;
6985 Bool_t hasname = pname && (strlen(pname) > 0);
6986 if ((!pname || !pname[0]) && (!emode || !emode[0])) testlast = kTRUE;
6987 if (testlast) gROOT->SetEditorMode();
6988 while (!gSystem->ProcessEvents() && gROOT->GetSelectedPad() && gPad) {
6989 if (gROOT->GetEditorMode() == 0) {
6990 if (hasname) {
6991 obj = FindObject(pname);
6992 if (obj) return obj;
6993 }
6994 if (testlast) {
6995 if (!gPad->GetListOfPrimitives()) return nullptr;
6996 obj = gPad->GetListOfPrimitives()->Last();
6997 if (obj != oldlast) return obj;
6998 Int_t event = GetEvent();
6999 if (event == kButton1Double || event == kKeyPress) {
7000 //the following statement is required against other loop executions
7001 //before returning
7002 fCanvas->HandleInput((EEventType)-1,0,0);
7003 return nullptr;
7004 }
7005 }
7006 }
7007 gSystem->Sleep(10);
7008 }
7009
7010 return nullptr;
7011}
7012
7013////////////////////////////////////////////////////////////////////////////////
7014/// Create a tool tip and return its pointer.
7015
7016TObject *TPad::CreateToolTip(const TBox *box, const char *text, Long_t delayms)
7017{
7018 if (gPad->IsBatch()) return nullptr;
7019 return (TObject*)gROOT->ProcessLineFast(TString::Format("new TGToolTip((TBox*)0x%zx,\"%s\",%d)",
7020 (size_t)box,text,(Int_t)delayms).Data());
7021}
7022
7023////////////////////////////////////////////////////////////////////////////////
7024/// Delete tool tip object.
7025
7027{
7028 // delete tip;
7029 if (!tip) return;
7030 gROOT->ProcessLineFast(TString::Format("delete (TGToolTip*)0x%zx", (size_t)tip).Data());
7031}
7032
7033////////////////////////////////////////////////////////////////////////////////
7034/// Reset tool tip, i.e. within time specified in CreateToolTip the
7035/// tool tip will pop up.
7036
7038{
7039 if (!tip) return;
7040 // tip->Reset(this);
7041 gROOT->ProcessLineFast(TString::Format("((TGToolTip*)0x%zx)->Reset((TPad*)0x%zx)",
7042 (size_t)tip,(size_t)this).Data());
7043}
7044
7045////////////////////////////////////////////////////////////////////////////////
7046/// Hide tool tip.
7047
7049{
7050 if (!tip) return;
7051 // tip->Hide();
7052 gROOT->ProcessLineFast(TString::Format("((TGToolTip*)0x%zx)->Hide()", (size_t)tip).Data());
7053}
7054
7055////////////////////////////////////////////////////////////////////////////////
7056/// Deprecated: use TPad::GetViewer3D() instead
7057
7059{
7060 ::Info("TPad::x3d()", "This function is deprecated. Use %s->GetViewer3D(\"x3d\") instead",this->GetName());
7061
7062 // Default on GetViewer3D is pad - for x3d it was x3d...
7063 if (!type || !type[0]) {
7064 type = "x3d";
7065 }
7067}
7068
7069////////////////////////////////////////////////////////////////////////////////
7070/// Create/obtain handle to 3D viewer. Valid types are:
7071/// - 'pad' - pad drawing via TViewer3DPad
7072/// any others registered with plugin manager supporting TVirtualViewer3D
7073/// If an invalid/null type is requested then the current viewer is returned
7074/// (if any), otherwise a default 'pad' type is returned
7075
7077{
7078 Bool_t validType = kFALSE;
7079
7080 if ((!type || !*type || (strstr(type, "gl") && !strstr(type, "ogl"))) && (!fCanvas || !fCanvas->UseGL()))
7081 type = "pad";
7082
7083 if (type && *type) {
7084 if (gPluginMgr->FindHandler("TVirtualViewer3D", type))
7085 validType = kTRUE;
7086 }
7087
7088 // Invalid/null type requested?
7089 if (!validType) {
7090 // Return current viewer if there is one
7091 if (fViewer3D)
7092 return fViewer3D;
7093 // otherwise default to the pad
7094 else
7095 type = "pad";
7096 }
7097
7098 // Ensure we can create the new viewer before removing any existing one
7099 TVirtualViewer3D *newViewer = nullptr;
7100
7101 Bool_t createdExternal = kFALSE;
7102
7103 // External viewers need to be created via plugin manager via interface...
7104 if (!strstr(type,"pad")) {
7105 newViewer = TVirtualViewer3D::Viewer3D(this, type);
7106
7107 if (!newViewer) {
7108 Warning("GetViewer3D", "Cannot create 3D viewer of type: %s", type);
7109 // Return the existing viewer
7110 return fViewer3D;
7111 }
7112
7113 if (strstr(type, "gl") && !strstr(type, "ogl")) {
7116 Modified();
7117 } else {
7118 createdExternal = kTRUE;
7119 }
7120
7121 } else {
7122 newViewer = new TViewer3DPad(*this);
7123 }
7124
7125 // If we had a previous viewer destroy it now
7126 // In this case we do take responsibility for destroying viewer
7127 // c.f. ReleaseViewer3D
7128 delete fViewer3D;
7129
7130 // Set and return new viewer
7131 fViewer3D = newViewer;
7132
7133 // Ensure any new external viewer is painted
7134 // For internal TViewer3DPad type we assume this is being
7135 // create on demand due to a paint - so this is not required
7136 if (createdExternal) {
7137 Modified();
7138 Update();
7139 }
7140
7141 return fViewer3D;
7142}
7143
7144////////////////////////////////////////////////////////////////////////////////
7145/// Release current (external) viewer
7146
7148{
7149 fViewer3D = nullptr;
7150
7151 // We would like to ensure the pad is repainted
7152 // when external viewer is closed down. However
7153 // a modify/paint call here will repaint the pad
7154 // before the external viewer window actually closes.
7155 // So the pad would have to be redraw twice over.
7156 // Currently we just have to live with the pad staying blank
7157 // any click in pad will refresh.
7158}
7159
7160////////////////////////////////////////////////////////////////////////////////
7161/// Get GL device.
7162
7164{
7165 return fGLDevice;
7166}
7167
7168////////////////////////////////////////////////////////////////////////////////
7169/// Emit RecordPave() signal.
7170
7172{
7173 Emit("RecordPave(const TObject*)", (Longptr_t)obj);
7174}
7175
7176////////////////////////////////////////////////////////////////////////////////
7177/// Emit RecordLatex() signal.
7178
7180{
7181 Emit("RecordLatex(const TObject*)", (Longptr_t)obj);
7182}
7183
7184////////////////////////////////////////////////////////////////////////////////
7185/// Get pad painter from TCanvas.
7186
7188{
7189 if (!fCanvas) return nullptr;
7190 return fCanvas->GetCanvasPainter();
7191}
7192
7193////////////////////////////////////////////////////////////////////////////////
7194/// Return the bounding Box of the Pad
7195
7197{
7198 Rectangle_t BBox{0, 0, 0, 0};
7199 if (gPad) {
7200 BBox.fX = gPad->XtoPixel(fXlowNDC * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1());
7201 BBox.fY = gPad->YtoPixel((fYlowNDC + fHNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1());
7202 BBox.fWidth = gPad->XtoPixel((fXlowNDC + fWNDC) * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1()) -
7203 gPad->XtoPixel(fXlowNDC * (gPad->GetX2() - gPad->GetX1()) + gPad->GetX1());
7204 BBox.fHeight = gPad->YtoPixel((fYlowNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1()) -
7205 gPad->YtoPixel((fYlowNDC + fHNDC) * (gPad->GetY2() - gPad->GetY1()) + gPad->GetY1());
7206 }
7207 return BBox;
7208}
7209
7210////////////////////////////////////////////////////////////////////////////////
7211/// Return the center of the Pad as TPoint in pixels
7212
7214{
7215 TPoint p(0, 0);
7216 if (gPad) {
7217 Double_t x = ((fXlowNDC + 0.5 * fWNDC) * (gPad->GetX2() - gPad->GetX1())) + gPad->GetX1();
7218 Double_t y = ((fYlowNDC + 0.5 * fHNDC) * (gPad->GetY2() - gPad->GetY1())) + gPad->GetY1();
7219 p.SetX(gPad->XtoPixel(x));
7220 p.SetY(gPad->YtoPixel(y));
7221 }
7222 return p;
7223}
7224
7225////////////////////////////////////////////////////////////////////////////////
7226/// Set center of the Pad
7227
7229{
7230 if (!gPad)
7231 return;
7232 fXlowNDC = (gPad->PixeltoX(p.GetX()) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1()) - 0.5 * fWNDC;
7233 fYlowNDC =
7234 (gPad->PixeltoY(p.GetY() - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - 0.5 * fHNDC;
7235 ResizePad();
7236}
7237
7238////////////////////////////////////////////////////////////////////////////////
7239/// Set X coordinate of the center of the Pad
7240
7242{
7243 if (!gPad)
7244 return;
7245 fXlowNDC = (gPad->PixeltoX(x) - gPad->GetX1())/(gPad->GetX2()-gPad->GetX1())-0.5*fWNDC;
7246 ResizePad();
7247}
7248
7249////////////////////////////////////////////////////////////////////////////////
7250/// Set Y coordinate of the center of the Pad
7251
7253{
7254 if (!gPad)
7255 return;
7256 fYlowNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - 0.5 * fHNDC;
7257 ResizePad();
7258}
7259
7260////////////////////////////////////////////////////////////////////////////////
7261/// Set lefthandside of BoundingBox to a value
7262/// (resize in x direction on left)
7263
7265{
7266 if (!gPad)
7267 return;
7268 fXlowNDC = (gPad->PixeltoX(x) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1());
7270 ResizePad();
7271}
7272
7273////////////////////////////////////////////////////////////////////////////////
7274/// Set right hand side of BoundingBox to a value
7275/// (resize in x direction on right)
7276
7278{
7279 if (!gPad)
7280 return;
7281 fWNDC = (gPad->PixeltoX(x) - gPad->GetX1()) / (gPad->GetX2() - gPad->GetX1()) - fXlowNDC;
7282 ResizePad();
7283}
7284
7285////////////////////////////////////////////////////////////////////////////////
7286/// Set top of BoundingBox to a value (resize in y direction on top)
7287
7289{
7290 if (!gPad)
7291 return;
7292 fHNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1()) - fYlowNDC;
7293 ResizePad();
7294}
7295
7296////////////////////////////////////////////////////////////////////////////////
7297/// Set bottom of BoundingBox to a value
7298/// (resize in y direction on bottom)
7299
7301{
7302 if (!gPad)
7303 return;
7304 fYlowNDC = (gPad->PixeltoY(y - gPad->VtoPixel(0)) - gPad->GetY1()) / (gPad->GetY2() - gPad->GetY1());
7306 ResizePad();
7307}
7308
7309////////////////////////////////////////////////////////////////////////////////
7310/// Mark pad modified
7311/// Will be repainted when TCanvas::Update() will be called next time
7312
7314{
7315 if (!fModified && flag) Emit("Modified()");
7316 fModified = flag;
7317}
7318
7319////////////////////////////////////////////////////////////////////////////////
7320/// Convert absolute pixel into X/Y coordinates
7321
7323{
7324 x = AbsPixeltoX(xpixel);
7325 y = AbsPixeltoY(ypixel);
7326}
7327
7328
7329////////////////////////////////////////////////////////////////////////////////
7330/// Convert pixel to X coordinate
7331
7333{
7334 if (fAbsCoord) return fAbsPixeltoXk + px*fPixeltoX;
7335 else return fPixeltoXk + px*fPixeltoX;
7336}
7337
7338////////////////////////////////////////////////////////////////////////////////
7339/// Convert pixel to Y coordinate
7340
7342{
7343 if (fAbsCoord) return fAbsPixeltoYk + py*fPixeltoY;
7344 else return fPixeltoYk + py*fPixeltoY;
7345}
7346
7347////////////////////////////////////////////////////////////////////////////////
7348/// Convert pixel to X/Y coordinates
7349
7351{
7352 x = PixeltoX(xpixel);
7353 y = PixeltoY(ypixel);
7354}
7355
7356////////////////////////////////////////////////////////////////////////////////
7357/// Convert X/Y into absolute pixel coordinates - integer
7358
7359void TPad::XYtoAbsPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const
7360{
7361 xpixel = XtoAbsPixel(x);
7362 ypixel = YtoAbsPixel(y);
7363}
7364
7365////////////////////////////////////////////////////////////////////////////////
7366/// Check value for valid range for pixel values
7367
7369{
7370 return v < -kMaxPixel ? -kMaxPixel : (v > kMaxPixel ? kMaxPixel : v);
7371}
7372
7373////////////////////////////////////////////////////////////////////////////////
7374/// Convert X/Y into absolute pixel coordinates - doble
7375/// Introduced to avoid pixel rounding problems
7376
7378{
7381}
7382
7383////////////////////////////////////////////////////////////////////////////////
7384/// Convert X/Y into pixel coordinates - integer
7385
7386void TPad::XYtoPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const
7387{
7388 xpixel = XtoPixel(x);
7389 ypixel = YtoPixel(y);
7390}
7391
7392////////////////////////////////////////////////////////////////////////////////
7393/// Convert X/Y into pixel coordinates - double
7394
7400
7401////////////////////////////////////////////////////////////////////////////////
7402/// Convert X NDC to pixel
7403
7408
7409////////////////////////////////////////////////////////////////////////////////
7410/// Convert Y NDC to pixel
7411
7416
7417////////////////////////////////////////////////////////////////////////////////
7418/// Convert X NDC to absolute pixel
7419
7424
7425////////////////////////////////////////////////////////////////////////////////
7426/// Convert Y NDC to absolute pixel
7427
7432
7433////////////////////////////////////////////////////////////////////////////////
7434/// Convert X coordinate to absolute pixel
7435
7440
7441////////////////////////////////////////////////////////////////////////////////
7442/// Convert X coordinate to pixel
7443
7448
7449////////////////////////////////////////////////////////////////////////////////
7450/// Convert Y coordinate to absolute pixel
7451
7456
7457////////////////////////////////////////////////////////////////////////////////
7458/// Convert a vertical distance [y1,y2] to pixel
7459
7461{
7462 double h1 = fYtoAbsPixelk + y1 * fYtoPixel;
7463 double h2 = fYtoAbsPixelk + y2 * fYtoPixel;
7464 return TMath::Nint(pixel_boundary(std::abs(h1 - h2)));
7465}
7466
7467////////////////////////////////////////////////////////////////////////////////
7468/// Convert a horizontal distance [x1,x2] to pixel
7469
7471{
7472 double w1 = fXtoAbsPixelk + x1 * fXtoPixel;
7473 double w2 = fXtoAbsPixelk + x2 * fXtoPixel;
7474 return TMath::Nint(pixel_boundary(std::abs(w1 - w2)));
7475}
7476
7477
7478////////////////////////////////////////////////////////////////////////////////
7479/// Convert Y coordinate to pixel
7480
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:7368
static Int_t gReadLevel
Definition TPad.cxx:70
#define NotFree(i, j)
Definition TPad.cxx:3171
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:1996
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:2676
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:2686
Bool_t IsGrayscale()
Check whether this canvas is to be drawn in grayscale mode.
Definition TCanvas.cxx:2627
void SaveSource(const char *filename="", Option_t *option="")
Save primitives in this canvas as a C++ macro file.
Definition TCanvas.cxx:1835
virtual void HandleInput(EEventType button, Int_t x, Int_t y)
Handle Input Events.
Definition TCanvas.cxx:1242
void UpdateAsync() override
Asynchronous canvas update.
Definition TCanvas.cxx:2600
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:1973
TVirtualPad * GetSelectedPad() const override
Definition TCanvas.h:151
void SetCursor(ECursor cursor) override
Set cursor.
Definition TCanvas.cxx:1987
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:2520
virtual void Cleared(TVirtualPad *pad)
Emit pad Cleared signal.
Definition TCanvas.cxx:784
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:1139
Int_t GetDoubleBuffer() const override
Definition TCanvas.h:139
static TClass * Class()
void SetSelected(TObject *obj) override
Set selected canvas.
Definition TCanvas.cxx:2145
Int_t GetEvent() const override
Definition TCanvas.h:140
Bool_t IsWeb() const override
Is web canvas.
Definition TCanvas.cxx:1517
void SetBatch(Bool_t batch=kTRUE) override
Toggle batch mode.
Definition TCanvas.cxx:1955
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:4610
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:6154
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:7412
void PaintBorder(Color_t color, Bool_t tops)
Paint the pad border.
Definition TPad.cxx:3564
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:6119
TVirtualViewer3D * GetViewer3D(Option_t *type="") override
Create/obtain handle to 3D viewer.
Definition TPad.cxx:7076
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:4051
void PaintLine3D(Float_t *p1, Float_t *p2) override
Paint 3-D line in the CurrentPad.
Definition TPad.cxx:4232
static Int_t fgMaxPickDistance
Maximum Pick Distance.
Definition TPad.h:121
void ResizePad(Option_t *option="") override
Compute pad conversion coefficients.
Definition TPad.cxx:5607
void PaintMarker3D(Double_t x, Double_t y, Double_t z) override
Paint 3-D marker in the CurrentPad.
Definition TPad.cxx:4268
void PaintPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override
Paint polymarker in CurrentPad World coordinates.
Definition TPad.cxx:4445
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:7179
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:5822
void CopyBackgroundPixmaps(TPad *stop, Int_t x, Int_t y)
Copy pixmaps of pads laying below pad "stop" into pad "stop".
Definition TPad.cxx:3893
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:3453
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:3795
void SetBBoxY1(const Int_t y) override
Set top of BoundingBox to a value (resize in y direction on top)
Definition TPad.cxx:7288
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:6035
Bool_t fEmbeddedGL
!
Definition TPad.h:93
Int_t UtoAbsPixel(Double_t u) const override
Convert X NDC to absolute pixel.
Definition TPad.cxx:7420
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:7444
void SetAttFillPS(Color_t color, Style_t style) override
Set postscript fill area attributes.
Definition TPad.cxx:6130
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:7252
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:7026
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:7322
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:5390
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:3699
void SetEditable(Bool_t mode=kTRUE) override
Set pad editable yes/no If a pad is not editable:
Definition TPad.cxx:5979
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:3637
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:6605
void PixeltoXY(Double_t xpixel, Double_t ypixel, Double_t &x, Double_t &y) override
Convert pixel to X/Y coordinates.
Definition TPad.cxx:7350
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:7277
void SetBBoxX1(const Int_t x) override
Set lefthandside of BoundingBox to a value (resize in x direction on left)
Definition TPad.cxx:7264
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:5998
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:3444
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:3474
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:6095
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:7460
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:7386
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:6852
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:7428
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:5314
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:7359
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:6972
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:6166
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:7341
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:4646
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:3974
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:7481
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:4197
Int_t GetGLDevice() override
Get GL device.
Definition TPad.cxx:7163
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:7171
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:3627
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:6024
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:7058
Bool_t HasCrosshair() const override
Return kTRUE if the crosshair has been activated (via SetCrosshair).
Definition TPad.cxx:6567
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:3912
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7313
void RecursiveRemove(TObject *obj) override
Recursively remove object from a pad and its sub-pads.
Definition TPad.cxx:5372
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:7048
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:6615
void PaintPolyLine(Int_t n, Float_t *x, Float_t *y, Option_t *option="") override
Paint polyline in CurrentPad World coordinates.
Definition TPad.cxx:4294
Int_t WtoAbsPixel(Double_t x1, Double_t x2) const override
Convert a horizontal distance [x1,x2] to pixel.
Definition TPad.cxx:7470
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:3432
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:6142
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:4516
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:6638
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:4557
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:7404
TPoint GetBBoxCenter() override
Return the center of the Pad as TPoint in pixels.
Definition TPad.cxx:7213
void FillCollideGridTFrame(TObject *o)
Definition TPad.cxx:3236
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:3176
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:3262
void SetFixedAspectRatio(Bool_t fixed=kTRUE) override
Fix pad aspect ratio to current value if fixed is true.
Definition TPad.cxx:5955
Short_t GetBorderSize() const override
Definition TPad.h:210
void RedrawAxis(Option_t *option="") override
Redraw the frame axis.
Definition TPad.cxx:5433
void DrawDist(Rectangle_t aBBox, Rectangle_t bBBox, char mode)
Draw Arrows to indicated equal distances of Objects with given BBoxes.
Definition TPad.cxx:6191
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:7452
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:4017
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:5352
@ 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:7037
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:7196
void Paint(Option_t *option="") override
Paint all primitives in pad.
Definition TPad.cxx:3486
void FillCollideGridTBox(TObject *o)
Definition TPad.cxx:3219
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:3375
TString fName
Pad name.
Definition TPad.h:115
void SetVertical(Bool_t vert=kTRUE) override
Set pad vertical (default) or horizontal.
Definition TPad.cxx:6629
void FillCollideGridTH1(TObject *o)
Definition TPad.cxx:3293
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:4571
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:5767
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:4219
void Print(const char *filename="") const override
This method is equivalent to SaveAs("filename"). See TPad::SaveAs for details.
Definition TPad.cxx:4787
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:7187
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:6275
Int_t GetCrosshair() const
Return the crosshair type (from the mother canvas) crosshair type = 0 means no crosshair.
Definition TPad.cxx:6576
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:3841
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:7228
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:7332
void PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *option="") override
Paint polyline in CurrentPad NDC coordinates.
Definition TPad.cxx:4409
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:3680
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:4597
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:4429
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:6010
void ReleaseViewer3D(Option_t *type="") override
Release current (external) viewer.
Definition TPad.cxx:7147
void SetCrosshair(Int_t crhair=1) override
Set crosshair active/inactive.
Definition TPad.cxx:6589
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:7241
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:7016
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:4765
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:7436
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:7300
Double_t XtoPad(Double_t x) const override
Convert x from X to pad.
Definition TPad.cxx:3462
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:6244
TAttBBox2D * fb
Definition TPad.cxx:6246
dField()
Definition TPad.cxx:6251
char fdir
Definition TPad.cxx:6248
dField(TAttBBox2D *a, TAttBBox2D *b, Int_t dist, char direction)
Definition TPad.cxx:6255
TAttBBox2D * fa
Definition TPad.cxx:6245
Int_t fdist
Definition TPad.cxx:6247
TMarker m
Definition textangle.C:8