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