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