Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
QuartzLine.mm
Go to the documentation of this file.
1// @(#)root/graf2d:$Id$
2// Author: Olivier Couet, 24/01/2012
3
4/*************************************************************************
5 * Copyright (C) 1995-2011, 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#include <cassert>
13#include <vector>
14
15#include "CocoaUtils.h"
16#include "TObjString.h"
17#include "QuartzLine.h"
18#include "RStipples.h"
19#include "TObjArray.h"
20#include "TString.h"
21#include "TColor.h"
22#include "TStyle.h"
23#include "TROOT.h"
24
25namespace ROOT {
26namespace Quartz {
27
28//______________________________________________________________________________
30{
31 assert(ctx != 0 && "SetLineColor, ctx parameter is null");
32
33 const TColor *color = gROOT->GetColor(colorIndex);
34 //Do as TGX11 does.
35 if (!color)
36 color = gROOT->GetColor(kWhite);
37
38 if (!color)
39 return kFALSE;
40
41 const CGFloat alpha = color->GetAlpha();
42 Float_t rgb[3] = {};
43 color->GetRGB(rgb[0], rgb[1], rgb[2]);
44 CGContextSetRGBStrokeColor(ctx, rgb[0], rgb[1], rgb[2], alpha);
45
46 return kTRUE;
47}
48
49//______________________________________________________________________________
51{
52 // Set the line type in the context ctx.
53 //
54 // n - length of the dash list
55 // n <= 0 use solid lines
56 // n > 0 use dashed lines described by dash(n)
57 // e.g. n = 4,dash = (6,3,1,3) gives a dashed-dotted line
58 // with dash length 6 and a gap of 7 between dashes
59 // dash(n) - dash segment lengths
60
61 assert(ctx != 0 && "SetLineType, ctx parameter is null");
62
63 if (n) {
64 CGFloat lengths[n];
65 for (int i = 0; i < n; i++)
66 lengths[i] = dash[i];
67 CGContextSetLineDash(ctx, 0, lengths, n);
68 } else {
69 CGContextSetLineDash(ctx, 0, NULL, 0);
70 }
71}
72
73//______________________________________________________________________________
75{
76 // Set current line style in the context ctx.
77 assert(ctx != 0 && "SetLineStyle, ctx parameter is null");
78
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};
82
83 if (lstyle <= 1 ) {
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);
91 } else {
93 TObjArray *tokens = st.Tokenize(" ");
94 Int_t nt;
95 nt = tokens->GetEntries();
96 std::vector<Int_t> linestyle(nt);
97 for (Int_t j = 0; j<nt; j++) {
98 Int_t it;
99 sscanf(((TObjString*)tokens->At(j))->GetName(), "%d", &it);
100 linestyle[j] = (Int_t)(it/4);
101 }
102 SetLineType(ctx, nt, &linestyle[0]);
103 delete tokens;
104 }
105}
106
107//______________________________________________________________________________
109{
110 // Set the line width in the context ctx.
111 //
112 // width - the line width in pixels
113 assert(ctx != 0 && "SetLineWidth, ctx parameter is null");
114
115
116 if (width < 0)
117 return;
118
119 CGContextSetLineWidth(ctx, width ? width : 1);
120}
121
122//______________________________________________________________________________
124{
125 assert(ctx != 0 && "DrawLine, ctx parameter is null");
126
127 CGContextBeginPath(ctx);
128 CGContextMoveToPoint(ctx, x1, y1);
129 CGContextAddLineToPoint(ctx, x2, y2);
130 CGContextStrokePath(ctx);
131}
132
133
134//______________________________________________________________________________
136{
137 // Draw a line through all points.
138 // n : number of points
139 // xy : list of points
140
141 assert(ctx != 0 && "DrawPolyLine, ctx parameter is null");
142 assert(xy != 0 && "DrawPolyLine, xy parameter is null");
143
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);
148
149 if (xy[n - 1].fX == xy[0].fX && xy[n - 1].fY == xy[0].fY)
150 CGContextClosePath(ctx);
151
152 CGContextStrokePath(ctx);
153}
154
155}//namespace Quartz
156}//namespace ROOT
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:85
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kWhite
Definition Rtypes.h:65
Option_t Option_t SetLineWidth
Option_t Option_t SetLineColor
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 width
Option_t Option_t TPoint TPoint const char y1
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
The color creation and management class.
Definition TColor.h:21
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition TColor.h:54
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1920
Float_t GetAlpha() const
Definition TColor.h:66
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
Collectable string class.
Definition TObjString.h:28
Basic string class.
Definition TString.h:139
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2264
const char * GetLineStyleString(Int_t i=1) const
Return line style string (used by PostScript).
Definition TStyle.cxx:1166
const Int_t n
Definition legend1.C:16
void DrawPolyLine(CGContextRef ctx, Int_t n, TPoint *xy)
void SetLineType(CGContextRef ctx, Int_t n, Int_t *dash)
Definition QuartzLine.mm:50
void SetLineStyle(CGContextRef ctx, Int_t lstyle)
Definition QuartzLine.mm:74
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...