Logo ROOT   6.16/01
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
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
63private:
64 Command(const Command &rhs);
66};
67
68class DrawLine : public Command {
69private:
70 const Point fP1;
71 const Point fP2;
72
73public:
74 DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2);
75 void Execute()const;
77 {
78 return true;
79 }
80};
81
82class DrawSegments : public Command {
83private:
84 std::vector<Segment_t> fSegments;
85
86public:
87 DrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
88 void Execute()const;
90 {
91 return true;
92 }
93};
94
95class ClearArea : public Command {
96private:
97 const Rectangle_t fArea;//to be replaced with X11::Rectangle
98
99public:
100 ClearArea(Window_t wid, const Rectangle_t &area);
101 void Execute()const;
103 {
104 return true;
105 }
106};
107
108class CopyArea : public Command {
109private:
111 const Rectangle_t fArea;//to be replaced with X11::Rectangle
113
114public:
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;
119 {
120 return true;
121 }
122
123 void Execute()const;
124
125};
126
127class DrawString : public Command {
128private:
130 const std::string fText;
131
132public:
133 DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text);
134
136 {
137 return true;
138 }
139
140 void Execute()const;
141};
142
143class FillRectangle : public Command {
144private:
145 const Rectangle_t fRectangle;//to be replaced with X11::Rectangle
146
147public:
148 FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
149
151 {
152 return true;
153 }
154
155 void Execute()const;
156};
157
158class FillPolygon : public Command {
159private:
160 std::vector<Point_t> fPolygon;
161
162public:
163 FillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *points, Int_t nPoints);
164
166 {
167 return true;
168 }
169
170 void Execute()const;
171};
172
173class DrawRectangle : public Command {
174private:
175 Rectangle_t fRectangle;//to be replaced with X11::Rectangle
176
177public:
178 DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
179
181 {
182 return true;
183 }
184
185 void Execute()const;
186};
187
188class UpdateWindow : public Command {
189private:
191
192public:
194
196 {
197 return true;
198 }
199
200 void Execute()const;
201};
202
203class DeletePixmap : public Command {
204public:
205 DeletePixmap(Pixmap_t pixmap);
206 void Execute()const;
207};
208
209//Set of 'xor' operations, required by TCanvas and ExecuteEvent's machinery.
210class DrawBoxXor : public Command {
211private:
214
215public:
216 DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2);
217
218 void Execute()const;
219 void Execute(CGContextRef ctx)const;
220};
221
222class DrawLineXor : public Command {
223private:
226
227public:
228 DrawLineXor(Window_t windowID, const Point &p1, const Point &p2);
229
230 void Execute()const;
231 void Execute(CGContextRef ctx)const;
232};
233
235private:
238
239 std::vector<Command *> fCommands;
240 std::vector<QuartzView *> fViewBranch;
241
242 std::vector<Command *> fXorOps;
243public:
244 typedef std::vector<Command *>::size_type size_type;
245
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);
269
271 {
272 return fCommands.size();
273 }
274private:
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
Handle_t Pixmap_t
Definition: GuiTypes.h:29
Handle_t Drawable_t
Definition: GuiTypes.h:30
Handle_t Window_t
Definition: GuiTypes.h:28
#define h(i)
Definition: RSha256.hxx:106
static double p1(double t, double a, double b)
static double p2(double t, double a, double b, double c)
static const double x2[5]
static const double x1[5]
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
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:110
const Rectangle_t fArea
Definition: X11Buffer.h:97
bool IsGraphicsCommand() const
Definition: X11Buffer.h:102
void RemoveXORGraphicsOperationsForWindow(Window_t wid)
Definition: X11Buffer.mm:687
void AddDrawBoxXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition: X11Buffer.mm:495
std::vector< WidgetRect > fRectsToClip
Definition: X11Buffer.h:300
std::vector< CGRect > fClippedRegion
Definition: X11Buffer.h:301
std::vector< Command * > fXorOps
Definition: X11Buffer.h:242
std::vector< bool > fGrid
Definition: X11Buffer.h:304
void AddDrawLineXor(Window_t windowID, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition: X11Buffer.mm:507
void Flush(Details::CocoaPrivate *impl)
Definition: X11Buffer.mm:519
CommandBuffer(const CommandBuffer &rhs)
void AddDrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments)
Definition: X11Buffer.mm:348
void AddFillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *polygon, Int_t nPoints)
Definition: X11Buffer.mm:453
void FlushXOROps(Details::CocoaPrivate *impl)
Definition: X11Buffer.mm:601
void ClipOverlaps(QuartzView *view)
Definition: X11Buffer.mm:737
std::vector< QuartzView * > fViewBranch
Definition: X11Buffer.h:240
void RemoveGraphicsOperationsForWindow(Window_t wid)
Definition: X11Buffer.mm:674
void AddClearArea(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: X11Buffer.mm:364
std::vector< int > fYBounds
Definition: X11Buffer.h:303
void AddDrawRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: X11Buffer.mm:435
void AddDrawLine(Drawable_t wid, const GCValues_t &gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition: X11Buffer.mm:334
void RemoveOperationsForDrawable(Drawable_t wid)
Definition: X11Buffer.mm:656
std::vector< Command * >::size_type size_type
Definition: X11Buffer.h:244
void AddDrawString(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *text, Int_t len)
Definition: X11Buffer.mm:401
CommandBuffer & operator=(const CommandBuffer &rhs)
void AddDeletePixmap(Pixmap_t pixmap)
Definition: X11Buffer.mm:483
std::vector< Command * > fCommands
Definition: X11Buffer.h:239
std::vector< int > fXBounds
Definition: X11Buffer.h:302
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:381
void AddUpdateWindow(QuartzView *view)
Definition: X11Buffer.mm:469
void BuildClipRegion(const WidgetRect &rect)
Definition: X11Buffer.mm:894
size_type BufferSize() const
Definition: X11Buffer.h:270
void AddFillRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: X11Buffer.mm:417
const GCValues_t fGC
Definition: X11Buffer.h:50
Command & operator=(const Command &rhs)
Command(Drawable_t wid)
Definition: X11Buffer.mm:44
const Drawable_t fID
Definition: X11Buffer.h:49
Command(const Command &rhs)
virtual bool IsGraphicsCommand() const
Definition: X11Buffer.mm:67
virtual void Execute() const =0
virtual bool HasOperand(Drawable_t drawable) const
Definition: X11Buffer.mm:61
bool IsGraphicsCommand() const
Definition: X11Buffer.h:118
bool HasOperand(Drawable_t drawable) const
Definition: X11Buffer.mm:136
const Drawable_t fSrc
Definition: X11Buffer.h:110
CopyArea(Drawable_t src, Drawable_t dst, const GCValues_t &gc, const Rectangle_t &area, const Point &dstPoint)
Definition: X11Buffer.mm:126
const Rectangle_t fArea
Definition: X11Buffer.h:111
DeletePixmap(Pixmap_t pixmap)
Definition: X11Buffer.mm:248
DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2)
Definition: X11Buffer.mm:263
DrawLineXor(Window_t windowID, const Point &p1, const Point &p2)
Definition: X11Buffer.mm:293
DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2)
Definition: X11Buffer.mm:73
bool IsGraphicsCommand() const
Definition: X11Buffer.h:76
DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle)
Definition: X11Buffer.mm:211
std::vector< Segment_t > fSegments
Definition: X11Buffer.h:84
DrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments)
Definition: X11Buffer.mm:90
DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text)
Definition: X11Buffer.mm:153
bool IsGraphicsCommand() const
Definition: X11Buffer.h:135
const std::string fText
Definition: X11Buffer.h:130
std::vector< Point_t > fPolygon
Definition: X11Buffer.h:160
FillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *points, Int_t nPoints)
Definition: X11Buffer.mm:191
const Rectangle_t fRectangle
Definition: X11Buffer.h:145
FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle)
Definition: X11Buffer.mm:172
UpdateWindow(QuartzView *view)
Definition: X11Buffer.mm:230
TText * text
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
WidgetRect(int leftX, int bottomY, int rightX, int topY)
Definition: X11Buffer.h:291