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
18#include "TROOT.h"
19#include "TBuffer.h"
20#include "TError.h"
21#include "TMath.h"
22#include "TSystem.h"
23#include "TStyle.h"
24#include "TFile.h"
25#include "TH1.h"
26#include "TH2.h"
27#include "TH3.h"
28#include "TClass.h"
29#include "TBaseClass.h"
30#include "TClassTable.h"
31#include "TVirtualPS.h"
32#include "TVirtualX.h"
33#include "TVirtualViewer3D.h"
34#include "TView.h"
35#include "TPoint.h"
36#include "TGraph.h"
37#include "TMultiGraph.h"
38#include "THStack.h"
39#include "TPaveText.h"
40#include "TPaveStats.h"
41#include "TGroupButton.h"
42#include "TBrowser.h"
43#include "TVirtualGL.h"
44#include "TString.h"
45#include "TDataMember.h"
46#include "TMethod.h"
47#include "TDataType.h"
48#include "TFrame.h"
49#include "TExec.h"
50#include "TDatime.h"
51#include "TColor.h"
52#include "TCanvas.h"
53#include "TPluginManager.h"
54#include "TEnv.h"
55#include "TImage.h"
56#include "TViewer3DPad.h"
57#include "TCreatePrimitives.h"
58#include "TLegend.h"
59#include "TAtt3D.h"
60#include "TVirtualPadPainter.h"
61#include "strlcpy.h"
62#include "snprintf.h"
63
64#include "TVirtualMutex.h"
65
66static Int_t gReadLevel = 0;
67
69
71
72/** \class TPad
73\ingroup gpad
74
75The most important graphics class in the ROOT system.
76
77A Pad is contained in a Canvas.
78
79A Pad may contain other pads (unlimited pad hierarchy).
80
81A pad is a linked list of primitives of any type (graphics objects,
82histograms, detectors, tracks, etc.).
83
84Adding a new element into a pad is in general performed by the Draw
85member function of the object classes.
86
87It is important to realize that the pad is a linked list of references
88to the original object.
89For example, in case of a histogram, the histogram.Draw() operation
90only stores a reference to the histogram object and not a graphical
91representation of this histogram.
92When the mouse is used to change (say the bin content), the bin content
93of the original histogram is changed.
94
95The convention used in ROOT is that a Draw operation only adds
96a reference to the object. The effective drawing is performed
97when the canvas receives a signal to be painted.
98
99\image html gpad_pad1.png
100
101This signal is generally sent when typing carriage return in the
102command input or when a graphical operation has been performed on one
103of the pads of this canvas.
104When a Canvas/Pad is repainted, the member function Paint for all
105objects in the Pad linked list is invoked.
106
107\image html gpad_pad2.png
108
109When the mouse is moved on the Pad, The member function DistancetoPrimitive
110is called for all the elements in the pad. DistancetoPrimitive returns
111the distance in pixels to this object.
112
113When the object is within the distance window, the member function
114ExecuteEvent is called for this object.
115
116In ExecuteEvent, move, changes can be performed on the object.
117
118For examples of DistancetoPrimitive and ExecuteEvent functions,
119see classes
120~~~ {.cpp}
121 TLine::DistancetoPrimitive, TLine::ExecuteEvent
122 TBox::DistancetoPrimitive, TBox::ExecuteEvent
123 TH1::DistancetoPrimitive, TH1::ExecuteEvent
124~~~
125A Pad supports linear and log scales coordinate systems.
126The transformation coefficients are explained in TPad::ResizePad.
127*/
128
129////////////////////////////////////////////////////////////////////////////////
130/// Pad default constructor.
131
133{
134 fModified = kTRUE;
135 fTip = nullptr;
136 fPadPointer = nullptr;
137 fPrimitives = nullptr;
138 fExecs = nullptr;
139 fCanvas = nullptr;
140 fPadPaint = 0;
141 fPixmapID = -1;
142 fGLDevice = -1;
143 fCopyGLDevice = kFALSE;
144 fEmbeddedGL = kFALSE;
145 fTheta = 30;
146 fPhi = 30;
147 fNumber = 0;
148 fAbsCoord = kFALSE;
149 fEditable = kTRUE;
150 fCrosshair = 0;
151 fCrosshairPos = 0;
152 fPadView3D = nullptr;
153 fMother = (TPad*)gPad;
154
155 fAbsHNDC = 0.;
156 fAbsPixeltoXk = 0.;
157 fAbsPixeltoYk = 0.;
158 fAbsWNDC = 0.;
159 fAbsXlowNDC = 0.;
160 fAbsYlowNDC = 0.;
161 fBorderMode = 0;
162 fBorderSize = 0;
163 fPixeltoX = 0;
164 fPixeltoXk = 0.;
165 fPixeltoY = 0.;
166 fPixeltoYk = 0.;
167 fUtoAbsPixelk = 0.;
168 fUtoPixel = 0.;
169 fUtoPixelk = 0.;
170 fVtoAbsPixelk = 0.;
171 fVtoPixel = 0.;
172 fVtoPixelk = 0.;
173 fXtoAbsPixelk = 0.;
174 fXtoPixel = 0.;
175 fXtoPixelk = 0.;
176 fYtoAbsPixelk = 0.;
177 fYtoPixel = 0.;
178 fYtoPixelk = 0.;
179 fXUpNDC = 0.;
180 fYUpNDC = 0.;
181
182 fFixedAspectRatio = kFALSE;
183 fAspectRatio = 0.;
184
185 fNumPaletteColor = 0;
186 fNextPaletteColor = 0;
187 fCGnx = 0;
188 fCGny = 0;
189
190 fLogx = 0;
191 fLogy = 0;
192 fLogz = 0;
193 fGridx = false;
194 fGridy = false;
195 fTickx = 0;
196 fTicky = 0;
197 fFrame = nullptr;
198 fView = nullptr;
199
200 fUxmin = fUymin = fUxmax = fUymax = 0;
201
202 // Set default world coordinates to NDC [0,1]
203 fX1 = 0;
204 fX2 = 1;
205 fY1 = 0;
206 fY2 = 1;
207
208 // Set default pad range
209 fXlowNDC = 0;
210 fYlowNDC = 0;
211 fWNDC = 1;
212 fHNDC = 1;
213
214 fViewer3D = nullptr;
215 SetBit(kMustCleanup);
216
217 // the following line is temporarily disabled. It has side effects
218 // when the pad is a TDrawPanelHist or a TFitPanel.
219 // the line was supposed to fix a problem with DrawClonePad
220 // gROOT->SetSelectedPad(this);
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Pad constructor.
225///
226/// A pad is a linked list of primitives.
227/// A pad is contained in a canvas. It may contain other pads.
228/// A pad has attributes. When a pad is created, the attributes
229/// defined in the current style are copied to the pad attributes.
230///
231/// \param[in] name pad name
232/// \param[in] title pad title
233/// \param[in] xlow [0,1] is the position of the bottom left point of the pad
234/// expressed in the mother pad reference system
235/// \param[in] ylow [0,1] is the Y position of this point.
236/// \param[in] xup [0,1] is the x position of the top right point of the pad
237/// expressed in the mother pad reference system
238/// \param[in] yup [0,1] is the Y position of this point.
239/// \param[in] color pad color
240/// \param[in] bordersize border size in pixels
241/// \param[in] bordermode border mode
242/// - bordermode = -1 box looks as it is behind the screen
243/// - bordermode = 0 no special effects
244/// - bordermode = 1 box looks as it is in front of the screen
245
246TPad::TPad(const char *name, const char *title, Double_t xlow,
247 Double_t ylow, Double_t xup, Double_t yup,
248 Color_t color, Short_t bordersize, Short_t bordermode)
249 : TVirtualPad(name,title,xlow,ylow,xup,yup,color,bordersize,bordermode)
250{
252 fTip = nullptr;
253 fBorderSize = bordersize;
254 fBorderMode = bordermode;
255 if (gPad) fCanvas = gPad->GetCanvas();
256 else fCanvas = (TCanvas*)this;
257 fMother = (TPad*)gPad;
258 fPrimitives = new TList;
259 fExecs = new TList;
260 fPadPointer = nullptr;
261 fTheta = 30;
262 fPhi = 30;
267 fFrame = nullptr;
268 fView = nullptr;
269 fPadPaint = 0;
270 fPadView3D = nullptr;
271 fPixmapID = -1; // -1 means pixmap will be created by ResizePad()
274 fNumber = 0;
277 fCrosshair = 0;
278 fCrosshairPos = 0;
279
280 fVtoAbsPixelk = 0.;
281 fVtoPixelk = 0.;
282 fVtoPixel = 0.;
283 fAbsPixeltoXk = 0.;
284 fPixeltoXk = 0.;
285 fPixeltoX = 0;
286 fAbsPixeltoYk = 0.;
287 fPixeltoYk = 0.;
288 fPixeltoY = 0.;
289 fXlowNDC = 0;
290 fYlowNDC = 0;
291 fWNDC = 1;
292 fHNDC = 1;
293 fXUpNDC = 0.;
294 fYUpNDC = 0.;
295 fAbsXlowNDC = 0.;
296 fAbsYlowNDC = 0.;
297 fAbsWNDC = 0.;
298 fAbsHNDC = 0.;
299 fXtoAbsPixelk = 0.;
300 fXtoPixelk = 0.;
301 fXtoPixel = 0.;
302 fYtoAbsPixelk = 0.;
303 fYtoPixelk = 0.;
304 fYtoPixel = 0.;
305 fUtoAbsPixelk = 0.;
306 fUtoPixelk = 0.;
307 fUtoPixel = 0.;
308
309 fUxmin = fUymin = fUxmax = fUymax = 0;
313
315 fAspectRatio = 0.;
316
319 fCGnx = 0;
320 fCGny = 0;
321
322 fViewer3D = nullptr;
323
325 // Set default world coordinates to NDC [0,1]
326 fX1 = 0;
327 fX2 = 1;
328 fY1 = 0;
329 fY2 = 1;
330
331 if (!gPad) {
332 Error("TPad", "You must create a TCanvas before creating a TPad");
333 MakeZombie();
334 return;
335 }
336
337 TContext ctxt(kTRUE);
338
339 Bool_t zombie = kFALSE;
340
341 if ((xlow < 0) || (xlow > 1) || (ylow < 0) || (ylow > 1)) {
342 Error("TPad", "illegal bottom left position: x=%f, y=%f", xlow, ylow);
343 zombie = kTRUE;
344 } else if ((xup < 0) || (xup > 1) || (yup < 0) || (yup > 1)) {
345 Error("TPad", "illegal top right position: x=%f, y=%f", xup, yup);
346 zombie = kTRUE;
347 } else if (xup-xlow <= 0) {
348 Error("TPad", "illegal width: %f", xup-xlow);
349 zombie = kTRUE;
350 } else if (yup-ylow <= 0) {
351 Error("TPad", "illegal height: %f", yup-ylow);
352 zombie = kTRUE;
353 }
354
355 if (zombie) {
356 // error in creating pad occurred, make this pad a zombie
357 MakeZombie();
358 return;
359 }
360
361
365
366 fUxmin = fUymin = fUxmax = fUymax = 0;
367
368 // Set pad parameters and Compute conversion coefficients
369 SetPad(name, title, xlow, ylow, xup, yup, color, bordersize, bordermode);
370 Range(0, 0, 1, 1);
373}
374
375
376////////////////////////////////////////////////////////////////////////////////
377/// Pad destructor.
378
380{
381 if (ROOT::Detail::HasBeenDeleted(this)) return;
382 Close();
385 auto primitives = fPrimitives;
386 // In some cases, fPrimitives has the kMustCleanup bit set which will lead
387 // its destructor to call RecursiveRemove and since this pad is still
388 // likely to be (indirectly) in the list of cleanups, we must set
389 // fPrimitives to nullptr to avoid TPad::RecursiveRemove from calling
390 // a member function of a partially destructed object.
391 fPrimitives = nullptr;
392 delete primitives;
394 delete fViewer3D;
395
396 // Required since we overload TObject::Hash.
398 if (this == gPad)
399 gPad = nullptr;
400}
401
402////////////////////////////////////////////////////////////////////////////////
403/// Add a new TExec object to the list of Execs.
404///
405/// When an event occurs in the pad (mouse click, etc) the list of C++ commands
406/// in the list of Execs are executed via TPad::AutoExec.
407///
408/// When a pad event occurs (mouse move, click, etc) all the commands
409/// contained in the fExecs list are executed in the order found in the list.
410///
411/// This facility is activated by default. It can be deactivated by using
412/// the canvas "Option" menu.
413///
414/// The following examples of TExec commands are provided in the tutorials:
415/// macros exec1.C and exec2.C.
416///
417/// ### Example1 of use of exec1.C
418///
419/// ~~~ {.cpp}
420/// Root > TFile f("hsimple.root")
421/// Root > hpx.Draw()
422/// Root > c1.AddExec("ex1",".x exec1.C")
423/// ~~~
424///
425/// At this point you can use the mouse to click on the contour of
426/// the histogram hpx. When the mouse is clicked, the bin number and its
427/// contents are printed.
428///
429/// ### Example2 of use of exec1.C
430///
431/// ~~~ {.cpp}
432/// Root > TFile f("hsimple.root")
433/// Root > hpxpy.Draw()
434/// Root > c1.AddExec("ex2",".x exec2.C")
435/// ~~~
436///
437/// When moving the mouse in the canvas, a second canvas shows the
438/// projection along X of the bin corresponding to the Y position
439/// of the mouse. The resulting histogram is fitted with a gaussian.
440/// A "dynamic" line shows the current bin position in Y.
441/// This more elaborated example can be used as a starting point
442/// to develop more powerful interactive applications exploiting the C++
443/// interpreter as a development engine.
444
445void TPad::AddExec(const char *name, const char *command)
446{
447 if (!fExecs) fExecs = new TList;
448 TExec *ex = new TExec(name,command);
449 fExecs->Add(ex);
450}
451
452////////////////////////////////////////////////////////////////////////////////
453/// Execute the list of Execs when a pad event occurs.
454
456{
457 if (GetCrosshair())
459
460 if (!fExecs)
461 return;
462 TIter next(fExecs);
463 while (auto exec = (TExec*)next())
464 exec->Exec();
465}
466
467////////////////////////////////////////////////////////////////////////////////
468/// Browse pad.
469
471{
472 cd();
474}
475
476////////////////////////////////////////////////////////////////////////////////
477/// Build a legend from the graphical objects in the pad.
478///
479/// A simple method to build automatically a TLegend from the primitives in a TPad.
480///
481/// Only those deriving from TAttLine, TAttMarker and TAttFill are added, excluding
482/// TPave and TFrame derived classes.
483///
484/// \return The built TLegend
485///
486/// \param[in] x1, y1, x2, y2 The TLegend coordinates
487/// \param[in] title The legend title. By default it is " "
488/// \param[in] option The TLegend option
489///
490/// The caller program owns the returned TLegend.
491///
492/// If the pad contains some TMultiGraph or THStack the individual
493/// graphs or histograms in them are added to the TLegend.
494///
495/// ### Automatic placement of the legend
496/// If `x1` is equal to `x2` and `y1` is equal to `y2` the legend will be automatically
497/// placed to avoid overlapping with the existing primitives already displayed.
498/// `x1` is considered as the width of the legend and `y1` the height. By default
499/// the legend is automatically placed with width = `x1`= `x2` = 0.3 and
500/// height = `y1`= `y2` = 0.21.
501
503 const char* title, Option_t *option)
504{
505 TList *lop = GetListOfPrimitives();
506 if (!lop) return nullptr;
507 TList *lof = nullptr;
508 TLegend *leg = nullptr;
509 TObject *obj = nullptr;
510 TIter next(lop);
511 TString mes;
512 TString opt;
513
514 auto AddEntryFromListOfFunctions = [&]() {
515 TIter nextobj(lof);
516 while ((obj = nextobj())) {
517 if (obj->InheritsFrom(TNamed::Class())) {
518 if (strlen(obj->GetTitle()))
519 mes = obj->GetTitle();
520 else
521 mes = obj->GetName();
522 } else {
523 mes = obj->ClassName();
524 }
525 leg->AddEntry(obj, mes.Data(), "lpf");
526 }
527 };
528
529 while(auto o = next()) {
530 if ((o->InheritsFrom(TAttLine::Class()) || o->InheritsFrom(TAttMarker::Class()) ||
531 o->InheritsFrom(TAttFill::Class())) &&
532 ( !(o->InheritsFrom(TFrame::Class())) && !(o->InheritsFrom(TPave::Class())) )) {
533 if (!leg)
534 leg = new TLegend(x1, y1, x2, y2, title);
535 if (o->InheritsFrom(TNamed::Class()) && strlen(o->GetTitle()))
536 mes = o->GetTitle();
537 else if (strlen(o->GetName()))
538 mes = o->GetName();
539 else
540 mes = o->ClassName();
541 if (option && strlen(option)) {
542 opt = option;
543 } else {
544 if (o->InheritsFrom(TAttLine::Class()))
545 opt += "l";
546 if (o->InheritsFrom(TAttMarker::Class()))
547 opt += "p";
548 if (o->InheritsFrom(TAttFill::Class()))
549 opt += "f";
550 }
551 leg->AddEntry(o,mes.Data(), opt.Data());
552 if (o->InheritsFrom(TH1::Class())) {
553 lof = ((TH1 *)o)->GetListOfFunctions();
554 AddEntryFromListOfFunctions();
555 }
556 if (o->InheritsFrom(TGraph::Class())) {
557 lof = ((TGraph *)o)->GetListOfFunctions();
558 AddEntryFromListOfFunctions();
559 }
560 } else if (o->InheritsFrom(TMultiGraph::Class())) {
561 if (!leg)
562 leg = new TLegend(x1, y1, x2, y2, title);
563 TList * grlist = ((TMultiGraph *)o)->GetListOfGraphs();
564 TIter nextgraph(grlist);
565 TGraph *gr = nullptr;
566 while ((obj = nextgraph())) {
567 gr = (TGraph*) obj;
568 if (strlen(gr->GetTitle()))
569 mes = gr->GetTitle();
570 else if (strlen(gr->GetName()))
571 mes = gr->GetName();
572 else
573 mes = gr->ClassName();
574 if (option && strlen(option))
575 opt = option;
576 else
577 opt = "lpf";
578 leg->AddEntry(obj, mes.Data(), opt);
579 }
580 lof = ((TMultiGraph *)o)->GetListOfFunctions();
581 AddEntryFromListOfFunctions();
582 } else if (o->InheritsFrom(THStack::Class())) {
583 if (!leg)
584 leg = new TLegend(x1, y1, x2, y2, title);
585 TList * hlist = ((THStack *)o)->GetHists();
586 TIter nexthist(hlist);
587 while ((obj = nexthist())) {
588 TH1 *hist = (TH1*) obj;
589 if (strlen(hist->GetTitle()))
590 mes = hist->GetTitle();
591 else if (strlen(hist->GetName()))
592 mes = hist->GetName();
593 else
594 mes = hist->ClassName();
595 if (option && strlen(option))
596 opt = option;
597 else
598 opt = "lpf";
599 leg->AddEntry( obj, mes.Data(), opt );
600 }
601 }
602 opt = "";
603 }
604 if (leg) {
605 TContext ctxt(this, kTRUE);
606 leg->Draw();
607 } else {
608 Info("BuildLegend", "No object(s) to build a TLegend.");
609 }
610 return leg;
611}
612
613////////////////////////////////////////////////////////////////////////////////
614/// Set Current pad.
615///
616/// When a canvas/pad is divided via TPad::Divide, one can directly
617/// set the current path to one of the subdivisions.
618/// See TPad::Divide for the convention to number sub-pads.
619///
620/// Returns the new current pad, or 0 in case of failure.
621///
622/// For example:
623/// ~~~ {.cpp}
624/// c1.Divide(2,3); // create 6 pads (2 divisions along x, 3 along y).
625/// ~~~
626/// To set the current pad to the bottom right pad, do
627/// ~~~ {.cpp}
628/// c1.cd(6);
629/// ~~~
630/// Note1: c1.cd() is equivalent to c1.cd(0) and sets the current pad
631/// to c1 itself.
632///
633/// Note2: after a statement like c1.cd(6), the global variable gPad
634/// points to the current pad. One can use gPad to set attributes
635/// of the current pad.
636///
637/// Note3: One can get a pointer to one of the sub-pads of pad with:
638/// TPad *subpad = (TPad*)pad->GetPad(subpadnumber);
639
641{
642 if (!subpadnumber) {
643 gPad = this;
644 if (!gPad->IsBatch() && GetPainter()) GetPainter()->SelectDrawable(fPixmapID);
645 if (!fPrimitives) fPrimitives = new TList;
646 return gPad;
647 }
648
649 if (!fPrimitives) fPrimitives = new TList;
650 TIter next(fPrimitives);
651 while (auto obj = next()) {
652 if (obj->InheritsFrom(TPad::Class())) {
653 Int_t n = ((TPad*)obj)->GetNumber();
654 if (n == subpadnumber) {
655 return ((TPad*)obj)->cd();
656 }
657 }
658 }
659 return nullptr;
660}
661
662////////////////////////////////////////////////////////////////////////////////
663/// Delete all pad primitives.
664///
665/// If the bit kClearAfterCR has been set for this pad, the Clear function
666/// will execute only after having pressed a CarriageReturn
667/// Set the bit with `mypad->SetBit(TPad::kClearAfterCR)`
668
670{
671 if (!IsEditable()) return;
672
674
675 if (!fPadPaint) {
678 if (fFrame) {
680 fFrame = nullptr;
681 }
682 }
683 if (fCanvas) fCanvas->Cleared(this);
684
685 cd();
686
687 if (TestBit(kClearAfterCR)) {
688 // Intentional do not use the return value of getchar,
689 // we just want to get it and forget it
690 getchar();
691 }
692
693 if (!gPad->IsBatch() && GetPainter()) GetPainter()->ClearDrawable();
694 if (gVirtualPS && gPad == gPad->GetCanvas()) gVirtualPS->NewPage();
695
697 fCrosshairPos = 0;
699 fCollideGrid.clear();
700 fCGnx = 0;
701 fCGny = 0;
703}
704
705////////////////////////////////////////////////////////////////////////////////
706/// Clipping routine: Cohen Sutherland algorithm.
707///
708/// - If Clip ==2 the segment is outside the boundary.
709/// - If Clip ==1 the segment has one point outside the boundary.
710/// - If Clip ==0 the segment is inside the boundary.
711///
712/// \param[inout] x[],y[] Segment coordinates (2 points)
713/// \param[in] xclipl,yclipb,xclipr,yclipt Clipping boundary
714
715Int_t TPad::Clip(Float_t *x, Float_t *y, Float_t xclipl, Float_t yclipb, Float_t xclipr, Float_t yclipt)
716{
717 const Float_t kP=10000;
718 Int_t clip = 0;
719
720 for (Int_t i=0;i<2;i++) {
721 if (TMath::Abs(xclipl-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipl;
722 if (TMath::Abs(xclipr-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipr;
723 if (TMath::Abs(yclipb-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipb;
724 if (TMath::Abs(yclipt-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipt;
725 }
726
727 // Compute the first endpoint codes.
728 Int_t code1 = ClippingCode(x[0],y[0],xclipl,yclipb,xclipr,yclipt);
729 Int_t code2 = ClippingCode(x[1],y[1],xclipl,yclipb,xclipr,yclipt);
730
731 Double_t xt=0, yt=0;
732 Int_t clipped = 0; //this variable could be used in a future version
733 while(code1 + code2) {
734 clipped = 1;
735
736 // The line lies entirely outside the clipping boundary
737 if (code1&code2) {
738 clip = 2;
739 return clip;
740 }
741
742 // The line is subdivided into several parts
743 Int_t ic = code1;
744 if (ic == 0) ic = code2;
745 if (ic & 0x1) {
746 yt = y[0] + (y[1]-y[0])*(xclipl-x[0])/(x[1]-x[0]);
747 xt = xclipl;
748 }
749 if (ic & 0x2) {
750 yt = y[0] + (y[1]-y[0])*(xclipr-x[0])/(x[1]-x[0]);
751 xt = xclipr;
752 }
753 if (ic & 0x4) {
754 xt = x[0] + (x[1]-x[0])*(yclipb-y[0])/(y[1]-y[0]);
755 yt = yclipb;
756 }
757 if (ic & 0x8) {
758 xt = x[0] + (x[1]-x[0])*(yclipt-y[0])/(y[1]-y[0]);
759 yt = yclipt;
760 }
761 if (ic == code1) {
762 x[0] = xt;
763 y[0] = yt;
764 code1 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
765 } else {
766 x[1] = xt;
767 y[1] = yt;
768 code2 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
769 }
770 }
771 clip = clipped;
772 return clip;
773}
774
775/// @copydoc TPad::Clip(Float_t*,Float_t*,Float_t,Float_t,Float_t,Float_t)
776
778{
779 const Double_t kP = 10000;
780 Int_t clip = 0;
781
782 for (Int_t i=0;i<2;i++) {
783 if (TMath::Abs(xclipl-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipl;
784 if (TMath::Abs(xclipr-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipr;
785 if (TMath::Abs(yclipb-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipb;
786 if (TMath::Abs(yclipt-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipt;
787 }
788
789 // Compute the first endpoint codes.
790 Int_t code1 = 0;
791 if (x[0] < xclipl) code1 = code1 | 0x1;
792 if (x[0] > xclipr) code1 = code1 | 0x2;
793 if (y[0] < yclipb) code1 = code1 | 0x4;
794 if (y[0] > yclipt) code1 = code1 | 0x8;
795 Int_t code2 = 0;
796 if (x[1] < xclipl) code2 = code2 | 0x1;
797 if (x[1] > xclipr) code2 = code2 | 0x2;
798 if (y[1] < yclipb) code2 = code2 | 0x4;
799 if (y[1] > yclipt) code2 = code2 | 0x8;
800
801 Double_t xt=0, yt=0;
802 Int_t clipped = 0; //this variable could be used in a future version
803 while(code1 + code2) {
804 clipped = 1;
805
806 // The line lies entirely outside the clipping boundary
807 if (code1&code2) {
808 clip = 2;
809 return clip;
810 }
811
812 // The line is subdivided into several parts
813 Int_t ic = code1;
814 if (ic == 0) ic = code2;
815 if (ic & 0x1) {
816 yt = y[0] + (y[1]-y[0])*(xclipl-x[0])/(x[1]-x[0]);
817 xt = xclipl;
818 }
819 if (ic & 0x2) {
820 yt = y[0] + (y[1]-y[0])*(xclipr-x[0])/(x[1]-x[0]);
821 xt = xclipr;
822 }
823 if (ic & 0x4) {
824 xt = x[0] + (x[1]-x[0])*(yclipb-y[0])/(y[1]-y[0]);
825 yt = yclipb;
826 }
827 if (ic & 0x8) {
828 xt = x[0] + (x[1]-x[0])*(yclipt-y[0])/(y[1]-y[0]);
829 yt = yclipt;
830 }
831 if (ic == code1) {
832 x[0] = xt;
833 y[0] = yt;
834 code1 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
835 } else {
836 x[1] = xt;
837 y[1] = yt;
838 code2 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
839 }
840 }
841 clip = clipped;
842 return clip;
843}
844
845////////////////////////////////////////////////////////////////////////////////
846/// Compute the endpoint codes for TPad::Clip.
847
849{
850 Int_t code = 0;
851 if (x < xcl1) code = code | 0x1;
852 if (x > xcl2) code = code | 0x2;
853 if (y < ycl1) code = code | 0x4;
854 if (y > ycl2) code = code | 0x8;
855 return code;
856}
857
858////////////////////////////////////////////////////////////////////////////////
859/// Clip polygon using the Sutherland-Hodgman algorithm.
860///
861/// \param[in] n Number of points in the polygon to
862/// be clipped
863/// \param[in] x,y Polygon x[n], y[n] do be clipped vertices
864/// \param[in] xclipl,yclipb,xclipr,yclipt Clipping boundary
865/// \param[out] nn Number of points in xc and yc
866/// \param[out] xc,yc Clipped polygon vertices. The Int_t
867/// returned by this function is
868/// the number of points in the clipped
869/// polygon. These vectors must
870/// be allocated by the calling function.
871/// A size of 2*n for each is
872/// enough.
873///
874/// Sutherland and Hodgman's polygon-clipping algorithm uses a divide-and-conquer
875/// strategy: It solves a series of simple and identical problems that, when
876/// combined, solve the overall problem. The simple problem is to clip a polygon
877/// against a single infinite clip edge. Four clip edges, each defining one boundary
878/// of the clip rectangle, successively clip a polygon against a clip rectangle.
879///
880/// Steps of Sutherland-Hodgman's polygon-clipping algorithm:
881///
882/// * Polygons can be clipped against each edge of the window one at a time.
883/// Windows/edge intersections, if any, are easy to find since the X or Y coordinates
884/// are already known.
885/// * Vertices which are kept after clipping against one window edge are saved for
886/// clipping against the remaining edges.
887/// * Note that the number of vertices usually changes and will often increases.
888///
889/// The clip boundary determines a visible and invisible region. The edges from
890/// vertex i to vertex i+1 can be one of four types:
891///
892/// * Case 1 : Wholly inside visible region - save endpoint
893/// * Case 2 : Exit visible region - save the intersection
894/// * Case 3 : Wholly outside visible region - save nothing
895/// * Case 4 : Enter visible region - save intersection and endpoint
896
898{
899 Int_t nc, nc2;
900 Double_t x1, y1, x2, y2, slope; // Segment to be clipped
901
902 std::vector<Double_t> xc2(nn), yc2(nn);
903
904 // Clip against the left boundary
905 x1 = x[n-1]; y1 = y[n-1];
906 nc2 = 0;
907 Int_t i;
908 for (i=0; i<n; i++) {
909 x2 = x[i]; y2 = y[i];
910 if (x1 == x2) {
911 slope = 0;
912 } else {
913 slope = (y2-y1)/(x2-x1);
914 }
915 if (x1 >= xclipl) {
916 if (x2 < xclipl) {
917 xc2[nc2] = xclipl; yc2[nc2++] = slope*(xclipl-x1)+y1;
918 } else {
919 xc2[nc2] = x2; yc2[nc2++] = y2;
920 }
921 } else {
922 if (x2 >= xclipl) {
923 xc2[nc2] = xclipl; yc2[nc2++] = slope*(xclipl-x1)+y1;
924 xc2[nc2] = x2; yc2[nc2++] = y2;
925 }
926 }
927 x1 = x2; y1 = y2;
928 }
929
930 // Clip against the top boundary
931 x1 = xc2[nc2-1]; y1 = yc2[nc2-1];
932 nc = 0;
933 for (i=0; i<nc2; i++) {
934 x2 = xc2[i]; y2 = yc2[i];
935 if (y1 == y2) {
936 slope = 0;
937 } else {
938 slope = (x2-x1)/(y2-y1);
939 }
940 if (y1 <= yclipt) {
941 if (y2 > yclipt) {
942 xc[nc] = x1+(yclipt-y1)*slope; yc[nc++] = yclipt;
943 } else {
944 xc[nc] = x2; yc[nc++] = y2;
945 }
946 } else {
947 if (y2 <= yclipt) {
948 xc[nc] = x1+(yclipt-y1)*slope; yc[nc++] = yclipt;
949 xc[nc] = x2; yc[nc++] = y2;
950 }
951 }
952 x1 = x2; y1 = y2;
953 }
954
955 if (nc>0) {
956
957 // Clip against the right boundary
958 x1 = xc[nc-1]; y1 = yc[nc-1];
959 nc2 = 0;
960 for (i=0; i<nc; i++) {
961 x2 = xc[i]; y2 = yc[i];
962 if (x1 == x2) {
963 slope = 0;
964 } else {
965 slope = (y2-y1)/(x2-x1);
966 }
967 if (x1 <= xclipr) {
968 if (x2 > xclipr) {
969 xc2[nc2] = xclipr; yc2[nc2++] = slope*(xclipr-x1)+y1;
970 } else {
971 xc2[nc2] = x2; yc2[nc2++] = y2;
972 }
973 } else {
974 if (x2 <= xclipr) {
975 xc2[nc2] = xclipr; yc2[nc2++] = slope*(xclipr-x1)+y1;
976 xc2[nc2] = x2; yc2[nc2++] = y2;
977 }
978 }
979 x1 = x2; y1 = y2;
980 }
981
982 // Clip against the bottom boundary
983 x1 = xc2[nc2-1]; y1 = yc2[nc2-1];
984 nc = 0;
985 for (i=0; i<nc2; i++) {
986 x2 = xc2[i]; y2 = yc2[i];
987 if (y1 == y2) {
988 slope = 0;
989 } else {
990 slope = (x2-x1)/(y2-y1);
991 }
992 if (y1 >= yclipb) {
993 if (y2 < yclipb) {
994 xc[nc] = x1+(yclipb-y1)*slope; yc[nc++] = yclipb;
995 } else {
996 xc[nc] = x2; yc[nc++] = y2;
997 }
998 } else {
999 if (y2 >= yclipb) {
1000 xc[nc] = x1+(yclipb-y1)*slope; yc[nc++] = yclipb;
1001 xc[nc] = x2; yc[nc++] = y2;
1002 }
1003 }
1004 x1 = x2; y1 = y2;
1005 }
1006 }
1007
1008 if (nc < 3) nc =0;
1009 return nc;
1010}
1011
1012////////////////////////////////////////////////////////////////////////////////
1013/// Delete all primitives in pad and pad itself.
1014/// Pad cannot be used anymore after this call.
1015/// Emits signal "Closed()".
1016
1018{
1019 if (ROOT::Detail::HasBeenDeleted(this)) return;
1020 if (!fMother) return;
1022
1023 if (fPrimitives)
1024 fPrimitives->Clear();
1025 if (fView) {
1027 fView = nullptr;
1028 }
1029 if (fFrame) {
1031 fFrame = nullptr;
1032 }
1033
1034 // emit signal
1035 if (IsA() != TCanvas::Class())
1036 Closed();
1037
1038 if (fPixmapID != -1) {
1039 if (gPad) {
1040 if (!gPad->IsBatch() && GetPainter())
1042 }
1043 fPixmapID = -1;
1044
1045 if (!gROOT->GetListOfCanvases()) return;
1046 if (fMother == this) {
1047 gROOT->GetListOfCanvases()->Remove(this);
1048 return; // in case of TCanvas
1049 }
1050
1051 // remove from the mother's list of primitives
1052 if (fMother) {
1055
1056 if (gPad == this) fMother->cd();
1057 }
1058 if (fCanvas) {
1059 if (fCanvas->GetPadSave() == this)
1061 if (fCanvas->GetSelectedPad() == this)
1062 fCanvas->SetSelectedPad(nullptr);
1063 if (fCanvas->GetClickSelectedPad() == this)
1064 fCanvas->SetClickSelectedPad(nullptr);
1065 }
1066 }
1067
1068 fMother = nullptr;
1069 if (gROOT->GetSelectedPad() == this)
1070 gROOT->SetSelectedPad(nullptr);
1071}
1072
1073////////////////////////////////////////////////////////////////////////////////
1074/// Copy the pixmap of the pad to the canvas.
1075
1077{
1078 int px, py;
1079 XYtoAbsPixel(fX1, fY2, px, py);
1080
1081 if (fPixmapID != -1 && GetPainter())
1082 GetPainter()->CopyDrawable(fPixmapID, px, py);
1083
1084 if (this == gPad) HighLight(gPad->GetHighLightColor());
1085}
1086
1087////////////////////////////////////////////////////////////////////////////////
1088/// Copy the sub-pixmaps of the pad to the canvas.
1089
1091{
1092 if (!fPrimitives) fPrimitives = new TList;
1093 TIter next(GetListOfPrimitives());
1094 while (auto obj = next()) {
1095 if (obj->InheritsFrom(TPad::Class())) {
1096 ((TPad*)obj)->CopyPixmap();
1097 ((TPad*)obj)->CopyPixmaps();
1098 }
1099 }
1100}
1101
1102////////////////////////////////////////////////////////////////////////////////
1103/// Remove TExec name from the list of Execs.
1104
1105void TPad::DeleteExec(const char *name)
1106{
1107 if (!fExecs) fExecs = new TList;
1109 if (!ex) return;
1110 fExecs->Remove(ex);
1111 delete ex;
1112}
1113
1114////////////////////////////////////////////////////////////////////////////////
1115/// Compute distance from point px,py to a box.
1116///
1117/// Compute the closest distance of approach from point px,py to the
1118/// edges of this pad.
1119/// The distance is computed in pixels units.
1120
1122{
1123 Int_t pxl, pyl, pxt, pyt;
1124 Int_t px1 = gPad->XtoAbsPixel(fX1);
1125 Int_t py1 = gPad->YtoAbsPixel(fY1);
1126 Int_t px2 = gPad->XtoAbsPixel(fX2);
1127 Int_t py2 = gPad->YtoAbsPixel(fY2);
1128 if (px1 < px2) {pxl = px1; pxt = px2;}
1129 else {pxl = px2; pxt = px1;}
1130 if (py1 < py2) {pyl = py1; pyt = py2;}
1131 else {pyl = py2; pyt = py1;}
1132
1133 // Are we inside the box?
1134 // ======================
1135 if ( (px > pxl && px < pxt) && (py > pyl && py < pyt) ) {
1136 if (GetFillStyle()) return 0; //*-* if pad is filled
1137 }
1138
1139 // Are we on the edges?
1140 // ====================
1141 Int_t dxl = TMath::Abs(px - pxl);
1142 if (py < pyl) dxl += pyl - py;
1143 if (py > pyt) dxl += py - pyt;
1144 Int_t dxt = TMath::Abs(px - pxt);
1145 if (py < pyl) dxt += pyl - py;
1146 if (py > pyt) dxt += py - pyt;
1147 Int_t dyl = TMath::Abs(py - pyl);
1148 if (px < pxl) dyl += pxl - px;
1149 if (px > pxt) dyl += px - pxt;
1150 Int_t dyt = TMath::Abs(py - pyt);
1151 if (px < pxl) dyt += pxl - px;
1152 if (px > pxt) dyt += px - pxt;
1153
1154 Int_t distance = dxl;
1155 if (dxt < distance) distance = dxt;
1156 if (dyl < distance) distance = dyl;
1157 if (dyt < distance) distance = dyt;
1158
1159 return distance - Int_t(0.5*fLineWidth);
1160}
1161
1162////////////////////////////////////////////////////////////////////////////////
1163/// Automatic pad generation by division.
1164///
1165/// - The current canvas is divided in nx by ny equal divisions (pads).
1166/// - xmargin is the space along x between pads in percent of canvas.
1167/// - ymargin is the space along y between pads in percent of canvas.
1168/// - color is the color of the new pads. If 0, color is the canvas color.
1169///
1170/// Pads are automatically named `canvasname_n` where `n` is the division number
1171/// starting from top left pad.
1172///
1173/// Example if canvasname=c1 , nx=2, ny=3:
1174///
1175/// \image html gpad_pad3.png
1176///
1177/// Once a pad is divided into sub-pads, one can set the current pad
1178/// to a subpad with a given division number as illustrated above
1179/// with TPad::cd(subpad_number).
1180///
1181/// For example, to set the current pad to c1_4, one can do:
1182/// ~~~ {.cpp}
1183/// c1->cd(4)
1184/// ~~~
1185/// __Note1:__ c1.cd() is equivalent to c1.cd(0) and sets the current pad
1186/// to c1 itself.
1187///
1188/// __Note2:__ after a statement like c1.cd(6), the global variable gPad
1189/// points to the current pad. One can use gPad to set attributes
1190/// of the current pad.
1191///
1192/// __Note3:__ in case xmargin <=0 and ymargin <= 0, there is no space
1193/// between pads. The current pad margins are recomputed to
1194/// optimize the layout.
1195
1196void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color)
1197{
1198 if (!IsEditable()) return;
1199
1200 if (gThreadXAR) {
1201 void *arr[7];
1202 arr[1] = this; arr[2] = (void*)&nx;arr[3] = (void*)& ny;
1203 arr[4] = (void*)&xmargin; arr[5] = (void *)& ymargin; arr[6] = (void *)&color;
1204 if ((*gThreadXAR)("PDCD", 7, arr, nullptr)) return;
1205 }
1206
1207 TContext ctxt(kTRUE);
1208
1209 cd();
1210 if (nx <= 0) nx = 1;
1211 if (ny <= 0) ny = 1;
1212 Int_t ix, iy;
1213 Double_t x1, y1, x2, y2, dx, dy;
1214 TPad *pad;
1215 TString name, title;
1216 Int_t n = 0;
1217 if (color == 0) color = GetFillColor();
1218 if (xmargin > 0 && ymargin > 0) {
1219 //general case
1220 dy = 1/Double_t(ny);
1221 dx = 1/Double_t(nx);
1222 for (iy=0;iy<ny;iy++) {
1223 y2 = 1 - iy*dy - ymargin;
1224 y1 = y2 - dy + 2*ymargin;
1225 if (y1 < 0) y1 = 0;
1226 if (y1 > y2) continue;
1227 for (ix=0;ix<nx;ix++) {
1228 x1 = ix*dx + xmargin;
1229 x2 = x1 +dx -2*xmargin;
1230 if (x1 > x2) continue;
1231 n++;
1232 name.Form("%s_%d", GetName(), n);
1233 pad = new TPad(name.Data(), name.Data(), x1, y1, x2, y2, color);
1234 pad->SetNumber(n);
1235 pad->Draw();
1236 }
1237 }
1238 } else {
1239 // special case when xmargin <= 0 && ymargin <= 0
1240 Double_t xl = GetLeftMargin();
1241 Double_t xr = GetRightMargin();
1243 Double_t yt = GetTopMargin();
1244 xl /= (1-xl+xr)*nx;
1245 xr /= (1-xl+xr)*nx;
1246 yb /= (1-yb+yt)*ny;
1247 yt /= (1-yb+yt)*ny;
1248 SetLeftMargin(xl);
1249 SetRightMargin(xr);
1250 SetBottomMargin(yb);
1251 SetTopMargin(yt);
1252 dx = (1-xl-xr)/nx;
1253 dy = (1-yb-yt)/ny;
1254 Int_t number = 0;
1255 for (Int_t i=0;i<nx;i++) {
1256 x1 = i*dx+xl;
1257 x2 = x1 + dx;
1258 if (i == 0) x1 = 0;
1259 if (i == nx-1) x2 = 1-xr;
1260 for (Int_t j=0;j<ny;j++) {
1261 number = j*nx + i +1;
1262 y2 = 1 -j*dy -yt;
1263 y1 = y2 - dy;
1264 if (j == 0) y2 = 1-yt;
1265 if (j == ny-1) y1 = 0;
1266 name.Form("%s_%d", GetName(), number);
1267 title.Form("%s_%d", GetTitle(), number);
1268 pad = new TPad(name.Data(), title.Data(), x1, y1, x2, y2);
1269 pad->SetNumber(number);
1270 pad->SetBorderMode(0);
1271 if (i == 0) pad->SetLeftMargin(xl*nx);
1272 else pad->SetLeftMargin(0);
1273 pad->SetRightMargin(0);
1274 pad->SetTopMargin(0);
1275 if (j == ny-1) pad->SetBottomMargin(yb*ny);
1276 else pad->SetBottomMargin(0);
1277 pad->Draw();
1278 }
1279 }
1280 }
1281 Modified();
1282}
1283
1284////////////////////////////////////////////////////////////////////////////////
1285/// "n" is the total number of sub-pads. The number of sub-pads along the X
1286/// and Y axis are computed according to the square root of n.
1287
1288void TPad::DivideSquare(Int_t n, Float_t xmargin, Float_t ymargin, Int_t color)
1289{
1290 Int_t w = 1, h = 1;
1291 if (!fCanvas) {
1292 Error("DivideSquare", "No canvas associated with this pad.");
1293 return;
1294 }
1298 if (w*h < n) w++;
1299 } else {
1302 if (w*h < n) h++;
1303 }
1304
1305 Divide( w, h, xmargin, ymargin, color);
1306}
1307
1308////////////////////////////////////////////////////////////////////////////////
1309/// Draw Pad in Current pad (re-parent pad if necessary).
1310
1312{
1313 // if no canvas opened yet create a default canvas
1314 if (!gPad) {
1315 gROOT->MakeDefCanvas();
1316 }
1317
1318 // pad cannot be in itself and it can only be in one other pad at a time
1319 if (!fPrimitives) fPrimitives = new TList;
1320 if (gPad != this) {
1323 TPad *oldMother = fMother;
1324 fCanvas = gPad->GetCanvas();
1325 //
1326 fMother = (TPad*)gPad;
1327 if (oldMother != fMother || fPixmapID == -1) ResizePad();
1328 }
1329
1330 if (fCanvas && fCanvas->IsWeb()) {
1331 Modified();
1333 } else {
1334 Paint();
1335 }
1336
1337 if (gPad->IsRetained() && gPad != this && fMother)
1339}
1340
1341////////////////////////////////////////////////////////////////////////////////
1342/// Draw class inheritance tree of the class to which obj belongs.
1343///
1344/// If a class B inherits from a class A, description of B is drawn
1345/// on the right side of description of A.
1346///
1347/// Member functions overridden by B are shown in class A with a blue line
1348/// crossing-out the corresponding member function.
1349
1351{
1352 if (!classobj) return;
1353 char dname[256];
1354 const Int_t kMAXLEVELS = 10;
1355 TClass *clevel[kMAXLEVELS], *cl, *cll;
1356 TBaseClass *base, *cinherit;
1357 TText *ptext = nullptr;
1358 TString opt=option;
1359 Double_t x,y,dy,y1,v1,v2,dv;
1360 Int_t nd,nf,nc,nkd,nkf,i,j;
1361 TPaveText *pt;
1362 Int_t maxlev = 4;
1363 if (opt.Contains("2")) maxlev = 2;
1364 if (opt.Contains("3")) maxlev = 3;
1365 if (opt.Contains("5")) maxlev = 5;
1366 if (opt.Contains("6")) maxlev = 6;
1367 if (opt.Contains("7")) maxlev = 7;
1368
1369 // Clear and Set Pad range
1370 Double_t xpad = 20.5;
1371 Double_t ypad = 27.5;
1372 Clear();
1373 Range(0,0,xpad,ypad);
1374
1375 // Find number of levels
1376 Int_t nlevel = 0;
1377 TClass *obj = (TClass*)classobj;
1378 clevel[nlevel] = obj;
1379 TList *lbase = obj->GetListOfBases();
1380 while(lbase) {
1381 base = (TBaseClass*)lbase->First();
1382 if (!base) break;
1383 if (!base->GetClassPointer()) break;
1384 nlevel++;
1385 clevel[nlevel] = base->GetClassPointer();
1386 lbase = clevel[nlevel]->GetListOfBases();
1387 if (nlevel >= maxlev-1) break;
1388 }
1389 Int_t maxelem = 0;
1390 Int_t ncdraw = 0;
1391 Int_t ilevel, nelem;
1392 for (ilevel=nlevel;ilevel>=0;ilevel--) {
1393 cl = clevel[ilevel];
1394 nelem = cl->GetNdata() + cl->GetNmethods();
1395 if (nelem > maxelem) maxelem = nelem;
1396 nc = (nelem/50) + 1;
1397 ncdraw += nc;
1398 }
1399
1400 Double_t tsizcm = 0.40;
1401 Double_t x1 = 0.25;
1402 Double_t x2 = 0;
1403 Double_t dx = 3.5;
1404 if (ncdraw > 4) {
1405 dx = dx - 0.42*Double_t(ncdraw-5);
1406 if (dx < 1.3) dx = 1.3;
1407 tsizcm = tsizcm - 0.03*Double_t(ncdraw-5);
1408 if (tsizcm < 0.27) tsizcm = 0.27;
1409 }
1410 Double_t tsiz = 1.2*tsizcm/ypad;
1411
1412 // Now loop on levels
1413 for (ilevel=nlevel;ilevel>=0;ilevel--) {
1414 cl = clevel[ilevel];
1415 nelem = cl->GetNdata() + cl->GetNmethods();
1416 if (nelem > maxelem) maxelem = nelem;
1417 nc = (nelem/50) + 1;
1418 dy = 0.45;
1419 if (ilevel < nlevel) x1 = x2 + 0.5;
1420 x2 = x1 + nc*dx;
1421 v2 = ypad - 0.5;
1422 lbase = cl->GetListOfBases();
1423 cinherit = nullptr;
1424 if (lbase) cinherit = (TBaseClass*)lbase->First();
1425
1426 do {
1427 nd = cl->GetNdata();
1428 nf = cl->GetNmethods() - 2; //do not show default constructor and destructor
1429 if (cl->GetListOfMethods()->FindObject("Dictionary")) {
1430 nf -= 6; // do not count the Dictionary/ClassDef functions
1431 }
1432 nkf= nf/nc +1;
1433 nkd= nd/nc +1;
1434 if (nd == 0) nkd=0;
1435 if (nf == 0) nkf=0;
1436 y1 = v2 - 0.7;
1437 v1 = y1 - Double_t(nkf+nkd+nc-1)*dy;
1438 dv = v2 - v1;
1439
1440 // Create a new PaveText
1441 pt = new TPaveText(x1,v1,x2,v2);
1443 pt->SetFillColor(19);
1444 pt->Draw();
1445 pt->SetTextColor(4);
1446 pt->SetTextFont(61);
1447 pt->SetTextAlign(12);
1448 pt->SetTextSize(tsiz);
1449 TBox *box = pt->AddBox(0,(y1+0.01-v1)/dv,0,(v2-0.01-v1)/dv);
1450 if (box) box->SetFillColor(17);
1451 pt->AddLine(0,(y1-v1)/dv,0,(y1-v1)/dv);
1452 TText *title = pt->AddText(0.5,(0.5*(y1+v2)-v1)/dv,(char*)cl->GetName());
1453 title->SetTextAlign(22);
1454 title->SetTextSize(0.6*(v2-y1)/ypad);
1455
1456 // Draw data Members
1457 i = 0;
1458 x = 0.03;
1459 y = y1 + 0.5*dy;
1460 TDataMember *d;
1461 TIter nextd(cl->GetListOfDataMembers());
1462 while ((d = (TDataMember *) nextd())) {
1463 if (i >= nkd) { i = 1; y = y1 - 0.5*dy; x += 1/Double_t(nc); }
1464 else { i++; y -= dy; }
1465
1466 // Take in account the room the array index will occupy
1467
1468 Int_t dim = d->GetArrayDim();
1469 Int_t indx = 0;
1470 snprintf(dname,256,"%s",d->GetName());
1471 Int_t ldname = 0;
1472 while (indx < dim ){
1473 ldname = strlen(dname);
1474 snprintf(&dname[ldname],256-ldname,"[%d]",d->GetMaxIndex(indx));
1475 indx++;
1476 }
1477 pt->AddText(x,(y-v1)/dv,dname);
1478 }
1479
1480 // Draw a separator line
1481 Double_t ysep;
1482 if (nd) {
1483 ysep = y1 - Double_t(nkd)*dy;
1484 pt->AddLine(0,(ysep-v1)/dv,0,(ysep-v1)/dv);
1485 ysep -= 0.5*dy;
1486 } else ysep = y1;
1487
1488 // Draw Member Functions
1489 Int_t fcount = 0;
1490 i = 0;
1491 x = 0.03;
1492 y = ysep + 0.5*dy;
1493 TMethod *m;
1494 TIter nextm(cl->GetListOfMethods());
1495 while ((m = (TMethod *) nextm())) {
1496 if (
1497 !strcmp( m->GetName(), "Dictionary" ) ||
1498 !strcmp( m->GetName(), "Class_Version" ) ||
1499 !strcmp( m->GetName(), "DeclFileName" ) ||
1500 !strcmp( m->GetName(), "DeclFileLine" ) ||
1501 !strcmp( m->GetName(), "ImplFileName" ) ||
1502 !strcmp( m->GetName(), "ImplFileLine" )
1503 ) continue;
1504 fcount++;
1505 if (fcount > nf) break;
1506 if (i >= nkf) { i = 1; y = ysep - 0.5*dy; x += 1/Double_t(nc); }
1507 else { i++; y -= dy; }
1508
1509 ptext = pt->AddText(x,(y-v1)/dv,m->GetName());
1510 // Check if method is overloaded in a derived class
1511 // If yes, Change the color of the text to blue
1512 for (j=ilevel-1;j>=0;j--) {
1513 if (cl == clevel[ilevel]) {
1514 if (clevel[j]->GetMethodAny((char*)m->GetName())) {
1515 ptext->SetTextColor(15);
1516 break;
1517 }
1518 }
1519 }
1520 }
1521
1522 // Draw second inheritance classes for this class
1523 cll = nullptr;
1524 if (cinherit) {
1525 cinherit = (TBaseClass*)lbase->After(cinherit);
1526 if (cinherit) {
1527 cl = cinherit->GetClassPointer();
1528 cll = cl;
1529 v2 = v1 -0.4;
1530 dy = 0.35;
1531 }
1532 }
1533 } while (cll);
1534 }
1535 Update();
1536}
1537
1538////////////////////////////////////////////////////////////////////////////////
1539/// Function called to draw a crosshair in the canvas
1540///
1541/// Example:
1542/// ~~~ {.cpp}
1543/// Root > TFile f("hsimple.root");
1544/// Root > hpxpy.Draw();
1545/// Root > c1.SetCrosshair();
1546/// ~~~
1547/// When moving the mouse in the canvas, a crosshair is drawn
1548///
1549/// - if the canvas fCrosshair = 1 , the crosshair spans the full canvas
1550/// - if the canvas fCrosshair > 1 , the crosshair spans only the pad
1551
1553{
1554 if (!gPad || (gPad->GetEvent() == kMouseEnter)) return;
1555
1556 TPad *cpad = (TPad*)gPad;
1557 TCanvas *canvas = cpad->GetCanvas();
1558 canvas->FeedbackMode(kTRUE);
1559
1560 //erase old position and draw a line at current position
1561 Int_t pxmin,pxmax,pymin,pymax,px,py;
1562#ifndef R__HAS_COCOA
1563 Int_t pxold = fCrosshairPos%10000;
1564 Int_t pyold = fCrosshairPos/10000;
1565#endif // R__HAS_COCOA
1566 px = cpad->GetEventX();
1567 py = cpad->GetEventY()+1;
1568 if (canvas->GetCrosshair() > 1) { //crosshair only in the current pad
1569 pxmin = cpad->XtoAbsPixel(fX1);
1570 pxmax = cpad->XtoAbsPixel(fX2);
1571 pymin = cpad->YtoAbsPixel(fY1);
1572 pymax = cpad->YtoAbsPixel(fY2);
1573 } else { //default; crosshair spans the full canvas
1574 pxmin = 0;
1575 pxmax = canvas->GetWw();
1576 pymin = 0;
1577 pymax = cpad->GetWh();
1578 }
1579#ifndef R__HAS_COCOA
1580 // Not needed, no XOR with Cocoa.
1581 if(pxold) gVirtualX->DrawLine(pxold,pymin,pxold,pymax);
1582 if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
1583#endif // R__HAS_COCOA
1584 if (cpad->GetEvent() == kButton1Down ||
1585 cpad->GetEvent() == kButton1Up ||
1586 cpad->GetEvent() == kMouseLeave) {
1587 fCrosshairPos = 0;
1588 return;
1589 }
1590 gVirtualX->DrawLine(px,pymin,px,pymax);
1591 gVirtualX->DrawLine(pxmin,py,pxmax,py);
1592 fCrosshairPos = px + 10000*py;
1593}
1594
1595////////////////////////////////////////////////////////////////////////////////
1596/// Draw an empty pad frame with X and Y axis.
1597///
1598/// \return The pointer to the histogram used to draw the frame.
1599///
1600/// \param[in] xmin X axis lower limit
1601/// \param[in] xmax X axis upper limit
1602/// \param[in] ymin Y axis lower limit
1603/// \param[in] ymax Y axis upper limit
1604/// \param[in] title Pad title.If title is of the form "stringt;stringx;stringy"
1605/// the pad title is set to stringt, the x axis title to
1606/// stringx, the y axis title to stringy.
1607///
1608/// #### Example:
1609///
1610/// Begin_Macro(source)
1611/// {
1612/// auto c = new TCanvas("c","c",200,10,500,300);
1613///
1614/// const Int_t n = 50;
1615/// auto g = new TGraph();
1616/// for (Int_t i=0;i<n;i++) g->SetPoint(i,i*0.1,100*sin(i*0.1+0.2));
1617///
1618/// auto frame = c->DrawFrame(0, -110, 2, 110);
1619/// frame->GetXaxis()->SetTitle("X axis");
1620///
1621/// g->Draw("L*");
1622/// }
1623/// End_Macro
1624
1626{
1627 if (!IsEditable())
1628 return nullptr;
1629
1630 if (this != gPad) {
1631 Warning("DrawFrame", "Must be called for the current pad only");
1632 if (gPad) return gPad->DrawFrame(xmin,ymin,xmax,ymax,title);
1633 }
1634
1635 cd();
1636
1637 TH1F *hframe = (TH1F*)FindObject("hframe");
1638 if (hframe) delete hframe;
1639 Int_t nbins = 1000;
1640 //if log scale in X, use variable bin size linear with log(x)
1641 //this gives a better precision when zooming on the axis
1642 if (fLogx && xmin > 0 && xmax > xmin) {
1643 Double_t xminl = TMath::Log(xmin);
1644 Double_t xmaxl = TMath::Log(xmax);
1645 Double_t dx = (xmaxl-xminl)/nbins;
1646 std::vector<Double_t> xbins(nbins+1);
1647 xbins[0] = xmin;
1648 for (Int_t i=1;i<=nbins;i++) {
1649 xbins[i] = TMath::Exp(xminl+i*dx);
1650 }
1651 hframe = new TH1F("hframe",title,nbins,xbins.data());
1652 } else {
1653 hframe = new TH1F("hframe",title,nbins,xmin,xmax);
1654 }
1655 hframe->SetBit(TH1::kNoStats);
1656 hframe->SetBit(kCanDelete);
1657 hframe->SetMinimum(ymin);
1658 hframe->SetMaximum(ymax);
1659 hframe->GetYaxis()->SetLimits(ymin,ymax);
1660 hframe->SetDirectory(nullptr);
1661 hframe->Draw(" ");
1662 Update();
1663 cd();
1664 return hframe;
1665}
1666
1667////////////////////////////////////////////////////////////////////////////////
1668/// Static function to Display Color Table in a pad.
1669
1671{
1672 Int_t i, j;
1673 Int_t color;
1674 Double_t xlow, ylow, xup, yup, hs, ws;
1675 Double_t x1, y1, x2, y2;
1676 x1 = y1 = 0;
1677 x2 = y2 = 20;
1678
1679 gPad->SetFillColor(0);
1680 gPad->Clear();
1681 gPad->Range(x1,y1,x2,y2);
1682
1683 TText text(0,0,"");
1684 text.SetTextFont(61);
1685 text.SetTextSize(0.07);
1686 text.SetTextAlign(22);
1687
1688 TBox box;
1689
1690 // Draw color table boxes.
1691 hs = (y2-y1)/Double_t(5);
1692 ws = (x2-x1)/Double_t(10);
1693 for (i=0;i<10;i++) {
1694 xlow = x1 + ws*(Double_t(i)+0.1);
1695 xup = x1 + ws*(Double_t(i)+0.9);
1696 for (j=0;j<5;j++) {
1697 ylow = y1 + hs*(Double_t(j)+0.1);
1698 yup = y1 + hs*(Double_t(j)+0.9);
1699 color = 10*j + i;
1700 box.SetFillStyle(1001);
1701 box.SetFillColor(color);
1702 box.DrawBox(xlow, ylow, xup, yup);
1703 box.SetFillStyle(0);
1704 box.SetLineColor(1);
1705 box.DrawBox(xlow, ylow, xup, yup);
1706 if (color == 1) text.SetTextColor(0);
1707 else text.SetTextColor(1);
1708 text.DrawText(0.5*(xlow+xup), 0.5*(ylow+yup), TString::Format("%d",color).Data());
1709 }
1710 }
1711}
1712
1713////////////////////////////////////////////////////////////////////////////////
1714/// Execute action corresponding to one event.
1715///
1716/// This member function is called when a TPad object is clicked.
1717///
1718/// If the mouse is clicked in one of the 4 corners of the pad (pA,pB,pC,pD)
1719/// the pad is resized with the rubber rectangle.
1720///
1721/// If the mouse is clicked inside the pad, the pad is moved.
1722///
1723/// If the mouse is clicked on the 4 edges (pL,pR,pTop,pBot), the pad is scaled
1724/// parallel to this edge.
1725///
1726/// \image html gpad_pad4.png
1727///
1728/// Note that this function duplicates on purpose the functionality
1729/// already implemented in TBox::ExecuteEvent.
1730/// If somebody modifies this function, may be similar changes should also
1731/// be applied to TBox::ExecuteEvent.
1732
1734{
1735 const Int_t kMaxDiff = 5;
1736 const Int_t kMinSize = 20;
1737 static Int_t pxorg, pyorg;
1738 static Int_t px1, px2, py1, py2, pxl, pyl, pxt, pyt, pxold, pyold;
1739 static Int_t px1p, px2p, py1p, py2p, pxlp, pylp, pxtp, pytp;
1740 static Bool_t pA, pB, pC, pD, pTop, pL, pR, pBot, pINSIDE;
1741 Int_t wx, wy;
1742 Bool_t opaque = OpaqueMoving();
1743 Bool_t ropaque = OpaqueResizing();
1744 Bool_t fixedr = HasFixedAspectRatio();
1745
1746 if (!IsEditable() && event != kMouseEnter) return;
1747 TVirtualPad *parent = GetMother();
1748 if (!parent->IsEditable()) return;
1749
1750 HideToolTip(event);
1751
1752 if (fXlowNDC < 0 && event != kButton1Down) return;
1753 if (fYlowNDC < 0 && event != kButton1Down) return;
1754
1755 // keep old mouse position
1756 if (event == kButton1Down) {
1757 pxorg = px;
1758 pyorg = py;
1759 }
1760
1761 Int_t newcode = gROOT->GetEditorMode();
1762 if (newcode)
1763 pA = pB = pC = pD = pTop = pL = pR = pBot = pINSIDE = kFALSE;
1764 switch (newcode) {
1765 case kPad:
1766 TCreatePrimitives::Pad(event,px,py,0);
1767 break;
1768 case kMarker:
1769 case kText:
1770 TCreatePrimitives::Text(event,px,py,newcode);
1771 break;
1772 case kLine:
1773 TCreatePrimitives::Line(event,px,py,kLine);
1774 break;
1775 case kArrow:
1776 TCreatePrimitives::Line(event,px,py,kArrow);
1777 break;
1778 case kCurlyLine:
1780 break;
1781 case kCurlyArc:
1783 break;
1784 case kPolyLine:
1786 break;
1787 case kCutG:
1789 break;
1790 case kArc:
1791 TCreatePrimitives::Ellipse(event,px,py,kArc);
1792 break;
1793 case kEllipse:
1795 break;
1796 case kButton:
1797 case kPave:
1798 case kPaveLabel:
1799 case kPaveText:
1800 case kPavesText:
1801 case kDiamond:
1802 TCreatePrimitives::Pave(event,px,py,newcode);
1803 return;
1804 default:
1805 break;
1806 }
1807 if (newcode) return;
1808
1809 switch (event) {
1810
1811 case kMouseEnter:
1812 if (fTip)
1814 break;
1815
1816 case kArrowKeyPress:
1817 case kButton1Down:
1818
1821
1822 GetPainter()->SetLineColor(-1);
1823 TAttLine::Modify(); //Change line attributes only if necessary
1824 if (GetFillColor())
1826 else
1829
1830 // No break !!!
1831
1832 case kMouseMotion:
1833
1834 px1 = XtoAbsPixel(fX1);
1835 py1 = YtoAbsPixel(fY1);
1836 px2 = XtoAbsPixel(fX2);
1837 py2 = YtoAbsPixel(fY2);
1838
1839 if (px1 < px2) {
1840 pxl = px1;
1841 pxt = px2;
1842 } else {
1843 pxl = px2;
1844 pxt = px1;
1845 }
1846 if (py1 < py2) {
1847 pyl = py1;
1848 pyt = py2;
1849 } else {
1850 pyl = py2;
1851 pyt = py1;
1852 }
1853
1854 px1p = parent->XtoAbsPixel(parent->GetX1()) + parent->GetBorderSize();
1855 py1p = parent->YtoAbsPixel(parent->GetY1()) - parent->GetBorderSize();
1856 px2p = parent->XtoAbsPixel(parent->GetX2()) - parent->GetBorderSize();
1857 py2p = parent->YtoAbsPixel(parent->GetY2()) + parent->GetBorderSize();
1858
1859 if (px1p < px2p) {
1860 pxlp = px1p;
1861 pxtp = px2p;
1862 } else {
1863 pxlp = px2p;
1864 pxtp = px1p;
1865 }
1866 if (py1p < py2p) {
1867 pylp = py1p;
1868 pytp = py2p;
1869 } else {
1870 pylp = py2p;
1871 pytp = py1p;
1872 }
1873
1874 pA = pB = pC = pD = pTop = pL = pR = pBot = pINSIDE = kFALSE;
1875
1876 // case pA
1877 if (TMath::Abs(px - pxl) <= kMaxDiff && TMath::Abs(py - pyl) <= kMaxDiff) {
1878 pxold = pxl; pyold = pyl; pA = kTRUE;
1880 }
1881 // case pB
1882 if (TMath::Abs(px - pxt) <= kMaxDiff && TMath::Abs(py - pyl) <= kMaxDiff) {
1883 pxold = pxt; pyold = pyl; pB = kTRUE;
1885 }
1886 // case pC
1887 if (TMath::Abs(px - pxt) <= kMaxDiff && TMath::Abs(py - pyt) <= kMaxDiff) {
1888 pxold = pxt; pyold = pyt; pC = kTRUE;
1890 }
1891 // case pD
1892 if (TMath::Abs(px - pxl) <= kMaxDiff && TMath::Abs(py - pyt) <= kMaxDiff) {
1893 pxold = pxl; pyold = pyt; pD = kTRUE;
1895 }
1896
1897 if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
1898 TMath::Abs(py - pyl) < kMaxDiff) { // top edge
1899 pxold = pxl; pyold = pyl; pTop = kTRUE;
1901 }
1902
1903 if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
1904 TMath::Abs(py - pyt) < kMaxDiff) { // bottom edge
1905 pxold = pxt; pyold = pyt; pBot = kTRUE;
1907 }
1908
1909 if ((py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
1910 TMath::Abs(px - pxl) < kMaxDiff) { // left edge
1911 pxold = pxl; pyold = pyl; pL = kTRUE;
1913 }
1914
1915 if ((py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
1916 TMath::Abs(px - pxt) < kMaxDiff) { // right edge
1917 pxold = pxt; pyold = pyt; pR = kTRUE;
1919 }
1920
1921 if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
1922 (py > pyl+kMaxDiff && py < pyt-kMaxDiff)) { // inside box
1923 pxold = px; pyold = py; pINSIDE = kTRUE;
1924 if (event == kButton1Down)
1926 else
1928 }
1929
1930 fResizing = kFALSE;
1931 if (pA || pB || pC || pD || pTop || pL || pR || pBot)
1932 fResizing = kTRUE;
1933
1934 if (!pA && !pB && !pC && !pD && !pTop && !pL && !pR && !pBot && !pINSIDE)
1936
1937 break;
1938
1939 case kArrowKeyRelease:
1940 case kButton1Motion:
1941
1942 if (TestBit(kCannotMove)) break;
1943 wx = wy = 0;
1944
1945 if (pA) {
1946 if (!ropaque) gVirtualX->DrawBox(pxold, pyt, pxt, pyold, TVirtualX::kHollow);
1947 if (px > pxt-kMinSize) { px = pxt-kMinSize; wx = px; }
1948 if (py > pyt-kMinSize) { py = pyt-kMinSize; wy = py; }
1949 if (px < pxlp) { px = pxlp; wx = px; }
1950 if (py < pylp) { py = pylp; wy = py; }
1951 if (fixedr) {
1952 Double_t dy = Double_t(TMath::Abs(pxt-px))/parent->UtoPixel(1.) /
1954 Int_t npy2 = pyt - TMath::Abs(parent->VtoAbsPixel(dy) -
1955 parent->VtoAbsPixel(0));
1956 if (npy2 < pylp) {
1957 px = pxold;
1958 py = pyold;
1959 } else
1960 py = npy2;
1961
1962 wx = wy = 0;
1963 }
1964 if (!ropaque) gVirtualX->DrawBox(px, pyt, pxt, py, TVirtualX::kHollow);
1965 }
1966 if (pB) {
1967 if (!ropaque) gVirtualX->DrawBox(pxl , pyt, pxold, pyold, TVirtualX::kHollow);
1968 if (px < pxl+kMinSize) { px = pxl+kMinSize; wx = px; }
1969 if (py > pyt-kMinSize) { py = pyt-kMinSize; wy = py; }
1970 if (px > pxtp) { px = pxtp; wx = px; }
1971 if (py < pylp) { py = pylp; wy = py; }
1972 if (fixedr) {
1973 Double_t dy = Double_t(TMath::Abs(pxl-px))/parent->UtoPixel(1.) /
1975 Int_t npy2 = pyt - TMath::Abs(parent->VtoAbsPixel(dy) -
1976 parent->VtoAbsPixel(0));
1977 if (npy2 < pylp) {
1978 px = pxold;
1979 py = pyold;
1980 } else
1981 py = npy2;
1982
1983 wx = wy = 0;
1984 }
1985 if (!ropaque) gVirtualX->DrawBox(pxl , pyt, px , py, TVirtualX::kHollow);
1986 }
1987 if (pC) {
1988 if (!ropaque) gVirtualX->DrawBox(pxl , pyl, pxold, pyold, TVirtualX::kHollow);
1989 if (px < pxl+kMinSize) { px = pxl+kMinSize; wx = px; }
1990 if (py < pyl+kMinSize) { py = pyl+kMinSize; wy = py; }
1991 if (px > pxtp) { px = pxtp; wx = px; }
1992 if (py > pytp) { py = pytp; wy = py; }
1993 if (fixedr) {
1994 Double_t dy = Double_t(TMath::Abs(pxl-px))/parent->UtoPixel(1.) /
1996 Int_t npy2 = pyl + TMath::Abs(parent->VtoAbsPixel(dy) -
1997 parent->VtoAbsPixel(0));
1998 if (npy2 > pytp) {
1999 px = pxold;
2000 py = pyold;
2001 } else
2002 py = npy2;
2003
2004 wx = wy = 0;
2005 }
2006 if (!ropaque) gVirtualX->DrawBox(pxl, pyl, px, py, TVirtualX::kHollow);
2007 }
2008 if (pD) {
2009 if (!ropaque) gVirtualX->DrawBox(pxold, pyold, pxt, pyl, TVirtualX::kHollow);
2010 if (px > pxt-kMinSize) { px = pxt-kMinSize; wx = px; }
2011 if (py < pyl+kMinSize) { py = pyl+kMinSize; wy = py; }
2012 if (px < pxlp) { px = pxlp; wx = px; }
2013 if (py > pytp) { py = pytp; wy = py; }
2014 if (fixedr) {
2015 Double_t dy = Double_t(TMath::Abs(pxt-px))/parent->UtoPixel(1.) /
2017 Int_t npy2 = pyl + TMath::Abs(parent->VtoAbsPixel(dy) -
2018 parent->VtoAbsPixel(0));
2019 if (npy2 > pytp) {
2020 px = pxold;
2021 py = pyold;
2022 } else
2023 py = npy2;
2024
2025 wx = wy = 0;
2026 }
2027 if (!ropaque) gVirtualX->DrawBox(px, py, pxt, pyl, TVirtualX::kHollow);
2028 }
2029 if (pTop) {
2030 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2031 py2 += py - pyold;
2032 if (py2 > py1-kMinSize) { py2 = py1-kMinSize; wy = py2; }
2033 if (py2 < py2p) { py2 = py2p; wy = py2; }
2034 if (fixedr) {
2035 Double_t dx = Double_t(TMath::Abs(py2-py1))/parent->VtoPixel(0) *
2037 Int_t npx2 = px1 + parent->UtoPixel(dx);
2038 if (npx2 > px2p)
2039 py2 -= py - pyold;
2040 else
2041 px2 = npx2;
2042 }
2043 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2044 }
2045 if (pBot) {
2046 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2047 py1 += py - pyold;
2048 if (py1 < py2+kMinSize) { py1 = py2+kMinSize; wy = py1; }
2049 if (py1 > py1p) { py1 = py1p; wy = py1; }
2050 if (fixedr) {
2051 Double_t dx = Double_t(TMath::Abs(py2-py1))/parent->VtoPixel(0) *
2053 Int_t npx2 = px1 + parent->UtoPixel(dx);
2054 if (npx2 > px2p)
2055 py1 -= py - pyold;
2056 else
2057 px2 = npx2;
2058 }
2059 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2060 }
2061 if (pL) {
2062 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2063 px1 += px - pxold;
2064 if (px1 > px2-kMinSize) { px1 = px2-kMinSize; wx = px1; }
2065 if (px1 < px1p) { px1 = px1p; wx = px1; }
2066 if (fixedr) {
2067 Double_t dy = Double_t(TMath::Abs(px2-px1))/parent->UtoPixel(1.) /
2069 Int_t npy2 = py1 - TMath::Abs(parent->VtoAbsPixel(dy) -
2070 parent->VtoAbsPixel(0));
2071 if (npy2 < py2p)
2072 px1 -= px - pxold;
2073 else
2074 py2 = npy2;
2075 }
2076 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2077 }
2078 if (pR) {
2079 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2080 px2 += px - pxold;
2081 if (px2 < px1+kMinSize) { px2 = px1+kMinSize; wx = px2; }
2082 if (px2 > px2p) { px2 = px2p; wx = px2; }
2083 if (fixedr) {
2084 Double_t dy = Double_t(TMath::Abs(px2-px1))/parent->UtoPixel(1.) /
2086 Int_t npy2 = py1 - TMath::Abs(parent->VtoAbsPixel(dy) -
2087 parent->VtoAbsPixel(0));
2088 if (npy2 < py2p)
2089 px2 -= px - pxold;
2090 else
2091 py2 = npy2;
2092 }
2093 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
2094 }
2095 if (pINSIDE) {
2096 if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the old box
2097 Int_t dx = px - pxold;
2098 Int_t dy = py - pyold;
2099 px1 += dx; py1 += dy; px2 += dx; py2 += dy;
2100 if (px1 < px1p) { dx = px1p - px1; px1 += dx; px2 += dx; wx = px+dx; }
2101 if (px2 > px2p) { dx = px2 - px2p; px1 -= dx; px2 -= dx; wx = px-dx; }
2102 if (py1 > py1p) { dy = py1 - py1p; py1 -= dy; py2 -= dy; wy = py-dy; }
2103 if (py2 < py2p) { dy = py2p - py2; py1 += dy; py2 += dy; wy = py+dy; }
2104 if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the new box
2105 }
2106
2107 if (wx || wy) {
2108 if (wx) px = wx;
2109 if (wy) py = wy;
2110 gVirtualX->Warp(px, py);
2111 }
2112
2113 pxold = px;
2114 pyold = py;
2115
2116 Double_t x1, y1, x2, y2;
2117 x1 = x2 = y1 = y2 = 0;
2118
2119 if ((!fResizing && opaque) || (fResizing && ropaque)) {
2120 if (pA) {
2121 x1 = AbsPixeltoX(pxold);
2122 y1 = AbsPixeltoY(pyt);
2123 x2 = AbsPixeltoX(pxt);
2124 y2 = AbsPixeltoY(pyold);
2125 }
2126 if (pB) {
2127 x1 = AbsPixeltoX(pxl);
2128 y1 = AbsPixeltoY(pyt);
2129 x2 = AbsPixeltoX(pxold);
2130 y2 = AbsPixeltoY(pyold);
2131 }
2132 if (pC) {
2133 x1 = AbsPixeltoX(pxl);
2134 y1 = AbsPixeltoY(pyold);
2135 x2 = AbsPixeltoX(pxold);
2136 y2 = AbsPixeltoY(pyl);
2137 }
2138 if (pD) {
2139 x1 = AbsPixeltoX(pxold);
2140 y1 = AbsPixeltoY(pyold);
2141 x2 = AbsPixeltoX(pxt);
2142 y2 = AbsPixeltoY(pyl);
2143 }
2144 if (pTop || pBot || pL || pR || pINSIDE) {
2145 x1 = AbsPixeltoX(px1);
2146 y1 = AbsPixeltoY(py1);
2147 x2 = AbsPixeltoX(px2);
2148 y2 = AbsPixeltoY(py2);
2149 }
2150
2151 if (px != pxorg || py != pyorg) {
2152
2153 // Get parent corners pixels coordinates
2154 Int_t parentpx1 = fMother->XtoAbsPixel(parent->GetX1());
2155 Int_t parentpx2 = fMother->XtoAbsPixel(parent->GetX2());
2156 Int_t parentpy1 = fMother->YtoAbsPixel(parent->GetY1());
2157 Int_t parentpy2 = fMother->YtoAbsPixel(parent->GetY2());
2158
2159 // Get pad new corners pixels coordinates
2160 Int_t apx1 = XtoAbsPixel(x1); if (apx1 < parentpx1) {apx1 = parentpx1; }
2161 Int_t apx2 = XtoAbsPixel(x2); if (apx2 > parentpx2) {apx2 = parentpx2; }
2162 Int_t apy1 = YtoAbsPixel(y1); if (apy1 > parentpy1) {apy1 = parentpy1; }
2163 Int_t apy2 = YtoAbsPixel(y2); if (apy2 < parentpy2) {apy2 = parentpy2; }
2164
2165 // Compute new pad positions in the NDC space of parent
2166 fXlowNDC = Double_t(apx1 - parentpx1)/Double_t(parentpx2 - parentpx1);
2167 fYlowNDC = Double_t(apy1 - parentpy1)/Double_t(parentpy2 - parentpy1);
2168 fWNDC = Double_t(apx2 - apx1)/Double_t(parentpx2 - parentpx1);
2169 fHNDC = Double_t(apy2 - apy1)/Double_t(parentpy2 - parentpy1);
2170 }
2171
2172 // Reset pad parameters and recompute conversion coefficients
2173 ResizePad();
2174
2175 if (pINSIDE) gPad->ShowGuidelines(this, event);
2176 if (pTop) gPad->ShowGuidelines(this, event, 't', true);
2177 if (pBot) gPad->ShowGuidelines(this, event, 'b', true);
2178 if (pL) gPad->ShowGuidelines(this, event, 'l', true);
2179 if (pR) gPad->ShowGuidelines(this, event, 'r', true);
2180 if (pA) gPad->ShowGuidelines(this, event, '1', true);
2181 if (pB) gPad->ShowGuidelines(this, event, '2', true);
2182 if (pC) gPad->ShowGuidelines(this, event, '3', true);
2183 if (pD) gPad->ShowGuidelines(this, event, '4', true);
2184
2185 Modified(kTRUE);
2186 }
2187
2188 break;
2189
2190 case kButton1Up:
2191
2192 if (gROOT->IsEscaped()) {
2193 gROOT->SetEscape(kFALSE);
2194 break;
2195 }
2196
2197 if (opaque||ropaque) {
2198 ShowGuidelines(this, event);
2199 } else {
2200 x1 = x2 = y1 = y2 = 0;
2201
2202 if (pA) {
2203 x1 = AbsPixeltoX(pxold);
2204 y1 = AbsPixeltoY(pyt);
2205 x2 = AbsPixeltoX(pxt);
2206 y2 = AbsPixeltoY(pyold);
2207 }
2208 if (pB) {
2209 x1 = AbsPixeltoX(pxl);
2210 y1 = AbsPixeltoY(pyt);
2211 x2 = AbsPixeltoX(pxold);
2212 y2 = AbsPixeltoY(pyold);
2213 }
2214 if (pC) {
2215 x1 = AbsPixeltoX(pxl);
2216 y1 = AbsPixeltoY(pyold);
2217 x2 = AbsPixeltoX(pxold);
2218 y2 = AbsPixeltoY(pyl);
2219 }
2220 if (pD) {
2221 x1 = AbsPixeltoX(pxold);
2222 y1 = AbsPixeltoY(pyold);
2223 x2 = AbsPixeltoX(pxt);
2224 y2 = AbsPixeltoY(pyl);
2225 }
2226 if (pTop || pBot || pL || pR || pINSIDE) {
2227 x1 = AbsPixeltoX(px1);
2228 y1 = AbsPixeltoY(py1);
2229 x2 = AbsPixeltoX(px2);
2230 y2 = AbsPixeltoY(py2);
2231 }
2232
2233 if (pA || pB || pC || pD || pTop || pL || pR || pBot)
2234 Modified(kTRUE);
2235
2236 gVirtualX->SetLineColor(-1);
2237 gVirtualX->SetLineWidth(-1);
2238
2239 if (px != pxorg || py != pyorg) {
2240
2241 // Get parent corners pixels coordinates
2242 Int_t parentpx1 = fMother->XtoAbsPixel(parent->GetX1());
2243 Int_t parentpx2 = fMother->XtoAbsPixel(parent->GetX2());
2244 Int_t parentpy1 = fMother->YtoAbsPixel(parent->GetY1());
2245 Int_t parentpy2 = fMother->YtoAbsPixel(parent->GetY2());
2246
2247 // Get pad new corners pixels coordinates
2248 Int_t apx1 = XtoAbsPixel(x1); if (apx1 < parentpx1) {apx1 = parentpx1; }
2249 Int_t apx2 = XtoAbsPixel(x2); if (apx2 > parentpx2) {apx2 = parentpx2; }
2250 Int_t apy1 = YtoAbsPixel(y1); if (apy1 > parentpy1) {apy1 = parentpy1; }
2251 Int_t apy2 = YtoAbsPixel(y2); if (apy2 < parentpy2) {apy2 = parentpy2; }
2252
2253 // Compute new pad positions in the NDC space of parent
2254 fXlowNDC = Double_t(apx1 - parentpx1)/Double_t(parentpx2 - parentpx1);
2255 fYlowNDC = Double_t(apy1 - parentpy1)/Double_t(parentpy2 - parentpy1);
2256 fWNDC = Double_t(apx2 - apx1)/Double_t(parentpx2 - parentpx1);
2257 fHNDC = Double_t(apy2 - apy1)/Double_t(parentpy2 - parentpy1);
2258 }
2259
2260 // Reset pad parameters and recompute conversion coefficients
2261 ResizePad();
2262
2263
2264 // emit signal
2265 RangeChanged();
2266 }
2267
2268 break;
2269
2270 case kButton1Locate:
2271
2272 ExecuteEvent(kButton1Down, px, py);
2273
2274 while (true) {
2275 px = py = 0;
2276 event = gVirtualX->RequestLocator(1, 1, px, py);
2277
2279
2280 if (event != -1) { // button is released
2281 ExecuteEvent(kButton1Up, px, py);
2282 return;
2283 }
2284 }
2285
2286 case kButton2Down:
2287
2288 Pop();
2289 break;
2290
2291 }
2292}
2293
2294////////////////////////////////////////////////////////////////////////////////
2295/// Execute action corresponding to one event for a TAxis object
2296/// (called by TAxis::ExecuteEvent.)
2297/// This member function is called when an axis is clicked with the locator
2298///
2299/// The axis range is set between the position where the mouse is pressed
2300/// and the position where it is released.
2301///
2302/// If the mouse position is outside the current axis range when it is released
2303/// the axis is unzoomed with the corresponding proportions.
2304///
2305/// Note that the mouse does not need to be in the pad or even canvas
2306/// when it is released.
2307
2309{
2310 if (!IsEditable()) return;
2311 if (!axis) return;
2313
2314 TView *view = GetView();
2315 static Int_t axisNumber;
2316 static Double_t ratio1, ratio2;
2317 static Int_t px1old, py1old, px2old, py2old;
2318 Int_t nbd, inc, bin1, bin2, first, last;
2319 Double_t temp, xmin,xmax;
2320 Bool_t opaque = gPad->OpaqueMoving();
2321 static std::unique_ptr<TBox> zoombox;
2322 Double_t zbx1=0,zbx2=0,zby1=0,zby2=0;
2323
2324 // The CONT4 option, used to paint TH2, is a special case; it uses a 3D
2325 // drawing technique to paint a 2D plot.
2326 TString opt = axis->GetParent()->GetDrawOption();
2327 opt.ToLower();
2328 Bool_t kCont4 = kFALSE;
2329 if (strstr(opt,"cont4")) {
2330 view = nullptr;
2331 kCont4 = kTRUE;
2332 }
2333
2334 switch (event) {
2335
2336 case kButton1Down:
2337 axisNumber = 1;
2338 if (!strcmp(axis->GetName(),"xaxis")) {
2339 axisNumber = 1;
2340 if (!IsVertical()) axisNumber = 2;
2341 }
2342 if (!strcmp(axis->GetName(),"yaxis")) {
2343 axisNumber = 2;
2344 if (!IsVertical()) axisNumber = 1;
2345 }
2346 if (!strcmp(axis->GetName(),"zaxis")) {
2347 axisNumber = 3;
2348 }
2349 if (view) {
2350 view->GetDistancetoAxis(axisNumber, px, py, ratio1);
2351 } else {
2352 if (axisNumber == 1) {
2353 ratio1 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
2354 px1old = XtoAbsPixel(GetUxmin()+ratio1*(GetUxmax() - GetUxmin()));
2355 py1old = YtoAbsPixel(GetUymin());
2356 px2old = px1old;
2357 py2old = YtoAbsPixel(GetUymax());
2358 } else if (axisNumber == 2) {
2359 ratio1 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
2360 py1old = YtoAbsPixel(GetUymin()+ratio1*(GetUymax() - GetUymin()));
2361 px1old = XtoAbsPixel(GetUxmin());
2362 px2old = XtoAbsPixel(GetUxmax());
2363 py2old = py1old;
2364 } else {
2365 ratio1 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
2366 py1old = YtoAbsPixel(GetUymin()+ratio1*(GetUymax() - GetUymin()));
2367 px1old = XtoAbsPixel(GetUxmax());
2368 px2old = XtoAbsPixel(GetX2());
2369 py2old = py1old;
2370 }
2371 if (!opaque) {
2372 gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow);
2373 } else {
2374 if (axisNumber == 1) {
2375 zbx1 = AbsPixeltoX(px1old);
2376 zbx2 = AbsPixeltoX(px2old);
2377 zby1 = GetUymin();
2378 zby2 = GetUymax();
2379 } else if (axisNumber == 2) {
2380 zbx1 = GetUxmin();
2381 zbx2 = GetUxmax();
2382 zby1 = AbsPixeltoY(py1old);
2383 zby2 = AbsPixeltoY(py2old);
2384 }
2385 if (GetLogx()) {
2386 zbx1 = TMath::Power(10,zbx1);
2387 zbx2 = TMath::Power(10,zbx2);
2388 }
2389 if (GetLogy()) {
2390 zby1 = TMath::Power(10,zby1);
2391 zby2 = TMath::Power(10,zby2);
2392 }
2393 zoombox = std::make_unique<TBox>(zbx1, zby1, zbx2, zby2);
2394 Int_t ci = TColor::GetColor("#7d7dff");
2395 TColor *zoomcolor = gROOT->GetColor(ci);
2396 if (!TCanvas::SupportAlpha() || !zoomcolor) zoombox->SetFillStyle(3002);
2397 else zoomcolor->SetAlpha(0.5);
2398 zoombox->SetFillColor(ci);
2399 zoombox->Draw();
2400 gPad->Modified();
2401 gPad->Update();
2402 }
2403 }
2404 if (!opaque) gVirtualX->SetLineColor(-1);
2405 // No break !!!
2406
2407 case kButton1Motion:
2408 if (view) {
2409 view->GetDistancetoAxis(axisNumber, px, py, ratio2);
2410 } else {
2411 if (!opaque) gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow);
2412 if (axisNumber == 1) {
2413 ratio2 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
2414 px2old = XtoAbsPixel(GetUxmin()+ratio2*(GetUxmax() - GetUxmin()));
2415 } else {
2416 ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
2417 py2old = YtoAbsPixel(GetUymin()+ratio2*(GetUymax() - GetUymin()));
2418 }
2419 if (!opaque) {
2420 gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow);
2421 } else {
2422 if (axisNumber == 1) {
2423 zbx1 = AbsPixeltoX(px1old);
2424 zbx2 = AbsPixeltoX(px2old);
2425 zby1 = GetUymin();
2426 zby2 = GetUymax();
2427 } else if (axisNumber == 2) {
2428 zbx1 = GetUxmin();
2429 zbx2 = GetUxmax();
2430 zby1 = AbsPixeltoY(py1old);
2431 zby2 = AbsPixeltoY(py2old);
2432 }
2433 if (GetLogx()) {
2434 zbx1 = TMath::Power(10,zbx1);
2435 zbx2 = TMath::Power(10,zbx2);
2436 }
2437 if (GetLogy()) {
2438 zby1 = TMath::Power(10,zby1);
2439 zby2 = TMath::Power(10,zby2);
2440 }
2441 if (zoombox) {
2442 zoombox->SetX1(zbx1);
2443 zoombox->SetY1(zby1);
2444 zoombox->SetX2(zbx2);
2445 zoombox->SetY2(zby2);
2446 }
2447 gPad->Modified();
2448 gPad->Update();
2449 }
2450 }
2451 break;
2452
2453 case kWheelUp:
2454 nbd = (axis->GetLast()-axis->GetFirst());
2455 inc = TMath::Max(nbd/100,1);
2456 bin1 = axis->GetFirst()+inc;
2457 bin2 = axis->GetLast()-inc;
2458 bin1 = TMath::Max(bin1, 1);
2459 bin2 = TMath::Min(bin2, axis->GetNbins());
2460 if (bin2>bin1) {
2461 axis->SetRange(bin1,bin2);
2462 gPad->Modified();
2463 gPad->Update();
2464 }
2465 break;
2466
2467 case kWheelDown:
2468 nbd = (axis->GetLast()-axis->GetFirst());
2469 inc = TMath::Max(nbd/100,1);
2470 bin1 = axis->GetFirst()-inc;
2471 bin2 = axis->GetLast()+inc;
2472 bin1 = TMath::Max(bin1, 1);
2473 bin2 = TMath::Min(bin2, axis->GetNbins());
2474 if (bin2>bin1) {
2475 axis->SetRange(bin1,bin2);
2476 gPad->Modified();
2477 gPad->Update();
2478 }
2479 break;
2480
2481 case kButton1Up:
2482 if (gROOT->IsEscaped()) {
2483 gROOT->SetEscape(kFALSE);
2484 if (opaque && zoombox)
2485 zoombox.reset();
2486 break;
2487 }
2488
2489 if (view) {
2490 view->GetDistancetoAxis(axisNumber, px, py, ratio2);
2491 if (ratio1 > ratio2) {
2492 temp = ratio1;
2493 ratio1 = ratio2;
2494 ratio2 = temp;
2495 }
2496 if (ratio2 - ratio1 > 0.05) {
2497 TH1 *hobj = (TH1*)axis->GetParent();
2498 if (axisNumber == 3 && hobj && hobj->GetDimension() != 3) {
2499 Float_t zmin = hobj->GetMinimum();
2500 Float_t zmax = hobj->GetMaximum();
2501 if(GetLogz()){
2502 if (zmin <= 0 && zmax > 0) zmin = TMath::Min((Double_t)1,
2503 (Double_t)0.001*zmax);
2504 zmin = TMath::Log10(zmin);
2505 zmax = TMath::Log10(zmax);
2506 }
2507 Float_t newmin = zmin + (zmax-zmin)*ratio1;
2508 Float_t newmax = zmin + (zmax-zmin)*ratio2;
2509 if (newmin < zmin) newmin = hobj->GetBinContent(hobj->GetMinimumBin());
2510 if (newmax > zmax) newmax = hobj->GetBinContent(hobj->GetMaximumBin());
2511 if (GetLogz()){
2512 newmin = TMath::Exp(2.302585092994*newmin);
2513 newmax = TMath::Exp(2.302585092994*newmax);
2514 }
2515 hobj->SetMinimum(newmin);
2516 hobj->SetMaximum(newmax);
2517 hobj->SetBit(TH1::kIsZoomed);
2518 } else {
2519 first = axis->GetFirst();
2520 last = axis->GetLast();
2521 bin1 = first + Int_t((last-first+1)*ratio1);
2522 bin2 = first + Int_t((last-first+1)*ratio2);
2523 bin1 = TMath::Max(bin1, 1);
2524 bin2 = TMath::Min(bin2, axis->GetNbins());
2525 axis->SetRange(bin1, bin2);
2526 }
2527 delete view;
2528 SetView(nullptr);
2529 Modified(kTRUE);
2530 }
2531 } else {
2532 if (axisNumber == 1) {
2533 ratio2 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
2534 xmin = GetUxmin() +ratio1*(GetUxmax() - GetUxmin());
2535 xmax = GetUxmin() +ratio2*(GetUxmax() - GetUxmin());
2536 if (GetLogx() && !kCont4) {
2537 xmin = PadtoX(xmin);
2538 xmax = PadtoX(xmax);
2539 }
2540 } else if (axisNumber == 2) {
2541 ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
2542 xmin = GetUymin() +ratio1*(GetUymax() - GetUymin());
2543 xmax = GetUymin() +ratio2*(GetUymax() - GetUymin());
2544 if (GetLogy() && !kCont4) {
2545 xmin = PadtoY(xmin);
2546 xmax = PadtoY(xmax);
2547 }
2548 } else {
2549 ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
2550 xmin = ratio1;
2551 xmax = ratio2;
2552 }
2553 if (xmin > xmax) {
2554 temp = xmin;
2555 xmin = xmax;
2556 xmax = temp;
2557 temp = ratio1;
2558 ratio1 = ratio2;
2559 ratio2 = temp;
2560 }
2561
2562 // xmin and xmax need to be adjusted in case of CONT4.
2563 if (kCont4) {
2564 Double_t low = axis->GetBinLowEdge(axis->GetFirst());
2565 Double_t up = axis->GetBinUpEdge(axis->GetLast());
2566 Double_t xmi = GetUxmin();
2567 Double_t xma = GetUxmax();
2568 xmin = ((xmin-xmi)/(xma-xmi))*(up-low)+low;
2569 xmax = ((xmax-xmi)/(xma-xmi))*(up-low)+low;
2570 }
2571
2572 if (!strcmp(axis->GetName(),"xaxis")) axisNumber = 1;
2573 if (!strcmp(axis->GetName(),"yaxis")) axisNumber = 2;
2574 if (ratio2 - ratio1 > 0.05) {
2575 //update object owning this axis
2576 TH1 *hobj1 = (TH1*)axis->GetParent();
2577 bin1 = axis->FindFixBin(xmin);
2578 bin2 = axis->FindFixBin(xmax);
2579 bin1 = TMath::Max(bin1, 1);
2580 bin2 = TMath::Min(bin2, axis->GetNbins());
2581 if (axisNumber == 1) axis->SetRange(bin1,bin2);
2582 if (axisNumber == 2 && hobj1) {
2583 if (hobj1->GetDimension() == 1) {
2584 if (hobj1->GetNormFactor() != 0) {
2585 Double_t norm = hobj1->GetSumOfWeights()/hobj1->GetNormFactor();
2586 xmin *= norm;
2587 xmax *= norm;
2588 }
2589 hobj1->SetMinimum(xmin);
2590 hobj1->SetMaximum(xmax);
2591 hobj1->SetBit(TH1::kIsZoomed);
2592 } else {
2593 axis->SetRange(bin1,bin2);
2594 }
2595 }
2596 //update all histograms in the pad
2597 TIter next(GetListOfPrimitives());
2598 TObject *obj;
2599 while ((obj= next())) {
2600 if (!obj->InheritsFrom(TH1::Class())) continue;
2601 TH1 *hobj = (TH1*)obj;
2602 if (hobj == hobj1) continue;
2603 bin1 = hobj->GetXaxis()->FindFixBin(xmin);
2604 bin2 = hobj->GetXaxis()->FindFixBin(xmax);
2605 if (axisNumber == 1) {
2606 hobj->GetXaxis()->SetRange(bin1,bin2);
2607 } else if (axisNumber == 2) {
2608 if (hobj->GetDimension() == 1) {
2609 Double_t xxmin = xmin;
2610 Double_t xxmax = xmax;
2611 if (hobj->GetNormFactor() != 0) {
2612 Double_t norm = hobj->GetSumOfWeights()/hobj->GetNormFactor();
2613 xxmin *= norm;
2614 xxmax *= norm;
2615 }
2616 hobj->SetMinimum(xxmin);
2617 hobj->SetMaximum(xxmax);
2618 hobj->SetBit(TH1::kIsZoomed);
2619 } else {
2620 bin1 = hobj->GetYaxis()->FindFixBin(xmin);
2621 bin2 = hobj->GetYaxis()->FindFixBin(xmax);
2622 hobj->GetYaxis()->SetRange(bin1,bin2);
2623 }
2624 }
2625 }
2626 Modified(kTRUE);
2627 }
2628 }
2629 if (!opaque) {
2630 gVirtualX->SetLineColor(-1);
2631 } else {
2632 if (zoombox) {
2633 zoombox.reset();
2634 gPad->Modified();
2635 gPad->Update();
2636 }
2637 }
2638 break;
2639 }
2640}
2641
2642////////////////////////////////////////////////////////////////////////////////
2643/// Search if object named name is inside this pad or in pads inside this pad.
2644///
2645/// In case name is in several sub-pads the first one is returned.
2646
2647TObject *TPad::FindObject(const char *name) const
2648{
2649 if (!fPrimitives) return nullptr;
2651 if (found) return found;
2652 TIter next(GetListOfPrimitives());
2653 while (auto cur = next()) {
2654 if (cur->InheritsFrom(TPad::Class())) {
2655 found = ((TPad*)cur)->FindObject(name);
2656 if (found) return found;
2657 }
2658 }
2659 return nullptr;
2660}
2661
2662////////////////////////////////////////////////////////////////////////////////
2663/// Search if obj is in pad or in pads inside this pad.
2664///
2665/// In case obj is in several sub-pads the first one is returned.
2666
2668{
2669 if (!fPrimitives) return nullptr;
2670 TObject *found = fPrimitives->FindObject(obj);
2671 if (found) return found;
2672 TIter next(GetListOfPrimitives());
2673 while (auto cur = next()) {
2674 if (cur->InheritsFrom(TPad::Class())) {
2675 found = ((TPad*)cur)->FindObject(obj);
2676 if (found) return found;
2677 }
2678 }
2679 return nullptr;
2680}
2681
2682////////////////////////////////////////////////////////////////////////////////
2683/// Get canvas identifier.
2684
2686{
2687 return fCanvas ? fCanvas->GetCanvasID() : -1;
2688}
2689
2690////////////////////////////////////////////////////////////////////////////////
2691/// Get canvas implementation pointer if any
2692
2694{
2695 return fCanvas ? fCanvas->GetCanvasImp() : nullptr;
2696}
2697
2698////////////////////////////////////////////////////////////////////////////////
2699/// Get Event.
2700
2702{
2703 return fCanvas ? fCanvas->GetEvent() : 0;
2704}
2705
2706////////////////////////////////////////////////////////////////////////////////
2707/// Get X event.
2708
2710{
2711 return fCanvas ? fCanvas->GetEventX() : 0;
2712}
2713
2714////////////////////////////////////////////////////////////////////////////////
2715/// Get Y event.
2716
2718{
2719 return fCanvas ? fCanvas->GetEventY() : 0;
2720}
2721
2722////////////////////////////////////////////////////////////////////////////////
2723/// Get virtual canvas.
2724
2726{
2727 return fCanvas ? (TVirtualPad*) fCanvas : nullptr;
2728}
2729
2730////////////////////////////////////////////////////////////////////////////////
2731/// Get highlight color.
2732
2734{
2735 return fCanvas ? fCanvas->GetHighLightColor() : 0;
2736}
2737
2738////////////////////////////////////////////////////////////////////////////////
2739/// Static function (see also TPad::SetMaxPickDistance)
2740
2742{
2743 return fgMaxPickDistance;
2744}
2745
2746////////////////////////////////////////////////////////////////////////////////
2747/// Get selected.
2748
2750{
2751 if (fCanvas == this) return nullptr;
2752 return fCanvas ? fCanvas->GetSelected() : nullptr;
2753}
2754
2755////////////////////////////////////////////////////////////////////////////////
2756/// Get selected pad.
2757
2759{
2760 if (fCanvas == this) return nullptr;
2761 return fCanvas ? fCanvas->GetSelectedPad() : nullptr;
2762}
2763
2764////////////////////////////////////////////////////////////////////////////////
2765/// Get save pad.
2766
2768{
2769 if (fCanvas == this) return nullptr;
2770 return fCanvas ? fCanvas->GetPadSave() : nullptr;
2771}
2772
2773////////////////////////////////////////////////////////////////////////////////
2774/// Get Wh.
2775
2777{
2778 return fCanvas ? fCanvas->GetWh() : 0;
2779}
2780
2781////////////////////////////////////////////////////////////////////////////////
2782/// Get Ww.
2783
2785{
2786 return fCanvas ? fCanvas->GetWw() : 0;
2787}
2788
2789////////////////////////////////////////////////////////////////////////////////
2790/// Hide tool tip depending on the event type. Typically tool tips
2791/// are hidden when event is not a kMouseEnter and not a kMouseMotion
2792/// event.
2793
2795{
2796 if (event != kMouseEnter && event != kMouseMotion && fTip)
2797 gPad->CloseToolTip(fTip);
2798}
2799
2800////////////////////////////////////////////////////////////////////////////////
2801/// Is pad in batch mode ?
2802
2804{
2805 return fCanvas ? fCanvas->IsBatch() : kFALSE;
2806}
2807
2808////////////////////////////////////////////////////////////////////////////////
2809/// Is pad retained ?
2810
2812{
2813 return fCanvas ? fCanvas->IsRetained() : kFALSE;
2814}
2815
2816////////////////////////////////////////////////////////////////////////////////
2817/// Is web ?
2819{
2820 return fCanvas ? fCanvas->IsWeb() : kFALSE;
2821}
2822
2823////////////////////////////////////////////////////////////////////////////////
2824/// Is pad moving in opaque mode ?
2825
2827{
2828 return fCanvas ? fCanvas->OpaqueMoving() : kFALSE;
2829}
2830
2831////////////////////////////////////////////////////////////////////////////////
2832/// Is pad resizing in opaque mode ?
2833
2835{
2836 return fCanvas ? fCanvas->OpaqueResizing() : kFALSE;
2837}
2838
2839////////////////////////////////////////////////////////////////////////////////
2840/// Set pad in batch mode.
2841
2843{
2844 if (fCanvas) fCanvas->SetBatch(batch);
2845}
2846
2847////////////////////////////////////////////////////////////////////////////////
2848/// Set canvas size.
2849
2851{
2852 if (fCanvas) fCanvas->SetCanvasSize(ww,wh);
2853}
2854
2855////////////////////////////////////////////////////////////////////////////////
2856/// Set cursor type.
2857
2859{
2861}
2862
2863////////////////////////////////////////////////////////////////////////////////
2864/// Set double buffer mode ON or OFF.
2865
2867{
2869}
2870
2871////////////////////////////////////////////////////////////////////////////////
2872/// Set selected.
2873
2875{
2876 if (fCanvas) fCanvas->SetSelected(obj);
2877}
2878
2879////////////////////////////////////////////////////////////////////////////////
2880/// Update pad.
2881
2883{
2884 if (fCanvas) fCanvas->Update();
2885}
2886
2887////////////////////////////////////////////////////////////////////////////////
2888/// Asynchronous pad update.
2889/// In case of web-based canvas triggers update of the canvas on the client side,
2890/// but does not wait that real update is completed. Avoids blocking of caller thread.
2891/// Have to be used if called from other web-based widget to avoid logical dead-locks.
2892/// In case of normal canvas just canvas->Update() is performed.
2893
2895{
2896 if (fCanvas) fCanvas->UpdateAsync();
2897}
2898
2899////////////////////////////////////////////////////////////////////////////////
2900/// Get frame.
2901
2903{
2904 if (!fPrimitives) fPrimitives = new TList;
2906 if (!frame) frame = (TFrame*)GetListOfPrimitives()->FindObject("TFrame");
2907 fFrame = frame;
2908 if (!fFrame) {
2909 if (!frame) fFrame = new TFrame(0,0,1,1);
2910 Int_t framecolor = GetFrameFillColor();
2911 if (!framecolor) framecolor = GetFillColor();
2912 fFrame->SetFillColor(framecolor);
2919 } else {
2920 // Preexisting and now assigned to fFrame, let's make sure it is not
2921 // deleted twice (the bit might have been set in TPad::Streamer)
2923 }
2924 return fFrame;
2925}
2926
2927////////////////////////////////////////////////////////////////////////////////
2928/// Get primitive.
2929
2931{
2932 if (!fPrimitives) return nullptr;
2933 TIter next(fPrimitives);
2934 TObject *found, *obj;
2935 while ((obj=next())) {
2936 if (!strcmp(name, obj->GetName())) return obj;
2937 if (obj->InheritsFrom(TPad::Class())) continue;
2938 found = obj->FindObject(name);
2939 if (found) return found;
2940 }
2941 return nullptr;
2942}
2943
2944////////////////////////////////////////////////////////////////////////////////
2945/// Get a pointer to subpadnumber of this pad.
2946
2947TVirtualPad *TPad::GetPad(Int_t subpadnumber) const
2948{
2949 if (!subpadnumber) {
2950 return (TVirtualPad*)this;
2951 }
2952
2953 TObject *obj;
2954 if (!fPrimitives) return nullptr;
2955 TIter next(GetListOfPrimitives());
2956 while ((obj = next())) {
2957 if (obj->InheritsFrom(TVirtualPad::Class())) {
2958 TVirtualPad *pad = (TVirtualPad*)obj;
2959 if (pad->GetNumber() == subpadnumber) return pad;
2960 }
2961 }
2962 return nullptr;
2963}
2964
2965////////////////////////////////////////////////////////////////////////////////
2966/// Return lower and upper bounds of the pad in NDC coordinates.
2967
2968void TPad::GetPadPar(Double_t &xlow, Double_t &ylow, Double_t &xup, Double_t &yup)
2969{
2970 xlow = fXlowNDC;
2971 ylow = fYlowNDC;
2972 xup = fXlowNDC+fWNDC;
2973 yup = fYlowNDC+fHNDC;
2974}
2975
2976////////////////////////////////////////////////////////////////////////////////
2977/// Return pad world coordinates range.
2978
2980{
2981 x1 = fX1;
2982 y1 = fY1;
2983 x2 = fX2;
2984 y2 = fY2;
2985}
2986
2987////////////////////////////////////////////////////////////////////////////////
2988/// Return pad axis coordinates range.
2989
2991{
2992 xmin = fUxmin;
2993 ymin = fUymin;
2994 xmax = fUxmax;
2995 ymax = fUymax;
2996}
2997
2998////////////////////////////////////////////////////////////////////////////////
2999/// Highlight pad.
3000/// do not highlight when printing on Postscript
3001
3003{
3004 if (gVirtualPS && gVirtualPS->TestBit(kPrintingPS)) return;
3005
3006 if (color <= 0) return;
3007
3009
3010 // We do not want to have active(executable) buttons, etc highlighted
3011 // in this manner, unless we want to edit'em
3013 //When doing a DrawClone from the GUI you would do
3014 // - select an empty pad -
3015 // - right click on object -
3016 // - select DrawClone on menu -
3017 //
3018 // Without the SetSelectedPad(); in the HighLight function, the
3019 // above instruction lead to the clone to be drawn in the
3020 // same canvas as the original object. This is because the
3021 // 'right clicking' (via TCanvas::HandleInput) changes gPad
3022 // momentarily such that when DrawClone is called, it is
3023 // not the right value (for DrawClone). Should be FIXED.
3024 gROOT->SetSelectedPad(this);
3025 if (GetBorderMode()>0) {
3026 if (set) PaintBorder(-color, kFALSE);
3028 }
3029 }
3030
3032}
3033
3034////////////////////////////////////////////////////////////////////////////////
3035/// List all primitives in pad.
3036
3038{
3040 std::cout <<IsA()->GetName()<<" fXlowNDC=" <<fXlowNDC<<" fYlowNDC="<<fYlowNDC<<" fWNDC="<<GetWNDC()<<" fHNDC="<<GetHNDC()
3041 <<" Name= "<<GetName()<<" Title= "<<GetTitle()<<" Option="<<option<<std::endl;
3043 if (!fPrimitives) return;
3046}
3047
3048////////////////////////////////////////////////////////////////////////////////
3049/// Increment (i==1) or set (i>1) the number of autocolor in the pad.
3050
3052{
3053 if (opt.Index("pfc")>=0 || opt.Index("plc")>=0 || opt.Index("pmc")>=0) {
3054 if (i==1) fNumPaletteColor++;
3055 else fNumPaletteColor = i;
3056 return fNumPaletteColor;
3057 } else {
3058 return 0;
3059 }
3060}
3061
3062////////////////////////////////////////////////////////////////////////////////
3063/// Get the next autocolor in the pad.
3064
3066{
3067 Int_t i = 0;
3068 Int_t ncolors = gStyle->GetNumberOfColors();
3069 if (fNumPaletteColor>1) {
3070 i = fNextPaletteColor*(ncolors/(fNumPaletteColor-1));
3071 if (i>=ncolors) i = ncolors-1;
3072 }
3075 return gStyle->GetColorPalette(i);
3076}
3077
3078////////////////////////////////////////////////////////////////////////////////
3079/// Initialise the grid used to find empty space when adding a box (Legend) in a pad
3080
3082{
3083 Int_t const cellSize = 10; // Size of an individual grid cell in pixels.
3084
3085 fCGnx = GetWw()/cellSize;
3086 fCGny = GetWh()/cellSize;
3087
3088 // Initialise the collide grid
3089 fCollideGrid.resize(fCGnx*fCGny);
3090 for (int i = 0; i < fCGnx; i++)
3091 for (int j = 0; j < fCGny; j++)
3092 fCollideGrid[i + j * fCGnx] = kTRUE;
3093
3094 // Fill the collide grid
3095 TIter iter(GetListOfPrimitives());
3096
3097 while(auto o = iter()) {
3098 if (o == oi)
3099 continue;
3100 if (o->InheritsFrom(TFrame::Class()))
3102 else if (o->InheritsFrom(TBox::Class()))
3104 else if (o->InheritsFrom(TH1::Class()))
3106 else if (o->InheritsFrom(TGraph::Class()))
3108 else if (o->InheritsFrom(TMultiGraph::Class())) {
3109 TIter nextgraph(((TMultiGraph *)o)->GetListOfGraphs());
3110 while (auto og = nextgraph())
3112 } else if (o->InheritsFrom(THStack::Class())) {
3113 TIter nexthist(((THStack *)o)->GetHists());
3114 while (auto oh = nexthist()) {
3115 if (oh->InheritsFrom(TH1::Class()))
3117 }
3118 }
3119 }
3120}
3121
3122////////////////////////////////////////////////////////////////////////////////
3123/// Check if a box of size w and h collide some primitives in the pad at
3124/// position i,j
3125
3127{
3128 for (int r = i; r < w + i; r++) {
3129 for (int c = j; c < h + j; c++) {
3130 if (!fCollideGrid[r + c * fCGnx])
3131 return kTRUE;
3132 }
3133 }
3134 return kFALSE;
3135}
3136
3137////////////////////////////////////////////////////////////////////////////////
3138/// Place a box in NDC space
3139///
3140/// \return `true` if the box could be placed, `false` if not.
3141///
3142/// \param[in] o pointer to the box to be placed
3143/// \param[in] w box width to be placed
3144/// \param[in] h box height to be placed
3145/// \param[out] xl x position of the bottom left corner of the placed box
3146/// \param[out] yb y position of the bottom left corner of the placed box
3147/// \param[in] option l=left, r=right, t=top, b=bottom, w=within margins. Order determines
3148/// priority for placement. Default is "lb" (prioritises horizontal over vertical)
3149
3151{
3152 FillCollideGrid(o);
3153
3154 Int_t iw = (int)(fCGnx*w);
3155 Int_t ih = (int)(fCGny*h);
3156
3157 Int_t nxbeg = 0;
3158 Int_t nybeg = 0;
3159 Int_t nxend = fCGnx-iw-1;
3160 Int_t nyend = fCGny-ih-1;
3161 Int_t dx = 1;
3162 Int_t dy = 1;
3163
3164 bool isFirstVertical = false;
3165 bool isFirstHorizontal = false;
3166
3167 for (std::size_t i = 0; option[i] != '\0'; ++i) {
3168 char letter = std::tolower(option[i]);
3169 if (letter == 'w') {
3170 nxbeg += fCGnx*GetLeftMargin();
3171 nybeg += fCGny*GetBottomMargin();
3172 nxend -= fCGnx*GetRightMargin();
3173 nyend -= fCGny*GetTopMargin();
3174 } else if (letter == 't' || letter == 'b') {
3175 isFirstVertical = !isFirstHorizontal;
3176 // go from top to bottom instead of bottom to top
3177 dy = letter == 't' ? -1 : 1;
3178 } else if (letter == 'l' || letter == 'r') {
3179 isFirstHorizontal = !isFirstVertical;
3180 // go from right to left instead of left to right
3181 dx = letter == 'r' ? -1 : 1;
3182 }
3183 }
3184
3185 if(dx < 0) std::swap(nxbeg, nxend);
3186 if(dy < 0) std::swap(nybeg, nyend);
3187
3188 auto attemptPlacement = [&](Int_t i, Int_t j) {
3189 if (Collide(i, j, iw, ih)) {
3190 return false;
3191 } else {
3192 xl = (Double_t)(i) / (Double_t)(fCGnx);
3193 yb = (Double_t)(j) / (Double_t)(fCGny);
3194 return true;
3195 }
3196 };
3197
3198 if(!isFirstVertical) {
3199 for (Int_t i = nxbeg; i != nxend; i += dx) {
3200 for (Int_t j = nybeg; j != nyend; j += dy) {
3201 if (attemptPlacement(i, j)) return true;
3202 }
3203 }
3204 } else {
3205 // prioritizing vertical over horizontal
3206 for (Int_t j = nybeg; j != nyend; j += dy) {
3207 for (Int_t i = nxbeg; i != nxend; i += dx) {
3208 if (attemptPlacement(i, j)) return true;
3209 }
3210 }
3211 }
3212
3213 return kFALSE;
3214}
3215
3216#define NotFree(i, j) fCollideGrid[TMath::Max(TMath::Min(i+j*fCGnx,fCGnx*fCGny),0)] = kFALSE;
3217
3218////////////////////////////////////////////////////////////////////////////////
3219/// Mark as "not free" the cells along a line.
3220
3222{
3223 NotFree(x1, y1);
3224 NotFree(x2, y2);
3225 Int_t i, j, xt, yt;
3226
3227 // horizontal lines
3228 if (y1==y2) {
3229 for (i=x1+1; i<x2; i++) NotFree(i,y1);
3230 return;
3231 }
3232
3233 // vertical lines
3234 if (x1==x2) {
3235 for (i=y1+1; i<y2; i++) NotFree(x1,i);
3236 return;
3237 }
3238
3239 // other lines
3240 if (TMath::Abs(x2-x1)>TMath::Abs(y2-y1)) {
3241 if (x1>x2) {
3242 xt = x1; x1 = x2; x2 = xt;
3243 yt = y1; y1 = y2; y2 = yt;
3244 }
3245 for (i=x1+1; i<x2; i++) {
3246 j = (Int_t)((Double_t)(y2-y1)*(Double_t)((i-x1)/(Double_t)(x2-x1))+y1);
3247 NotFree(i,j);
3248 NotFree(i,(j+1));
3249 }
3250 } else {
3251 if (y1>y2) {
3252 yt = y1; y1 = y2; y2 = yt;
3253 xt = x1; x1 = x2; x2 = xt;
3254 }
3255 for (j=y1+1; j<y2; j++) {
3256 i = (Int_t)((Double_t)(x2-x1)*(Double_t)((j-y1)/(Double_t)(y2-y1))+x1);
3257 NotFree(i,j);
3258 NotFree((i+1),j);
3259 }
3260 }
3261}
3262
3263////////////////////////////////////////////////////////////////////////////////
3265{
3266 TBox *b = (TBox *)o;
3267 if (fCGnx==0||fCGny==0) return;
3268 Double_t xs = (fX2-fX1)/fCGnx;
3269 Double_t ys = (fY2-fY1)/fCGny;
3270
3271 Int_t x1 = (Int_t)((b->GetX1()-fX1)/xs);
3272 Int_t x2 = (Int_t)((b->GetX2()-fX1)/xs);
3273 Int_t y1 = (Int_t)((b->GetY1()-fY1)/ys);
3274 Int_t y2 = (Int_t)((b->GetY2()-fY1)/ys);
3275 for (int i = x1; i<=x2; i++) {
3276 for (int j = y1; j<=y2; j++) NotFree(i, j);
3277 }
3278}
3279
3280////////////////////////////////////////////////////////////////////////////////
3282{
3283 TFrame *f = (TFrame *)o;
3284 if (fCGnx==0||fCGny==0) return;
3285 Double_t xs = (fX2-fX1)/fCGnx;
3286 Double_t ys = (fY2-fY1)/fCGny;
3287
3288 Int_t x1 = (Int_t)((f->GetX1()-fX1)/xs);
3289 Int_t x2 = (Int_t)((f->GetX2()-fX1)/xs);
3290 Int_t y1 = (Int_t)((f->GetY1()-fY1)/ys);
3291 Int_t y2 = (Int_t)((f->GetY2()-fY1)/ys);
3292 Int_t i;
3293
3294 for (i = x1; i<=x2; i++) {
3295 NotFree(i, y1);
3296 NotFree(i, (y1-1));
3297 NotFree(i, (y1-2));
3298 }
3299 for (i = y1; i<=y2; i++) {
3300 NotFree(x1, i);
3301 NotFree((x1-1), i);
3302 NotFree((x1-2), i);
3303 }
3304}
3305
3306////////////////////////////////////////////////////////////////////////////////
3308{
3309 TGraph *g = (TGraph *)o;
3310 if (fCGnx==0||fCGny==0) return;
3311 Double_t xs = (fX2-fX1)/fCGnx;
3312 Double_t ys = (fY2-fY1)/fCGny;
3313
3314 Int_t n = g->GetN();
3315 Int_t s = TMath::Max(n/10,1);
3316 Double_t x1, x2, y1, y2;
3317 for (Int_t i=s; i<n; i=i+s) {
3318 g->GetPoint(TMath::Max(0,i-s),x1,y1);
3319 g->GetPoint(i ,x2,y2);
3320 if (fLogx) {
3321 if (x1 > 0) x1 = TMath::Log10(x1);
3322 else x1 = fUxmin;
3323 if (x2 > 0) x2 = TMath::Log10(x2);
3324 else x2 = fUxmin;
3325 }
3326 if (fLogy) {
3327 if (y1 > 0) y1 = TMath::Log10(y1);
3328 else y1 = fUymin;
3329 if (y2 > 0) y2 = TMath::Log10(y2);
3330 else y2 = fUymin;
3331 }
3332 LineNotFree((int)((x1-fX1)/xs), (int)((x2-fX1)/xs),
3333 (int)((y1-fY1)/ys), (int)((y2-fY1)/ys));
3334 }
3335}
3336
3337////////////////////////////////////////////////////////////////////////////////
3339{
3340 TH1 *h = (TH1 *)o;
3341 if (fCGnx==0||fCGny==0) return;
3342 if (o->InheritsFrom(TH2::Class())) return;
3343 if (o->InheritsFrom(TH3::Class())) return;
3344
3345 TString name = h->GetName();
3346 if (name.Index("hframe") >= 0) return;
3347
3348 Double_t xs = (fX2-fX1)/fCGnx;
3349 Double_t ys = (fY2-fY1)/fCGny;
3350
3351 bool haserrors = false;
3352 TString drawOption = h->GetDrawOption();
3353 drawOption.ToLower();
3354 drawOption.ReplaceAll("same","");
3355
3356 if (drawOption.Index("hist") < 0) {
3357 if (drawOption.Index("e") >= 0) haserrors = true;
3358 }
3359
3360 Int_t nx = h->GetNbinsX();
3361 Int_t x1, y1, y2;
3362 Int_t i, j;
3363 Double_t x1l, y1l, y2l;
3364
3365 for (i = 1; i<nx; i++) {
3366 if (haserrors) {
3367 x1l = h->GetBinCenter(i);
3368 if (fLogx) {
3369 if (x1l > 0) x1l = TMath::Log10(x1l);
3370 else x1l = fUxmin;
3371 }
3372 x1 = (Int_t)((x1l-fX1)/xs);
3373 y1l = h->GetBinContent(i)-h->GetBinErrorLow(i);
3374 if (fLogy) {
3375 if (y1l > 0) y1l = TMath::Log10(y1l);
3376 else y1l = fUymin;
3377 }
3378 y1 = (Int_t)((y1l-fY1)/ys);
3379 y2l = h->GetBinContent(i)+h->GetBinErrorUp(i);
3380 if (fLogy) {
3381 if (y2l > 0) y2l = TMath::Log10(y2l);
3382 else y2l = fUymin;
3383 }
3384 y2 = (Int_t)((y2l-fY1)/ys);
3385 for (j=y1; j<=y2; j++) {
3386 NotFree(x1, j);
3387 }
3388 }
3389 x1l = h->GetBinLowEdge(i);
3390 if (fLogx) {
3391 if (x1l > 0) x1l = TMath::Log10(x1l);
3392 else x1l = fUxmin;
3393 }
3394 x1 = (Int_t)((x1l-fX1)/xs);
3395 y1l = h->GetBinContent(i);
3396 if (fLogy) {
3397 if (y1l > 0) y1l = TMath::Log10(y1l);
3398 else y1l = fUymin;
3399 }
3400 y1 = (Int_t)((y1l-fY1)/ys);
3401 NotFree(x1, y1);
3402 x1l = h->GetBinLowEdge(i)+h->GetBinWidth(i);
3403 if (fLogx) {
3404 if (x1l > 0) x1l = TMath::Log10(x1l);
3405 else x1l = fUxmin;
3406 }
3407 x1 = (int)((x1l-fX1)/xs);
3408 NotFree(x1, y1);
3409 }
3410
3411 // Extra objects in the list of function
3412 TPaveStats *ps = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
3413 if (ps) FillCollideGridTBox(ps);
3414}
3415
3416////////////////////////////////////////////////////////////////////////////////
3417/// This method draws the collide grid on top of the canvas. This is used for
3418/// debugging only. At some point it will be removed.
3419
3421{
3422 if (fCGnx==0||fCGny==0) return;
3423
3424 TContext ctxt(this, kTRUE);
3425
3426 TBox box;
3428
3429 Double_t xs = (fX2-fX1)/fCGnx;
3430 Double_t ys = (fY2-fY1)/fCGny;
3431
3432 Double_t X1L, X2L, Y1L, Y2L;
3433 Double_t t = 0.15;
3434 Double_t Y1, Y2;
3435 Double_t X1 = fX1;
3436 Double_t X2 = X1+xs;
3437
3438 for (int i = 0; i<fCGnx; i++) {
3439 Y1 = fY1;
3440 Y2 = Y1+ys;
3441 for (int j = 0; j<fCGny; j++) {
3442 if (GetLogx()) {
3443 X1L = TMath::Power(10,X1);
3444 X2L = TMath::Power(10,X2);
3445 } else {
3446 X1L = X1;
3447 X2L = X2;
3448 }
3449 if (GetLogy()) {
3450 Y1L = TMath::Power(10,Y1);
3451 Y2L = TMath::Power(10,Y2);
3452 } else {
3453 Y1L = Y1;
3454 Y2L = Y2;
3455 }
3456 if (!fCollideGrid[i + j*fCGnx]) {
3457 box.SetFillColorAlpha(kBlack,t);
3458 box.DrawBox(X1L, Y1L, X2L, Y2L);
3459 } else {
3460 box.SetFillColorAlpha(kRed,t);
3461 box.DrawBox(X1L, Y1L, X2L, Y2L);
3462 }
3463 Y1 = Y2;
3464 Y2 = Y1+ys;
3465 if (t==0.15) t = 0.1;
3466 else t = 0.15;
3467 }
3468 X1 = X2;
3469 X2 = X1+xs;
3470 }
3471}
3472
3473////////////////////////////////////////////////////////////////////////////////
3474/// Short cut to call Modified() and Update() in a single call.
3475/// On Mac with Cocoa, it performs an additional ProcessEvents().
3476
3478{
3479 Modified();
3480 Update();
3481#ifdef R__HAS_COCOA
3483#endif
3484}
3485
3486////////////////////////////////////////////////////////////////////////////////
3487/// Convert x from pad to X.
3488
3490{
3491 if (fLogx && x < 50) return Double_t(TMath::Exp(2.302585092994*x));
3492 return x;
3493}
3494
3495////////////////////////////////////////////////////////////////////////////////
3496/// Convert y from pad to Y.
3497
3499{
3500 if (fLogy && y < 50) return Double_t(TMath::Exp(2.302585092994*y));
3501 return y;
3502}
3503
3504////////////////////////////////////////////////////////////////////////////////
3505/// Convert x from X to pad.
3506
3508{
3509 if (fLogx) {
3510 if (x > 0) x = TMath::Log10(x);
3511 else x = fUxmin;
3512 }
3513 return x;
3514}
3515
3516////////////////////////////////////////////////////////////////////////////////
3517/// Convert y from Y to pad.
3518
3520{
3521 if (fLogy) {
3522 if (y > 0) y = TMath::Log10(y);
3523 else y = fUymin;
3524 }
3525 return y;
3526}
3527
3528////////////////////////////////////////////////////////////////////////////////
3529/// Paint all primitives in pad.
3530
3531void TPad::Paint(Option_t * /*option*/)
3532{
3533 if (!fPrimitives)
3534 fPrimitives = new TList;
3536 fViewer3D->PadPaint(this);
3538 if (GetGLDevice()!=-1 && gVirtualPS) {
3539 TContext ctxt(this, kFALSE);
3540 if (gGLManager) gGLManager->PrintViewer(GetViewer3D());
3541 }
3542 return;
3543 }
3544
3546
3547 Bool_t began3DScene = kFALSE;
3548 fPadPaint = 1;
3549
3550 {
3551 TContext ctxt(this, kTRUE);
3552
3554 PaintDate();
3555
3556 auto lnk = GetListOfPrimitives()->FirstLink();
3557
3558 while (lnk) {
3559 TObject *obj = lnk->GetObject();
3560
3561 // Create a pad 3D viewer if none exists and we encounter a 3D shape
3562 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3563 GetViewer3D("pad");
3564 }
3565
3566 // Open a 3D scene if required
3567 if (fViewer3D && !fViewer3D->BuildingScene()) {
3569 began3DScene = kTRUE;
3570 }
3571
3572 obj->Paint(lnk->GetOption());
3573 lnk = lnk->Next();
3574 }
3575 }
3576
3577 fPadPaint = 0;
3579
3580 // Close the 3D scene if we opened it. This must be done after modified
3581 // flag is cleared, as some viewers will invoke another paint by marking pad modified again
3582 if (began3DScene) {
3584 }
3585}
3586
3587////////////////////////////////////////////////////////////////////////////////
3588/// Paint the pad border.
3589/// Draw first a box as a normal filled box
3590
3592{
3593 if (color >= 0) {
3594 TAttLine::Modify(); //Change line attributes only if necessary
3595 TAttFill::Modify(); //Change fill area attributes only if necessary
3596
3597 //With Cocoa we have a transparency. But we also have
3598 //pixmaps, and if you just paint a new content over the old one
3599 //with alpha < 1., you'll be able to see the old content.
3600 if (!gROOT->IsBatch() && gVirtualX->InheritsFrom("TGCocoa") && GetPainter())
3602
3604 }
3605 if (color < 0) color = -color;
3606 // then paint 3d frame (depending on bordermode)
3607 if (IsTransparent()) return;
3608 // Paint a 3D frame around the pad.
3609
3610 if (fBorderMode == 0) return;
3611 Int_t bordersize = fBorderSize;
3612 if (bordersize <= 0) bordersize = 2;
3613
3614 const Double_t realBsX = bordersize / (GetAbsWNDC() * GetWw()) * (fX2 - fX1);
3615 const Double_t realBsY = bordersize / (GetAbsHNDC() * GetWh()) * (fY2 - fY1);
3616
3617 Short_t px1,py1,px2,py2;
3618 Double_t xl, xt, yl, yt;
3619
3620 // GetDarkColor() and GetLightColor() use GetFillColor()
3621 Color_t oldcolor = GetFillColor();
3622 SetFillColor(color);
3624 Color_t light = 0, dark = 0;
3625 if (color != 0) {
3626 light = TColor::GetColorBright(color);
3627 dark = TColor::GetColorDark(color);
3628 }
3629
3630 // Compute real left bottom & top right of the box in pixels
3631 px1 = XtoPixel(fX1); py1 = YtoPixel(fY1);
3632 px2 = XtoPixel(fX2); py2 = YtoPixel(fY2);
3633 if (px1 < px2) {xl = fX1; xt = fX2; }
3634 else {xl = fX2; xt = fX1;}
3635 if (py1 > py2) {yl = fY1; yt = fY2;}
3636 else {yl = fY2; yt = fY1;}
3637
3638 Double_t frameXs[7] = {}, frameYs[7] = {};
3639
3640 if (!IsBatch() && GetPainter()) {
3641 // Draw top&left part of the box
3642 frameXs[0] = xl; frameYs[0] = yl;
3643 frameXs[1] = xl + realBsX; frameYs[1] = yl + realBsY;
3644 frameXs[2] = frameXs[1]; frameYs[2] = yt - realBsY;
3645 frameXs[3] = xt - realBsX; frameYs[3] = frameYs[2];
3646 frameXs[4] = xt; frameYs[4] = yt;
3647 frameXs[5] = xl; frameYs[5] = yt;
3648 frameXs[6] = xl; frameYs[6] = yl;
3649
3650 if (fBorderMode == -1) GetPainter()->SetFillColor(dark);
3651 else GetPainter()->SetFillColor(light);
3652 GetPainter()->DrawFillArea(7, frameXs, frameYs);
3653
3654 // Draw bottom&right part of the box
3655 frameXs[0] = xl; frameYs[0] = yl;
3656 frameXs[1] = xl + realBsX; frameYs[1] = yl + realBsY;
3657 frameXs[2] = xt - realBsX; frameYs[2] = frameYs[1];
3658 frameXs[3] = frameXs[2]; frameYs[3] = yt - realBsY;
3659 frameXs[4] = xt; frameYs[4] = yt;
3660 frameXs[5] = xt; frameYs[5] = yl;
3661 frameXs[6] = xl; frameYs[6] = yl;
3662
3663 if (fBorderMode == -1) GetPainter()->SetFillColor(light);
3664 else GetPainter()->SetFillColor(dark);
3665 GetPainter()->DrawFillArea(7, frameXs, frameYs);
3666
3667 // If this pad is a button, highlight it
3668 if (InheritsFrom(TButton::Class()) && fBorderMode == -1) {
3669 if (TestBit(kFraming)) { // bit set in TButton::SetFraming
3670 if (GetFillColor() != 2) GetPainter()->SetLineColor(2);
3671 else GetPainter()->SetLineColor(4);
3672 GetPainter()->DrawBox(xl + realBsX, yl + realBsY, xt - realBsX, yt - realBsY, TVirtualPadPainter::kHollow);
3673 }
3674 }
3675 GetPainter()->SetFillColor(-1);
3676 SetFillColor(oldcolor);
3677 }
3678
3679 if (!tops) return;
3680
3681 PaintBorderPS(xl, yl, xt, yt, fBorderMode, bordersize, dark, light);
3682}
3683
3684////////////////////////////////////////////////////////////////////////////////
3685/// Paint a frame border with Postscript.
3686
3688{
3689 if (!gVirtualPS) return;
3690 gVirtualPS->DrawFrame(xl, yl, xt, yt, bmode,bsize,dark,light);
3691}
3692
3693////////////////////////////////////////////////////////////////////////////////
3694/// Paint the current date and time if the option `Date` is set on via `gStyle->SetOptDate()`
3695/// Paint the current file name if the option `File` is set on via `gStyle->SetOptFile()`
3696
3698{
3699 if (fCanvas == this) {
3700 if (gStyle->GetOptDate()) {
3701 TDatime dt;
3702 const char *dates;
3703 char iso[16];
3704 if (gStyle->GetOptDate() < 10) {
3705 //by default use format like "Wed Sep 25 17:10:35 2002"
3706 dates = dt.AsString();
3707 } else if (gStyle->GetOptDate() < 20) {
3708 //use ISO format like 2002-09-25
3709 strlcpy(iso,dt.AsSQLString(),16);
3710 dates = iso;
3711 } else {
3712 //use ISO format like 2002-09-25 17:10:35
3713 dates = dt.AsSQLString();
3714 }
3715 TText tdate(gStyle->GetDateX(),gStyle->GetDateY(),dates);
3721 tdate.SetNDC();
3722 tdate.Paint();
3723 }
3724 if (gStyle->GetOptFile() && gFile) {
3725 TText tfile(1. - gStyle->GetDateX(),gStyle->GetDateY(),gFile->GetName());
3729 tfile.SetTextAlign(31);
3731 tfile.SetNDC();
3732 tfile.Paint();
3733 }
3734 }
3735}
3736
3737////////////////////////////////////////////////////////////////////////////////
3738/// Paint histogram/graph frame.
3739
3741{
3742 if (!fPrimitives) fPrimitives = new TList;
3743 TList *glist = GetListOfPrimitives();
3744 TFrame *frame = GetFrame();
3745 frame->SetX1(xmin);
3746 frame->SetX2(xmax);
3747 frame->SetY1(ymin);
3748 frame->SetY2(ymax);
3749 if (!glist->FindObject(fFrame)) {
3750 glist->AddFirst(frame);
3752 }
3753 frame->Paint();
3754}
3755
3756////////////////////////////////////////////////////////////////////////////////
3757/// Traverse pad hierarchy and (re)paint only modified pads.
3758
3760{
3762 if (IsModified()) {
3763 fViewer3D->PadPaint(this);
3765 }
3766 TList *pList = GetListOfPrimitives();
3767 auto lnk = pList ? pList->FirstLink() : nullptr;
3768 while (lnk) {
3769 auto obj = lnk->GetObject();
3770 if (obj->InheritsFrom(TPad::Class()))
3771 ((TPad*)obj)->PaintModified();
3772 lnk = lnk->Next();
3773 }
3774 return;
3775 }
3776
3778
3779 TVirtualPS *saveps = gVirtualPS;
3780 if (gVirtualPS) {
3782 gVirtualPS = nullptr;
3783 }
3784
3785 Bool_t began3DScene = kFALSE;
3786 fPadPaint = 1;
3787 {
3788 TContext ctxt(this, kTRUE);
3789 if (IsModified() || IsTransparent()) {
3790 if ((fFillStyle < 3026) && (fFillStyle > 3000)) {
3791 if (!gPad->IsBatch() && GetPainter()) GetPainter()->ClearDrawable();
3792 }
3794 }
3795
3796 PaintDate();
3797
3798 TList *pList = GetListOfPrimitives();
3799 auto lnk = pList ? pList->FirstLink() : nullptr;
3800
3801 while (lnk) {
3802 TObject *obj = lnk->GetObject();
3803 if (obj->InheritsFrom(TPad::Class())) {
3804 ((TPad*)obj)->PaintModified();
3805 } else if (IsModified() || IsTransparent()) {
3806
3807 // Create a pad 3D viewer if none exists and we encounter a
3808 // 3D shape
3809 if (!fViewer3D && obj->InheritsFrom(TAtt3D::Class())) {
3810 GetViewer3D("pad");
3811 }
3812
3813 // Open a 3D scene if required
3814 if (fViewer3D && !fViewer3D->BuildingScene()) {
3816 began3DScene = kTRUE;
3817 }
3818
3819 obj->Paint(lnk->GetOption());
3820 }
3821 lnk = lnk->Next();
3822 }
3823 }
3824
3825 fPadPaint = 0;
3827
3828 // This must be done after modified flag is cleared, as some
3829 // viewers will invoke another paint by marking pad modified again
3830 if (began3DScene) {
3832 }
3833
3834 gVirtualPS = saveps;
3835}
3836
3837////////////////////////////////////////////////////////////////////////////////
3838/// Paint box in CurrentPad World coordinates.
3839///
3840/// - if option[0] = 's' the box is forced to be paint with style=0
3841/// - if option[0] = 'l' the box contour is drawn
3842
3844{
3845 if (!gPad->IsBatch() && GetPainter()) {
3846 Int_t style0 = GetPainter()->GetFillStyle();
3847 Int_t style = style0;
3848 if (option[0] == 's') {
3850 style = 0;
3851 }
3852 if (style) {
3853 if (style > 3000 && style < 4000) {
3854 if (style < 3026) {
3855 // draw stipples with fFillColor foreground
3857 }
3858
3859 if (style >= 3100 && style < 4000) {
3860 Double_t xb[4], yb[4];
3861 xb[0] = x1; xb[1] = x1; xb[2] = x2; xb[3] = x2;
3862 yb[0] = y1; yb[1] = y2; yb[2] = y2; yb[3] = y1;
3863 PaintFillAreaHatches(4, xb, yb, style);
3864 return;
3865 }
3866 //special case for TAttFillCanvas
3867 if (GetPainter()->GetFillColor() == 10) {
3870 GetPainter()->SetFillColor(10);
3871 }
3872 } else if (style >= 4000 && style <= 4100) {
3873 // For style >=4000 we make the window transparent.
3874 // From 4000 to 4100 the window is 100% transparent to 100% opaque
3875
3876 //ignore this style option when this is the canvas itself
3877 if (this == fMother) {
3878 //It's clear, that virtual X checks a style (4000) and will render a hollow rect!
3879 const Style_t oldFillStyle = GetPainter()->GetFillStyle();
3880 if (gVirtualX->InheritsFrom("TGCocoa"))
3881 GetPainter()->SetFillStyle(1000);
3883 if (gVirtualX->InheritsFrom("TGCocoa"))
3884 GetPainter()->SetFillStyle(oldFillStyle);
3885 } else {
3886 //draw background by blitting all bottom pads
3887 int px, py;
3888 XYtoAbsPixel(fX1, fY2, px, py);
3889
3890 if (fMother) {
3892 CopyBackgroundPixmaps(fMother, this, px, py);
3893 }
3894
3895 GetPainter()->SetOpacity(style - 4000);
3896 }
3897 } else if (style >= 1000 && style <= 1999) {
3899 } else {
3901 }
3903 } else {
3905 if (option[0] == 's') GetPainter()->SetFillStyle(style0);
3906 }
3907 }
3908
3909 if (gVirtualPS) {
3910 Int_t style0 = gVirtualPS->GetFillStyle();
3911 if (option[0] == 's') {
3913 } else {
3914 if (style0 >= 3100 && style0 < 4000) {
3915 Double_t xb[4], yb[4];
3916 xb[0] = x1; xb[1] = x1; xb[2] = x2; xb[3] = x2;
3917 yb[0] = y1; yb[1] = y2; yb[2] = y2; yb[3] = y1;
3918 PaintFillAreaHatches(4, xb, yb, style0);
3919 return;
3920 }
3921 }
3922 gVirtualPS->DrawBox(x1, y1, x2, y2);
3923 if (option[0] == 'l') {
3925 gVirtualPS->DrawBox(x1, y1, x2, y2);
3926 }
3927 if (option[0] == 's' || option[0] == 'l') gVirtualPS->SetFillStyle(style0);
3928 }
3929
3930 Modified();
3931}
3932
3933////////////////////////////////////////////////////////////////////////////////
3934/// Copy pixmaps of pads laying below pad "stop" into pad "stop". This
3935/// gives the effect of pad "stop" being transparent.
3936
3938{
3939 if (!start) return;
3940 TObject *obj;
3941 if (!fPrimitives) fPrimitives = new TList;
3942 TIter next(start->GetListOfPrimitives());
3943 while ((obj = next())) {
3944 if (obj->InheritsFrom(TPad::Class())) {
3945 if (obj == stop) break;
3946 ((TPad*)obj)->CopyBackgroundPixmap(x, y);
3947 ((TPad*)obj)->CopyBackgroundPixmaps((TPad*)obj, stop, x, y);
3948 }
3949 }
3950}
3951
3952////////////////////////////////////////////////////////////////////////////////
3953/// Copy pixmap of this pad as background of the current pad.
3954
3956{
3957 int px, py;
3958 XYtoAbsPixel(fX1, fY2, px, py);
3959 if (GetPainter()) GetPainter()->CopyDrawable(GetPixmapID(), px-x, py-y);
3960}
3961
3962////////////////////////////////////////////////////////////////////////////////
3963
3965{
3966 Warning("TPad::PaintFillArea", "Float_t signature is obsolete. Use Double_t signature.");
3967}
3968
3969////////////////////////////////////////////////////////////////////////////////
3970/// Paint fill area in CurrentPad World coordinates.
3971
3973{
3974 if (nn <3) return;
3975 Int_t n=0;
3979 } else {
3980 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
3981 }
3982
3983 Int_t nc = 2*nn+1;
3984 std::vector<Double_t> x(nc, 0.);
3985 std::vector<Double_t> y(nc, 0.);
3986
3987 n = ClipPolygon(nn, xx, yy, nc, &x.front(), &y.front(),xmin,ymin,xmax,ymax);
3988 if (!n)
3989 return;
3990
3991 // Paint the fill area with hatches
3992 Int_t fillstyle = GetPainter()?GetPainter()->GetFillStyle():1;
3993 if (gPad->IsBatch() && GetPainter() && gVirtualPS) fillstyle = gVirtualPS->GetFillStyle();
3994 if (fillstyle >= 3100 && fillstyle < 4000) {
3995 PaintFillAreaHatches(nn, &x.front(), &y.front(), fillstyle);
3996 return;
3997 }
3998
3999 if (!gPad->IsBatch() && GetPainter())
4000 // invoke the graphics subsystem
4001 GetPainter()->DrawFillArea(n, &x.front(), &y.front());
4002
4003 if (gVirtualPS)
4004 gVirtualPS->DrawPS(-n, &x.front(), &y.front());
4005
4006 Modified();
4007}
4008
4009////////////////////////////////////////////////////////////////////////////////
4010/// Paint fill area in CurrentPad NDC coordinates.
4011
4013{
4014 std::vector<Double_t> xw(n), yw(n);
4015 for (int i=0; i<n; i++) {
4016 xw[i] = fX1 + x[i]*(fX2 - fX1);
4017 yw[i] = fY1 + y[i]*(fY2 - fY1);
4018 }
4019 PaintFillArea(n, xw.data(), yw.data(), option);
4020}
4021
4022////////////////////////////////////////////////////////////////////////////////
4023/// This function paints hatched fill area according to the FillStyle value
4024/// The convention for the Hatch is the following:
4025///
4026/// `FillStyle = 3ijk`
4027///
4028/// - i (1-9) : specify the space between each hatch
4029/// 1 = minimum 9 = maximum
4030/// the final spacing is i*GetHatchesSpacing(). The hatches spacing
4031/// is set by SetHatchesSpacing()
4032/// - j (0-9) : specify angle between 0 and 90 degrees
4033/// * 0 = 0
4034/// * 1 = 10
4035/// * 2 = 20
4036/// * 3 = 30
4037/// * 4 = 45
4038/// * 5 = Not drawn
4039/// * 6 = 60
4040/// * 7 = 70
4041/// * 8 = 80
4042/// * 9 = 90
4043/// - k (0-9) : specify angle between 90 and 180 degrees
4044/// * 0 = 180
4045/// * 1 = 170
4046/// * 2 = 160
4047/// * 3 = 150
4048/// * 4 = 135
4049/// * 5 = Not drawn
4050/// * 6 = 120
4051/// * 7 = 110
4052/// * 8 = 100
4053/// * 9 = 90
4054
4056{
4057 static Double_t ang1[10] = { 0., 10., 20., 30., 45.,5., 60., 70., 80., 89.99};
4058 static Double_t ang2[10] = {180.,170.,160.,150.,135.,5.,120.,110.,100., 89.99};
4059
4060 Int_t fasi = FillStyle % 1000;
4061 Int_t idSPA = fasi / 100;
4062 Int_t iAng2 = (fasi - 100 * idSPA) / 10;
4063 Int_t iAng1 = fasi % 10;
4064 Double_t dy = 0.003 * idSPA * gStyle->GetHatchesSpacing();
4065 Short_t lws = 0, lws2 = 0, lw = gStyle->GetHatchesLineWidth();
4066 Int_t lss = 0, lss2 = 0, lcs = 0, lcs2 = 0;
4067
4068 // Save the current line attributes and change to draw hatches
4069 if (!gPad->IsBatch() && GetPainter()) {
4070 lws = GetPainter()->GetLineWidth();
4071 lss = GetPainter()->GetLineStyle();
4072 lcs = GetPainter()->GetLineColor();
4074 GetPainter()->SetLineWidth(lw);
4076 }
4077 if (gVirtualPS) {
4078 lws2 = gVirtualPS->GetLineWidth();
4079 lss2 = gVirtualPS->GetLineStyle();
4080 lcs2 = gVirtualPS->GetLineColor();
4084 }
4085
4086 // Draw the hatches
4087 if (ang1[iAng1] != 5.) PaintHatches(dy, ang1[iAng1], nn, xx, yy);
4088 if (ang2[iAng2] != 5.) PaintHatches(dy, ang2[iAng2], nn, xx, yy);
4089
4090 // Restore the line attributes
4091 if (!gPad->IsBatch() && GetPainter()) {
4092 GetPainter()->SetLineStyle(lss);
4093 GetPainter()->SetLineWidth(lws);
4094 GetPainter()->SetLineColor(lcs);
4095 }
4096 if (gVirtualPS) {
4097 gVirtualPS->SetLineStyle(lss2);
4098 gVirtualPS->SetLineWidth(lws2);
4099 gVirtualPS->SetLineColor(lcs2);
4100 }
4101}
4102
4103////////////////////////////////////////////////////////////////////////////////
4104/// This routine draw hatches inclined with the
4105/// angle "angle" and spaced of "dy" in normalized device
4106/// coordinates in the surface defined by n,xx,yy.
4107
4109 Int_t nn, Double_t *xx, Double_t *yy)
4110{
4111 Int_t i, i1, i2, nbi, m, inv;
4112 Double_t ratiox, ratioy, ymin, ymax, yrot, ycur;
4113 const Double_t angr = TMath::Pi()*(180.-angle)/180.;
4114 const Double_t epsil = 0.0001;
4115 const Int_t maxnbi = 100;
4116 Double_t xli[maxnbi], xlh[2], ylh[2], xt1, xt2, yt1, yt2;
4117 Double_t ll, x, y, x1, x2, y1, y2, a, b, xi, xip, xin, yi, yip;
4118
4119 Double_t rwxmin = gPad->GetX1();
4120 Double_t rwxmax = gPad->GetX2();
4121 Double_t rwymin = gPad->GetY1();
4122 Double_t rwymax = gPad->GetY2();
4123 ratiox = 1./(rwxmax-rwxmin);
4124 ratioy = 1./(rwymax-rwymin);
4125
4126 Double_t sina = TMath::Sin(angr), sinb;
4127 Double_t cosa = TMath::Cos(angr), cosb;
4128 if (TMath::Abs(cosa) <= epsil) cosa=0.;
4129 if (TMath::Abs(sina) <= epsil) sina=0.;
4130 sinb = -sina;
4131 cosb = cosa;
4132
4133 // Values needed to compute the hatches in TRUE normalized space (NDC)
4134 Int_t iw = (Int_t)gPad->GetWw();
4135 Int_t ih = (Int_t)gPad->GetWh();
4136 Double_t x1p,y1p,x2p,y2p;
4137 gPad->GetPadPar(x1p,y1p,x2p,y2p);
4138 iw = (Int_t)(iw*x2p)-(Int_t)(iw*x1p);
4139 ih = (Int_t)(ih*y2p)-(Int_t)(ih*y1p);
4140 Double_t wndc = TMath::Min(1.,(Double_t)iw/(Double_t)ih);
4141 Double_t hndc = TMath::Min(1.,(Double_t)ih/(Double_t)iw);
4142
4143 // Search ymin and ymax
4144 ymin = 1.;
4145 ymax = 0.;
4146 for (i=1; i<=nn; i++) {
4147 x = wndc*ratiox*(xx[i-1]-rwxmin);
4148 y = hndc*ratioy*(yy[i-1]-rwymin);
4149 yrot = sina*x+cosa*y;
4150 if (yrot > ymax) ymax = yrot;
4151 if (yrot < ymin) ymin = yrot;
4152 }
4153 ymax = (Double_t)((Int_t)(ymax/dy))*dy;
4154
4155 for (ycur=ymax; ycur>=ymin; ycur=ycur-dy) {
4156 nbi = 0;
4157 for (i=2; i<=nn+1; i++) {
4158 i2 = i;
4159 i1 = i-1;
4160 if (i == nn+1) i2=1;
4161 x1 = wndc*ratiox*(xx[i1-1]-rwxmin);
4162 y1 = hndc*ratioy*(yy[i1-1]-rwymin);
4163 x2 = wndc*ratiox*(xx[i2-1]-rwxmin);
4164 y2 = hndc*ratioy*(yy[i2-1]-rwymin);
4165 xt1 = cosa*x1-sina*y1;
4166 yt1 = sina*x1+cosa*y1;
4167 xt2 = cosa*x2-sina*y2;
4168 yt2 = sina*x2+cosa*y2;
4169
4170 // Line segment parallel to oy
4171 if (xt1 == xt2) {
4172 if (yt1 < yt2) {
4173 yi = yt1;
4174 yip = yt2;
4175 } else {
4176 yi = yt2;
4177 yip = yt1;
4178 }
4179 if ((yi <= ycur) && (ycur < yip)) {
4180 nbi++;
4181 if (nbi >= maxnbi) return;
4182 xli[nbi-1] = xt1;
4183 }
4184 continue;
4185 }
4186
4187 // Line segment parallel to ox
4188 if (yt1 == yt2) {
4189 if (yt1 == ycur) {
4190 nbi++;
4191 if (nbi >= maxnbi) return;
4192 xli[nbi-1] = xt1;
4193 nbi++;
4194 if (nbi >= maxnbi) return;
4195 xli[nbi-1] = xt2;
4196 }
4197 continue;
4198 }
4199
4200 // Other line segment
4201 a = (yt1-yt2)/(xt1-xt2);
4202 b = (yt2*xt1-xt2*yt1)/(xt1-xt2);
4203 if (xt1 < xt2) {
4204 xi = xt1;
4205 xip = xt2;
4206 } else {
4207 xi = xt2;
4208 xip = xt1;
4209 }
4210 xin = (ycur-b)/a;
4211 if ((xi <= xin) && (xin < xip) &&
4212 (TMath::Min(yt1,yt2) <= ycur) &&
4213 (ycur < TMath::Max(yt1,yt2))) {
4214 nbi++;
4215 if (nbi >= maxnbi) return;
4216 xli[nbi-1] = xin;
4217 }
4218 }
4219
4220 // Sorting of the x coordinates intersections
4221 inv = 0;
4222 m = nbi-1;
4223L30:
4224 for (i=1; i<=m; i++) {
4225 if (xli[i] < xli[i-1]) {
4226 inv++;
4227 ll = xli[i-1];
4228 xli[i-1] = xli[i];
4229 xli[i] = ll;
4230 }
4231 }
4232 m--;
4233 if (inv == 0) goto L50;
4234 inv = 0;
4235 goto L30;
4236
4237 // Draw the hatches
4238L50:
4239 if (nbi%2 != 0) continue;
4240
4241 for (i=1; i<=nbi; i=i+2) {
4242 // Rotate back the hatches
4243 xlh[0] = cosb*xli[i-1]-sinb*ycur;
4244 ylh[0] = sinb*xli[i-1]+cosb*ycur;
4245 xlh[1] = cosb*xli[i] -sinb*ycur;
4246 ylh[1] = sinb*xli[i] +cosb*ycur;
4247 // Convert hatches' positions from true NDC to WC
4248 xlh[0] = (xlh[0]/wndc)*(rwxmax-rwxmin)+rwxmin;
4249 ylh[0] = (ylh[0]/hndc)*(rwymax-rwymin)+rwymin;
4250 xlh[1] = (xlh[1]/wndc)*(rwxmax-rwxmin)+rwxmin;
4251 ylh[1] = (ylh[1]/hndc)*(rwymax-rwymin)+rwymin;
4252 gPad->PaintLine(xlh[0], ylh[0], xlh[1], ylh[1]);
4253 }
4254 }
4255}
4256
4257////////////////////////////////////////////////////////////////////////////////
4258/// Paint line in CurrentPad World coordinates.
4259
4261{
4262 Double_t x[2] = {x1, x2}, y[2] = {y1, y2};
4263
4264 //If line is totally clipped, return
4266 if (Clip(x,y,fUxmin,fUymin,fUxmax,fUymax) == 2) return;
4267 } else {
4268 if (Clip(x,y,fX1,fY1,fX2,fY2) == 2) return;
4269 }
4270
4271 if (!gPad->IsBatch() && GetPainter())
4272 GetPainter()->DrawLine(x[0], y[0], x[1], y[1]);
4273
4274 if (gVirtualPS)
4275 gVirtualPS->DrawPS(2, x, y);
4276
4277 Modified();
4278}
4279
4280////////////////////////////////////////////////////////////////////////////////
4281/// Paint line in normalized coordinates.
4282
4284{
4285 static Double_t xw[2], yw[2];
4286 if (!gPad->IsBatch() && GetPainter())
4287 GetPainter()->DrawLineNDC(u1, v1, u2, v2);
4288
4289 if (gVirtualPS) {
4290 xw[0] = fX1 + u1*(fX2 - fX1);
4291 xw[1] = fX1 + u2*(fX2 - fX1);
4292 yw[0] = fY1 + v1*(fY2 - fY1);
4293 yw[1] = fY1 + v2*(fY2 - fY1);
4294 gVirtualPS->DrawPS(2, xw, yw);
4295 }
4296
4297 Modified();
4298}
4299
4300////////////////////////////////////////////////////////////////////////////////
4301/// Paint 3-D line in the CurrentPad.
4302
4304{
4305 if (!fView) return;
4306
4307 // convert from 3-D to 2-D pad coordinate system
4308 Double_t xpad[6];
4309 Double_t temp[3];
4310 Int_t i;
4311 for (i=0;i<3;i++) temp[i] = p1[i];
4312 fView->WCtoNDC(temp, &xpad[0]);
4313 for (i=0;i<3;i++) temp[i] = p2[i];
4314 fView->WCtoNDC(temp, &xpad[3]);
4315 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4316}
4317
4318////////////////////////////////////////////////////////////////////////////////
4319/// Paint 3-D line in the CurrentPad.
4320
4322{
4323 //take into account perspective view
4324 if (!fView) return;
4325 // convert from 3-D to 2-D pad coordinate system
4326 Double_t xpad[6];
4327 Double_t temp[3];
4328 Int_t i;
4329 for (i=0;i<3;i++) temp[i] = p1[i];
4330 fView->WCtoNDC(temp, &xpad[0]);
4331 for (i=0;i<3;i++) temp[i] = p2[i];
4332 fView->WCtoNDC(temp, &xpad[3]);
4333 PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
4334}
4335
4336////////////////////////////////////////////////////////////////////////////////
4337/// Paint polyline in CurrentPad World coordinates.
4338
4340{
4341 if (n < 2) return;
4342
4346 } else {
4347 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4348 }
4349 Int_t i, i1=-1,np=1;
4350 for (i=0; i<n-1; i++) {
4351 Double_t x1=x[i];
4352 Double_t y1=y[i];
4353 Double_t x2=x[i+1];
4354 Double_t y2=y[i+1];
4355 Int_t iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4356 if (iclip == 2) {
4357 i1 = -1;
4358 continue;
4359 }
4360 np++;
4361 if (i1 < 0) i1 = i;
4362 if (iclip == 0 && i < n-2) continue;
4363 if (!gPad->IsBatch() && GetPainter())
4364 GetPainter()->DrawPolyLine(np, &x[i1], &y[i1]);
4365 if (gVirtualPS) {
4366 gVirtualPS->DrawPS(np, &x[i1], &y[i1]);
4367 }
4368 if (iclip) {
4369 x[i] = x1;
4370 y[i] = y1;
4371 x[i+1] = x2;
4372 y[i+1] = y2;
4373 }
4374 i1 = -1;
4375 np = 1;
4376 }
4377
4378 Modified();
4379}
4380
4381////////////////////////////////////////////////////////////////////////////////
4382/// Paint polyline in CurrentPad World coordinates.
4383///
4384/// If option[0] == 'C' no clipping
4385
4387{
4388 if (n < 2) return;
4389
4391 Bool_t mustClip = kTRUE;
4394 } else {
4395 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4396 if (option && (option[0] == 'C')) mustClip = kFALSE;
4397 }
4398
4399 Int_t i, i1=-1, np=1, iclip=0;
4400
4401 for (i=0; i < n-1; i++) {
4402 Double_t x1=x[i];
4403 Double_t y1=y[i];
4404 Double_t x2=x[i+1];
4405 Double_t y2=y[i+1];
4406 if (mustClip) {
4407 iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
4408 if (iclip == 2) {
4409 i1 = -1;
4410 continue;
4411 }
4412 }
4413 np++;
4414 if (i1 < 0) i1 = i;
4415 if (iclip == 0 && i < n-2) continue;
4416 if (!gPad->IsBatch() && GetPainter())
4417 GetPainter()->DrawPolyLine(np, &x[i1], &y[i1]);
4418 if (gVirtualPS) {
4419 gVirtualPS->DrawPS(np, &x[i1], &y[i1]);
4420 }
4421 if (iclip) {
4422 x[i] = x1;
4423 y[i] = y1;
4424 x[i+1] = x2;
4425 y[i+1] = y2;
4426 }
4427 i1 = -1;
4428 np = 1;
4429 }
4430
4431 Modified();
4432}
4433
4434////////////////////////////////////////////////////////////////////////////////
4435/// Paint polyline in CurrentPad NDC coordinates.
4436
4438{
4439 if (n <=0) return;
4440
4441 if (!gPad->IsBatch() && GetPainter())
4443
4444 if (gVirtualPS) {
4445 std::vector<Double_t> xw(n), yw(n);
4446 for (Int_t i=0; i<n; i++) {
4447 xw[i] = fX1 + x[i]*(fX2 - fX1);
4448 yw[i] = fY1 + y[i]*(fY2 - fY1);
4449 }
4450 gVirtualPS->DrawPS(n, xw.data(), yw.data());
4451 }
4452 Modified();
4453}
4454
4455////////////////////////////////////////////////////////////////////////////////
4456/// Paint 3-D polyline in the CurrentPad.
4457
4459{
4460 if (!fView) return;
4461
4462 // Loop on each individual line
4463 for (Int_t i = 1; i < n; i++)
4464 PaintLine3D(&p[3*i-3], &p[3*i]);
4465
4466 Modified();
4467}
4468
4469////////////////////////////////////////////////////////////////////////////////
4470/// Paint polymarker in CurrentPad World coordinates.
4471
4473{
4474 Int_t n = TMath::Abs(nn);
4476 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4478 } else {
4479 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4480 }
4481 Int_t i,i1=-1,np=0;
4482 for (i=0; i<n; i++) {
4483 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4484 np++;
4485 if (i1 < 0) i1 = i;
4486 if (i < n-1) continue;
4487 }
4488 if (np == 0) continue;
4489 if (!gPad->IsBatch() && GetPainter())
4490 GetPainter()->DrawPolyMarker(np, &x[i1], &y[i1]);
4491 if (gVirtualPS) {
4492 gVirtualPS->DrawPolyMarker(np, &x[i1], &y[i1]);
4493 }
4494 i1 = -1;
4495 np = 0;
4496 }
4497 Modified();
4498}
4499
4500////////////////////////////////////////////////////////////////////////////////
4501/// Paint polymarker in CurrentPad World coordinates.
4502
4504{
4505 Int_t n = TMath::Abs(nn);
4507 if (nn > 0 || TestBit(TGraph::kClipFrame)) {
4509 } else {
4510 xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
4511 }
4512 Int_t i,i1=-1,np=0;
4513 for (i=0; i<n; i++) {
4514 if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
4515 np++;
4516 if (i1 < 0) i1 = i;
4517 if (i < n-1) continue;
4518 }
4519 if (np == 0) continue;
4520 if (!gPad->IsBatch() && GetPainter())
4521 GetPainter()->DrawPolyMarker(np, &x[i1], &y[i1]);
4522 if (gVirtualPS) {
4523 gVirtualPS->DrawPolyMarker(np, &x[i1], &y[i1]);
4524 }
4525 i1 = -1;
4526 np = 0;
4527 }
4528 Modified();
4529}
4530
4531////////////////////////////////////////////////////////////////////////////////
4532/// Paint text in CurrentPad World coordinates.
4533
4535{
4536 Modified();
4537
4538 if (!gPad->IsBatch() && GetPainter())
4540
4541 if (gVirtualPS) gVirtualPS->Text(x, y, text);
4542}
4543
4544////////////////////////////////////////////////////////////////////////////////
4545/// Paint text in CurrentPad World coordinates.
4546
4547void TPad::PaintText(Double_t x, Double_t y, const wchar_t *text)
4548{
4549 Modified();
4550
4551 if (!gPad->IsBatch() && GetPainter())
4553
4554 if (gVirtualPS) gVirtualPS->Text(x, y, text);
4555}
4556
4557////////////////////////////////////////////////////////////////////////////////
4558/// Paint text in CurrentPad NDC coordinates.
4559
4561{
4562 Modified();
4563
4564 if (!gPad->IsBatch() && GetPainter())
4566
4567 if (gVirtualPS) {
4568 Double_t x = fX1 + u*(fX2 - fX1);
4569 Double_t y = fY1 + v*(fY2 - fY1);
4570 gVirtualPS->Text(x, y, text);
4571 }
4572}
4573
4574////////////////////////////////////////////////////////////////////////////////
4575/// Paint text in CurrentPad NDC coordinates.
4576
4578{
4579 Modified();
4580
4581 if (!gPad->IsBatch() && GetPainter())
4583
4584 if (gVirtualPS) {
4585 Double_t x = fX1 + u*(fX2 - fX1);
4586 Double_t y = fY1 + v*(fY2 - fY1);
4587 gVirtualPS->Text(x, y, text);
4588 }
4589}
4590
4591////////////////////////////////////////////////////////////////////////////////
4592/// Search for an object at pixel position px,py.
4593///
4594/// Check if point is in this pad.
4595///
4596/// If yes, check if it is in one of the sub-pads
4597///
4598/// If found in the pad, compute closest distance of approach
4599/// to each primitive.
4600///
4601/// If one distance of approach is found to be within the limit Distancemaximum
4602/// the corresponding primitive is selected and the routine returns.
4603
4605{
4606 //the two following statements are necessary under NT (multithreaded)
4607 //when a TCanvas object is being created and a thread calling TPad::Pick
4608 //before the TPad constructor has completed in the other thread
4609 if (!gPad) return nullptr; //Andy Haas
4610 if (!GetListOfPrimitives())