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