Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TCanvas.h
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 #ifndef ROOT_TCanvas
13 #define ROOT_TCanvas
14 
15 
16 
17 #include "TPad.h"
18 
19 #include "TAttCanvas.h"
20 
21 #include "TVirtualX.h"
22 
23 #include "TString.h"
24 
25 #include "TCanvasImp.h"
26 
27 class TContextMenu;
28 class TControlBar;
29 class TBrowser;
30 
31 class TCanvas : public TPad {
32 
33 friend class TCanvasImp;
34 friend class TThread;
35 friend class TInterpreter;
36 
37 protected:
38  TAttCanvas fCatt; ///< Canvas attributes
39  TString fDISPLAY; ///< Name of destination screen
40  Size_t fXsizeUser; ///< User specified size of canvas along X in CM
41  Size_t fYsizeUser; ///< User specified size of canvas along Y in CM
42  Size_t fXsizeReal; ///< Current size of canvas along X in CM
43  Size_t fYsizeReal; ///< Current size of canvas along Y in CM
44  Color_t fHighLightColor; ///< Highlight color of active pad
45  Int_t fDoubleBuffer; ///< Double buffer flag (0=off, 1=on)
46  Int_t fWindowTopX; ///< Top X position of window (in pixels)
47  Int_t fWindowTopY; ///< Top Y position of window (in pixels)
48  UInt_t fWindowWidth; ///< Width of window (including borders, etc.)
49  UInt_t fWindowHeight; ///< Height of window (including menubar, borders, etc.)
50  UInt_t fCw; ///< Width of the canvas along X (pixels)
51  UInt_t fCh; ///< Height of the canvas along Y (pixels)
52  Int_t fEvent; ///<! Type of current or last handled event
53  Int_t fEventX; ///<! Last X mouse position in canvas
54  Int_t fEventY; ///<! Last Y mouse position in canvas
55  Int_t fCanvasID; ///<! Canvas identifier
56  TObject *fSelected; ///<! Currently selected object
57  TObject *fClickSelected; ///<! Currently click-selected object
58  Int_t fSelectedX; ///<! X of selected object
59  Int_t fSelectedY; ///<! Y of selected object
60  TString fSelectedOpt; ///<! Drawing option of selected object
61  TPad *fSelectedPad; ///<! Pad containing currently selected object
62  TPad *fClickSelectedPad;///<! Pad containing currently click-selected object
63  TPad *fPadSave; ///<! Pointer to saved pad in HandleInput
64  TCanvasImp *fCanvasImp; ///<! Window system specific canvas implementation
65  TContextMenu *fContextMenu; ///<! Context menu pointer
66  Bool_t fBatch; ///<! True when in batchmode
67  Bool_t fUpdating; ///<! True when Updating the canvas
68  Bool_t fRetained; ///< Retain structure flag
69  Bool_t fUseGL; ///<! True when rendering is with GL
70  Bool_t fDrawn; ///<! Set to True when the Draw method is called
71  //
72  TVirtualPadPainter *fPainter; ///<! Canvas (pad) painter.
73 
74  static Bool_t fgIsFolder; ///< Indicates if canvas can be browsed as a folder
75 
76 private:
77  TCanvas(const TCanvas &canvas); // cannot copy canvas, use TObject::Clone()
78  TCanvas &operator=(const TCanvas &rhs); // idem
79  void Build();
80  void CopyPixmaps();
81  void DrawEventStatus(Int_t event, Int_t x, Int_t y, TObject *selected);
82  void RunAutoExec();
83 
84  //Initialize PadPainter.
85  void CreatePainter();
86 
87 protected:
88  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
89  //-- used by friend TThread class
90  void Init();
91 
92 public:
93  // TCanvas status bits
94  enum {
95  kShowEventStatus = BIT(15),
96  kAutoExec = BIT(16),
97  kMenuBar = BIT(17),
98  kShowToolBar = BIT(18),
99  kShowEditor = BIT(19),
100  kMoveOpaque = BIT(20),
101  kResizeOpaque = BIT(21),
102  kIsGrayscale = BIT(22),
103  kShowToolTips = BIT(23)
104  };
105 
106  TCanvas(Bool_t build=kTRUE);
107  TCanvas(const char *name, const char *title="", Int_t form=1);
108  TCanvas(const char *name, const char *title, Int_t ww, Int_t wh);
109  TCanvas(const char *name, const char *title, Int_t wtopx, Int_t wtopy,
110  Int_t ww, Int_t wh);
111  TCanvas(const char *name, Int_t ww, Int_t wh, Int_t winid);
112  virtual ~TCanvas();
113 
114  //-- used by friend TThread class
115  void Constructor();
116  void Constructor(const char *name, const char *title, Int_t form);
117  void Constructor(const char *name, const char *title, Int_t ww, Int_t wh);
118  void Constructor(const char *name, const char *title,
119  Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh);
120  void Destructor();
121 
122  TVirtualPad *cd(Int_t subpadnumber=0);
123  virtual void Browse(TBrowser *b);
124  void Clear(Option_t *option="");
125  void Close(Option_t *option="");
126  virtual void Delete(Option_t * = "") { MayNotUse("Delete()"); }
127  void DisconnectWidget(); // used by TCanvasImp
128  virtual void Draw(Option_t *option="");
129  virtual TObject *DrawClone(Option_t *option="") const; // *MENU*
130  virtual TObject *DrawClonePad(); // *MENU*
131  virtual void EditorBar();
132  void EmbedInto(Int_t winid, Int_t ww, Int_t wh);
133  void EnterLeave(TPad *prevSelPad, TObject *prevSelObj);
134  void FeedbackMode(Bool_t set);
135  void Flush();
136  void UseCurrentStyle(); // *MENU*
137  void ForceUpdate() { if (fCanvasImp) fCanvasImp->ForceUpdate(); }
138  const char *GetDISPLAY() const {return fDISPLAY.Data();}
139  TContextMenu *GetContextMenu() const {return fContextMenu;};
140  Int_t GetDoubleBuffer() const {return fDoubleBuffer;}
141  Int_t GetEvent() const { return fEvent; }
142  Int_t GetEventX() const { return fEventX; }
143  Int_t GetEventY() const { return fEventY; }
144  Color_t GetHighLightColor() const { return fHighLightColor; }
145  TVirtualPad *GetPadSave() const { return fPadSave; }
146  void ClearPadSave() { fPadSave = 0; }
147  TObject *GetSelected() const {return fSelected;}
148  TObject *GetClickSelected() const {return fClickSelected;}
149  Int_t GetSelectedX() const {return fSelectedX;}
150  Int_t GetSelectedY() const {return fSelectedY;}
151  Option_t *GetSelectedOpt() const {return fSelectedOpt.Data();}
152  TVirtualPad *GetSelectedPad() const { return fSelectedPad; }
153  TVirtualPad *GetClickSelectedPad() const { return fClickSelectedPad; }
154  Bool_t GetShowEventStatus() const { return TestBit(kShowEventStatus); }
155  Bool_t GetShowToolBar() const { return TestBit(kShowToolBar); }
156  Bool_t GetShowEditor() const { return TestBit(kShowEditor); }
157  Bool_t GetShowToolTips() const { return TestBit(kShowToolTips); }
158  Bool_t GetAutoExec() const { return TestBit(kAutoExec); }
159  Size_t GetXsizeUser() const {return fXsizeUser;}
160  Size_t GetYsizeUser() const {return fYsizeUser;}
161  Size_t GetXsizeReal() const {return fXsizeReal;}
162  Size_t GetYsizeReal() const {return fYsizeReal;}
163  Int_t GetCanvasID() const {return fCanvasID;}
164  TCanvasImp *GetCanvasImp() const {return fCanvasImp;}
165  Int_t GetWindowTopX();
166  Int_t GetWindowTopY();
167  UInt_t GetWindowWidth() const { return fWindowWidth; }
168  UInt_t GetWindowHeight() const { return fWindowHeight; }
169  UInt_t GetWw() const { return fCw; }
170  UInt_t GetWh() const { return fCh; }
171  virtual void GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
172  {wtopx=GetWindowTopX(); wtopy=fWindowTopY; ww=fWindowWidth; wh=fWindowHeight;}
173  virtual void HandleInput(EEventType button, Int_t x, Int_t y);
174  Bool_t HasMenuBar() const { return TestBit(kMenuBar); }
175  virtual void HighlightConnect(const char *slot);
176  void Iconify() { if (fCanvasImp) fCanvasImp->Iconify(); }
177  Bool_t IsBatch() const { return fBatch; }
178  Bool_t IsDrawn() { return fDrawn; }
179  Bool_t IsFolder() const;
180  Bool_t IsGrayscale();
181  Bool_t IsRetained() const { return fRetained; }
182  Bool_t IsWeb() const { return fCanvasImp ? fCanvasImp->IsWeb() : kFALSE; }
183  virtual void ls(Option_t *option="") const;
184  void MoveOpaque(Int_t set=1);
185  Bool_t OpaqueMoving() const { return TestBit(kMoveOpaque); }
186  Bool_t OpaqueResizing() const { return TestBit(kResizeOpaque); }
187  virtual void Paint(Option_t *option="");
188  virtual TPad *Pick(Int_t px, Int_t py, TObjLink *&pickobj) { return TPad::Pick(px, py, pickobj); }
189  virtual TPad *Pick(Int_t px, Int_t py, TObject *prevSelObj);
190  virtual void Picked(TPad *selpad, TObject *selected, Int_t event); // *SIGNAL*
191  virtual void Highlighted(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y); // *SIGNAL*
192  virtual void ProcessedEvent(Int_t event, Int_t x, Int_t y, TObject *selected); // *SIGNAL*
193  virtual void Selected(TVirtualPad *pad, TObject *obj, Int_t event); // *SIGNAL*
194  virtual void Cleared(TVirtualPad *pad); // *SIGNAL*
195  virtual void Closed(); // *SIGNAL*
196  void RaiseWindow() { if (fCanvasImp) fCanvasImp->RaiseWindow(); }
197  void ResetDrawn() { fDrawn=kFALSE; }
198  virtual void Resize(Option_t *option="");
199  void ResizeOpaque(Int_t set=1);
200  void SaveSource(const char *filename="", Option_t *option="");
201  void SavePrimitive(std::ostream &out, Option_t *option = "");
202  virtual void SetCursor(ECursor cursor);
203  virtual void SetDoubleBuffer(Int_t mode=1);
204  virtual void SetName(const char *name="");
205  virtual void SetFixedAspectRatio(Bool_t fixed = kTRUE); // *TOGGLE*
206  void SetGrayscale(Bool_t set = kTRUE); // *TOGGLE* *GETTER=IsGrayscale
207  void SetWindowPosition(Int_t x, Int_t y) { if (fCanvasImp) fCanvasImp->SetWindowPosition(x, y); }
208  void SetWindowSize(UInt_t ww, UInt_t wh)
209  {
210  if (fBatch)
211  SetCanvasSize((ww + fCw) / 2, (wh + fCh) / 2);
212  else if (fCanvasImp)
213  fCanvasImp->SetWindowSize(ww, wh);
214  }
215  void SetCanvasImp(TCanvasImp *i) { fCanvasImp = i; }
216  void SetCanvasSize(UInt_t ww, UInt_t wh); // *MENU*
217  void SetHighLightColor(Color_t col) { fHighLightColor = col; }
218  void SetSelected(TObject *obj);
219  void SetClickSelected(TObject *obj) { fClickSelected = obj; }
220  void SetSelectedPad(TPad *pad) { fSelectedPad = pad; }
221  void SetClickSelectedPad(TPad *pad) { fClickSelectedPad = pad; }
222  void Show() { if (fCanvasImp) fCanvasImp->Show(); }
223  virtual void Size(Float_t xsizeuser=0, Float_t ysizeuser=0);
224  void SetBatch(Bool_t batch=kTRUE);
225  static void SetFolder(Bool_t isfolder=kTRUE);
226  void SetPadSave(TPad *pad) {fPadSave = pad;}
227  void SetRetained(Bool_t retained=kTRUE) { fRetained=retained;}
228  void SetTitle(const char *title="");
229  virtual void ToggleEventStatus();
230  virtual void ToggleAutoExec();
231  virtual void ToggleToolBar();
232  virtual void ToggleEditor();
233  virtual void ToggleToolTips();
234  virtual void Update();
235 
236  Bool_t UseGL() const { return fUseGL; }
237  void SetSupportGL(Bool_t support) {fUseGL = support;}
238  TVirtualPadPainter *GetCanvasPainter();
239  void DeleteCanvasPainter();
240 
241  static TCanvas *MakeDefCanvas();
242  static Bool_t SupportAlpha();
243 
244  ClassDef(TCanvas,8) //Graphics canvas
245 };
246 
247 #endif