<commit_before>//
//  ItemAddingMapFilterView.swift
//  AxReminder
//
//  Created by devedbox on 2017/7/19.
//  Copyright © 2017年 devedbox. All rights reserved.
//

import UIKit

private let RadiusMinimalThreshold: CGFloat = 20.0

class ItemAddingMapFilterView: UIView {
    fileprivate var _circleView: UIView
    fileprivate var _handlerView: UIView
    public var widthOfHandler: CGFloat = 20.0 {
        didSet {
            _handlerView.layer.cornerRadius = widthOfHandler * 0.5
            _handlerView.layer.masksToBounds = true
        }
    }
    public var radius: CGFloat = 50.0 {
        didSet {
            setNeedsLayout()
            layoutIfNeeded()
        }
    }
    
    override init(frame: CGRect) {
        _circleView = UIView()
        _handlerView = UIView()
        super.init(frame: frame)
    }
    required init?(coder aDecoder: NSCoder) {
        _circleView = UIView()
        _handlerView = UIView()
        super.init(coder: aDecoder)
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        _initializer()
    }
    private func _initializer() {
        _circleView.isUserInteractionEnabled = false
        _circleView.backgroundColor = UIColor.clear
        _circleView.layer.borderWidth = 5.0
        _circleView.layer.borderColor = UIColor.application.blue.cgColor
        
        _handlerView.backgroundColor = .black
        _handlerView.layer.cornerRadius = widthOfHandler * 0.5
        _handlerView.layer.masksToBounds = true
        _handlerView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(_handleSliderPanGesture(_:))))
        
        addSubview(_circleView)
        addSubview(_handlerView)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let size = CGSize(width: radius*2.0, height: radius*2.0)
        let origin = CGPoint(x: bounds.width * 0.5 - size.width * 0.5, y: bounds.height * 0.5 - size.height * 0.5)
        _circleView.frame = CGRect(origin: origin, size: size)
        _circleView.layer.cornerRadius = radius
        _circleView.layer.masksToBounds = true
        
        _handlerView.frame = CGRect(origin: .zero, size: CGSize(width: widthOfHandler, height: widthOfHandler))
        _handlerView.center = CGPoint(x: _circleView.center.x + _circleView.bounds.width * 0.5 - _circleView.layer.borderWidth * 0.5, y: _circleView.center.y)
        
        setNeedsDisplay()
    }
    
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if _handlerView.frame.contains(point) {
            return _handlerView
        }
        return nil
    }

    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
        super.draw(rect)
        guard let context = UIGraphicsGetCurrentContext() else { return }
        context.setFillColor(UIColor.application.blue.withAlphaComponent(0.05).cgColor)
        
        let outterPath = CGPath(rect: bounds, transform: nil)
        context.addPath(outterPath)
        context.fillPath()
        
        let innerPath = CGPath(roundedRect: _circleView.frame, cornerWidth: radius, cornerHeight: radius, transform: nil)
        context.addPath(innerPath)
        
        context.setBlendMode(.clear)
        context.fillPath()
        
        // context.beginPath()
        context.setLineWidth(1.0)
        context.setLineDash(phase: 1.0, lengths: [1.0, 2])
        context.setStrokeColor(UIColor.black.cgColor)
        context.move(to: _circleView.center)
        context.addLine(to: _handlerView.center)
        context.strokePath()
    }
    
    // MARK: - Private.
    <commit_msg>Deleted circle view.<commit_after>//
//  ItemAddingMapFilterView.swift
//  AxReminder
//
//  Created by devedbox on 2017/7/19.
//  Copyright © 2017年 devedbox. All rights reserved.
//

import UIKit

private let RadiusMinimalThreshold: CGFloat = 20.0

extension ItemAddingMapFilterView {
    enum DrawingMode {
        case inside
        case outside
    }
}

class ItemAddingMapFilterView: UIView {
    fileprivate var _handlerView: UIView
    public var widthOfHandler: CGFloat = 20.0 {
        didSet {
            _handlerView.layer.cornerRadius = widthOfHandler * 0.5
            _handlerView.layer.masksToBounds = true
        }
    }
    public var radius: CGFloat = 50.0 {
        didSet {
            setNeedsLayout()
            layoutIfNeeded()
        }
    }
    
    public var drawingMode: DrawingMode = .outside {
        didSet {
            setNeedsDisplay()
        }
    }
    
    override init(frame: CGRect) {
        _handlerView = UIView()
        super.init(frame: frame)
    }
    required init?(coder aDecoder: NSCoder) {
        _handlerView = UIView()
        super.init(coder: aDecoder)
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        _initializer()
    }
    private func _initializer() {
        backgroundColor = .clear
        
        _handlerView.backgroundColor = .black
        _handlerView.layer.cornerRadius = widthOfHandler * 0.5
        _handlerView.layer.masksToBounds = true
        _handlerView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(_handleSliderPanGesture(_:))))
        
        addSubview(_handlerView)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let size = CGSize(width: radius*2.0, height: radius*2.0)
        let origin = CGPoint(x: bounds.width * 0.5 - size.width * 0.5, y: bounds.height * 0.5 - size.height * 0.5)
        let frame = CGRect(origin: origin, size: size)
        
        _handlerView.frame = CGRect(origin: .zero, size: CGSize(width: widthOfHandler, height: widthOfHandler))
        _handlerView.center = CGPoint(x: bounds.width * 0.5 + frame.width * 0.5 - 5.0 * 0.5, y: bounds.height * 0.5)
        
        setNeedsDisplay()
    }
    
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if _handlerView.frame.contains(point) {
            return _handlerView
        }
        return nil
    }

    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
        super.draw(rect)
        guard let context = UIGraphicsGetCurrentContext() else { return }
        let _center = CGPoint(x: bounds.width * 0.5, y: bounds.height * 0.5)
        
        context.setFillColor(UIColor.application.blue.withAlphaComponent(0.15).cgColor)
        
        if drawingMode == .outside {
            let outterPath = CGPath(rect: bounds, transform: nil)
            context.addPath(outterPath)
            context.fillPath()
        }
        
        context.addArc(center: _center, radius: radius - 2.5, startAngle: 0.0, endAngle: CGFloat.pi * 2.0, clockwise: true)
        
        if drawingMode == .outside {
            context.setBlendMode(.clear)
        }
        context.fillPath()
        
        if drawingMode == .outside {
            context.setBlendMode(.normal)
        }
        
        context.beginPath()
        context.setLineWidth(5.0)
        context.setStrokeColor(UIColor.application.blue.cgColor)
        context.addArc(center: _center, radius: radius - 2.5, startAngle: 0.0, endAngle: CGFloat.pi * 2.0, clockwise: true)
        context.strokePath()
        
        context.beginPath()
        context.setLineWidth(1.0)
        context.setStrokeColor(UIColor.black.cgColor)
        context.setLineDash(phase: 2.0, lengths: [4.0, 2.0])
        context.setStrokeColor(UIColor.black.cgColor)
        context.move(to: _center)
        context.addLine(to: _handlerView.center)
        context.strokePath()
    }
    
    // MARK: - Private.
    
{'fraction_non_alphanumeric': 0.0977310178729877, 'fraction_numerical': 0.016098364811763216, 'mean_word_length': 2.2177814029363785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1463622', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2355, 'n_words': 499}