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#include "TAttMarker.h"
23#include "TAttLine.h"
24#include "TPoint.h"
25
26//////////////////////////////////////////////////////////////////////////////////
27// //
28// Unfortunately, TGCocoa's drawing methods can be called in a //
29// "wrong" time and place: not from QuartzView -drawRect. //
30// For example, on mouse move. This is bad and unnatural for Cocoa application, //
31// since I expect GUI to draw only when I'm ready == ... called from drawRect. //
32// In X11 commands are buffered and this buffer is flushed at some points. //
33// I'm trying to emulate this, just to make GUI happy. //
34// //
35//////////////////////////////////////////////////////////////////////////////////
36
37@class QuartzView;
38
39namespace ROOT {
40namespace MacOSX {
41
42namespace Details {
43class CocoaPrivate;
44}
45
46namespace X11 {
47
48class Command {
49 friend class CommandBuffer;
50
51protected:
55public:
58 virtual ~Command();
59
60 virtual bool HasOperand(Drawable_t drawable) const;
61 virtual bool IsGraphicsCommand() const;//By-default - false.
62
63 virtual void Execute() const = 0;
64 virtual void Execute(CGContextRef /*ctx*/) const;
65
67 {
68 view = v;
69 }
70private:
73};
74
75class DrawLine : public Command {
76private:
77 const Point fP1;
78 const Point fP2;
79
80public:
81 DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2);
82 void Execute() const override;
83 bool IsGraphicsCommand() const override
84 {
85 return true;
86 }
87};
88
89class DrawSegments : public Command {
90private:
91 std::vector<Segment_t> fSegments;
92
93public:
95 void Execute() const override;
96 bool IsGraphicsCommand() const override
97 {
98 return true;
99 }
100};
101
102class ClearArea : public Command {
103private:
104 const Rectangle_t fArea;//to be replaced with X11::Rectangle
105
106public:
108 void Execute() const override;
109 bool IsGraphicsCommand() const override
110 {
111 return true;
112 }
113};
114
115class CopyArea : public Command {
116private:
118 const Rectangle_t fArea;//to be replaced with X11::Rectangle
120
121public:
123
124 bool HasOperand(Drawable_t drawable) const override;
125 bool IsGraphicsCommand() const override
126 {
127 return true;
128 }
129
130 void Execute() const override;
131
132};
133
134class DrawString : public Command {
135private:
137 const std::string fText;
138
139public:
140 DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text);
141
142 bool IsGraphicsCommand() const override
143 {
144 return true;
145 }
146
147 void Execute() const override;
148};
149
150class FillRectangle : public Command {
151private:
152 const Rectangle_t fRectangle;//to be replaced with X11::Rectangle
153
154public:
155 FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
156
157 bool IsGraphicsCommand() const override
158 {
159 return true;
160 }
161
162 void Execute() const override;
163};
164
165class FillPolygon : public Command {
166private:
167 std::vector<Point_t> fPolygon;
168
169public:
171
172 bool IsGraphicsCommand() const override
173 {
174 return true;
175 }
176
177 void Execute() const override;
178};
179
180class DrawRectangle : public Command {
181private:
182 Rectangle_t fRectangle;//to be replaced with X11::Rectangle
183
184public:
185 DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
186
187 bool IsGraphicsCommand() const override
188 {
189 return true;
190 }
191
192 void Execute() const override;
193};
194
195class UpdateWindow : public Command {
196private:
198
199public:
201
202 bool IsGraphicsCommand() const override
203 {
204 return true;
205 }
206
207 void Execute() const override;
208};
209
210class DeletePixmap : public Command {
211public:
213 void Execute() const override;
214};
215
216//Set of 'xor' operations, required by TCanvas and ExecuteEvent's machinery.
217class DrawBoxXor : public Command {
218private:
221
222public:
223 DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2);
224
225 void Execute() const override {}
226 void Execute(CGContextRef ctx) const override;
227};
228
229class DrawLineXor : public Command {
230private:
233
234public:
235 DrawLineXor(Window_t windowID, const Point &p1, const Point &p2);
236
237 void Execute() const override {}
238 void Execute(CGContextRef ctx) const override;
239
240 Point start() const { return fP1; }
241 Point end() const { return fP2; }
242};
243
244class DrawPolyLineXor : public Command {
245private:
246 std::vector<TPoint> fPnts;
248 float fScaleFactor = 1.;
249
250public:
253 void setPoints(Int_t n, TPoint *xy);
254
255 void Execute() const override {}
256 void Execute(CGContextRef ctx) const override;
257};
258
259
260class DrawMarkerXor : public Command {
261private:
262 std::vector<TPoint> fPnts;
264 float fScaleFactor = 1.;
265
266public:
269 void setPoints(Int_t n, TPoint *xy);
270
271 void Execute() const override {}
272 void Execute(CGContextRef ctx) const override;
273};
274
275
277private:
280
281 std::vector<Command *> fCommands;
282 std::vector<QuartzView *> fViewBranch;
283public:
284 typedef std::vector<Command *>::size_type size_type;
285
288
293 void AddDrawString(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *text, Int_t len);
297 void AddUpdateWindow(QuartzView *view);
299
303
305 {
306 return fCommands.size();
307 }
308
309private:
310 void ClearCommands();
311 //Clip related stuff.
312 struct WidgetRect {
313 int fX1;
314 int fY1;
315 int fX2;
316 int fY2;
317
319 : fX1(0), fY1(0), fX2(0), fY2(0)
320 {
321 }
322
323 WidgetRect(int leftX, int bottomY, int rightX, int topY)
325 {
326 }
327 };
328
329 void ClipOverlaps(QuartzView *view);
330 void BuildClipRegion(const WidgetRect &rect);
331
332 std::vector<WidgetRect> fRectsToClip;
333 std::vector<CGRect> fClippedRegion;
334 std::vector<int> fXBounds;
335 std::vector<int> fYBounds;
336 std::vector<bool> fGrid;
337};
338
339}//X11
340}//MacOSX
341}//ROOT
342
343#endif
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:31
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:32
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 CopyArea
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char FillPolygon
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 xy
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char DrawLine
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t FillRectangle
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
bool IsGraphicsCommand() const override
Definition X11Buffer.h:109
ClearArea(Window_t wid, const Rectangle_t &area)
Definition X11Buffer.mm:114
const Rectangle_t fArea
Definition X11Buffer.h:104
void Execute() const override
Definition X11Buffer.mm:121
std::vector< WidgetRect > fRectsToClip
Definition X11Buffer.h:332
std::vector< CGRect > fClippedRegion
Definition X11Buffer.h:333
std::vector< bool > fGrid
Definition X11Buffer.h:336
CommandBuffer(const CommandBuffer &rhs)
void AddDrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments)
Definition X11Buffer.mm:400
void AddFillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *polygon, Int_t nPoints)
Definition X11Buffer.mm:505
void ClipOverlaps(QuartzView *view)
Definition X11Buffer.mm:683
std::vector< QuartzView * > fViewBranch
Definition X11Buffer.h:282
void RemoveGraphicsOperationsForWindow(Window_t wid)
Definition X11Buffer.mm:640
void AddClearArea(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition X11Buffer.mm:416
std::vector< int > fYBounds
Definition X11Buffer.h:335
void AddDrawRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition X11Buffer.mm:487
void AddDrawLine(Drawable_t wid, const GCValues_t &gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition X11Buffer.mm:386
void RemoveOperationsForDrawable(Drawable_t wid)
Definition X11Buffer.mm:629
std::vector< Command * >::size_type size_type
Definition X11Buffer.h:284
void AddDrawString(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *text, Int_t len)
Definition X11Buffer.mm:453
CommandBuffer & operator=(const CommandBuffer &rhs)
void AddDeletePixmap(Pixmap_t pixmap)
Definition X11Buffer.mm:535
std::vector< Command * > fCommands
Definition X11Buffer.h:281
std::vector< int > fXBounds
Definition X11Buffer.h:334
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:433
void AddUpdateWindow(QuartzView *view)
Definition X11Buffer.mm:521
void BuildClipRegion(const WidgetRect &rect)
Definition X11Buffer.mm:840
void AddFillRectangle(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition X11Buffer.mm:469
const GCValues_t fGC
Definition X11Buffer.h:53
Command & operator=(const Command &rhs)
Command(Drawable_t wid)
Definition X11Buffer.mm:48
const Drawable_t fID
Definition X11Buffer.h:52
Command(const Command &rhs)
void setView(NSView *v)
Definition X11Buffer.h:66
virtual bool IsGraphicsCommand() const
Definition X11Buffer.mm:71
virtual void Execute() const =0
virtual bool HasOperand(Drawable_t drawable) const
Definition X11Buffer.mm:65
const Drawable_t fSrc
Definition X11Buffer.h:117
bool HasOperand(Drawable_t drawable) const override
Definition X11Buffer.mm:140
bool IsGraphicsCommand() const override
Definition X11Buffer.h:125
const Rectangle_t fArea
Definition X11Buffer.h:118
void Execute() const override
Definition X11Buffer.mm:146
void Execute() const override
Definition X11Buffer.mm:258
void Execute() const override
Definition X11Buffer.h:225
DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2)
Definition X11Buffer.mm:267
DrawLineXor(Window_t windowID, const Point &p1, const Point &p2)
Definition X11Buffer.mm:296
void Execute() const override
Definition X11Buffer.h:237
bool IsGraphicsCommand() const override
Definition X11Buffer.h:83
void Execute() const override
Definition X11Buffer.mm:85
DrawMarkerXor(Window_t windowID, const TAttMarker &att)
Definition X11Buffer.h:267
void setPoints(Int_t n, TPoint *xy)
Definition X11Buffer.mm:353
std::vector< TPoint > fPnts
Definition X11Buffer.h:262
void Execute() const override
Definition X11Buffer.h:271
std::vector< TPoint > fPnts
Definition X11Buffer.h:246
DrawPolyLineXor(Window_t windowID, const TAttLine &att)
Definition X11Buffer.h:251
void setPoints(Int_t n, TPoint *xy)
Definition X11Buffer.mm:322
void Execute() const override
Definition X11Buffer.h:255
bool IsGraphicsCommand() const override
Definition X11Buffer.h:187
DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle)
Definition X11Buffer.mm:215
void Execute() const override
Definition X11Buffer.mm:223
std::vector< Segment_t > fSegments
Definition X11Buffer.h:91
bool IsGraphicsCommand() const override
Definition X11Buffer.h:96
DrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments)
Definition X11Buffer.mm:94
void Execute() const override
Definition X11Buffer.mm:105
DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text)
Definition X11Buffer.mm:157
void Execute() const override
Definition X11Buffer.mm:166
bool IsGraphicsCommand() const override
Definition X11Buffer.h:142
const std::string fText
Definition X11Buffer.h:137
bool IsGraphicsCommand() const override
Definition X11Buffer.h:172
std::vector< Point_t > fPolygon
Definition X11Buffer.h:167
void Execute() const override
Definition X11Buffer.mm:206
bool IsGraphicsCommand() const override
Definition X11Buffer.h:157
void Execute() const override
Definition X11Buffer.mm:184
void Execute() const override
Definition X11Buffer.mm:242
UpdateWindow(QuartzView *view)
Definition X11Buffer.mm:234
bool IsGraphicsCommand() const override
Definition X11Buffer.h:202
Line Attributes class.
Definition TAttLine.h:21
Marker Attributes class.
Definition TAttMarker.h:21
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
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:323
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