29 Bool_t SetLineColor(CGContextRef ctx, Color_t colorIndex)
31 assert(ctx != 0 &&
"SetLineColor, ctx parameter is null");
33 const TColor *color = gROOT->GetColor(colorIndex);
36 color = gROOT->GetColor(kWhite);
41 const CGFloat alpha = color->GetAlpha();
43 color->GetRGB(rgb[0], rgb[1], rgb[2]);
44 CGContextSetRGBStrokeColor(ctx, rgb[0], rgb[1], rgb[2], alpha);
50 void SetLineType(CGContextRef ctx, Int_t n, Int_t *dash)
61 assert(ctx != 0 &&
"SetLineType, ctx parameter is null");
65 for (
int i = 0; i < n; i++)
67 CGContextSetLineDash(ctx, 0, lengths, n);
69 CGContextSetLineDash(ctx, 0, NULL, 0);
74 void SetLineStyle(CGContextRef ctx, Int_t lstyle)
77 assert(ctx != 0 &&
"SetLineStyle, ctx parameter is null");
79 static Int_t dashed[2] = {3, 3};
80 static Int_t dotted[2] = {1, 2};
81 static Int_t dasheddotted[4] = {3, 4, 1, 4};
84 SetLineType(ctx, 0, 0);
85 }
else if (lstyle == 2) {
86 SetLineType(ctx, 2, dashed);
87 }
else if (lstyle == 3) {
88 SetLineType(ctx, 2,dotted);
89 }
else if (lstyle == 4) {
90 SetLineType(ctx, 4, dasheddotted);
92 TString st = (TString)gStyle->GetLineStyleString(lstyle);
93 TObjArray *tokens = st.Tokenize(
" ");
95 nt = tokens->GetEntries();
96 std::vector<Int_t> linestyle(nt);
97 for (Int_t j = 0; j<nt; j++) {
99 sscanf(((TObjString*)tokens->At(j))->GetName(),
"%d", &it);
100 linestyle[j] = (Int_t)(it/4);
102 SetLineType(ctx, nt, &linestyle[0]);
108 void SetLineWidth(CGContextRef ctx, Int_t width)
113 assert(ctx != 0 &&
"SetLineWidth, ctx parameter is null");
119 CGContextSetLineWidth(ctx, width ? width : 1);
123 void DrawLine(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
125 assert(ctx != 0 &&
"DrawLine, ctx parameter is null");
127 CGContextBeginPath(ctx);
128 CGContextMoveToPoint(ctx, x1, y1);
129 CGContextAddLineToPoint(ctx, x2, y2);
130 CGContextStrokePath(ctx);
135 void DrawPolyLine(CGContextRef ctx, Int_t n, TPoint * xy)
141 assert(ctx != 0 &&
"DrawPolyLine, ctx parameter is null");
142 assert(xy != 0 &&
"DrawPolyLine, xy parameter is null");
144 CGContextBeginPath(ctx);
145 CGContextMoveToPoint(ctx, xy[0].fX, xy[0].fY);
146 for (Int_t i = 1; i < n; ++i)
147 CGContextAddLineToPoint(ctx, xy[i].fX, xy[i].fY);
149 if (xy[n - 1].fX == xy[0].fX && xy[n - 1].fY == xy[0].fY)
150 CGContextClosePath(ctx);
152 CGContextStrokePath(ctx);