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 = new CGFloat[n];
65 for (int i = 0; i < n; i++)
66 lengths[i] = dash[i];
67 CGContextSetLineDash(ctx, 0, lengths, n);
68 delete[] lengths;
69 } else {
70 CGContextSetLineDash(ctx, 0, NULL, 0);
71 }
72}
73
74//______________________________________________________________________________
76{
77 // Set current line style in the context ctx.
78 assert(ctx != 0 && "SetLineStyle, ctx parameter is null");
79
80 static Int_t dashed[2] = {3, 3};
81 static Int_t dotted[2] = {1, 2};
82 static Int_t dasheddotted[4] = {3, 4, 1, 4};
83
84 if (lstyle <= 1 ) {
85 SetLineType(ctx, 0, 0);
86 } else if (lstyle == 2) {
87 SetLineType(ctx, 2, dashed);
88 } else if (lstyle == 3) {
89 SetLineType(ctx, 2,dotted);
90 } else if (lstyle == 4) {
91 SetLineType(ctx, 4, dasheddotted);
92 } else {
93 TString st = (TString)gStyle->GetLineStyleString(lstyle);
94 TObjArray *tokens = st.Tokenize(" ");
95 Int_t nt;
96 nt = tokens->GetEntries();
97 std::vector<Int_t> linestyle(nt);
98 for (Int_t j = 0; j<nt; j++) {
99 Int_t it;
100 sscanf(((TObjString*)tokens->At(j))->GetName(), "%d", &it);
101 linestyle[j] = (Int_t)(it/4);
102 }
103 SetLineType(ctx, nt, &linestyle[0]);
104 delete tokens;
105 }
106}
107
108//______________________________________________________________________________
110{
111 // Set the line width in the context ctx.
112 //
113 // width - the line width in pixels
114 assert(ctx != 0 && "SetLineWidth, ctx parameter is null");
115
116
117 if (width < 0)
118 return;
119
120 CGContextSetLineWidth(ctx, width ? width : 1);
121}
122
123//______________________________________________________________________________
124void DrawLine(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
125{
126 assert(ctx != 0 && "DrawLine, ctx parameter is null");
127
128 CGContextBeginPath(ctx);
129 CGContextMoveToPoint(ctx, x1, y1);
130 CGContextAddLineToPoint(ctx, x2, y2);
131 CGContextStrokePath(ctx);
132}
133
134
135//______________________________________________________________________________
137{
138 // Draw a line through all points.
139 // n : number of points
140 // xy : list of points
141
142 assert(ctx != 0 && "DrawPolyLine, ctx parameter is null");
143 assert(xy != 0 && "DrawPolyLine, xy parameter is null");
144
145 CGContextBeginPath(ctx);
146 CGContextMoveToPoint(ctx, xy[0].fX, xy[0].fY);
147 for (Int_t i = 1; i < n; ++i)
148 CGContextAddLineToPoint(ctx, xy[i].fX, xy[i].fY);
149
150 if (xy[n - 1].fX == xy[0].fX && xy[n - 1].fY == xy[0].fY)
151 CGContextClosePath(ctx);
152
153 CGContextStrokePath(ctx);
154}
155
156}//namespace Quartz
157}//namespace ROOT
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
short Color_t
Color number (short).
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kWhite
Definition Rtypes.h:66
#define gROOT
Definition TROOT.h:417
externTStyle * gStyle
Definition TStyle.h:442
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:170
Collectable string class.
Definition TObjString.h:28
Basic string class.
Definition TString.h:138
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2270
const Int_t n
Definition legend1.C:16
void DrawPolyLine(CGContextRef ctx, Int_t n, TPoint *xy)
Bool_t SetLineColor(CGContextRef ctx, Color_t colorIndex)
Definition QuartzLine.mm:29
void SetLineType(CGContextRef ctx, Int_t n, Int_t *dash)
Definition QuartzLine.mm:50
void DrawLine(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
void SetLineWidth(CGContextRef ctx, Int_t width)
void SetLineStyle(CGContextRef ctx, Int_t lstyle)
Definition QuartzLine.mm:75