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