Logo ROOT   6.08/07
Reference Guide
X11Buffer.h
Go to the documentation of this file.
1 // @(#)root/graf2d:$Id$
2 // Author: Timur Pocheptsov 29/02/2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, 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_X11Buffer
13 #define ROOT_X11Buffer
14 
15 #include <vector>
16 #include <string>
17 
18 #include <Cocoa/Cocoa.h>
19 
20 #ifndef ROOT_CocoaGuiTypes
21 #include "CocoaGuiTypes.h"
22 #endif
23 #ifndef ROOT_GuiTypes
24 #include "GuiTypes.h"
25 #endif
26 
27 //////////////////////////////////////////////////////////////////////////////////
28 // //
29 // Unfortunately, TGCocoa's drawing methods can be called in a //
30 // "wrong" time and place: not from QuartzView -drawRect. //
31 // For example, on mouse move. This is bad and unnatural for Cocoa application, //
32 // since I expect GUI to draw only when I'm ready == ... called from drawRect. //
33 // In X11 commands are buffered and this buffer is flushed at some points. //
34 // I'm trying to emulate this, just to make GUI happy. //
35 // //
36 //////////////////////////////////////////////////////////////////////////////////
37 
38 @class QuartzView;
39 
40 namespace ROOT {
41 namespace MacOSX {
42 
43 namespace Details {
44 class CocoaPrivate;
45 }
46 
47 namespace X11 {
48 
49 class Command {
50  friend class CommandBuffer;
51 
52 protected:
53  const Drawable_t fID;
54  const GCValues_t fGC;
55 
56 public:
57  Command(Drawable_t wid);
58  Command(Drawable_t wid, const GCValues_t &gc);
59  virtual ~Command();
60 
61  virtual bool HasOperand(Drawable_t drawable)const;
62  virtual bool IsGraphicsCommand()const;//By-default - false.
63 
64  virtual void Execute()const = 0;
65  virtual void Execute(CGContextRef /*ctx*/)const;
66 
67 private:
68  Command(const Command &rhs);
69  Command &operator = (const Command &rhs);
70 };
71 
72 class DrawLine : public Command {
73 private:
74  const Point fP1;
75  const Point fP2;
76 
77 public:
78  DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2);
79  void Execute()const;
80  bool IsGraphicsCommand()const
81  {
82  return true;
83  }
84 };
85 
86 class DrawSegments : public Command {
87 private:
88  std::vector<Segment_t> fSegments;
89 
90 public:
91  DrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
92  void Execute()const;
93  bool IsGraphicsCommand()const
94  {
95  return true;
96  }
97 };
98 
99 class ClearArea : public Command {
100 private:
101  const Rectangle_t fArea;//to be replaced with X11::Rectangle
102 
103 public:
104  ClearArea(Window_t wid, const Rectangle_t &area);
105  void Execute()const;
106  bool IsGraphicsCommand()const
107  {
108  return true;
109  }
110 };
111 
112 class CopyArea : public Command {
113 private:
115  const Rectangle_t fArea;//to be replaced with X11::Rectangle
117 
118 public:
119  CopyArea(Drawable_t src, Drawable_t dst, const GCValues_t &gc, const Rectangle_t &area, const Point &dstPoint);
120 
121  bool HasOperand(Drawable_t drawable)const;
122  bool IsGraphicsCommand()const
123  {
124  return true;
125  }
126 
127  void Execute()const;
128 
129 };
130 
131 class DrawString : public Command {
132 private:
133  const Point fPoint;
134  const std::string fText;
135 
136 public:
137  DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text);
138 
139  bool IsGraphicsCommand()const
140  {
141  return true;
142  }
143 
144  void Execute()const;
145 };
146 
147 class FillRectangle : public Command {
148 private:
149  const Rectangle_t fRectangle;//to be replaced with X11::Rectangle
150 
151 public:
152  FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
153 
154  bool IsGraphicsCommand()const
155  {
156  return true;
157  }
158 
159  void Execute()const;
160 };
161 
162 class FillPolygon : public Command {
163 private:
164  std::vector<Point_t> fPolygon;
165 
166 public:
167  FillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *points, Int_t nPoints);
168 
169  bool IsGraphicsCommand()const
170  {
171  return true;
172  }
173 
174  void Execute()const;
175 };
176 
177 class DrawRectangle : public Command {
178 private:
179  Rectangle_t fRectangle;//to be replaced with X11::Rectangle
180 
181 public:
182  DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
183 
184  bool IsGraphicsCommand()const
185  {
186  return true;
187  }
188 
189  void Execute()const;
190 };
191 
192 class UpdateWindow : public Command {
193 private:
195 
196 public:
197  UpdateWindow(QuartzView *view);
198 
199  bool IsGraphicsCommand()const
200  {
201  return true;
202  }
203 
204  void Execute()const;
205 };
206 
207 class DeletePixmap : public Command {
208 public:
209  DeletePixmap(Pixmap_t pixmap);
210  void Execute()const;
211 };
212 
213 //Set of 'xor' operations, required by TCanvas and ExecuteEvent's machinery.
214 class DrawBoxXor : public Command {
215 private:
218 
219 public:
220  DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2);
221 
222  void Execute()const;
223  void Execute(CGContextRef ctx)const;
224 };
225 
226 class DrawLineXor : public Command {
227 private:
230 
231 public:
232  DrawLineXor(Window_t windowID, const Point &p1, const Point &p2);
233 
234  void Execute()const;
235  void Execute(CGContextRef ctx)const;
236 };
237 
239 private:
240  CommandBuffer(const CommandBuffer &rhs);
241  CommandBuffer &operator = (const CommandBuffer &rhs);
242 
243  std::vector<Command *> fCommands;
244  std::vector<QuartzView *> fViewBranch;
245 
246  std::vector<Command *> fXorOps;
247 public:
248  typedef std::vector<Command *>::size_type size_type;
249 
250  CommandBuffer();
251  ~CommandBuffer();
252 
253  void AddDrawLine(Drawable_t wid, const GCValues_t &gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
254  void AddDrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
255  void AddClearArea(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h);
256  void AddCopyArea(Drawable_t src, Drawable_t dst, const GCValues_t &gc, Int_t srcX, Int_t srcY, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY);
257  void AddDrawString(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *text, Int_t len);
258  void AddFillRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h);
259  void AddFillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *polygon, Int_t nPoints);
260  void AddDrawRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h);
261  void AddUpdateWindow(QuartzView *view);
262  void AddDeletePixmap(Pixmap_t pixmap);
263 
264  //'XOR' graphics for canvas.
265  void AddDrawBoxXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
266  void AddDrawLineXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
267 
268  void Flush(Details::CocoaPrivate *impl);
269  void FlushXOROps(Details::CocoaPrivate *impl);
270  void RemoveOperationsForDrawable(Drawable_t wid);
271  void RemoveGraphicsOperationsForWindow(Window_t wid);
272  void RemoveXORGraphicsOperationsForWindow(Window_t wid);
273 
274  size_type BufferSize()const
275  {
276  return fCommands.size();
277  }
278 private:
279  void ClearCommands();
280  void ClearXOROperations();
281 
282  //Clip related stuff.
283 
284  struct WidgetRect {
285  int fX1;
286  int fY1;
287  int fX2;
288  int fY2;
289 
291  : fX1(0), fY1(0), fX2(0), fY2(0)
292  {
293  }
294 
295  WidgetRect(int leftX, int bottomY, int rightX, int topY)
296  : fX1(leftX), fY1(bottomY), fX2(rightX), fY2(topY)
297  {
298  }
299  };
300 
301  void ClipOverlaps(QuartzView *view);
302  void BuildClipRegion(const WidgetRect &rect);
303 
304  std::vector<WidgetRect> fRectsToClip;
305  std::vector<CGRect> fClippedRegion;
306  std::vector<int> fXBounds;
307  std::vector<int> fYBounds;
308  std::vector<bool> fGrid;
309 };
310 
311 }//X11
312 }//MacOSX
313 }//ROOT
314 
315 #endif
std::vector< bool > fGrid
Definition: X11Buffer.h:308
std::vector< Command * > fCommands
Definition: X11Buffer.h:243
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
std::vector< WidgetRect > fRectsToClip
Definition: X11Buffer.h:304
TH1 * h
Definition: legend2.C:5
bool IsGraphicsCommand() const
Definition: X11Buffer.h:80
int Int_t
Definition: RtypesCore.h:41
size_type BufferSize() const
Definition: X11Buffer.h:274
Handle_t Drawable_t
Definition: GuiTypes.h:32
const GCValues_t fGC
Definition: X11Buffer.h:54
bool IsGraphicsCommand() const
Definition: X11Buffer.h:122
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
std::vector< QuartzView * > fViewBranch
Definition: X11Buffer.h:244
static double p2(double t, double a, double b, double c)
std::vector< Segment_t > fSegments
Definition: X11Buffer.h:88
const std::string fText
Definition: X11Buffer.h:134
point * points
Definition: X3DBuffer.c:20
std::vector< CGRect > fClippedRegion
Definition: X11Buffer.h:305
const Drawable_t fSrc
Definition: X11Buffer.h:114
bool IsGraphicsCommand() const
Definition: X11Buffer.h:106
const Rectangle_t fRectangle
Definition: X11Buffer.h:149
const Rectangle_t fArea
Definition: X11Buffer.h:101
std::vector< Command * > fXorOps
Definition: X11Buffer.h:246
unsigned int UInt_t
Definition: RtypesCore.h:42
static double p1(double t, double a, double b)
std::vector< int > fYBounds
Definition: X11Buffer.h:307
int topY
lv DrawLine(0.33, 0.0, 0.33, 1.0)
bool IsGraphicsCommand() const
Definition: X11Buffer.h:139
const Drawable_t fID
Definition: X11Buffer.h:53
std::vector< Command * >::size_type size_type
Definition: X11Buffer.h:248
static const double x1[5]
TText * text
std::vector< Point_t > fPolygon
Definition: X11Buffer.h:164
const Rectangle_t fArea
Definition: X11Buffer.h:115
Double_t y[n]
Definition: legend1.C:17
Handle_t Window_t
Definition: GuiTypes.h:30
Handle_t Pixmap_t
Definition: GuiTypes.h:31
std::vector< int > fXBounds
Definition: X11Buffer.h:306
WidgetRect(int leftX, int bottomY, int rightX, int topY)
Definition: X11Buffer.h:295