Logo ROOT  
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
36namespace ROOT {
37namespace MacOSX {
38
39namespace Details {
40class CocoaPrivate;
41}
42
43namespace X11 {
44
45class Command {
46 friend class CommandBuffer;
47
48protected:
51 NSView * view = nil;
52public:
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
64 {
65 view = v;
66 }
67private:
68 Command(const Command &rhs);
70};
71
72class DrawLine : public Command {
73private:
74 const Point fP1;
75 const Point fP2;
76
77public:
78 DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2);
79 void Execute()const;
81 {
82 return true;
83 }
84};
85
86class DrawSegments : public Command {
87private:
88 std::vector<Segment_t> fSegments;
89
90public:
91 DrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
92 void Execute()const;
94 {
95 return true;
96 }
97};
98
99class ClearArea : public Command {
100private:
101 const Rectangle_t fArea;//to be replaced with X11::Rectangle
102
103public:
104 ClearArea(Window_t wid, const Rectangle_t &area);
105 void Execute()const;
107 {
108 return true;
109 }
110};
111
112class CopyArea : public Command {
113private:
115 const Rectangle_t fArea;//to be replaced with X11::Rectangle
117
118public:
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;
123 {
124 return true;
125 }
126
127 void Execute()const;
128
129};
130
131class DrawString : public Command {
132private:
134 const std::string fText;
135
136public:
137 DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text);
138
140 {
141 return true;
142 }
143
144 void Execute()const;
145};
146
147class FillRectangle : public Command {
148private:
149 const Rectangle_t fRectangle;//to be replaced with X11::Rectangle
150
151public:
152 FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
153
155 {
156 return true;
157 }
158
159 void Execute()const;
160};
161
162class FillPolygon : public Command {
163private:
164 std::vector<Point_t> fPolygon;
165
166public:
167 FillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *points, Int_t nPoints);
168
170 {
171 return true;
172 }
173
174 void Execute()const;
175};
176
177class DrawRectangle : public Command {
178private:
179 Rectangle_t fRectangle;//to be replaced with X11::Rectangle
180
181public:
182 DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
183
185 {
186 return true;
187 }
188
189 void Execute()const;
190};
191
192class UpdateWindow : public Command {
193private:
195
196public:
198
200 {
201 return true;
202 }
203
204 void Execute()const;
205};
206
207class DeletePixmap : public Command {
208public:
209 DeletePixmap(Pixmap_t pixmap);
210 void Execute()const;
211};
212
213//Set of 'xor' operations, required by TCanvas and ExecuteEvent's machinery.
214class DrawBoxXor : public Command {
215private:
218
219public:
220 DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2);
221
222 void Execute()const;
223 void Execute(CGContextRef ctx)const;
224};
225
226class DrawLineXor : public Command {
227private:
230
231public:
232 DrawLineXor(Window_t windowID, const Point &p1, const Point &p2);
233
234 void Execute()const;
235 void Execute(CGContextRef ctx)const;
236
237 Point start() const {return fP1;}
238 Point end() const {return fP2;}
239};
240
242private:
245
246 std::vector<Command *> fCommands;
247 std::vector<QuartzView *> fViewBranch;
248
249 std::vector<Command *> fXorOps;
250public:
251 typedef std::vector<Command *>::size_type size_type;
252
255
256 void AddDrawLine(Drawable_t wid, const GCValues_t &gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
257 void AddDrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
258 void AddClearArea(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h);
259 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);
260 void AddDrawString(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *text, Int_t len);
261 void AddFillRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h);
262 void AddFillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *polygon, Int_t nPoints);
263 void AddDrawRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h);
264 void AddUpdateWindow(QuartzView *view);
265 void AddDeletePixmap(Pixmap_t pixmap);
266
267 //'XOR' graphics for canvas.
268 void AddDrawBoxXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
269 void AddDrawLineXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
270
271 void Flush(Details::CocoaPrivate *impl);
276
278 {
279 return fCommands.size();
280 }
281
282 void ClearXOROperations();
283private:
284 void ClearCommands();
285 //Clip related stuff.
286 struct WidgetRect {
287 int fX1;
288 int fY1;
289 int fX2;
290 int fY2;
291
293 : fX1(0), fY1(0), fX2(0), fY2(0)
294 {
295 }
296
297 WidgetRect(int leftX, int bottomY, int rightX, int topY)
298 : fX1(leftX), fY1(bottomY), fX2(rightX), fY2(topY)
299 {
300 }
301 };
302
303 void ClipOverlaps(QuartzView *view);
304 void BuildClipRegion(const WidgetRect &rect);
305
306 std::vector<WidgetRect> fRectsToClip;
307 std::vector<CGRect> fClippedRegion;
308 std::vector<int> fXBounds;
309 std::vector<int> fYBounds;
310 std::vector<bool> fGrid;
311};
312
313}//X11
314}//MacOSX
315}//ROOT
316
317#endif
Handle_t Pixmap_t
Pixmap handle.
Definition: GuiTypes.h:30
Handle_t Drawable_t
Drawable handle.
Definition: GuiTypes.h:31
Handle_t Window_t
Window handle.
Definition: GuiTypes.h:29
#define h(i)
Definition: RSha256.hxx:106
static const double x2[5]
static const double x1[5]
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
point * points
Definition: X3DBuffer.c:22
ClearArea(Window_t wid, const Rectangle_t &area)
Definition: X11Buffer.mm:111
const Rectangle_t fArea
Definition: X11Buffer.h:101
bool IsGraphicsCommand() const
Definition: X11Buffer.h:106
void RemoveXORGraphicsOperationsForWindow(Window_t wid)
Definition: X11Buffer.mm:675
void AddDrawBoxXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition: X11Buffer.mm:502
std::vector< WidgetRect > fRectsToClip
Definition: X11Buffer.h:306
std::vector< CGRect > fClippedRegion
Definition: X11Buffer.h:307
std::vector< Command * > fXorOps
Definition: X11Buffer.h:249
std::vector< bool > fGrid
Definition: X11Buffer.h:310
void AddDrawLineXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition: X11Buffer.mm:514
void Flush(Details::CocoaPrivate *impl)
Definition: X11Buffer.mm:526
CommandBuffer(const CommandBuffer &rhs)
void AddDrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments)
Definition: X11Buffer.mm:355
void AddFillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *polygon, Int_t nPoints)
Definition: X11Buffer.mm:460
void FlushXOROps(Details::CocoaPrivate *impl)
Definition: X11Buffer.mm:608
void ClipOverlaps(QuartzView *view)
Definition: X11Buffer.mm:725
std::vector< QuartzView * > fViewBranch
Definition: X11Buffer.h:247
void RemoveGraphicsOperationsForWindow(Window_t wid)
Definition: X11Buffer.mm:662
void AddClearArea(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: X11Buffer.mm:371
std::vector< int > fYBounds
Definition: X11Buffer.h:309
void AddDrawRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: X11Buffer.mm:442
void AddDrawLine(Drawable_t wid, const GCValues_t &gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition: X11Buffer.mm:341
void RemoveOperationsForDrawable(Drawable_t wid)
Definition: X11Buffer.mm:644
std::vector< Command * >::size_type size_type
Definition: X11Buffer.h:251
void AddDrawString(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *text, Int_t len)
Definition: X11Buffer.mm:408
CommandBuffer & operator=(const CommandBuffer &rhs)
void AddDeletePixmap(Pixmap_t pixmap)
Definition: X11Buffer.mm:490
std::vector< Command * > fCommands
Definition: X11Buffer.h:246
std::vector< int > fXBounds
Definition: X11Buffer.h:308
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)
Definition: X11Buffer.mm:388
void AddUpdateWindow(QuartzView *view)
Definition: X11Buffer.mm:476
void BuildClipRegion(const WidgetRect &rect)
Definition: X11Buffer.mm:882
size_type BufferSize() const
Definition: X11Buffer.h:277
void AddFillRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: X11Buffer.mm:424
const GCValues_t fGC
Definition: X11Buffer.h:50
Command & operator=(const Command &rhs)
Command(Drawable_t wid)
Definition: X11Buffer.mm:45
const Drawable_t fID
Definition: X11Buffer.h:49
Command(const Command &rhs)
void setView(NSView *v)
Definition: X11Buffer.h:63
virtual bool IsGraphicsCommand() const
Definition: X11Buffer.mm:68
virtual void Execute() const =0
virtual bool HasOperand(Drawable_t drawable) const
Definition: X11Buffer.mm:62
bool IsGraphicsCommand() const
Definition: X11Buffer.h:122
bool HasOperand(Drawable_t drawable) const
Definition: X11Buffer.mm:137
const Drawable_t fSrc
Definition: X11Buffer.h:114
CopyArea(Drawable_t src, Drawable_t dst, const GCValues_t &gc, const Rectangle_t &area, const Point &dstPoint)
Definition: X11Buffer.mm:127
const Rectangle_t fArea
Definition: X11Buffer.h:115
DeletePixmap(Pixmap_t pixmap)
Definition: X11Buffer.mm:249
DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2)
Definition: X11Buffer.mm:264
DrawLineXor(Window_t windowID, const Point &p1, const Point &p2)
Definition: X11Buffer.mm:297
DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2)
Definition: X11Buffer.mm:74
bool IsGraphicsCommand() const
Definition: X11Buffer.h:80
DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle)
Definition: X11Buffer.mm:212
std::vector< Segment_t > fSegments
Definition: X11Buffer.h:88
DrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments)
Definition: X11Buffer.mm:91
DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text)
Definition: X11Buffer.mm:154
bool IsGraphicsCommand() const
Definition: X11Buffer.h:139
const std::string fText
Definition: X11Buffer.h:134
std::vector< Point_t > fPolygon
Definition: X11Buffer.h:164
FillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *points, Int_t nPoints)
Definition: X11Buffer.mm:192
const Rectangle_t fRectangle
Definition: X11Buffer.h:149
FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle)
Definition: X11Buffer.mm:173
UpdateWindow(QuartzView *view)
Definition: X11Buffer.mm:231
TText * text
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Graphics context structure.
Definition: GuiTypes.h:224
Point structure (maps to the X11 XPoint structure)
Definition: GuiTypes.h:356
WidgetRect(int leftX, int bottomY, int rightX, int topY)
Definition: X11Buffer.h:297
Rectangle structure (maps to the X11 XRectangle structure)
Definition: GuiTypes.h:361
Used for drawing line segments (maps to the X11 XSegments structure)
Definition: GuiTypes.h:351