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:
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
257 void AddDrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
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);
262 void AddFillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *polygon, Int_t nPoints);
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 Window_t
Window handle.
Definition GuiTypes.h:29
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:31
#define h(i)
Definition RSha256.hxx:106
winID h Flush
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t rect
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
const Rectangle_t fArea
Definition X11Buffer.h:101
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
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
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)
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
const Rectangle_t fArea
Definition X11Buffer.h:115
bool IsGraphicsCommand() const
Definition X11Buffer.h:80
std::vector< Segment_t > fSegments
Definition X11Buffer.h:88
const std::string fText
Definition X11Buffer.h:134
std::vector< Point_t > fPolygon
Definition X11Buffer.h:164
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
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