Skip to content

Commit 2f13c0c

Browse files
committed
[quartz] use override syntax, use temporary points buffer
TGQuartz use internal vector for coordinates conversion Do not keep it while vector can be deleted afterwards
1 parent eeb4420 commit 2f13c0c

5 files changed

Lines changed: 46 additions & 48 deletions

File tree

graf2d/cocoa/inc/TGQuartz.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ class TGQuartz : public TGCocoa {
9595

9696
private:
9797

98-
//Unfortunately, I have to convert from
99-
//top-left to bottom-left corner system.
100-
std::vector<TPoint> fConvertedPoints;
101-
10298
//Lines with AA can be quite different
10399
//from what we always had with X11.
104100
//Now this is a switch in our configuration file (system.rootrc),

graf2d/cocoa/inc/X11Buffer.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class Command {
5757
Command(Drawable_t wid, const GCValues_t &gc);
5858
virtual ~Command();
5959

60-
virtual bool HasOperand(Drawable_t drawable)const;
61-
virtual bool IsGraphicsCommand()const;//By-default - false.
60+
virtual bool HasOperand(Drawable_t drawable) const;
61+
virtual bool IsGraphicsCommand() const;//By-default - false.
6262

63-
virtual void Execute()const = 0;
64-
virtual void Execute(CGContextRef /*ctx*/)const;
63+
virtual void Execute() const = 0;
64+
virtual void Execute(CGContextRef /*ctx*/) const;
6565

6666
void setView(NSView *v)
6767
{
@@ -79,8 +79,8 @@ class DrawLine : public Command {
7979

8080
public:
8181
DrawLine(Drawable_t wid, const GCValues_t &gc, const Point &p1, const Point &p2);
82-
void Execute()const;
83-
bool IsGraphicsCommand()const
82+
void Execute() const override;
83+
bool IsGraphicsCommand() const override
8484
{
8585
return true;
8686
}
@@ -92,8 +92,8 @@ class DrawSegments : public Command {
9292

9393
public:
9494
DrawSegments(Drawable_t wid, const GCValues_t &gc, const Segment_t *segments, Int_t nSegments);
95-
void Execute()const;
96-
bool IsGraphicsCommand()const
95+
void Execute() const override;
96+
bool IsGraphicsCommand() const override
9797
{
9898
return true;
9999
}
@@ -105,8 +105,8 @@ class ClearArea : public Command {
105105

106106
public:
107107
ClearArea(Window_t wid, const Rectangle_t &area);
108-
void Execute()const;
109-
bool IsGraphicsCommand()const
108+
void Execute() const override;
109+
bool IsGraphicsCommand() const override
110110
{
111111
return true;
112112
}
@@ -121,13 +121,13 @@ class CopyArea : public Command {
121121
public:
122122
CopyArea(Drawable_t src, Drawable_t dst, const GCValues_t &gc, const Rectangle_t &area, const Point &dstPoint);
123123

124-
bool HasOperand(Drawable_t drawable)const;
125-
bool IsGraphicsCommand()const
124+
bool HasOperand(Drawable_t drawable) const override;
125+
bool IsGraphicsCommand() const override
126126
{
127127
return true;
128128
}
129129

130-
void Execute()const;
130+
void Execute() const override;
131131

132132
};
133133

@@ -139,12 +139,12 @@ class DrawString : public Command {
139139
public:
140140
DrawString(Drawable_t wid, const GCValues_t &gc, const Point &point, const std::string &text);
141141

142-
bool IsGraphicsCommand()const
142+
bool IsGraphicsCommand() const override
143143
{
144144
return true;
145145
}
146146

147-
void Execute()const;
147+
void Execute() const override;
148148
};
149149

150150
class FillRectangle : public Command {
@@ -154,12 +154,12 @@ class FillRectangle : public Command {
154154
public:
155155
FillRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
156156

157-
bool IsGraphicsCommand()const
157+
bool IsGraphicsCommand() const override
158158
{
159159
return true;
160160
}
161161

162-
void Execute()const;
162+
void Execute() const override;
163163
};
164164

165165
class FillPolygon : public Command {
@@ -169,12 +169,12 @@ class FillPolygon : public Command {
169169
public:
170170
FillPolygon(Drawable_t wid, const GCValues_t &gc, const Point_t *points, Int_t nPoints);
171171

172-
bool IsGraphicsCommand()const
172+
bool IsGraphicsCommand() const override
173173
{
174174
return true;
175175
}
176176

177-
void Execute()const;
177+
void Execute() const override;
178178
};
179179

180180
class DrawRectangle : public Command {
@@ -184,12 +184,12 @@ class DrawRectangle : public Command {
184184
public:
185185
DrawRectangle(Drawable_t wid, const GCValues_t &gc, const Rectangle_t &rectangle);
186186

187-
bool IsGraphicsCommand()const
187+
bool IsGraphicsCommand() const override
188188
{
189189
return true;
190190
}
191191

192-
void Execute()const;
192+
void Execute() const override;
193193
};
194194

195195
class UpdateWindow : public Command {
@@ -199,18 +199,18 @@ class UpdateWindow : public Command {
199199
public:
200200
UpdateWindow(QuartzView *view);
201201

202-
bool IsGraphicsCommand()const
202+
bool IsGraphicsCommand() const override
203203
{
204204
return true;
205205
}
206206

207-
void Execute()const;
207+
void Execute() const override;
208208
};
209209

210210
class DeletePixmap : public Command {
211211
public:
212212
DeletePixmap(Pixmap_t pixmap);
213-
void Execute()const;
213+
void Execute() const override;
214214
};
215215

216216
//Set of 'xor' operations, required by TCanvas and ExecuteEvent's machinery.
@@ -222,8 +222,8 @@ class DrawBoxXor : public Command {
222222
public:
223223
DrawBoxXor(Window_t windowID, const Point &p1, const Point &p2);
224224

225-
void Execute()const;
226-
void Execute(CGContextRef ctx)const;
225+
void Execute() const override {}
226+
void Execute(CGContextRef ctx) const override;
227227
};
228228

229229
class DrawLineXor : public Command {
@@ -234,8 +234,8 @@ class DrawLineXor : public Command {
234234
public:
235235
DrawLineXor(Window_t windowID, const Point &p1, const Point &p2);
236236

237-
void Execute() const {}
238-
void Execute(CGContextRef ctx) const;
237+
void Execute() const override {}
238+
void Execute(CGContextRef ctx) const override;
239239

240240
Point start() const { return fP1; }
241241
Point end() const { return fP2; }
@@ -252,8 +252,8 @@ class DrawPolyLineXor : public Command {
252252
Command(windowID, GCValues_t()), fAtt(att) {}
253253
void setPoints(Int_t n, TPoint *xy);
254254

255-
void Execute() const {}
256-
void Execute(CGContextRef ctx) const;
255+
void Execute() const override {}
256+
void Execute(CGContextRef ctx) const override;
257257
};
258258

259259

@@ -268,8 +268,8 @@ class DrawMarkerXor : public Command {
268268
Command(windowID, GCValues_t()), fAtt(att) {}
269269
void setPoints(Int_t n, TPoint *xy);
270270

271-
void Execute() const {}
272-
void Execute(CGContextRef ctx) const;
271+
void Execute() const override {}
272+
void Execute(CGContextRef ctx) const override;
273273
};
274274

275275

graf2d/cocoa/src/QuartzWindow.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ - (void) addXorBox : (QuartzView *) view : (Int_t) x1 : (Int_t) y1 : (Int_t) x2
15781578
auto xorWindow = [self addXorWindow];
15791579

15801580
try {
1581-
std::unique_ptr<ROOT::MacOSX::X11::DrawBoxXor> cmd(new ROOT::MacOSX::X11::DrawBoxXor(-1, ROOT::MacOSX::X11::Point(x1, y1), ROOT::MacOSX::X11::Point(x2, y2)));
1581+
auto cmd = std::make_unique<ROOT::MacOSX::X11::DrawBoxXor>(-1, ROOT::MacOSX::X11::Point(x1, y1), ROOT::MacOSX::X11::Point(x2, y2));
15821582
cmd->setView(view);
15831583

15841584
auto cv = (XorDrawingView *)xorWindow.contentView;

graf2d/cocoa/src/TGQuartz.mm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin
203203

204204
CGContextRef ctx = drawable.fContext;
205205

206+
std::vector<TPoint> pnts;
207+
206208
//Convert points to bottom-left system:
207-
ConvertPointsROOTToCocoa(n, xy, fConvertedPoints, drawable);
209+
ConvertPointsROOTToCocoa(n, xy, pnts, drawable);
208210

209211
const Quartz::CGStateGuard ctxGuard(ctx);
210212
//AA flag is not a part of a state.
@@ -223,7 +225,7 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin
223225

224226
if (const TColorGradient * const gradient = dynamic_cast<const TColorGradient *>(fillColor)) {
225227
Quartz::DrawPolygonWithGradientFill(ctx, gradient, CGSizeMake(drawable.fWidth, drawable.fHeight),
226-
n, &fConvertedPoints[0], kFALSE);//kFALSE == don't draw a shadow.
228+
pnts.size(), pnts.data(), kFALSE);//kFALSE == don't draw a shadow.
227229
} else {
228230
unsigned patternIndex = 0;
229231
if (!Quartz::SetFillAreaParameters(ctx, &patternIndex, attfill)) {
@@ -233,7 +235,7 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin
233235

234236
// kFALSE - do not draw shadows.
235237
// last argument - fill style
236-
Quartz::DrawFillArea(ctx, n, &fConvertedPoints[0], kFALSE, attfill);
238+
Quartz::DrawFillArea(ctx, pnts.size(), pnts.data(), kFALSE, attfill);
237239
}
238240
}
239241

@@ -350,13 +352,15 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin
350352
Quartz::SetLineStyle(ctx, attline.GetLineStyle());
351353
Quartz::SetLineWidth(ctx, attline.GetLineWidth());
352354

355+
std::vector<TPoint> pnts;
356+
353357
//Convert to bottom-left-corner system.
354-
ConvertPointsROOTToCocoa(n, xy, fConvertedPoints, drawable);
358+
ConvertPointsROOTToCocoa(n, xy, pnts, drawable);
355359

356360
if (drawable.fScaleFactor > 1.)
357361
CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
358362

359-
Quartz::DrawPolyLine(ctx, n, &fConvertedPoints[0]);
363+
Quartz::DrawPolyLine(ctx, pnts.size(), pnts.data());
360364

361365
// CTM (current transformation matrix) is restored by 'ctxGuard's dtor.
362366
}
@@ -408,14 +412,16 @@ void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoin
408412
if (!drawable)
409413
return;
410414

411-
ConvertPointsROOTToCocoa(n, xy, fConvertedPoints, drawable);
415+
std::vector<TPoint> pnts;
416+
417+
ConvertPointsROOTToCocoa(n, xy, pnts, drawable);
412418

413419
CGContextRef ctx = drawable.fContext;
414420
const Quartz::CGStateGuard ctxGuard(ctx);
415421
//AA flag is not a part of a state.
416422
const Quartz::CGAAStateGuard aaCtxGuard(ctx, fUseAA);
417423

418-
Quartz::DrawPolyMarker(ctx, n, fConvertedPoints.data(), attmark, drawable.fScaleFactor);
424+
Quartz::DrawPolyMarker(ctx, pnts.size(), pnts.data(), attmark, drawable.fScaleFactor);
419425
}
420426

421427
//______________________________________________________________________________

graf2d/cocoa/src/X11Buffer.mm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@
276276
}
277277

278278
//______________________________________________________________________________
279-
void DrawBoxXor::Execute()const
280-
{
281-
//Noop.
282-
}
283279

284280
const auto rootToNs = [](Point rp) {
285281
return NSPoint{CGFloat(rp.fX), CGFloat(rp.fY)};

0 commit comments

Comments
 (0)