//
//  PrizeDetailProcessView.m
//  Open
//
//  Created by 雷俊博 on 2019/9/5.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "PrizeDetailProcessView.h"
#import "Constants.h"
#define degreesToRadian(x) (M_PI * (x) / 180.0)
@interface PrizeDetailProcessView ()
{
    CGFloat _radius;
}

/** 遮罩 */

@property (nonatomic, strong) CAShapeLayer *maskLayer;

/** 路径 */

@property (nonatomic, strong) UIBezierPath *borderPath;

@end

@implementation PrizeDetailProcessView

-(instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        // 初始化遮罩
        self.maskLayer = [CAShapeLayer layer];
        // 设置遮罩
        [self.layer setMask:self.maskLayer];
        // 初始化路径
        self.borderPath = [UIBezierPath bezierPath];
        
        _radius = (frame.size.width - 21 * 5*WIDTHRADIU)/40;
    }
    
    return self;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //遮罩层frame
    self.maskLayer.frame = self.bounds;
    
    //设置path的起点
    [self.borderPath moveToPoint:CGPointMake(0, 10)];
    
    //左上角的圆角
    [self.borderPath addQuadCurveToPoint:CGPointMake(10, 0) controlPoint:CGPointMake(0, 0)];
    
    // 直线，到右上角
    
    [self.borderPath addLineToPoint:CGPointMake(self.bounds.size.width - 10, 0)];
    
    // 右上角的圆角
    
    [self.borderPath addQuadCurveToPoint:CGPointMake(self.bounds.size.width, 10) controlPoint:CGPointMake(self.bounds.size.width, 0)];
    
    // 直线，到右下角
    
    [self.borderPath addLineToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height)];
    [self.borderPath addLineToPoint:CGPointMake(self.bounds.size.width - 5 * WIDTHRADIU, self.bounds.size.height)];
    
    for (int i = 0; i < 20; i++) {
        
        [self.borderPath addArcWithCenter:CGPointMake(self.bounds.size.width -_radius - 5 * WIDTHRADIU - i *(_radius * 2 + 5 * WIDTHRADIU ) , self.bounds.size.height) radius:_radius startAngle:degreesToRadian(0) endAngle:degreesToRadian(180) clockwise:NO];
        
        [self.borderPath addLineToPoint:CGPointMake((5 * WIDTHRADIU + 2 *_radius)*(19 - i), self.bounds.size.height)];
    }
    
    
    
    [self.borderPath addLineToPoint:CGPointMake(0, 10)];
    
    self.maskLayer.path = self.borderPath.CGPath;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
