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