Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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;
248public:
249 typedef std::vector<Command *>::size_type size_type;
250
253
254 void AddDrawLine(Drawable_t wid, const GCValues_t &gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2);
255 void AddDrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
256 void AddClearArea(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h);
257 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);
258 void AddDrawString(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *text, Int_t len);
259 void AddFillRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h);
260 void AddFillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *polygon, Int_t nPoints);
261 void AddDrawRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h);
262 void AddUpdateWindow(QuartzView *view);
263 void AddDeletePixmap(Pixmap_t pixmap);
264
265 void Flush(Details::CocoaPrivate *impl);
268
270 {
271 return fCommands.size();
272 }
273
274private:
275 void ClearCommands();
276 //Clip related stuff.
277 struct WidgetRect {
278 int fX1;
279 int fY1;
280 int fX2;
281 int fY2;
282
284 : fX1(0), fY1(0), fX2(0), fY2(0)
285 {
286 }
287
288 WidgetRect(int leftX, int bottomY, int rightX, int topY)
289 : fX1(leftX), fY1(bottomY), fX2(rightX), fY2(topY)
290 {
291 }
292 };
293
294 void ClipOverlaps(QuartzView *view);
295 void BuildClipRegion(const WidgetRect &rect);
296
297 std::vector<WidgetRect> fRectsToClip;
298 std::vector<CGRect> fClippedRegion;
299 std::vector<int> fXBounds;
300 std::vector<int> fYBounds;
301 std::vector<bool> fGrid;
302};
303
304}//X11
305}//MacOSX
306}//ROOT
307
308#endif
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:31
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:32
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
point * points
Definition X3DBuffer.c:22
ClearArea(Window_t wid, const Rectangle_t &area)
Definition X11Buffer.mm:112
const Rectangle_t fArea
Definition X11Buffer.h:101
std::vector< WidgetRect > fRectsToClip
Definition X11Buffer.h:297
std::vector< CGRect > fClippedRegion
Definition X11Buffer.h:298
std::vector< bool > fGrid
Definition X11Buffer.h:301
void Flush(Details::CocoaPrivate *impl)
Definition X11Buffer.mm:502
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 ClipOverlaps(QuartzView *view)
Definition X11Buffer.mm:638
std::vector< QuartzView * > fViewBranch
Definition X11Buffer.h:247
void RemoveGraphicsOperationsForWindow(Window_t wid)
Definition X11Buffer.mm:595
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:300
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:584
std::vector< Command * >::size_type size_type
Definition X11Buffer.h:249
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:299
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:795
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)
friend class CommandBuffer
Definition X11Buffer.h:46
Command(Drawable_t wid)
Definition X11Buffer.mm:46
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:69
virtual void Execute() const =0
virtual bool HasOperand(Drawable_t drawable) const
Definition X11Buffer.mm:63
bool IsGraphicsCommand() const
Definition X11Buffer.h:122
bool HasOperand(Drawable_t drawable) const
Definition X11Buffer.mm:138
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:128
const Rectangle_t fArea
Definition X11Buffer.h:115
DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2)
Definition X11Buffer.mm:265
DrawLineXor(Window_t windowID, const Point &p1, const Point &p2)
Definition X11Buffer.mm:298
DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2)
Definition X11Buffer.mm:75
bool IsGraphicsCommand() const
Definition X11Buffer.h:80
DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle)
Definition X11Buffer.mm:213
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:92
DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text)
Definition X11Buffer.mm:155
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:193
FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle)
Definition X11Buffer.mm:174
UpdateWindow(QuartzView *view)
Definition X11Buffer.mm:232
TText * text
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Graphics context structure.
Definition GuiTypes.h:225
Point structure (maps to the X11 XPoint structure).
Definition GuiTypes.h:357
WidgetRect(int leftX, int bottomY, int rightX, int topY)
Definition X11Buffer.h:288
Rectangle structure (maps to the X11 XRectangle structure).
Definition GuiTypes.h:362
Used for drawing line segments (maps to the X11 XSegments structure).
Definition GuiTypes.h:352