Logo ROOT  
Reference Guide
TCanvas.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 <fstream>
16
17#include "TROOT.h"
18#include "TBuffer.h"
19#include "TCanvas.h"
20#include "TCanvasImp.h"
21#include "TDatime.h"
22#include "TClass.h"
23#include "TStyle.h"
24#include "TBox.h"
25#include "TCanvasImp.h"
26#include "TDialogCanvas.h"
27#include "TGuiFactory.h"
28#include "TEnv.h"
29#include "TError.h"
30#include "TContextMenu.h"
31#include "TControlBar.h"
32#include "TInterpreter.h"
33#include "TApplication.h"
34#include "TColor.h"
35#include "TObjArray.h"
36#include "TVirtualPadEditor.h"
37#include "TVirtualViewer3D.h"
38#include "TPadPainter.h"
39#include "TVirtualGL.h"
40#include "TVirtualPS.h"
41#include "TVirtualX.h"
42#include "TAxis.h"
43#include "TH1.h"
44#include "TGraph.h"
45#include "TMath.h"
46#include "TView.h"
47#include "strlcpy.h"
48#include "snprintf.h"
49
50#include "TVirtualMutex.h"
51
53public:
56
57//*-*x16 macros/layout_canvas
58
60
62
64
65
67{
68 const char *defcanvas = gROOT->GetDefCanvasName();
69 TString cdef = defcanvas;
70
71 auto lc = (TList*)gROOT->GetListOfCanvases();
72 Int_t n = lc->GetSize() + 1;
73
74 while(lc->FindObject(cdef.Data()))
75 cdef.Form("%s_n%d", defcanvas, n++);
76
77 return cdef;
78}
79
80
81/** \class TCanvas
82\ingroup gpad
83
84The Canvas class.
85
86A Canvas is an area mapped to a window directly under the control of the display
87manager. A ROOT session may have several canvases open at any given time.
88
89A Canvas may be subdivided into independent graphical areas: the __Pads__.
90A canvas has a default pad which has the name of the canvas itself.
91An example of a Canvas layout is sketched in the picture below.
92
93\image html gpad_canvas.png
94
95This canvas contains two pads named P1 and P2. Both Canvas, P1 and P2 can be
96moved, grown, shrunk using the normal rules of the Display manager.
97
98Once objects have been drawn in a canvas, they can be edited/moved by pointing
99directly to them. The cursor shape is changed to suggest the type of action that
100one can do on this object. Clicking with the right mouse button on an object
101pops-up a contextmenu with a complete list of actions possible on this object.
102
103A graphical editor may be started from the canvas "View" menu under the menu
104entry "Toolbar".
105
106An interactive HELP is available by clicking on the HELP button at the top right
107of the canvas. It gives a short explanation about the canvas' menus.
108
109A canvas may be automatically divided into pads via `TPad::Divide`.
110
111At creation time, no matter if in interactive or batch mode, the constructor
112defines the size of the canvas window (including the size of the window
113manager's decoration). To define precisely the graphics area size of a canvas in
114the interactive mode, the following four lines of code should be used:
115~~~ {.cpp}
116 {
117 Double_t w = 600;
118 Double_t h = 600;
119 auto c = new TCanvas("c", "c", w, h);
120 c->SetWindowSize(w + (w - c->GetWw()), h + (h - c->GetWh()));
121 }
122~~~
123and in the batch mode simply do:
124~~~ {.cpp}
125 c->SetCanvasSize(w,h);
126~~~
127
128If the canvas size exceeds the window size, scroll bars will be added to the canvas
129This allows to display very large canvases (even bigger than the screen size). The
130Following example shows how to proceed.
131~~~ {.cpp}
132 {
133 auto c = new TCanvas("c","c");
134 c->SetCanvasSize(1500, 1500);
135 c->SetWindowSize(500, 500);
136 }
137~~~
138*/
139
140////////////////////////////////////////////////////////////////////////////////
141/// Canvas default constructor.
142
143TCanvas::TCanvas(Bool_t build) : TPad(), fDoubleBuffer(0)
144{
145 fPainter = nullptr;
146 fWindowTopX = 0;
147 fWindowTopY = 0;
148 fWindowWidth = 0;
149 fWindowHeight = 0;
150 fCw = 0;
151 fCh = 0;
152 fXsizeUser = 0;
153 fYsizeUser = 0;
156 fHighLightColor = gEnv->GetValue("Canvas.HighLightColor", kRed);
157 fEvent = -1;
158 fEventX = -1;
159 fEventY = -1;
160 fSelectedX = 0;
161 fSelectedY = 0;
163 fDrawn = kFALSE;
164 fSelected = nullptr;
165 fClickSelected = nullptr;
166 fSelectedPad = nullptr;
167 fClickSelectedPad = nullptr;
168 fPadSave = nullptr;
169 fCanvasImp = nullptr;
170 fContextMenu = nullptr;
171
173
174 if (!build || TClass::IsCallingNew() != TClass::kRealNew) {
175 Constructor();
176 } else {
177 TString cdef = GetNewCanvasName();
178
179 Constructor(cdef.Data(), cdef.Data(), 1);
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Canvas default constructor
185
187{
188 if (gThreadXAR) {
189 void *arr[2];
190 arr[1] = this;
191 if ((*gThreadXAR)("CANV", 2, arr, 0)) return;
192 }
193
194 fCanvas = nullptr;
195 fCanvasID = -1;
196 fCanvasImp = nullptr;
197 fBatch = kTRUE;
199
200 fContextMenu = nullptr;
201 fSelected = nullptr;
202 fClickSelected = nullptr;
203 fSelectedPad = nullptr;
204 fClickSelectedPad = nullptr;
205 fPadSave = nullptr;
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Create an embedded canvas, i.e. a canvas that is in a TGCanvas widget
213/// which is placed in a TGFrame. This ctor is only called via the
214/// TRootEmbeddedCanvas class.
215///
216/// If "name" starts with "gl" the canvas is ready to receive GL output.
217
218TCanvas::TCanvas(const char *name, Int_t ww, Int_t wh, Int_t winid) : TPad(), fDoubleBuffer(0)
219{
220 fCanvasImp = nullptr;
221 fPainter = nullptr;
222 Init();
223
224 fCanvasID = winid;
225 fWindowTopX = 0;
226 fWindowTopY = 0;
227 fWindowWidth = ww;
228 fWindowHeight = wh;
229 fCw = ww + 4;
230 fCh = wh +28;
231 fBatch = kFALSE;
233
234 //This is a very special ctor. A window exists already!
235 //Can create painter now.
237
238 if (fUseGL) {
239 fGLDevice = gGLManager->CreateGLContext(winid);
240 if (fGLDevice == -1)
241 fUseGL = kFALSE;
242 }
243
245 if (!fCanvasImp) return;
246
248 SetName(name);
249 Build();
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Create a new canvas with a predefined size form.
254/// If form < 0 the menubar is not shown.
255///
256/// - form = 1 700x500 at 10,10 (set by TStyle::SetCanvasDefH,W,X,Y)
257/// - form = 2 500x500 at 20,20
258/// - form = 3 500x500 at 30,30
259/// - form = 4 500x500 at 40,40
260/// - form = 5 500x500 at 50,50
261///
262/// If "name" starts with "gl" the canvas is ready to receive GL output.
263
264TCanvas::TCanvas(const char *name, const char *title, Int_t form) : TPad(), fDoubleBuffer(0)
265{
266 fPainter = nullptr;
268
269 Constructor(name, title, form);
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Create a new canvas with a predefined size form.
274/// If form < 0 the menubar is not shown.
275///
276/// - form = 1 700x500 at 10,10 (set by TStyle::SetCanvasDefH,W,X,Y)
277/// - form = 2 500x500 at 20,20
278/// - form = 3 500x500 at 30,30
279/// - form = 4 500x500 at 40,40
280/// - form = 5 500x500 at 50,50
281
282void TCanvas::Constructor(const char *name, const char *title, Int_t form)
283{
284 if (gThreadXAR) {
285 void *arr[6];
286 static Int_t ww = 500;
287 static Int_t wh = 500;
288 arr[1] = this; arr[2] = (void*)name; arr[3] = (void*)title; arr[4] =&ww; arr[5] = &wh;
289 if ((*gThreadXAR)("CANV", 6, arr, 0)) return;
290 }
291
292 Init();
293 SetBit(kMenuBar,1);
294 if (form < 0) {
295 form = -form;
296 SetBit(kMenuBar,0);
297 }
298
299 fCanvas = this;
300
301 fCanvasID = -1;
302 TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
303 if (old && old->IsOnHeap()) {
304 Warning("Constructor","Deleting canvas with same name: %s",name);
305 delete old;
306 }
307 if (gROOT->IsBatch()) { //We are in Batch mode
309 if (form == 1) {
312 } else {
313 fWindowWidth = 500;
314 fWindowHeight = 500;
315 }
319 if (!fCanvasImp) return;
320 fBatch = kTRUE;
321 } else { //normal mode with a screen window
323 if (form < 1 || form > 5) form = 1;
324 if (form == 1) {
325 UInt_t uh = UInt_t(cx*gStyle->GetCanvasDefH());
326 UInt_t uw = UInt_t(cx*gStyle->GetCanvasDefW());
327 Int_t ux = Int_t(cx*gStyle->GetCanvasDefX());
328 Int_t uy = Int_t(cx*gStyle->GetCanvasDefY());
329 fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, ux, uy, uw, uh);
330 }
331 fCw = 500;
332 fCh = 500;
333 if (form == 2) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 20, 20, UInt_t(cx*500), UInt_t(cx*500));
334 if (form == 3) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 30, 30, UInt_t(cx*500), UInt_t(cx*500));
335 if (form == 4) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 40, 40, UInt_t(cx*500), UInt_t(cx*500));
336 if (form == 5) fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, 50, 50, UInt_t(cx*500), UInt_t(cx*500));
337 if (!fCanvasImp) return;
338
339 if (!gROOT->IsBatch() && fCanvasID == -1)
341
343 fBatch = kFALSE;
344 }
345
347
348 SetName(name);
349 SetTitle(title); // requires fCanvasImp set
350 Build();
351
352 // Popup canvas
353 fCanvasImp->Show();
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// Create a new canvas at a random position.
358///
359/// \param[in] name canvas name
360/// \param[in] title canvas title
361/// \param[in] ww is the window size in pixels along X
362/// (if ww < 0 the menubar is not shown)
363/// \param[in] wh is the window size in pixels along Y
364///
365/// If "name" starts with "gl" the canvas is ready to receive GL output.
366
367TCanvas::TCanvas(const char *name, const char *title, Int_t ww, Int_t wh) : TPad(), fDoubleBuffer(0)
368{
369 fPainter = nullptr;
371
372 Constructor(name, title, ww, wh);
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// Create a new canvas at a random position.
377///
378/// \param[in] name canvas name
379/// \param[in] title canvas title
380/// \param[in] ww is the window size in pixels along X
381/// (if ww < 0 the menubar is not shown)
382/// \param[in] wh is the window size in pixels along Y
383
384void TCanvas::Constructor(const char *name, const char *title, Int_t ww, Int_t wh)
385{
386 if (gThreadXAR) {
387 void *arr[6];
388 arr[1] = this; arr[2] = (void*)name; arr[3] = (void*)title; arr[4] =&ww; arr[5] = &wh;
389 if ((*gThreadXAR)("CANV", 6, arr, 0)) return;
390 }
391
392 Init();
393 SetBit(kMenuBar,1);
394 if (ww < 0) {
395 ww = -ww;
396 SetBit(kMenuBar,0);
397 }
398 if (wh <= 0) {
399 Error("Constructor", "Invalid canvas height: %d",wh);
400 return;
401 }
402 fCw = ww;
403 fCh = wh;
404 fCanvasID = -1;
405 TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
406 if (old && old->IsOnHeap()) {
407 Warning("Constructor","Deleting canvas with same name: %s",name);
408 delete old;
409 }
410 if (gROOT->IsBatch()) { //We are in Batch mode
412 fWindowWidth = ww;
413 fWindowHeight = wh;
414 fCw = ww;
415 fCh = wh;
417 if (!fCanvasImp) return;
418 fBatch = kTRUE;
419 } else {
421 fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, UInt_t(cx*ww), UInt_t(cx*wh));
422 if (!fCanvasImp) return;
423
424 if (!gROOT->IsBatch() && fCanvasID == -1)
426
428 fBatch = kFALSE;
429 }
430
432
433 SetName(name);
434 SetTitle(title); // requires fCanvasImp set
435 Build();
436
437 // Popup canvas
438 fCanvasImp->Show();
439}
440
441////////////////////////////////////////////////////////////////////////////////
442/// Create a new canvas.
443///
444/// \param[in] name canvas name
445/// \param[in] title canvas title
446/// \param[in] wtopx,wtopy are the pixel coordinates of the top left corner of
447/// the canvas (if wtopx < 0) the menubar is not shown)
448/// \param[in] ww is the window size in pixels along X
449/// \param[in] wh is the window size in pixels along Y
450///
451/// If "name" starts with "gl" the canvas is ready to receive GL output.
452
453TCanvas::TCanvas(const char *name, const char *title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh)
454 : TPad(), fDoubleBuffer(0)
455{
456 fPainter = nullptr;
458
459 Constructor(name, title, wtopx, wtopy, ww, wh);
460}
461
462////////////////////////////////////////////////////////////////////////////////
463/// Create a new canvas.
464///
465/// \param[in] name canvas name
466/// \param[in] title canvas title
467/// \param[in] wtopx,wtopy are the pixel coordinates of the top left corner of
468/// the canvas (if wtopx < 0) the menubar is not shown)
469/// \param[in] ww is the window size in pixels along X
470/// \param[in] wh is the window size in pixels along Y
471
472void TCanvas::Constructor(const char *name, const char *title, Int_t wtopx,
473 Int_t wtopy, Int_t ww, Int_t wh)
474{
475 if (gThreadXAR) {
476 void *arr[8];
477 arr[1] = this; arr[2] = (void*)name; arr[3] = (void*)title;
478 arr[4] = &wtopx; arr[5] = &wtopy; arr[6] = &ww; arr[7] = &wh;
479 if ((*gThreadXAR)("CANV", 8, arr, 0)) return;
480 }
481
482 Init();
483 SetBit(kMenuBar,1);
484 if (wtopx < 0) {
485 wtopx = -wtopx;
486 SetBit(kMenuBar,0);
487 }
488 fCw = ww;
489 fCh = wh;
490 fCanvasID = -1;
491 TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
492 if (old && old->IsOnHeap()) {
493 Warning("Constructor","Deleting canvas with same name: %s",name);
494 delete old;
495 }
496 if (gROOT->IsBatch()) { //We are in Batch mode
498 fWindowWidth = ww;
499 fWindowHeight = wh;
500 fCw = ww;
501 fCh = wh;
503 if (!fCanvasImp) return;
504 fBatch = kTRUE;
505 } else { //normal mode with a screen window
507 fCanvasImp = gGuiFactory->CreateCanvasImp(this, name, Int_t(cx*wtopx), Int_t(cx*wtopy), UInt_t(cx*ww), UInt_t(cx*wh));
508 if (!fCanvasImp) return;
509
510 if (!gROOT->IsBatch() && fCanvasID == -1)
512
514 fBatch = kFALSE;
515 }
516
518
519 SetName(name);
520 SetTitle(title); // requires fCanvasImp set
521 Build();
522
523 // Popup canvas
524 fCanvasImp->Show();
525}
526
527////////////////////////////////////////////////////////////////////////////////
528/// Initialize the TCanvas members. Called by all constructors.
529
531{
532 // Make sure the application environment exists. It is need for graphics
533 // (colors are initialized in the TApplication ctor).
534 if (!gApplication)
536
537 // Load and initialize graphics libraries if
538 // TApplication::NeedGraphicsLibs() has been called by a
539 // library static initializer.
540 if (gApplication)
542
543 // Get some default from .rootrc. Used in fCanvasImp->InitWindow().
544 fHighLightColor = gEnv->GetValue("Canvas.HighLightColor", kRed);
545 SetBit(kMoveOpaque, gEnv->GetValue("Canvas.MoveOpaque", 0));
546 SetBit(kResizeOpaque, gEnv->GetValue("Canvas.ResizeOpaque", 0));
547 if (gEnv->GetValue("Canvas.ShowEventStatus", kFALSE)) SetBit(kShowEventStatus);
548 if (gEnv->GetValue("Canvas.ShowToolTips", kFALSE)) SetBit(kShowToolTips);
549 if (gEnv->GetValue("Canvas.ShowToolBar", kFALSE)) SetBit(kShowToolBar);
550 if (gEnv->GetValue("Canvas.ShowEditor", kFALSE)) SetBit(kShowEditor);
551 if (gEnv->GetValue("Canvas.AutoExec", kTRUE)) SetBit(kAutoExec);
552
553 // Fill canvas ROOT data structure
554 fXsizeUser = 0;
555 fYsizeUser = 0;
558
559 fDISPLAY = "$DISPLAY";
562 fSelected = nullptr;
563 fClickSelected = nullptr;
564 fSelectedX = 0;
565 fSelectedY = 0;
566 fSelectedPad = nullptr;
567 fClickSelectedPad= nullptr;
568 fPadSave = nullptr;
569 fEvent = -1;
570 fEventX = -1;
571 fEventY = -1;
572 fContextMenu = nullptr;
573 fDrawn = kFALSE;
574}
575
576////////////////////////////////////////////////////////////////////////////////
577/// Build a canvas. Called by all constructors.
578
580{
581 // Get window identifier
582 if (fCanvasID == -1 && fCanvasImp)
584 if (fCanvasID == -1) return;
585
586 if (fCw !=0 && fCh !=0) {
589 }
590
591 // Set Pad parameters
592 gPad = this;
593 fCanvas = this;
594 fMother = (TPad*)gPad;
595
596 if (IsBatch()) {
597 // Make sure that batch interactive canvas sizes are the same
598 fCw -= 4;
599 fCh -= 28;
600 } else if (IsWeb()) {
601 // mark canvas as batch - avoid virtualx in many places
603 } else {
604 //normal mode with a screen window
605 // Set default physical canvas attributes
606 //Should be done via gVirtualX, not via fPainter (at least now). No changes here.
607 gVirtualX->SelectWindow(fCanvasID);
608 gVirtualX->SetFillColor(1); //Set color index for fill area
609 gVirtualX->SetLineColor(1); //Set color index for lines
610 gVirtualX->SetMarkerColor(1); //Set color index for markers
611 gVirtualX->SetTextColor(1); //Set color index for text
612 // Clear workstation
613 gVirtualX->ClearWindow();
614
615 // Set Double Buffer on by default
617
618 // Get effective window parameters (with borders and menubar)
621
622 // Get effective canvas parameters without borders
623 Int_t dum1, dum2;
624 gVirtualX->GetGeometry(fCanvasID, dum1, dum2, fCw, fCh);
625
626 fContextMenu = new TContextMenu("ContextMenu");
627 }
628
629 gROOT->GetListOfCanvases()->Add(this);
630
631 if (!fPrimitives) {
632 fPrimitives = new TList;
634 SetFillStyle(1001);
646 fBorderMode=gStyle->GetCanvasBorderMode(); // do not call SetBorderMode (function redefined in TCanvas)
647 SetPad(0, 0, 1, 1);
648 Range(0, 0, 1, 1); //pad range is set by default to [0,1] in x and y
649
651 if (vpp) vpp->SelectDrawable(fPixmapID);//gVirtualX->SelectPixmap(fPixmapID); //pixmap must be selected
652 PaintBorder(GetFillColor(), kTRUE); //paint background
653 }
654
655 // transient canvases have typically no menubar and should not get
656 // by default the event status bar (if set by default)
657 if (TestBit(kMenuBar) && fCanvasImp) {
659 // ... and toolbar + editor
663 }
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Canvas destructor
668
670{
671 Destructor();
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Browse.
676
678{
679 Draw();
680 cd();
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Actual canvas destructor.
686
688{
689 if (gThreadXAR) {
690 void *arr[2];
691 arr[1] = this;
692 if ((*gThreadXAR)("CDEL", 2, arr, 0)) return;
693 }
694
695 if (ROOT::Detail::HasBeenDeleted(this)) return;
696
698 if (!gPad) return;
699
700 Close();
701
702 //If not yet (batch mode?).
704}
705
706////////////////////////////////////////////////////////////////////////////////
707/// Set current canvas & pad. Returns the new current pad,
708/// or 0 in case of failure.
709/// See TPad::cd() for an explanation of the parameter.
710
712{
713 if (fCanvasID == -1) return nullptr;
714
715 TPad::cd(subpadnumber);
716
717 // in case doublebuffer is off, draw directly onto display window
718 if (!IsBatch()) {
719 if (!fDoubleBuffer)
720 gVirtualX->SelectWindow(fCanvasID);//Ok, does not matter for glpad.
721 }
722 return gPad;
723}
724
725////////////////////////////////////////////////////////////////////////////////
726/// Remove all primitives from the canvas.
727/// If option "D" is specified, direct sub-pads are cleared but not deleted.
728/// This option is not recursive, i.e. pads in direct sub-pads are deleted.
729
731{
732 if (fCanvasID == -1) return;
733
735
736 TString opt = option;
737 opt.ToLower();
738 if (opt.Contains("d")) {
739 // clear subpads, but do not delete pads in case the canvas
740 // has been divided (note: option "D" is propagated so could cause
741 // conflicts for primitives using option "D" for something else)
742 if (fPrimitives) {
743 TIter next(fPrimitives);
744 TObject *obj;
745 while ((obj=next())) {
746 obj->Clear(option);
747 }
748 }
749 } else {
750 //default, clear everything in the canvas. Subpads are deleted
751 TPad::Clear(option); //Remove primitives from pad
752 }
753
754 fSelected = nullptr;
755 fClickSelected = nullptr;
756 fSelectedPad = nullptr;
757 fClickSelectedPad = nullptr;
758}
759
760////////////////////////////////////////////////////////////////////////////////
761/// Emit pad Cleared signal.
762
764{
765 Emit("Cleared(TVirtualPad*)", (Longptr_t)pad);
766}
767
768////////////////////////////////////////////////////////////////////////////////
769/// Emit Closed signal.
770
772{
773 Emit("Closed()");
774}
775
776////////////////////////////////////////////////////////////////////////////////
777/// Close canvas.
778///
779/// Delete window/pads data structure
780
782{
783 TPad *padsave = (TPad*)gPad;
784 TCanvas *cansave = nullptr;
785 if (padsave) cansave = (TCanvas*)gPad->GetCanvas();
786
787 if (fCanvasID != -1) {
788
789 if ((!gROOT->IsLineProcessing()) && (!gVirtualX->IsCmdThread())) {
790 gInterpreter->Execute(this, IsA(), "Close", option);
791 return;
792 }
793
795
797
798 cd();
800
801 if (!IsBatch()) {
802 gVirtualX->SelectWindow(fCanvasID); //select current canvas
803
805
806 if (fCanvasImp)
807 fCanvasImp->Close();
808 }
809 fCanvasID = -1;
810 fBatch = kTRUE;
811
812 gROOT->GetListOfCanvases()->Remove(this);
813
814 // Close actual window on screen
816 }
817
818 if (cansave == this) {
819 gPad = (TCanvas *) gROOT->GetListOfCanvases()->First();
820 } else {
821 gPad = padsave;
822 }
823
824 Closed();
825}
826
827////////////////////////////////////////////////////////////////////////////////
828/// Copy the canvas pixmap of the pad to the canvas.
829
831{
832 if (!IsBatch()) {
833 CopyPixmap();
835 }
836}
837
838////////////////////////////////////////////////////////////////////////////////
839/// Draw a canvas.
840/// If a canvas with the name is already on the screen, the canvas is repainted.
841/// This function is useful when a canvas object has been saved in a Root file.
842/// One can then do:
843/// ~~~ {.cpp}
844/// Root > Tfile f("file.root");
845/// Root > canvas.Draw();
846/// ~~~
847
849{
850 // Load and initialize graphics libraries if
851 // TApplication::NeedGraphicsLibs() has been called by a
852 // library static initializer.
853 if (gApplication)
855
856 fDrawn = kTRUE;
857
858 TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(GetName());
859 if (old == this) {
860 Paint();
861 return;
862 }
863 if (old) { gROOT->GetListOfCanvases()->Remove(old); delete old;}
864
865 if (fWindowWidth == 0) {
866 if (fCw !=0) fWindowWidth = fCw+4;
867 else fWindowWidth = 800;
868 }
869 if (fWindowHeight == 0) {
870 if (fCh !=0) fWindowHeight = fCh+28;
871 else fWindowHeight = 600;
872 }
873 if (gROOT->IsBatch()) { //We are in Batch mode
875 if (!fCanvasImp) return;
876 fBatch = kTRUE;
877
878 } else { //normal mode with a screen window
881 if (!fCanvasImp) return;
883 }
884 Build();
885 ResizePad();
887 fCanvasImp->Show();
888 Modified();
889}
890
891////////////////////////////////////////////////////////////////////////////////
892/// Draw a clone of this canvas
893/// A new canvas is created that is a clone of this canvas
894
896{
897 TCanvas *newCanvas = (TCanvas*)Clone();
898 newCanvas->SetName();
899
900 newCanvas->Draw(option);
901 newCanvas->Update();
902 return newCanvas;
903}
904
905////////////////////////////////////////////////////////////////////////////////
906/// Draw a clone of this canvas into the current pad
907/// In an interactive session, select the destination/current pad
908/// with the middle mouse button, then point to the canvas area to select
909/// the canvas context menu item DrawClonePad.
910/// Note that the original canvas may have subpads.
911
913{
914 TPad *padsav = (TPad*)gPad;
915 TPad *selpad = (TPad*)gROOT->GetSelectedPad();
916 TPad *pad = padsav;
917 if (pad == this) pad = selpad;
918 if (!padsav || !pad || pad == this) {
919 TCanvas *newCanvas = (TCanvas*)DrawClone();
921 return newCanvas;
922 }
923 if (fCanvasID == -1) {
926 if (!fCanvasImp) return nullptr;
929 }
930 this->cd();
931 //copy pad attributes
932 pad->Range(fX1,fY1,fX2,fY2);
933 pad->SetTickx(GetTickx());
934 pad->SetTicky(GetTicky());
935 pad->SetGridx(GetGridx());
936 pad->SetGridy(GetGridy());
937 pad->SetLogx(GetLogx());
938 pad->SetLogy(GetLogy());
939 pad->SetLogz(GetLogz());
942 TAttLine::Copy((TAttLine&)*pad);
943 TAttFill::Copy((TAttFill&)*pad);
944 TAttPad::Copy((TAttPad&)*pad);
945
946 //copy primitives
948 while (auto obj=next()) {
949 pad->cd();
950 auto clone = obj->Clone();
951 pad->GetListOfPrimitives()->Add(clone,next.GetOption());
952 }
953 pad->ResizePad();
954 pad->Modified();
955 pad->Update();
956 if (padsav) padsav->cd();
957 return nullptr;
958}
959
960////////////////////////////////////////////////////////////////////////////////
961/// Report name and title of primitive below the cursor.
962///
963/// This function is called when the option "Event Status"
964/// in the canvas menu "Options" is selected.
965
967{
968 const Int_t kTMAX=256;
969 static char atext[kTMAX];
970
971 if (!TestBit(kShowEventStatus) || !selected) return;
972
973 if (!fCanvasImp) return; //this may happen when closing a TAttCanvas
974
975 TVirtualPad* savepad;
976 savepad = gPad;
978
979 fCanvasImp->SetStatusText(selected->GetTitle(),0);
980 fCanvasImp->SetStatusText(selected->GetName(),1);
981 if (event == kKeyPress)
982 snprintf(atext, kTMAX, "%c", (char) px);
983 else
984 snprintf(atext, kTMAX, "%d,%d", px, py);
985 fCanvasImp->SetStatusText(atext,2);
986
987 // Show date/time if TimeDisplay is selected
988 TAxis *xaxis = NULL;
989 if ( selected->InheritsFrom("TH1") )
990 xaxis = ((TH1*)selected)->GetXaxis();
991 else if ( selected->InheritsFrom("TGraph") )
992 xaxis = ((TGraph*)selected)->GetXaxis();
993 else if ( selected->InheritsFrom("TAxis") )
994 xaxis = (TAxis*)selected;
995 if ( xaxis != NULL && xaxis->GetTimeDisplay()) {
996 TString objinfo = selected->GetObjectInfo(px,py);
997 // check if user has overwritten GetObjectInfo and altered
998 // the default text from TObject::GetObjectInfo "x=.. y=.."
999 if (objinfo.Contains("x=") && objinfo.Contains("y=") ) {
1000 UInt_t toff = 0;
1001 TString time_format(xaxis->GetTimeFormat());
1002 // TimeFormat may contain offset: %F2000-01-01 00:00:00
1003 Int_t idF = time_format.Index("%F");
1004 if (idF>=0) {
1005 Int_t lnF = time_format.Length();
1006 // minimal check for correct format
1007 if (lnF - idF == 21) {
1008 time_format = time_format(idF+2, lnF);
1009 TDatime dtoff(time_format);
1010 toff = dtoff.Convert();
1011 }
1012 } else {
1013 toff = (UInt_t)gStyle->GetTimeOffset();
1014 }
1015 TDatime dt((UInt_t)gPad->AbsPixeltoX(px) + toff);
1016 snprintf(atext, kTMAX, "%s, y=%g",
1017 dt.AsSQLString(),gPad->AbsPixeltoY(py));
1018 fCanvasImp->SetStatusText(atext,3);
1019 gPad = savepad;
1020 return;
1021 }
1022 }
1023 // default
1024 fCanvasImp->SetStatusText(selected->GetObjectInfo(px,py),3);
1025
1026 gPad = savepad;
1027}
1028
1029////////////////////////////////////////////////////////////////////////////////
1030/// Get editor bar.
1031
1033{
1035}
1036
1037////////////////////////////////////////////////////////////////////////////////
1038/// Embedded a canvas into a TRootEmbeddedCanvas. This method is only called
1039/// via TRootEmbeddedCanvas::AdoptCanvas.
1040
1042{
1043 // If fCanvasImp already exists, no need to go further.
1044 if(fCanvasImp) return;
1045
1046 fCanvasID = winid;
1047 fWindowTopX = 0;
1048 fWindowTopY = 0;
1049 fWindowWidth = ww;
1050 fWindowHeight = wh;
1051 fCw = ww;
1052 fCh = wh;
1053 fBatch = kFALSE;
1054 fUpdating = kFALSE;
1055
1057 if (!fCanvasImp) return;
1058 Build();
1059 Resize();
1060}
1061
1062////////////////////////////////////////////////////////////////////////////////
1063/// Generate kMouseEnter and kMouseLeave events depending on the previously
1064/// selected object and the currently selected object. Does nothing if the
1065/// selected object does not change.
1066
1067void TCanvas::EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
1068{
1069 if (prevSelObj == fSelected) return;
1070
1071 TPad *padsav = (TPad *)gPad;
1072 Int_t sevent = fEvent;
1073
1074 if (prevSelObj) {
1075 gPad = prevSelPad;
1076 prevSelObj->ExecuteEvent(kMouseLeave, fEventX, fEventY);
1078 RunAutoExec();
1079 ProcessedEvent(kMouseLeave, fEventX, fEventY, prevSelObj); // emit signal
1080 }
1081
1083
1084 if (fSelected) {
1087 RunAutoExec();
1089 }
1090
1091 fEvent = sevent;
1092 gPad = padsav;
1093}
1094
1095////////////////////////////////////////////////////////////////////////////////
1096/// Execute action corresponding to one event.
1097///
1098/// This member function must be implemented to realize the action
1099/// corresponding to the mouse click on the object in the canvas
1100///
1101/// Only handle mouse motion events in TCanvas, all other events are
1102/// ignored for the time being
1103
1105{
1106 if (gROOT->GetEditorMode()) {
1108 return;
1109 }
1110
1111 switch (event) {
1112
1113 case kMouseMotion:
1115 break;
1116 }
1117}
1118
1119////////////////////////////////////////////////////////////////////////////////
1120/// Turn rubberband feedback mode on or off.
1121
1123{
1124 if (set) {
1125 SetDoubleBuffer(0); // turn off double buffer mode
1126 gVirtualX->SetDrawMode(TVirtualX::kInvert); // set the drawing mode to XOR mode
1127 } else {
1128 SetDoubleBuffer(1); // turn on double buffer mode
1129 gVirtualX->SetDrawMode(TVirtualX::kCopy); // set drawing mode back to normal (copy) mode
1130 }
1131}
1132
1133////////////////////////////////////////////////////////////////////////////////
1134/// Flush canvas buffers.
1135
1137{
1138 if ((fCanvasID == -1) || IsWeb()) return;
1139
1140 TPad *padsav = (TPad*)gPad;
1141 cd();
1142 if (!IsBatch()) {
1143 if (!UseGL() || fGLDevice == -1) {
1144 gVirtualX->SelectWindow(fCanvasID);
1145 gPad = padsav; //don't do cd() because than also the pixmap is changed
1146 CopyPixmaps();
1147 gVirtualX->UpdateWindow(1);
1148 } else {
1149 TVirtualPS *tvps = gVirtualPS;
1150 gVirtualPS = nullptr;
1151 gGLManager->MakeCurrent(fGLDevice);
1153 Paint();
1154 if (padsav && padsav->GetCanvas() == this) {
1155 padsav->cd();
1156 padsav->HighLight(padsav->GetHighLightColor());
1157 //cd();
1158 }
1160 gGLManager->Flush(fGLDevice);
1161 gVirtualPS = tvps;
1162 }
1163 }
1164 if (padsav) padsav->cd();
1165}
1166
1167////////////////////////////////////////////////////////////////////////////////
1168/// Force canvas update
1169
1171{
1173}
1174
1175////////////////////////////////////////////////////////////////////////////////
1176/// Force a copy of current style for all objects in canvas.
1177
1179{
1180 if ((!gROOT->IsLineProcessing()) && (!gVirtualX->IsCmdThread())) {
1181 gInterpreter->Execute(this, IsA(), "UseCurrentStyle", "");
1182 return;
1183 }
1184
1186
1188
1189 if (gStyle->IsReading()) {
1193 } else {
1197 }
1198}
1199
1200////////////////////////////////////////////////////////////////////////////////
1201/// Returns current top x position of window on screen.
1202
1204{
1207
1208 return fWindowTopX;
1209}
1210
1211////////////////////////////////////////////////////////////////////////////////
1212/// Returns current top y position of window on screen.
1213
1215{
1218
1219 return fWindowTopY;
1220}
1221
1222////////////////////////////////////////////////////////////////////////////////
1223/// Handle Input Events.
1224///
1225/// Handle input events, like button up/down in current canvas.
1226
1228{
1229 TPad *pad;
1230 TPad *prevSelPad = (TPad*) fSelectedPad;
1231 TObject *prevSelObj = fSelected;
1232
1233 fPadSave = (TPad*)gPad;
1234 cd(); // make sure this canvas is the current canvas
1235
1236 fEvent = event;
1237 fEventX = px;
1238 fEventY = py;
1239
1240 switch (event) {
1241
1242 case kMouseMotion:
1243 // highlight object tracked over
1244 pad = Pick(px, py, prevSelObj);
1245 if (!pad) return;
1246
1247 EnterLeave(prevSelPad, prevSelObj);
1248
1249 gPad = pad; // don't use cd() we will use the current
1250 // canvas via the GetCanvas member and not via
1251 // gPad->GetCanvas
1252
1253 if (fSelected) {
1254 fSelected->ExecuteEvent(event, px, py);
1255 RunAutoExec();
1256 }
1257
1258 break;
1259
1260 case kMouseEnter:
1261 // mouse enters canvas
1263 break;
1264
1265 case kMouseLeave:
1266 // mouse leaves canvas
1267 {
1268 // force popdown of tooltips
1269 TObject *sobj = fSelected;
1270 TPad *spad = fSelectedPad;
1271 fSelected = nullptr;
1272 fSelectedPad = nullptr;
1273 EnterLeave(prevSelPad, prevSelObj);
1274 fSelected = sobj;
1275 fSelectedPad = spad;
1277 }
1278 break;
1279
1280 case kButton1Double:
1281 // triggered on the second button down within 350ms and within
1282 // 3x3 pixels of the first button down, button up finishes action
1283
1284 case kButton1Down:
1285 // find pad in which input occurred
1286 pad = Pick(px, py, prevSelObj);
1287 if (!pad) return;
1288
1289 gPad = pad; // don't use cd() because we won't draw in pad
1290 // we will only use its coordinate system
1291
1292 if (fSelected) {
1293 FeedbackMode(kTRUE); // to draw in rubberband mode
1294 fSelected->ExecuteEvent(event, px, py);
1295
1296 RunAutoExec();
1297 }
1298
1299 break;
1300
1301 case kArrowKeyPress:
1302 case kArrowKeyRelease:
1303 case kButton1Motion:
1304 case kButton1ShiftMotion: //8 == kButton1Motion + shift modifier
1305 if (fSelected) {
1307
1308 fSelected->ExecuteEvent(event, px, py);
1309 gVirtualX->Update();
1311 Bool_t resize = kFALSE;
1313 resize = ((TBox*)fSelected)->IsBeingResized();
1315 resize = ((TVirtualPad*)fSelected)->IsBeingResized();
1316
1317 if ((!resize && TestBit(kMoveOpaque)) || (resize && TestBit(kResizeOpaque))) {
1318 gPad = fPadSave;
1319 Update();
1321 }
1322 }
1323
1324 RunAutoExec();
1325 }
1326
1327 break;
1328
1329 case kButton1Up:
1330
1331 if (fSelected) {
1333
1334 fSelected->ExecuteEvent(event, px, py);
1335
1336 RunAutoExec();
1337
1338 if (fPadSave)
1339 gPad = fPadSave;
1340 else {
1341 gPad = this;
1342 fPadSave = this;
1343 }
1344
1345 Update(); // before calling update make sure gPad is reset
1346 }
1347 break;
1348
1349//*-*----------------------------------------------------------------------
1350
1351 case kButton2Down:
1352 // find pad in which input occurred
1353 pad = Pick(px, py, prevSelObj);
1354 if (!pad) return;
1355
1356 gPad = pad; // don't use cd() because we won't draw in pad
1357 // we will only use its coordinate system
1358
1360
1361 if (fSelected) fSelected->Pop(); // pop object to foreground
1362 pad->cd(); // and make its pad the current pad
1363 if (gDebug)
1364 printf("Current Pad: %s / %s\n", pad->GetName(), pad->GetTitle());
1365
1366 // loop over all canvases to make sure that only one pad is highlighted
1367 {
1368 TIter next(gROOT->GetListOfCanvases());
1369 TCanvas *tc;
1370 while ((tc = (TCanvas *)next()))
1371 tc->Update();
1372 }
1373
1374 //if (pad->GetGLDevice() != -1 && fSelected)
1375 // fSelected->ExecuteEvent(event, px, py);
1376
1377 break; // don't want fPadSave->cd() to be executed at the end
1378
1379 case kButton2Motion:
1380 //was empty!
1381 case kButton2Up:
1382 if (fSelected) {
1384
1385 fSelected->ExecuteEvent(event, px, py);
1386 RunAutoExec();
1387 }
1388 break;
1389
1390 case kButton2Double:
1391 break;
1392
1393//*-*----------------------------------------------------------------------
1394
1395 case kButton3Down:
1396 // popup context menu
1397 pad = Pick(px, py, prevSelObj);
1398 if (!pad) return;
1399
1401
1404 fContextMenu->Popup(px, py, fSelected, this, pad);
1405
1406 break;
1407
1408 case kButton3Motion:
1409 break;
1410
1411 case kButton3Up:
1413 break;
1414
1415 case kButton3Double:
1416 break;
1417
1418 case kKeyPress:
1419 if (!fSelectedPad || !fSelected) return;
1420 gPad = fSelectedPad; // don't use cd() because we won't draw in pad
1421 // we will only use its coordinate system
1422 fSelected->ExecuteEvent(event, px, py);
1423
1424 RunAutoExec();
1425
1426 break;
1427
1428 case kButton1Shift:
1429 // Try to select
1430 pad = Pick(px, py, prevSelObj);
1431
1432 if (!pad) return;
1433
1434 EnterLeave(prevSelPad, prevSelObj);
1435
1436 gPad = pad; // don't use cd() we will use the current
1437 // canvas via the GetCanvas member and not via
1438 // gPad->GetCanvas
1439 if (fSelected) {
1440 fSelected->ExecuteEvent(event, px, py);
1441 RunAutoExec();
1442 }
1443 break;
1444
1445 case kWheelUp:
1446 case kWheelDown:
1447 pad = Pick(px, py, prevSelObj);
1448 if (!pad) return;
1449
1450 gPad = pad;
1451 if (fSelected)
1452 fSelected->ExecuteEvent(event, px, py);
1453 break;
1454
1455 default:
1456 break;
1457 }
1458
1459 if (fPadSave && event != kButton2Down)
1460 fPadSave->cd();
1461
1462 if (event != kMouseLeave) { // signal was already emitted for this event
1463 ProcessedEvent(event, px, py, fSelected); // emit signal
1465 }
1466}
1467
1468////////////////////////////////////////////////////////////////////////////////
1469/// Iconify canvas
1470
1472{
1473 if (fCanvasImp)
1475}
1476
1477////////////////////////////////////////////////////////////////////////////////
1478/// Is folder ?
1479
1481{
1482 return fgIsFolder;
1483}
1484
1485////////////////////////////////////////////////////////////////////////////////
1486/// Is web canvas
1487
1489{
1490 return fCanvasImp ? fCanvasImp->IsWeb() : kFALSE;
1491}
1492
1493////////////////////////////////////////////////////////////////////////////////
1494/// List all pads.
1495
1497{
1499 std::cout <<"Canvas Name=" <<GetName()<<" Title="<<GetTitle()<<" Option="<<option<<std::endl;
1503}
1504
1505////////////////////////////////////////////////////////////////////////////////
1506/// Static function to build a default canvas.
1507
1509{
1510 TString cdef = GetNewCanvasName();
1511
1512 TCanvas *c = new TCanvas(cdef.Data(), cdef.Data(), 1);
1513
1514 ::Info("TCanvas::MakeDefCanvas"," created default TCanvas with name %s", cdef.Data());
1515 return c;
1516}
1517
1518////////////////////////////////////////////////////////////////////////////////
1519/// Set option to move objects/pads in a canvas.
1520///
1521/// - set = 1 (default) graphics objects are moved in opaque mode
1522/// - set = 0 only the outline of objects is drawn when moving them
1523///
1524/// The option opaque produces the best effect. It requires however a
1525/// a reasonably fast workstation or response time.
1526
1528{
1529 SetBit(kMoveOpaque,set);
1530}
1531
1532////////////////////////////////////////////////////////////////////////////////
1533/// Paint canvas.
1534
1536{
1537 if (fCanvas)
1539}
1540
1541////////////////////////////////////////////////////////////////////////////////
1542/// Prepare for pick, call TPad::Pick() and when selected object
1543/// is different from previous then emit Picked() signal.
1544
1545TPad *TCanvas::Pick(Int_t px, Int_t py, TObject *prevSelObj)
1546{
1547 TObjLink *pickobj = nullptr;
1548
1549 fSelected = nullptr;
1550 fSelectedOpt = "";
1551 fSelectedPad = nullptr;
1552
1553 TPad *pad = Pick(px, py, pickobj);
1554 if (!pad) return nullptr;
1555
1556 if (!pickobj) {
1557 fSelected = pad;
1558 fSelectedOpt = "";
1559 } else {
1560 if (!fSelected) { // can be set via TCanvas::SetSelected()
1561 fSelected = pickobj->GetObject();
1562 fSelectedOpt = pickobj->GetOption();
1563 }
1564 }
1565 fSelectedPad = pad;
1566
1567 if (fSelected != prevSelObj)
1568 Picked(fSelectedPad, fSelected, fEvent); // emit signal
1569
1570 if ((fEvent == kButton1Down) || (fEvent == kButton2Down) || (fEvent == kButton3Down)) {
1574 Selected(fSelectedPad, fSelected, fEvent); // emit signal
1575 fSelectedX = px;
1576 fSelectedY = py;
1577 }
1578 }
1579 return pad;
1580}
1581
1582////////////////////////////////////////////////////////////////////////////////
1583/// Emit Picked() signal.
1584
1586{
1587 Longptr_t args[3];
1588
1589 args[0] = (Longptr_t) pad;
1590 args[1] = (Longptr_t) obj;
1591 args[2] = event;
1592
1593 Emit("Picked(TPad*,TObject*,Int_t)", args);
1594}
1595
1596////////////////////////////////////////////////////////////////////////////////
1597/// Emit Highlighted() signal.
1598///
1599/// - pad is pointer to pad with highlighted histogram or graph
1600/// - obj is pointer to highlighted histogram or graph
1601/// - x is highlighted x bin for 1D histogram or highlighted x-th point for graph
1602/// - y is highlighted y bin for 2D histogram (for 1D histogram or graph not in use)
1603
1605{
1606 Longptr_t args[4];
1607
1608 args[0] = (Longptr_t) pad;
1609 args[1] = (Longptr_t) obj;
1610 args[2] = x;
1611 args[3] = y;
1612
1613 Emit("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)", args);
1614}
1615
1616////////////////////////////////////////////////////////////////////////////////
1617/// This is "simplification" for function TCanvas::Connect with Highlighted
1618/// signal for specific slot.
1619///
1620/// Slot has to be defined "UserFunction(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y)"
1621/// all parameters of UserFunction are taken from TCanvas::Highlighted
1622
1623void TCanvas::HighlightConnect(const char *slot)
1624{
1625 Connect("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)", 0, 0, slot);
1626}
1627
1628////////////////////////////////////////////////////////////////////////////////
1629/// Emit Selected() signal.
1630
1632{
1633 Longptr_t args[3];
1634
1635 args[0] = (Longptr_t) pad;
1636 args[1] = (Longptr_t) obj;
1637 args[2] = event;
1638
1639 Emit("Selected(TVirtualPad*,TObject*,Int_t)", args);
1640}
1641
1642////////////////////////////////////////////////////////////////////////////////
1643/// Emit ProcessedEvent() signal.
1644
1646{
1647 Longptr_t args[4];
1648
1649 args[0] = event;
1650 args[1] = x;
1651 args[2] = y;
1652 args[3] = (Longptr_t) obj;
1653
1654 Emit("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", args);
1655}
1656
1657////////////////////////////////////////////////////////////////////////////////
1658/// Recompute canvas parameters following a X11 Resize.
1659
1661{
1662 if (fCanvasID == -1) return;
1663
1664 if ((!gROOT->IsLineProcessing()) && (!gVirtualX->IsCmdThread())) {
1665 gInterpreter->Execute(this, IsA(), "Resize", "");
1666 return;
1667 }
1668
1670
1671 TPad *padsav = (TPad*)gPad;
1672 cd();
1673
1674 if (!IsBatch()) {
1675 gVirtualX->SelectWindow(fCanvasID); //select current canvas
1676 gVirtualX->ResizeWindow(fCanvasID); //resize canvas and off-screen buffer
1677
1678 // Get effective window parameters including menubar and borders
1681
1682 // Get effective canvas parameters without borders
1683 Int_t dum1, dum2;
1684 gVirtualX->GetGeometry(fCanvasID, dum1, dum2, fCw, fCh);
1685 }
1686
1687 if (fXsizeUser && fYsizeUser) {
1688 UInt_t nwh = fCh;
1689 UInt_t nww = fCw;
1691 if (rxy < 1) {
1692 UInt_t twh = UInt_t(Double_t(fCw)/rxy);
1693 if (twh > fCh)
1694 nww = UInt_t(Double_t(fCh)*rxy);
1695 else
1696 nwh = twh;
1697 if (nww > fCw) {
1698 nww = fCw; nwh = twh;
1699 }
1700 if (nwh > fCh) {
1701 nwh = fCh; nww = UInt_t(Double_t(fCh)/rxy);
1702 }
1703 } else {
1704 UInt_t twh = UInt_t(Double_t(fCw)*rxy);
1705 if (twh > fCh)
1706 nwh = UInt_t(Double_t(fCw)/rxy);
1707 else
1708 nww = twh;
1709 if (nww > fCw) {
1710 nww = fCw; nwh = twh;
1711 }
1712 if (nwh > fCh) {
1713 nwh = fCh; nww = UInt_t(Double_t(fCh)*rxy);
1714 }
1715 }
1716 fCw = nww;
1717 fCh = nwh;
1718 }
1719
1720 if (fCw < fCh) {
1723 }
1724 else {
1727 }
1728
1729//*-*- Loop on all pads to recompute conversion coefficients
1731
1732 if (padsav) padsav->cd();
1733}
1734
1735
1736////////////////////////////////////////////////////////////////////////////////
1737/// Raise canvas window
1738
1740{
1741 if (fCanvasImp)
1743}
1744
1745////////////////////////////////////////////////////////////////////////////////
1746/// Set option to resize objects/pads in a canvas.
1747///
1748/// - set = 1 (default) graphics objects are resized in opaque mode
1749/// - set = 0 only the outline of objects is drawn when resizing them
1750///
1751/// The option opaque produces the best effect. It requires however a
1752/// a reasonably fast workstation or response time.
1753
1755{
1756 SetBit(kResizeOpaque,set);
1757}
1758
1759////////////////////////////////////////////////////////////////////////////////
1760/// Execute the list of TExecs in the current pad.
1761
1763{
1764 if (!TestBit(kAutoExec)) return;
1765 if (!gPad) return;
1766 ((TPad*)gPad)->AutoExec();
1767}
1768
1769////////////////////////////////////////////////////////////////////////////////
1770/// Save primitives in this canvas in C++ macro file with GUI.
1771
1772void TCanvas::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1773{
1774 // Write canvas options (in $TROOT or $TStyle)
1775 if (gStyle->GetOptFit()) {
1776 out<<" gStyle->SetOptFit(1);"<<std::endl;
1777 }
1778 if (!gStyle->GetOptStat()) {
1779 out<<" gStyle->SetOptStat(0);"<<std::endl;
1780 }
1781 if (!gStyle->GetOptTitle()) {
1782 out<<" gStyle->SetOptTitle(0);"<<std::endl;
1783 }
1784 if (gROOT->GetEditHistograms()) {
1785 out<<" gROOT->SetEditHistograms();"<<std::endl;
1786 }
1787 if (GetShowEventStatus()) {
1788 out<<" "<<GetName()<<"->ToggleEventStatus();"<<std::endl;
1789 }
1790 if (GetShowToolTips()) {
1791 out<<" "<<GetName()<<"->ToggleToolTips();"<<std::endl;
1792 }
1793 if (GetShowToolBar()) {
1794 out<<" "<<GetName()<<"->ToggleToolBar();"<<std::endl;
1795 }
1796 if (GetHighLightColor() != 5) {
1797 if (GetHighLightColor() > 228) {
1799 out<<" "<<GetName()<<"->SetHighLightColor(ci);" << std::endl;
1800 } else
1801 out<<" "<<GetName()<<"->SetHighLightColor("<<GetHighLightColor()<<");"<<std::endl;
1802 }
1803
1804 // Now recursively scan all pads of this canvas
1805 cd();
1807}
1808
1809////////////////////////////////////////////////////////////////////////////////
1810/// Save primitives in this canvas as a C++ macro file.
1811/// This function loops on all the canvas primitives and for each primitive
1812/// calls the object SavePrimitive function.
1813/// When outputting floating point numbers, the default precision is 7 digits.
1814/// The precision can be changed (via system.rootrc) by changing the value
1815/// of the environment variable "Canvas.SavePrecision"
1816
1818{
1819 // reset bit TClass::kClassSaved for all classes
1820 TIter next(gROOT->GetListOfClasses());
1821 TClass *cl;
1822 while((cl = (TClass*)next())) {
1824 }
1825
1826 char quote = '"';
1827 std::ofstream out;
1828 TString fname;
1829 const char *cname = GetName();
1830 Bool_t invalid = kFALSE;
1831 // if filename is given, open this file, otherwise create a file
1832 // with a name equal to the canvasname.C
1833 if (filename && (strlen(filename) > 0)) {
1834 fname = filename;
1835 } else {
1836 fname = cname;
1837 fname = fname.Strip(TString::kBoth);
1838 if (fname.IsNull()) {
1839 invalid = kTRUE;
1840 fname = "c1";
1841 }
1842 fname.Append(".C");
1843 }
1844 out.open(fname.Data(), std::ios::out);
1845 if (!out.good()) {
1846 Error("SaveSource", "Cannot open file: %s", fname.Data());
1847 return;
1848 }
1849
1850 //set precision
1851 Int_t precision = gEnv->GetValue("Canvas.SavePrecision",7);
1852 out.precision(precision);
1853
1854 // Write macro header and date/time stamp
1855 TDatime t;
1857 Int_t topx,topy;
1858 UInt_t w, h;
1859 if (!fCanvasImp) {
1860 Error("SaveSource", "Cannot open TCanvas");
1861 return;
1862 }
1863 UInt_t editorWidth = fCanvasImp->GetWindowGeometry(topx,topy,w,h);
1864 w = UInt_t((fWindowWidth - editorWidth)/cx);
1865 h = UInt_t((fWindowHeight)/cx);
1866 topx = GetWindowTopX();
1867 topy = GetWindowTopY();
1868
1869 if (w == 0) {
1870 w = GetWw()+4; h = GetWh()+4;
1871 topx = 1; topy = 1;
1872 }
1873
1874 TString mname = fname;
1875 out << R"CODE(#ifdef __CLING__
1876#pragma cling optimize(0)
1877#endif
1878)CODE";
1879 Int_t p = mname.Last('.');
1880 Int_t s = mname.Last('/')+1;
1881
1882 // A named macro is generated only if the function name is valid. If not, the
1883 // macro is unnamed.
1884 TString first(mname(s,s+1));
1885 if (!first.IsDigit()) out <<"void " << mname(s,p-s) << "()" << std::endl;
1886
1887 out <<"{"<<std::endl;
1888 out <<"//=========Macro generated from canvas: "<<GetName()<<"/"<<GetTitle()<<std::endl;
1889 out <<"//========= ("<<t.AsString()<<") by ROOT version "<<gROOT->GetVersion()<<std::endl;
1890
1892 out <<std::endl<<" gStyle->SetCanvasPreferGL(kTRUE);"<<std::endl<<std::endl;
1893
1894 // Write canvas parameters (TDialogCanvas case)
1896 out<<" "<<ClassName()<<" *"<<cname<<" = new "<<ClassName()<<"("<<quote<<GetName()
1897 <<quote<<", "<<quote<<GetTitle()<<quote<<","<<w<<","<<h<<");"<<std::endl;
1898 } else {
1899 // Write canvas parameters (TCanvas case)
1900 out<<" TCanvas *"<<cname<<" = new TCanvas("<<quote<<GetName()<<quote<<", "<<quote<<GetTitle()
1901 <<quote;
1902 if (!HasMenuBar())
1903 out<<",-"<<topx<<","<<topy<<","<<w<<","<<h<<");"<<std::endl;
1904 else
1905 out<<","<<topx<<","<<topy<<","<<w<<","<<h<<");"<<std::endl;
1906 }
1907 // Write canvas options (in $TROOT or $TStyle)
1908 if (gStyle->GetOptFit()) {
1909 out<<" gStyle->SetOptFit(1);"<<std::endl;
1910 }
1911 if (!gStyle->GetOptStat()) {
1912 out<<" gStyle->SetOptStat(0);"<<std::endl;
1913 }
1914 if (!gStyle->GetOptTitle()) {
1915 out<<" gStyle->SetOptTitle(0);"<<std::endl;
1916 }
1917 if (gROOT->GetEditHistograms()) {
1918 out<<" gROOT->SetEditHistograms();"<<std::endl;
1919 }
1920 if (GetShowEventStatus()) {
1921 out<<" "<<GetName()<<"->ToggleEventStatus();"<<std::endl;
1922 }
1923 if (GetShowToolTips()) {
1924 out<<" "<<GetName()<<"->ToggleToolTips();"<<std::endl;
1925 }
1926 if (GetHighLightColor() != 5) {
1927 if (GetHighLightColor() > 228) {
1929 out<<" "<<GetName()<<"->SetHighLightColor(ci);" << std::endl;
1930 } else
1931 out<<" "<<GetName()<<"->SetHighLightColor("<<GetHighLightColor()<<");"<<std::endl;
1932 }
1933
1934 // Now recursively scan all pads of this canvas
1935 cd();
1936 if (invalid) SetName("c1");
1938 // Write canvas options related to pad editor
1939 out<<" "<<GetName()<<"->SetSelected("<<GetName()<<");"<<std::endl;
1940 if (GetShowToolBar()) {
1941 out<<" "<<GetName()<<"->ToggleToolBar();"<<std::endl;
1942 }
1943 if (invalid) SetName(" ");
1944
1945 out <<"}"<<std::endl;
1946 out.close();
1947 Info("SaveSource","C++ Macro file: %s has been generated", fname.Data());
1948
1949 // reset bit TClass::kClassSaved for all classes
1950 next.Reset();
1951 while((cl = (TClass*)next())) {
1953 }
1954}
1955
1956////////////////////////////////////////////////////////////////////////////////
1957/// Toggle batch mode. However, if the canvas is created without a window
1958/// then batch mode always stays set.
1959
1960void TCanvas::SetBatch(Bool_t batch)
1961{
1962 if (gROOT->IsBatch() || IsWeb())
1963 fBatch = kTRUE;
1964 else
1965 fBatch = batch;
1966}
1967
1968////////////////////////////////////////////////////////////////////////////////
1969/// Set Width and Height of canvas to ww and wh respectively. If ww and/or wh
1970/// are greater than the current canvas window a scroll bar is automatically
1971/// generated. Use this function to zoom in a canvas and navigate via
1972/// the scroll bars. The Width and Height in this method are different from those
1973/// given in the TCanvas constructors where these two dimension include the size
1974/// of the window decoration whereas they do not in this method.
1975
1977{
1978 if (fCanvasImp) {
1979 fCanvasImp->SetCanvasSize(ww, wh);
1980 fCw = ww;
1981 fCh = wh;
1982 TPad *padsav = (TPad*)gPad;
1983 cd();
1984 ResizePad();
1985 if (padsav) padsav->cd();
1986 }
1987}
1988
1989////////////////////////////////////////////////////////////////////////////////
1990/// Set cursor.
1991
1993{
1994 if (IsBatch()) return;
1995 gVirtualX->SetCursor(fCanvasID, cursor);
1996}
1997
1998////////////////////////////////////////////////////////////////////////////////
1999/// Set Double Buffer On/Off.
2000
2002{
2003 if (IsBatch()) return;
2005 gVirtualX->SetDoubleBuffer(fCanvasID, mode);
2006
2007 // depending of the buffer mode set the drawing window to either
2008 // the canvas pixmap or to the canvas on-screen window
2009 if (fDoubleBuffer) {
2011 } else
2013}
2014
2015////////////////////////////////////////////////////////////////////////////////
2016/// Fix canvas aspect ratio to current value if fixed is true.
2017
2019{
2020 if (fixed) {
2021 if (!fFixedAspectRatio) {
2022 if (fCh != 0)
2024 else {
2025 Error("SetAspectRatio", "cannot fix aspect ratio, height of canvas is 0");
2026 return;
2027 }
2029 }
2030 } else {
2032 fAspectRatio = 0;
2033 }
2034}
2035
2036////////////////////////////////////////////////////////////////////////////////
2037/// If isfolder=kTRUE, the canvas can be browsed like a folder
2038/// by default a canvas is not browsable.
2039
2040void TCanvas::SetFolder(Bool_t isfolder)
2041{
2042 fgIsFolder = isfolder;
2043}
2044
2045////////////////////////////////////////////////////////////////////////////////
2046/// Set canvas name. In case `name` is an empty string, a default name is set.
2047
2048void TCanvas::SetName(const char *name)
2049{
2050 if (name && *name)
2051 fName = name;
2052 else
2054
2055 if (gPad && TestBit(kMustCleanup))
2056 gPad->Modified();
2057}
2058
2059
2060////////////////////////////////////////////////////////////////////////////////
2061/// Function to resize a canvas so that the plot inside is shown in real aspect
2062/// ratio
2063///
2064/// \param[in] axis 1 for resizing horizontally (x-axis) in order to get real
2065/// aspect ratio, 2 for the resizing vertically (y-axis)
2066/// \return false if error is encountered, true otherwise
2067///
2068/// ~~~ {.cpp}
2069/// hpxpy->Draw();
2070/// c1->SetRealAspectRatio();
2071/// ~~~
2072///
2073/// - For defining the concept of real aspect ratio, it is assumed that x and y
2074/// axes are in same units, e.g. both in MeV or both in ns.
2075/// - You can resize either the width of the canvas or the height, but not both
2076/// at the same time
2077/// - Call this function AFTER drawing AND zooming (SetUserRange) your TGraph or
2078/// Histogram, otherwise it cannot infer your actual axes lengths
2079/// - This function ensures that the TFrame has a real aspect ratio, this does not
2080/// mean that the full pad (i.e. the canvas or png output) including margins has
2081/// exactly the same ratio
2082/// - This function does not work if the canvas is divided in several subpads
2083
2084bool TCanvas::SetRealAspectRatio(const Int_t axis)
2085{
2086 Update();
2087
2088 //Get how many pixels are occupied by the canvas
2089 Int_t npx = GetWw();
2090 Int_t npy = GetWh();
2091
2092 //Get x-y coordinates at the edges of the canvas (extrapolating outside the axes, NOT at the edges of the histogram)
2093 Double_t x1 = GetX1();
2094 Double_t y1 = GetY1();
2095 Double_t x2 = GetX2();
2096 Double_t y2 = GetY2();
2097
2098 //Get the length of extrapolated x and y axes
2099 Double_t xlength2 = x2 - x1;
2100 Double_t ylength2 = y2 - y1;
2101 Double_t ratio2 = xlength2/ylength2;
2102
2103 //Now get the number of pixels including the canvas borders
2104 Int_t bnpx = GetWindowWidth();
2105 Int_t bnpy = GetWindowHeight();
2106
2107 if (axis==1) {
2108 SetCanvasSize(TMath::Nint(npy*ratio2), npy);
2109 SetWindowSize((bnpx-npx)+TMath::Nint(npy*ratio2), bnpy);
2110 } else if (axis==2) {
2111 SetCanvasSize(npx, TMath::Nint(npx/ratio2));
2112 SetWindowSize(bnpx, (bnpy-npy)+TMath::Nint(npx/ratio2));
2113 } else {
2114 Error("SetRealAspectRatio", "axis value %d is neither 1 (resize along x-axis) nor 2 (resize along y-axis).",axis);
2115 return false;
2116 }
2117
2118 //Check now that resizing has worked
2119
2120 Update();
2121
2122 //Get how many pixels are occupied by the canvas
2123 npx = GetWw();
2124 npy = GetWh();
2125
2126 //Get x-y coordinates at the edges of the canvas (extrapolating outside the axes,
2127 //NOT at the edges of the histogram)
2128 x1 = GetX1();
2129 y1 = GetY1();
2130 x2 = GetX2();
2131 y2 = GetY2();
2132
2133 //Get the length of extrapolated x and y axes
2134 xlength2 = x2 - x1;
2135 ylength2 = y2 - y1;
2136 ratio2 = xlength2/ylength2;
2137
2138 //Check accuracy +/-1 pixel due to rounding
2139 if (abs(TMath::Nint(npy*ratio2) - npx)<2) {
2140 return true;
2141 } else {
2142 Error("SetRealAspectRatio", "Resizing failed.");
2143 return false;
2144 }
2145}
2146
2147
2148////////////////////////////////////////////////////////////////////////////////
2149/// Set selected canvas.
2150
2152{
2153 fSelected = obj;
2154 if (obj) obj->SetBit(kMustCleanup);
2155}
2156
2157////////////////////////////////////////////////////////////////////////////////
2158/// Set canvas title.
2159
2160void TCanvas::SetTitle(const char *title)
2161{
2162 fTitle = title;
2164}
2165
2166////////////////////////////////////////////////////////////////////////////////
2167/// Set canvas window position
2168
2170{
2171 if (fCanvasImp)
2173}
2174
2175////////////////////////////////////////////////////////////////////////////////
2176/// Set canvas window size
2177
2179{
2180 if (fBatch)
2181 SetCanvasSize((ww + fCw) / 2, (wh + fCh) / 2);
2182 else if (fCanvasImp)
2183 fCanvasImp->SetWindowSize(ww, wh);
2184}
2185
2186////////////////////////////////////////////////////////////////////////////////
2187/// Set the canvas scale in centimeters.
2188///
2189/// This information is used by PostScript to set the page size.
2190///
2191/// \param[in] xsize size of the canvas in centimeters along X
2192/// \param[in] ysize size of the canvas in centimeters along Y
2193///
2194/// if xsize and ysize are not equal to 0, then the scale factors will
2195/// be computed to keep the ratio ysize/xsize independently of the canvas
2196/// size (parts of the physical canvas will be unused).
2197///
2198/// if xsize = 0 and ysize is not zero, then xsize will be computed
2199/// to fit to the current canvas scale. If the canvas is resized,
2200/// a new value for xsize will be recomputed. In this case the aspect
2201/// ratio is not preserved.
2202///
2203/// if both xsize = 0 and ysize = 0, then the scaling is automatic.
2204/// the largest dimension will be allocated a size of 20 centimeters.
2205
2206void TCanvas::Size(Float_t xsize, Float_t ysize)
2207{
2208 fXsizeUser = xsize;
2209 fYsizeUser = ysize;
2210
2211 Resize();
2212}
2213
2214////////////////////////////////////////////////////////////////////////////////
2215/// Show canvas
2216
2217void TCanvas::Show()
2218{
2219 if (fCanvasImp)
2220 fCanvasImp->Show();
2221}
2222
2223////////////////////////////////////////////////////////////////////////////////
2224/// Stream a class object.
2225
2227{
2228 UInt_t R__s, R__c;
2229 if (b.IsReading()) {
2230 Version_t v = b.ReadVersion(&R__s, &R__c);
2231 gPad = this;
2232 fCanvas = this;
2233 if (v>7) b.ClassBegin(TCanvas::IsA());
2234 if (v>7) b.ClassMember("TPad");
2236 gPad = this;
2237 //restore the colors
2238 TObjArray *colors = (TObjArray*)fPrimitives->FindObject("ListOfColors");
2239 if (colors) {
2240 TIter next(colors);
2241 TColor *colold;
2242 while ((colold = (TColor*)next())) {
2243 if (colold) {
2244 Int_t cn = 0;
2245 if (colold) cn = colold->GetNumber();
2246 TColor *colcur = gROOT->GetColor(cn);
2247 if (colcur) {
2248 colcur->SetRGB(colold->GetRed(),colold->GetGreen(),colold->GetBlue());
2249 } else {
2250 colcur = new TColor(cn,colold->GetRed(),
2251 colold->GetGreen(),
2252 colold->GetBlue(),
2253 colold->GetName());
2254 if (!colcur) return;
2255 }
2256 }
2257 }
2258 //restore the palette if needed
2259 TObjArray *currentpalette = (TObjArray*)fPrimitives->FindObject("CurrentColorPalette");
2260 if (currentpalette) {
2261 TIter nextpal(currentpalette);
2262 Int_t n = currentpalette->GetEntries();
2263 TArrayI palcolors(n);
2264 TColor *col = nullptr;
2265 Int_t i = 0;
2266 while ((col = (TColor*)nextpal())) palcolors[i++] = col->GetNumber();
2267 gStyle->SetPalette(n,palcolors.GetArray());
2268 fPrimitives->Remove(currentpalette);
2269 delete currentpalette;
2270 }
2272 colors->Delete();
2273 delete colors;
2274 }
2275
2276 if (v>7) b.ClassMember("fDISPLAY","TString");
2278 if (v>7) b.ClassMember("fDoubleBuffer", "Int_t");
2279 b >> fDoubleBuffer;
2280 if (v>7) b.ClassMember("fRetained", "Bool_t");
2281 b >> fRetained;
2282 if (v>7) b.ClassMember("fXsizeUser", "Size_t");
2283 b >> fXsizeUser;
2284 if (v>7) b.ClassMember("fYsizeUser", "Size_t");
2285 b >> fYsizeUser;
2286 if (v>7) b.ClassMember("fXsizeReal", "Size_t");
2287 b >> fXsizeReal;
2288 if (v>7) b.ClassMember("fYsizeReal", "Size_t");
2289 b >> fYsizeReal;
2290 fCanvasID = -1;
2291 if (v>7) b.ClassMember("fWindowTopX", "Int_t");
2292 b >> fWindowTopX;
2293 if (v>7) b.ClassMember("fWindowTopY", "Int_t");
2294 b >> fWindowTopY;
2295 if (v > 2) {
2296 if (v>7) b.ClassMember("fWindowWidth", "UInt_t");
2297 b >> fWindowWidth;
2298 if (v>7) b.ClassMember("fWindowHeight", "UInt_t");
2299 b >> fWindowHeight;
2300 }
2301 if (v>7) b.ClassMember("fCw", "UInt_t");
2302 b >> fCw;
2303 if (v>7) b.ClassMember("fCh", "UInt_t");
2304 b >> fCh;
2305 if (v <= 2) {
2306 fWindowWidth = fCw;
2308 }
2309 if (v>7) b.ClassMember("fCatt", "TAttCanvas");
2310 fCatt.Streamer(b);
2311 Bool_t dummy;
2312 if (v>7) b.ClassMember("kMoveOpaque", "Bool_t");
2313 b >> dummy; if (dummy) MoveOpaque(1);
2314 if (v>7) b.ClassMember("kResizeOpaque", "Bool_t");
2315 b >> dummy; if (dummy) ResizeOpaque(1);
2316 if (v>7) b.ClassMember("fHighLightColor", "Color_t");
2317 b >> fHighLightColor;
2318 if (v>7) b.ClassMember("fBatch", "Bool_t");
2319 b >> dummy; //was fBatch
2320 if (v < 2) return;
2321 if (v>7) b.ClassMember("kShowEventStatus", "Bool_t");
2322 b >> dummy; if (dummy) SetBit(kShowEventStatus);
2323
2324 if (v > 3) {
2325 if (v>7) b.ClassMember("kAutoExec", "Bool_t");
2326 b >> dummy; if (dummy) SetBit(kAutoExec);
2327 }
2328 if (v>7) b.ClassMember("kMenuBar", "Bool_t");
2329 b >> dummy; if (dummy) SetBit(kMenuBar);
2330 fBatch = gROOT->IsBatch();
2331 if (v>7) b.ClassEnd(TCanvas::IsA());
2332 b.CheckByteCount(R__s, R__c, TCanvas::IsA());
2333 } else {
2334 //save list of colors
2335 //we must protect the case when two or more canvases are saved
2336 //in the same buffer. If the list of colors has already been saved
2337 //in the buffer, do not add the list of colors to the list of primitives.
2338 TObjArray *colors = nullptr;
2339 TObjArray *CurrentColorPalette = nullptr;
2340 if (TColor::DefinedColors()) {
2341 if (!b.CheckObject(gROOT->GetListOfColors(),TObjArray::Class())) {
2342 colors = (TObjArray*)gROOT->GetListOfColors();
2344 }
2345 //save the current palette
2347 Int_t palsize = pal.GetSize();
2348 CurrentColorPalette = new TObjArray();
2349 CurrentColorPalette->SetName("CurrentColorPalette");
2350 for (Int_t i=0; i<palsize; i++) CurrentColorPalette->Add(gROOT->GetColor(pal[i]));
2351 fPrimitives->Add(CurrentColorPalette);
2352 }
2353
2354 R__c = b.WriteVersion(TCanvas::IsA(), kTRUE);
2355 b.ClassBegin(TCanvas::IsA());
2356 b.ClassMember("TPad");
2359 if (CurrentColorPalette) { fPrimitives->Remove(CurrentColorPalette); delete CurrentColorPalette; }
2360 b.ClassMember("fDISPLAY","TString");
2362 b.ClassMember("fDoubleBuffer", "Int_t");
2363 b << fDoubleBuffer;
2364 b.ClassMember("fRetained", "Bool_t");
2365 b << fRetained;
2366 b.ClassMember("fXsizeUser", "Size_t");
2367 b << fXsizeUser;
2368 b.ClassMember("fYsizeUser", "Size_t");
2369 b << fYsizeUser;
2370 b.ClassMember("fXsizeReal", "Size_t");
2371 b << fXsizeReal;
2372 b.ClassMember("fYsizeReal", "Size_t");
2373 b << fYsizeReal;
2375 Int_t topx = fWindowTopX, topy = fWindowTopY;
2376 UInt_t editorWidth = 0;
2377 if(fCanvasImp) editorWidth = fCanvasImp->GetWindowGeometry(topx,topy,w,h);
2378 b.ClassMember("fWindowTopX", "Int_t");
2379 b << topx;
2380 b.ClassMember("fWindowTopY", "Int_t");
2381 b << topy;
2382 b.ClassMember("fWindowWidth", "UInt_t");
2383 b << (UInt_t)(w-editorWidth);
2384 b.ClassMember("fWindowHeight", "UInt_t");
2385 b << h;
2386 b.ClassMember("fCw", "UInt_t");
2387 b << fCw;
2388 b.ClassMember("fCh", "UInt_t");
2389 b << fCh;
2390 b.ClassMember("fCatt", "TAttCanvas");
2391 fCatt.Streamer(b);
2392 b.ClassMember("kMoveOpaque", "Bool_t");
2393 b << TestBit(kMoveOpaque); //please remove in ROOT version 6
2394 b.ClassMember("kResizeOpaque", "Bool_t");
2395 b << TestBit(kResizeOpaque); //please remove in ROOT version 6
2396 b.ClassMember("fHighLightColor", "Color_t");
2397 b << fHighLightColor;
2398 b.ClassMember("fBatch", "Bool_t");
2399 b << fBatch; //please remove in ROOT version 6
2400 b.ClassMember("kShowEventStatus", "Bool_t");
2401 b << TestBit(kShowEventStatus); //please remove in ROOT version 6
2402 b.ClassMember("kAutoExec", "Bool_t");
2403 b << TestBit(kAutoExec); //please remove in ROOT version 6
2404 b.ClassMember("kMenuBar", "Bool_t");
2405 b << TestBit(kMenuBar); //please remove in ROOT version 6
2406 b.ClassEnd(TCanvas::IsA());
2407 b.SetByteCount(R__c, kTRUE);
2408 }
2409}
2410
2411////////////////////////////////////////////////////////////////////////////////
2412/// Toggle pad auto execution of list of TExecs.
2413
2415{
2416 Bool_t autoExec = TestBit(kAutoExec);
2417 SetBit(kAutoExec,!autoExec);
2418}
2419
2420////////////////////////////////////////////////////////////////////////////////
2421/// Toggle event statusbar.
2422
2424{
2425 Bool_t showEventStatus = !TestBit(kShowEventStatus);
2426 SetBit(kShowEventStatus,showEventStatus);
2427
2428 if (fCanvasImp) fCanvasImp->ShowStatusBar(showEventStatus);
2429}
2430
2431////////////////////////////////////////////////////////////////////////////////
2432/// Toggle toolbar.
2433
2435{
2436 Bool_t showToolBar = !TestBit(kShowToolBar);
2437 SetBit(kShowToolBar,showToolBar);
2438
2439 if (fCanvasImp) fCanvasImp->ShowToolBar(showToolBar);
2440}
2441
2442////////////////////////////////////////////////////////////////////////////////
2443/// Toggle editor.
2444
2446{
2447 Bool_t showEditor = !TestBit(kShowEditor);
2448 SetBit(kShowEditor,showEditor);
2449
2450 if (fCanvasImp) fCanvasImp->ShowEditor(showEditor);
2451}
2452
2453////////////////////////////////////////////////////////////////////////////////
2454/// Toggle tooltip display.
2455
2457{
2458 Bool_t showToolTips = !TestBit(kShowToolTips);
2459 SetBit(kShowToolTips, showToolTips);
2460
2461 if (fCanvasImp) fCanvasImp->ShowToolTips(showToolTips);
2462}
2463
2464
2465////////////////////////////////////////////////////////////////////////////////
2466/// Static function returning "true" if transparency is supported.
2467
2469{
2470 return gPad && (gVirtualX->InheritsFrom("TGQuartz") ||
2471 gPad->GetGLDevice() != -1);
2472}
2473
2474extern "C" void ROOT_TCanvas_Update(void* TheCanvas) {
2475 static_cast<TCanvas*>(TheCanvas)->Update();
2476}
2477
2478////////////////////////////////////////////////////////////////////////////////
2479/// Update canvas pad buffers.
2480
2481void TCanvas::Update()
2482{
2483 if (fUpdating) return;
2484
2485 if (fPixmapID == -1) return;
2486
2487 static const union CastFromFuncToVoidPtr_t {
2488 CastFromFuncToVoidPtr_t(): fFuncPtr(ROOT_TCanvas_Update) {}
2489 void (*fFuncPtr)(void*);
2490 void* fVoidPtr;
2491 } castFromFuncToVoidPtr;
2492
2493 if (gThreadXAR) {
2494 void *arr[3];
2495 arr[1] = this;
2496 arr[2] = castFromFuncToVoidPtr.fVoidPtr;
2497 if ((*gThreadXAR)("CUPD", 3, arr, 0)) return;
2498 }
2499
2500 if (!fCanvasImp) return;
2501
2502 if (!gVirtualX->IsCmdThread()) {
2503 // Why do we have this (which uses the interpreter to funnel the Update()
2504 // through the main thread) when the gThreadXAR mechanism does seemingly
2505 // the same?
2506 gInterpreter->Execute(this, IsA(), "Update", "");
2507 return;
2508 }
2509
2511
2512 fUpdating = kTRUE;
2513
2514 if (!fCanvasImp->PerformUpdate()) {
2515
2516 if (!IsBatch()) FeedbackMode(kFALSE); // Goto double buffer mode
2517
2518 if (!UseGL() || fGLDevice == -1) PaintModified(); // Repaint all modified pad's
2519
2520 Flush(); // Copy all pad pixmaps to the screen
2521
2523 }
2524
2525 fUpdating = kFALSE;
2526}
2527
2528////////////////////////////////////////////////////////////////////////////////
2529/// Used by friend class TCanvasImp.
2530
2532{
2533 fCanvasID = 0;
2534 fContextMenu = nullptr;
2535}
2536
2537////////////////////////////////////////////////////////////////////////////////
2538/// Check whether this canvas is to be drawn in grayscale mode.
2539
2541{
2542 return TestBit(kIsGrayscale);
2543}
2544
2545////////////////////////////////////////////////////////////////////////////////
2546/// Set whether this canvas should be painted in grayscale, and re-paint
2547/// it if necessary.
2548
2549void TCanvas::SetGrayscale(Bool_t set /*= kTRUE*/)
2550{
2551 if (IsGrayscale() == set) return;
2552 SetBit(kIsGrayscale, set);
2553 Paint(); // update canvas and all sub-pads, unconditionally!
2554}
2555
2556////////////////////////////////////////////////////////////////////////////////
2557/// Probably, TPadPainter must be placed in a separate ROOT module -
2558/// "padpainter" (the same as "histpainter"). But now, it's directly in a
2559/// gpad dir, so, in case of default painter, no *.so should be loaded,
2560/// no need in plugin managers.
2561/// May change in future.
2562
2564{
2565 //Even for batch mode painter is still required, just to delegate
2566 //some calls to batch "virtual X".
2567 if (!UseGL() || fBatch) {
2568 fPainter = nullptr;
2570 if (!fPainter) fPainter = new TPadPainter; // Do not need plugin manager for this!
2571 } else {
2573 if (!fPainter) {
2574 Error("CreatePainter", "GL Painter creation failed! Will use default!");
2575 fPainter = new TPadPainter;
2576 fUseGL = kFALSE;
2577 }
2578 }
2579}
2580
2581////////////////////////////////////////////////////////////////////////////////
2582/// Access and (probably) creation of pad painter.
2583
2585{
2586 if (!fPainter) CreatePainter();
2587 return fPainter;
2588}
2589
2590
2591////////////////////////////////////////////////////////////////////////////////
2592///assert on IsBatch() == false?
2593
2595{
2596 if (fGLDevice != -1) {
2597 //fPainter has a font manager.
2598 //Font manager will delete textures.
2599 //If context is wrong (we can have several canvases) -
2600 //wrong texture will be deleted, damaging some of our fonts.
2601 gGLManager->MakeCurrent(fGLDevice);
2602 }
2603
2605
2606 if (fGLDevice != -1) {
2607 gGLManager->DeleteGLContext(fGLDevice);//?
2608 fGLDevice = -1;
2609 }
2610}
EEventType
Definition: Buttons.h:15
@ kButton1ShiftMotion
Definition: Buttons.h:18
@ kMouseMotion
Definition: Buttons.h:23
@ kWheelUp
Definition: Buttons.h:18
@ kButton3Up
Definition: Buttons.h:19
@ kButton2Motion
Definition: Buttons.h:20
@ kButton3Motion
Definition: Buttons.h:20
@ kButton3Down
Definition: Buttons.h:17
@ kButton2Down
Definition: Buttons.h:17
@ kKeyPress
Definition: Buttons.h:20
@ kButton2Double
Definition: Buttons.h:24
@ kArrowKeyRelease
Definition: Buttons.h:21
@ kButton1Double
Definition: Buttons.h:24
@ kButton3Double
Definition: Buttons.h:24
@ kButton1Shift
Definition: Buttons.h:18
@ kButton1Motion
Definition: Buttons.h:20
@ kButton1Up
Definition: Buttons.h:19
@ kWheelDown
Definition: Buttons.h:18
@ kArrowKeyPress
Definition: Buttons.h:21
@ kButton2Up
Definition: Buttons.h:19
@ kMouseLeave
Definition: Buttons.h:23
@ kButton1Down
Definition: Buttons.h:17
@ kMouseEnter
Definition: Buttons.h:23
ECursor
Definition: GuiTypes.h:372
@ kCross
Definition: GuiTypes.h:374
#define SafeDelete(p)
Definition: RConfig.hxx:537
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
bool Bool_t
Definition: RtypesCore.h:63
int Int_t
Definition: RtypesCore.h:45
float Size_t
Definition: RtypesCore.h:96
long Longptr_t
Definition: RtypesCore.h:82
short Version_t
Definition: RtypesCore.h:65
const Bool_t kFALSE
Definition: RtypesCore.h:101
unsigned int UInt_t
Definition: RtypesCore.h:46
float Float_t
Definition: RtypesCore.h:57
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
@ kRed
Definition: Rtypes.h:66
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
void ROOT_TCanvas_Update(void *TheCanvas)
Definition: TCanvas.cxx:2471
class TCanvasInit gCanvasInit
auto GetNewCanvasName()
Definition: TCanvas.cxx:66
const Size_t kDefaultCanvasSize
Definition: TCanvas.cxx:61
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
ClassImpQ(TGImageMap) TGRegionWithId *gCurrentRegion
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition: TGX11.cxx:110
R__EXTERN TGuiFactory * gBatchGuiFactory
Definition: TGuiFactory.h:67
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
#define gInterpreter
Definition: TInterpreter.h:564
Int_t gDebug
Definition: TROOT.cxx:585
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
#define gROOT
Definition: TROOT.h:404
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
#define gGLManager
Definition: TVirtualGL.h:160
#define R__LOCKGUARD(mutex)
R__EXTERN TVirtualPS * gVirtualPS
Definition: TVirtualPS.h:81
#define gPad
Definition: TVirtualPad.h:288
R__EXTERN Int_t(* gThreadXAR)(const char *xact, Int_t nb, void **ar, Int_t *iret)
Definition: TVirtualPad.h:290
#define gVirtualX
Definition: TVirtualX.h:338
Color * colors
Definition: X3DBuffer.c:21
#define snprintf
Definition: civetweb.c:1540
void InitializeGraphics()
Initialize the graphics environment.
static void CreateApplication()
Static function used to create a default application environment.
static void NeedGraphicsLibs()
Static method.
Array of integers (32 bits per element).
Definition: TArrayI.h:27
const Int_t * GetArray() const
Definition: TArrayI.h:43
Int_t GetSize() const
Definition: TArray.h:47
virtual void Streamer(TBuffer &)
Fill Area Attributes class.
Definition: TAttFill.h:19
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition: TAttFill.cxx:204
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
Line Attributes class.
Definition: TAttLine.h:18
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition: TAttLine.cxx:175
Manages default Pad attributes.
Definition: TAttPad.h:19
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:99
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition: TAttPad.cxx:109
virtual void Copy(TAttPad &attpad) const
copy function
Definition: TAttPad.cxx:44
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:119
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition: TAttPad.cxx:129
Class to manage histogram axis.
Definition: TAxis.h:30
static TClass * Class()
virtual Bool_t GetTimeDisplay() const
Definition: TAxis.h:127
virtual const char * GetTimeFormat() const
Definition: TAxis.h:128
Create a Box.
Definition: TBox.h:22
static TClass * Class()
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
virtual void SetStatusText(const char *text=nullptr, Int_t partidx=0)
Definition: TCanvasImp.h:69
virtual void SetWindowPosition(Int_t x, Int_t y)
Definition: TCanvasImp.h:70
virtual void ShowMenuBar(Bool_t show=kTRUE)
Definition: TCanvasImp.h:75
virtual void Show()
Definition: TCanvasImp.h:74
virtual void ShowToolTips(Bool_t show=kTRUE)
Definition: TCanvasImp.h:82
virtual void Iconify()
Definition: TCanvasImp.h:67
virtual Int_t InitWindow()
Definition: TCanvasImp.h:68
virtual void Close()
Definition: TCanvasImp.h:59
virtual void SetWindowTitle(const char *newTitle)
Definition: TCanvasImp.h:72
virtual Bool_t IsWeb() const
Definition: TCanvasImp.h:48
virtual UInt_t GetWindowGeometry(Int_t &x, Int_t &y, UInt_t &w, UInt_t &h)
Definition: TCanvasImp.h:61
virtual TVirtualPadPainter * CreatePadPainter()
Definition: TCanvasImp.h:50
virtual void ShowEditor(Bool_t show=kTRUE)
Definition: TCanvasImp.h:80
virtual void RaiseWindow()
Definition: TCanvasImp.h:77
virtual Bool_t PerformUpdate()
Definition: TCanvasImp.h:49
virtual void SetWindowSize(UInt_t width, UInt_t height)
Definition: TCanvasImp.h:71
virtual void SetCanvasSize(UInt_t w, UInt_t h)
Definition: TCanvasImp.h:73
virtual void ForceUpdate()
Definition: TCanvasImp.h:60
virtual void ShowStatusBar(Bool_t show=kTRUE)
Definition: TCanvasImp.h:76
virtual void ShowToolBar(Bool_t show=kTRUE)
Definition: TCanvasImp.h:81
The Canvas class.
Definition: TCanvas.h:23
void Init()
Initialize the TCanvas members. Called by all constructors.
Definition: TCanvas.cxx:530
UInt_t fCw
Width of the canvas along X (pixels)
Definition: TCanvas.h:43
void EmbedInto(Int_t winid, Int_t ww, Int_t wh)
Embedded a canvas into a TRootEmbeddedCanvas.
Definition: TCanvas.cxx:1041
void SetWindowSize(UInt_t ww, UInt_t wh)
Set canvas window size.
Definition: TCanvas.cxx:2175
static void SetFolder(Bool_t isfolder=kTRUE)
If isfolder=kTRUE, the canvas can be browsed like a folder by default a canvas is not browsable.
Definition: TCanvas.cxx:2037
void Browse(TBrowser *b) override
Browse.
Definition: TCanvas.cxx:677
UInt_t GetWindowHeight() const
Definition: TCanvas.h:161
virtual void EditorBar()
Get editor bar.
Definition: TCanvas.cxx:1032
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
Definition: TCanvas.cxx:1508
void EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
Generate kMouseEnter and kMouseLeave events depending on the previously selected object and the curre...
Definition: TCanvas.cxx:1067
Size_t fYsizeReal
Current size of canvas along Y in CM.
Definition: TCanvas.h:36
void Constructor()
Canvas default constructor.
Definition: TCanvas.cxx:186
virtual void ToggleAutoExec()
Toggle pad auto execution of list of TExecs.
Definition: TCanvas.cxx:2411
TCanvas(const TCanvas &canvas)=delete
Int_t fWindowTopX
Top X position of window (in pixels)
Definition: TCanvas.h:39
void Draw(Option_t *option="") override
Draw a canvas.
Definition: TCanvas.cxx:848
void SetDoubleBuffer(Int_t mode=1) override
Set Double Buffer On/Off.
Definition: TCanvas.cxx:1998
virtual void ToggleToolTips()
Toggle tooltip display.
Definition: TCanvas.cxx:2453
void Clear(Option_t *option="") override
Remove all primitives from the canvas.
Definition: TCanvas.cxx:730
void UseCurrentStyle() override
Force a copy of current style for all objects in canvas.
Definition: TCanvas.cxx:1178
void Iconify()
Iconify canvas.
Definition: TCanvas.cxx:1471
Int_t GetWindowTopX()
Returns current top x position of window on screen.
Definition: TCanvas.cxx:1203
Bool_t IsWeb() const
Is web canvas.
Definition: TCanvas.cxx:1488
virtual void ToggleEventStatus()
Toggle event statusbar.
Definition: TCanvas.cxx:2420
void Destructor()
Actual canvas destructor.
Definition: TCanvas.cxx:687
void DeleteCanvasPainter()
assert on IsBatch() == false?
Definition: TCanvas.cxx:2591
TPad * fPadSave
! Pointer to saved pad in HandleInput
Definition: TCanvas.h:56
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2465
Bool_t fBatch
! True when in batchmode
Definition: TCanvas.h:59
Bool_t fUseGL
! True when rendering is with GL
Definition: TCanvas.h:62
Int_t fEventX
! Last X mouse position in canvas
Definition: TCanvas.h:46
Bool_t IsBatch() const override
Definition: TCanvas.h:170
TObject * DrawClone(Option_t *option="") const override
Draw a clone of this canvas A new canvas is created that is a clone of this canvas.
Definition: TCanvas.cxx:895
Size_t fXsizeReal
Current size of canvas along X in CM.
Definition: TCanvas.h:35
Bool_t HasMenuBar() const
Definition: TCanvas.h:167
TVirtualPadPainter * GetCanvasPainter()
Access and (probably) creation of pad painter.
Definition: TCanvas.cxx:2581
virtual void HighlightConnect(const char *slot)
This is "simplification" for function TCanvas::Connect with Highlighted signal for specific slot.
Definition: TCanvas.cxx:1623
TPad * Pick(Int_t px, Int_t py, TObjLink *&pickobj) override
Search for an object at pixel position px,py.
Definition: TCanvas.h:181
void Close(Option_t *option="") override
Close canvas.
Definition: TCanvas.cxx:781
void SetFixedAspectRatio(Bool_t fixed=kTRUE) override
Fix canvas aspect ratio to current value if fixed is true.
Definition: TCanvas.cxx:2015
virtual void Resize(Option_t *option="")
Recompute canvas parameters following a X11 Resize.
Definition: TCanvas.cxx:1660
Color_t GetHighLightColor() const override
Definition: TCanvas.h:137
Bool_t GetShowToolBar() const
Definition: TCanvas.h:148
void DrawEventStatus(Int_t event, Int_t x, Int_t y, TObject *selected)
Report name and title of primitive below the cursor.
Definition: TCanvas.cxx:966
Bool_t IsFolder() const override
Is folder ?
Definition: TCanvas.cxx:1480
UInt_t fWindowWidth
Width of window (including borders, etc.)
Definition: TCanvas.h:41
TVirtualPadPainter * fPainter
! Canvas (pad) painter.
Definition: TCanvas.h:65
void CopyPixmaps() override
Copy the canvas pixmap of the pad to the canvas.
Definition: TCanvas.cxx:830
Bool_t IsGrayscale()
Check whether this canvas is to be drawn in grayscale mode.
Definition: TCanvas.cxx:2537
TPad * fClickSelectedPad
! Pad containing currently click-selected object
Definition: TCanvas.h:55
Bool_t fUpdating
! True when Updating the canvas
Definition: TCanvas.h:60
void SaveSource(const char *filename="", Option_t *option="")
Save primitives in this canvas as a C++ macro file.
Definition: TCanvas.cxx:1817
Color_t fHighLightColor
Highlight color of active pad.
Definition: TCanvas.h:37
virtual void Size(Float_t xsizeuser=0, Float_t ysizeuser=0)
Set the canvas scale in centimeters.
Definition: TCanvas.cxx:2203
virtual void ProcessedEvent(Int_t event, Int_t x, Int_t y, TObject *selected)
Emit ProcessedEvent() signal.
Definition: TCanvas.cxx:1645
virtual void HandleInput(EEventType button, Int_t x, Int_t y)
Handle Input Events.
Definition: TCanvas.cxx:1227
Size_t fXsizeUser
User specified size of canvas along X in CM.
Definition: TCanvas.h:33
Int_t fEventY
! Last Y mouse position in canvas
Definition: TCanvas.h:47
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition: TCanvas.cxx:711
UInt_t fWindowHeight
Height of window (including menubar, borders, etc.)
Definition: TCanvas.h:42
Int_t GetWindowTopY()
Returns current top y position of window on screen.
Definition: TCanvas.cxx:1214
TObject * fClickSelected
! Currently click-selected object
Definition: TCanvas.h:50
void SetCanvasSize(UInt_t ww, UInt_t wh) override
Set Width and Height of canvas to ww and wh respectively.
Definition: TCanvas.cxx:1973
void Show()
Show canvas.
Definition: TCanvas.cxx:2214
TPad * fSelectedPad
! Pad containing currently selected object
Definition: TCanvas.h:54
virtual void Selected(TVirtualPad *pad, TObject *obj, Int_t event)
Emit Selected() signal.
Definition: TCanvas.cxx:1631
Int_t fSelectedX
! X of selected object
Definition: TCanvas.h:51
virtual void ToggleEditor()
Toggle editor.
Definition: TCanvas.cxx:2442
TVirtualPad * GetSelectedPad() const override
Definition: TCanvas.h:145
virtual void Picked(TPad *selpad, TObject *selected, Int_t event)
Emit Picked() signal.
Definition: TCanvas.cxx:1585
TObject * fSelected
! Currently selected object
Definition: TCanvas.h:49
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitives in this canvas in C++ macro file with GUI.
Definition: TCanvas.cxx:1772
void SetCursor(ECursor cursor) override
Set cursor.
Definition: TCanvas.cxx:1989
void Streamer(TBuffer &) override
Stream a class object.
Definition: TCanvas.cxx:2223
Bool_t GetShowToolTips() const
Definition: TCanvas.h:150
Int_t fCanvasID
! Canvas identifier
Definition: TCanvas.h:48
void SetGrayscale(Bool_t set=kTRUE)
Set whether this canvas should be painted in grayscale, and re-paint it if necessary.
Definition: TCanvas.cxx:2546
void SetTitle(const char *title="") override
Set canvas title.
Definition: TCanvas.cxx:2157
UInt_t fCh
Height of the canvas along Y (pixels)
Definition: TCanvas.h:44
TContextMenu * fContextMenu
! Context menu pointer
Definition: TCanvas.h:58
TAttCanvas fCatt
Canvas attributes.
Definition: TCanvas.h:31
void SetName(const char *name="") override
Set canvas name. In case name is an empty string, a default name is set.
Definition: TCanvas.cxx:2045
UInt_t GetWindowWidth() const
Definition: TCanvas.h:160
Bool_t fRetained
Retain structure flag.
Definition: TCanvas.h:61
void DisconnectWidget()
Used by friend class TCanvasImp.
Definition: TCanvas.cxx:2528
void FeedbackMode(Bool_t set)
Turn rubberband feedback mode on or off.
Definition: TCanvas.cxx:1122
void ls(Option_t *option="") const override
List all pads.
Definition: TCanvas.cxx:1496
void RaiseWindow()
Raise canvas window.
Definition: TCanvas.cxx:1739
void Build()
Build a canvas. Called by all constructors.
Definition: TCanvas.cxx:579
Int_t fWindowTopY
Top Y position of window (in pixels)
Definition: TCanvas.h:40
void Paint(Option_t *option="") override
Paint canvas.
Definition: TCanvas.cxx:1535
TClass * IsA() const override
Definition: TCanvas.h:232
void Update() override
Update canvas pad buffers.
Definition: TCanvas.cxx:2478
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition: TCanvas.cxx:1104
void RunAutoExec()
Execute the list of TExecs in the current pad.
Definition: TCanvas.cxx:1762
virtual void Cleared(TVirtualPad *pad)
Emit pad Cleared signal.
Definition: TCanvas.cxx:763
UInt_t GetWw() const override
Definition: TCanvas.h:162
TCanvasImp * fCanvasImp
! Window system specific canvas implementation
Definition: TCanvas.h:57
UInt_t GetWh() const override
Definition: TCanvas.h:163
virtual void Highlighted(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y)
Emit Highlighted() signal.
Definition: TCanvas.cxx:1604
void Flush()
Flush canvas buffers.
Definition: TCanvas.cxx:1136
Size_t fYsizeUser
User specified size of canvas along Y in CM.
Definition: TCanvas.h:34
Int_t fDoubleBuffer
Double buffer flag (0=off, 1=on)
Definition: TCanvas.h:38
void ForceUpdate()
Force canvas update.
Definition: TCanvas.cxx:1170
void CreatePainter()
Probably, TPadPainter must be placed in a separate ROOT module - "padpainter" (the same as "histpaint...
Definition: TCanvas.cxx:2560
void SetSelected(TObject *obj) override
Set selected canvas.
Definition: TCanvas.cxx:2148
void MoveOpaque(Int_t set=1)
Set option to move objects/pads in a canvas.
Definition: TCanvas.cxx:1527
virtual ~TCanvas()
Canvas destructor.
Definition: TCanvas.cxx:669
static Bool_t fgIsFolder
Indicates if canvas can be browsed as a folder.
Definition: TCanvas.h:67
void Closed() override
Emit Closed signal.
Definition: TCanvas.cxx:771
void SetWindowPosition(Int_t x, Int_t y)
Set canvas window position.
Definition: TCanvas.cxx:2166
TString fDISPLAY
Name of destination screen.
Definition: TCanvas.h:32
bool SetRealAspectRatio(const Int_t axis=1)
Function to resize a canvas so that the plot inside is shown in real aspect ratio.
Definition: TCanvas.cxx:2081
Int_t fEvent
! Type of current or last handled event
Definition: TCanvas.h:45
Bool_t GetShowEventStatus() const
Definition: TCanvas.h:147
TString fSelectedOpt
! Drawing option of selected object
Definition: TCanvas.h:53
Int_t fSelectedY
! Y of selected object
Definition: TCanvas.h:52
Bool_t fDrawn
! Set to True when the Draw method is called
Definition: TCanvas.h:63
void SetBatch(Bool_t batch=kTRUE) override
Toggle batch mode.
Definition: TCanvas.cxx:1957
Bool_t UseGL() const
Definition: TCanvas.h:224
@ kResizeOpaque
Definition: TCanvas.h:94
@ kShowToolTips
Definition: TCanvas.h:96
@ kShowToolBar
Definition: TCanvas.h:91
@ kMoveOpaque
Definition: TCanvas.h:93
@ kIsGrayscale
Definition: TCanvas.h:95
@ kShowEventStatus
Definition: TCanvas.h:88
@ kAutoExec
Definition: TCanvas.h:89
@ kMenuBar
Definition: TCanvas.h:90
@ kShowEditor
Definition: TCanvas.h:92
void ResizeOpaque(Int_t set=1)
Set option to resize objects/pads in a canvas.
Definition: TCanvas.cxx:1754
virtual void ToggleToolBar()
Toggle toolbar.
Definition: TCanvas.cxx:2431
virtual TObject * DrawClonePad()
Draw a clone of this canvas into the current pad In an interactive session, select the destination/cu...
Definition: TCanvas.cxx:912
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:81
@ kRealNew
Definition: TClass.h:108
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition: TClass.cxx:5891
@ kClassSaved
Definition: TClass.h:95
void SetName(const char *name)
Definition: TCollection.h:206
void Browse(TBrowser *b) override
Browse this collection (called by TBrowser).
The color creation and management class.
Definition: TColor.h:19
virtual void SetRGB(Float_t r, Float_t g, Float_t b)
Initialize this color and its associated colors.
Definition: TColor.cxx:1759
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition: TColor.cxx:1462
Float_t GetRed() const
Definition: TColor.h:58
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2187
Int_t GetNumber() const
Definition: TColor.h:56
Float_t GetBlue() const
Definition: TColor.h:60
Float_t GetGreen() const
Definition: TColor.h:59
static Bool_t DefinedColors()
Static function returning kTRUE if some new colors have been defined after initialisation or since th...
Definition: TColor.cxx:1480
This class provides an interface to context sensitive popup menus.
Definition: TContextMenu.h:44
virtual void Popup(Int_t x, Int_t y, TObject *obj, TVirtualPad *c=nullptr, TVirtualPad *p=nullptr)
Popup context menu at given location in canvas c and pad p for selected object.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
const char * AsSQLString() const
Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.
Definition: TDatime.cxx:152
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:182
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition: TDatime.cxx:102
static TClass * Class()
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual TCanvasImp * CreateCanvasImp(TCanvas *c, const char *title, UInt_t width, UInt_t height)
Create a batch version of TCanvasImp.
Definition: TGuiFactory.cxx:58
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
Option_t * GetOption() const
Definition: TCollection.h:253
void Reset()
Definition: TCollection.h:254
A doubly linked list.
Definition: TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition: TList.cxx:578
void Add(TObject *obj) override
Definition: TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition: TList.cxx:822
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
An array of TObjects.
Definition: TObjArray.h:31
Int_t GetEntries() const override
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:523
static TClass * Class()
void Add(TObject *obj) override
Definition: TObjArray.h:68
Mother of all ROOT objects.
Definition: TObject.h:41
virtual void Clear(Option_t *="")
Definition: TObject.h:119
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:440
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:201
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:223
R__ALWAYS_INLINE Bool_t IsOnHeap() const
Definition: TObject.h:152
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:207
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:956
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to an event at (px,py).
Definition: TObject.cxx:394
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition: TObject.cxx:469
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:775
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:526
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:970
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:484
virtual void Pop()
Pop on object drawn in a pad to the top of the display list.
Definition: TObject.cxx:611
void ResetBit(UInt_t f)
Definition: TObject.h:200
@ kNoContextMenu
if object does not want context menu
Definition: TObject.h:69
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition: TObject.h:64
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:944
Implement TVirtualPadPainter which abstracts painting operations.
Definition: TPadPainter.h:26
The most important graphics class in the ROOT system.
Definition: TPad.h:28
void SetGridx(Int_t value=1) override
Definition: TPad.h:331
Short_t GetBorderMode() const override
Definition: TPad.h:197
void SetBorderSize(Short_t bordersize) override
Definition: TPad.h:321
Int_t GetTicky() const override
Definition: TPad.h:237
void PaintBorder(Color_t color, Bool_t tops)
Paint the pad border.
Definition: TPad.cxx:3467
void ResizePad(Option_t *option="") override
Compute pad conversion coefficients.
Definition: TPad.cxx:5446
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
Definition: TPad.h:330
void SetTickx(Int_t value=1) override
Definition: TPad.h:351
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitives in this pad on the C++ source file out.
Definition: TPad.cxx:5671
Bool_t GetGridx() const override
Definition: TPad.h:233
Double_t fX2
X of upper X coordinate.
Definition: TPad.h:38
void SetLogz(Int_t value=1) override
Set Lin/Log scale for Z.
Definition: TPad.cxx:5934
Double_t GetY2() const override
Definition: TPad.h:241
void Close(Option_t *option="") override
Delete all primitives in pad and pad itself.
Definition: TPad.cxx:975
void PaintModified() override
Traverse pad hierarchy and (re)paint only modified pads.
Definition: TPad.cxx:3635
const char * GetTitle() const override
Returns title of object.
Definition: TPad.h:259
Double_t fX1
X of lower X coordinate.
Definition: TPad.h:36
TList * GetListOfPrimitives() const override
Definition: TPad.h:243
void SetFillStyle(Style_t fstyle) override
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition: TPad.cxx:5897
void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1) override
Set all pad parameters.
Definition: TPad.cxx:5994
void UseCurrentStyle() override
Force a copy of current style for all objects in pad.
Definition: TPad.cxx:6747
void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Set world coordinate system for the pad.
Definition: TPad.cxx:5165
Double_t fY1
Y of lower Y coordinate.
Definition: TPad.h:37
Int_t fGLDevice
! OpenGL off-screen pixmap identifier
Definition: TPad.h:85
void Update() override
Update pad.
Definition: TPad.cxx:2822
void Clear(Option_t *option="") override
Delete all pad primitives.
Definition: TPad.cxx:627
Int_t GetTickx() const override
Definition: TPad.h:236
Double_t fAspectRatio
ratio of w/h in case of fixed ratio
Definition: TPad.h:82
void Modified(Bool_t flag=1) override
Definition: TPad.h:417
void SetLogy(Int_t value=1) override
Set Lin/Log scale for Y.
Definition: TPad.cxx:5923
void HighLight(Color_t col=kRed, Bool_t set=kTRUE) override
Highlight pad.
Definition: TPad.cxx:2926
TCanvas * fCanvas
! Pointer to mother canvas
Definition: TPad.h:106
Bool_t fFixedAspectRatio
True if fixed aspect ratio.
Definition: TPad.h:104
void ls(Option_t *option="") const override
List all primitives in pad.
Definition: TPad.cxx:2961
void Streamer(TBuffer &) override
Stream a class object.
Definition: TPad.cxx:6538
TString fTitle
Pad title.
Definition: TPad.h:110
void CopyPixmaps() override
Copy the sub-pixmaps of the pad to the canvas.
Definition: TPad.cxx:1047
void CopyPixmap() override
Copy the pixmap of the pad to the canvas.
Definition: TPad.cxx:1033
Double_t GetY1() const override
Definition: TPad.h:240
Bool_t GetGridy() const override
Definition: TPad.h:234
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition: TPad.cxx:1684
Int_t GetLogz() const override
Definition: TPad.h:256
Short_t GetBorderSize() const override
Definition: TPad.h:198
TList * fPrimitives
->List of primitives (subpads)
Definition: TPad.h:107
TCanvas * GetCanvas() const override
Definition: TPad.h:260
Short_t fBorderSize
pad bordersize in pixels
Definition: TPad.h:97
void SetGridy(Int_t value=1) override
Definition: TPad.h:332
void Paint(Option_t *option="") override
Paint all primitives in pad.
Definition: TPad.cxx:3406
TString fName
Pad name.
Definition: TPad.h:109
Int_t fPixmapID
! Off-screen pixmap identifier
Definition: TPad.h:84
Color_t GetHighLightColor() const override
Get highlight color.
Definition: TPad.cxx:2680
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition: TPad.cxx:598
Int_t GetLogy() const override
Definition: TPad.h:255
void SetBorderMode(Short_t bordermode) override
Definition: TPad.h:320
void SetTicks(Int_t valuex=1, Int_t valuey=1) override
Definition: TPad.h:350
void SetTicky(Int_t value=1) override
Definition: TPad.h:352
Double_t fY2
Y of upper Y coordinate.
Definition: TPad.h:39
Short_t fBorderMode
Bordermode (-1=down, 0 = no border, 1=up)
Definition: TPad.h:98
void SetLogx(Int_t value=1) override
Set Lin/Log scale for X.
Definition: TPad.cxx:5909
Int_t GetLogx() const override
Definition: TPad.h:254
Double_t GetX2() const override
Definition: TPad.h:239
Double_t GetX1() const override
Definition: TPad.h:238
TPad * fMother
! pointer to mother of the list
Definition: TPad.h:105
const char * GetName() const override
Returns name of object.
Definition: TPad.h:258
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:869
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition: TROOT.cxx:2805
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2813
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2698
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1159
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1140
const char * Data() const
Definition: TString.h:369
@ kBoth
Definition: TString.h:267
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:925
Bool_t IsNull() const
Definition: TString.h:407
virtual void Streamer(TBuffer &)
Stream a string object.
Definition: TString.cxx:1379
TString & Append(const char *cs)
Definition: TString.h:564
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2323
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:639
Double_t GetTimeOffset() const
Definition: TStyle.h:261
Int_t GetOptLogy() const
Definition: TStyle.h:240
Int_t GetOptStat() const
Definition: TStyle.h:237
Int_t GetOptTitle() const
Definition: TStyle.h:238
void SetCanvasBorderSize(Width_t size=1)
Definition: TStyle.h:329
Float_t GetScreenFactor() const
Definition: TStyle.h:248
Int_t GetPadTickX() const
Definition: TStyle.h:209
Bool_t IsReading() const
Definition: TStyle.h:283
void SetCanvasColor(Color_t color=19)
Definition: TStyle.h:328
Float_t GetPadRightMargin() const
Definition: TStyle.h:206
void SetCanvasBorderMode(Int_t mode=1)
Definition: TStyle.h:330
Int_t GetCanvasDefH() const
Definition: TStyle.h:184
Int_t GetCanvasDefX() const
Definition: TStyle.h:186
Bool_t GetPadGridY() const
Definition: TStyle.h:208
Float_t GetPadLeftMargin() const
Definition: TStyle.h:205
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1781
Bool_t GetCanvasPreferGL() const
Definition: TStyle.h:180
Int_t GetCanvasDefY() const
Definition: TStyle.h:187
Bool_t GetPadGridX() const
Definition: TStyle.h:207
Int_t GetPadTickY() const
Definition: TStyle.h:210
Color_t GetCanvasColor() const
Definition: TStyle.h:181
Float_t GetPadBottomMargin() const
Definition: TStyle.h:203
Int_t GetCanvasDefW() const
Definition: TStyle.h:185
Int_t GetOptLogx() const
Definition: TStyle.h:239
Int_t GetCanvasBorderMode() const
Definition: TStyle.h:183
Width_t GetCanvasBorderSize() const
Definition: TStyle.h:182
Int_t GetOptFit() const
Definition: TStyle.h:236
Int_t GetOptLogz() const
Definition: TStyle.h:241
Float_t GetPadTopMargin() const
Definition: TStyle.h:204
static TClass * Class()
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition: TVirtualPS.h:30
static TVirtualPadEditor * GetPadEditor(Bool_t load=kTRUE)
Returns the pad editor dialog. Static method.
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
virtual void LockPainter()
Empty definition.
static TVirtualPadPainter * PadPainter(Option_t *opt="")
Create a pad painter of specified type.
virtual void SelectDrawable(Int_t device)=0
virtual void InitPainter()
Empty definition.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:51
static TClass * Class()
RVec< PromoteType< T > > abs(const RVec< T > &v)
Definition: RVec.hxx:1769
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
Definition: TObject.h:404
void(off) SmallVectorTemplateBase< T
static constexpr double s
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition: TMath.h:691
Definition: first.py:1