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