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