圆环,扇形控件基本算法一种实现 - 代码库 - CocoaChina_让移动开发更简单

 

//
//  CircleCore.h
//  Quartz
//
//  Created by 仙人掌 on 12-11-5.
//  Copyright (c) 2012年 仙人掌. All rights reserved.
//

#import

#define ToRad( degree ) ( degree * M_PI / 180 )

#define ToDeg( rad )    ( rad / M_PI * 180 )

#define ZERO_DEGREE     (-90.0f)

typedef enum{
    PT_DONE   = 0,
    PT_UNDONE,
}Path_Type;

typedef struct CircleData{
    CGPoint center;
    CGFloat radius;
}CircleData;

CircleData CircleDataMake(CGPoint center, CGFloat radius);
CGFloat DistanceBetweenPoints(CGPoint point1,CGPoint point2);
@interface CircleCore : NSObject{
    CGFloat referenceDegree_;
    CGFloat currentDegree_;
    CircleData smallCircle_;
    CircleData largeCircle_;
}
@property( nonatomic ) CGFloat referenceDegree;
@property( nonatomic ) CGFloat currentDegree;
@property( nonatomic ) CircleData smallCircle;
@property( nonatomic ) CircleData largeCircle;
-(CGMutablePathRef)GetPathForMode:(Path_Type)pathType;
-(BOOL)PointInPathWithPoint:(CGPoint)point BetweenDegree:(CGFloat)start And:(CGFloat)end;
@end
//-----------------------------------------------------------------------------------------------------------------------------------------------------
//
//  CircleCore.m
//  Quartz
//
//  Created by 仙人掌 on 12-11-5.
//  Copyright (c) 2012年 仙人掌. All rights reserved.
//

#import "CircleCore.h"

CircleData CircleDataMake(CGPoint center, CGFloat radius){
    CircleData myCircleData;
    myCircleData.center = center;
    myCircleData.radius = radius;
    return myCircleData;
}
CGFloat DistanceBetweenPoints(CGPoint point1,CGPoint point2){
    CGFloat temp = ( point1.x - point2.x ) * ( point1.x - point2.x ) + ( point1.y - point2.y ) * ( point1.y - point2.y );
    return ( CGFloat )sqrt( temp );
}

@interface CircleCore(Pravite)
-(CGMutablePathRef)GetPathForMode_DONE;
-(CGMutablePathRef)GetPathForMode_UNDONE;
-(CGPoint)GetPointWithCircle:(CircleData)circle AtDegree:(CGFloat)degree;

@end

@implementation CircleCore(Pravite)
-(CGPoint)GetPointWithCircle:(CircleData)circle AtDegree:(CGFloat)degree{
    CGFloat x,y;
    x = circle.center.x + cos( ToRad( degree ) ) * circle.radius;
    y = circle.center.y + sin( ToRad( degree ) ) * circle.radius;
    return CGPointMake( x, y );
}
-(CGMutablePathRef)GetPathForMode_DONE{
    CGMutablePathRef resultPath = CGPathCreateMutable();
    
    CGPoint smallCircle_referencePoint = [self GetPointWithCircle:smallCircle_ AtDegree:referenceDegree_];
    CGPoint largeCircle_referencePoint = [self GetPointWithCircle:largeCircle_ AtDegree:referenceDegree_];
    CGPoint smallCircle_currentPoint = [self GetPointWithCircle:smallCircle_ AtDegree:currentDegree_];
    CGPathMoveToPoint( resultPath, NULL, smallCircle_referencePoint.x, smallCircle_referencePoint.y );
    CGPathAddLineToPoint( resultPath, NULL, largeCircle_referencePoint.x, largeCircle_referencePoint.y );
    CGPathAddArc( resultPath, NULL, smallCircle_.center.x, smallCircle_.center.y, largeCircle_.radius, ToRad( referenceDegree_ ), ToRad( currentDegree_ ), 0 );
    CGPathAddLineToPoint( resultPath, NULL, smallCircle_currentPoint.x, smallCircle_currentPoint.y );
    CGPathAddArc( resultPath, NULL, smallCircle_.center.x, smallCircle_.center.y, smallCircle_.radius, ToRad( currentDegree_ ), ToRad( referenceDegree_ ), 1 );

return resultPath;
}

-(CGMutablePathRef)GetPathForMode_UNDONE{
    CGMutablePathRef resultPath = CGPathCreateMutable();
    CGPoint largeCircle_referencePoint = [self GetPointWithCircle:largeCircle_ AtDegree:referenceDegree_];
    CGPoint smallCircle_currentPoint = [self GetPointWithCircle:smallCircle_ AtDegree:currentDegree_];
    
    CGPathMoveToPoint(resultPath, NULL, largeCircle_referencePoint.x, largeCircle_referencePoint.y);
    CGPathAddArc(resultPath, NULL, largeCircle_.center.x, largeCircle_.center.y, largeCircle_.radius, ToRad(referenceDegree_), ToRad(currentDegree_), 1);
    CGPathAddLineToPoint(resultPath, NULL, smallCircle_currentPoint.x, smallCircle_currentPoint.y);
    CGPathAddArc(resultPath, NULL, smallCircle_.center.x, smallCircle_.center.y, smallCircle_.radius, ToRad(currentDegree_), ToRad(referenceDegree_), 0);
    CGPathAddLineToPoint(resultPath, NULL, largeCircle_referencePoint.x, largeCircle_referencePoint.y);
    return resultPath;
}
@end

@implementation CircleCore
@synthesize referenceDegree = referenceDegree_;
@synthesize currentDegree = currentDegree_;
@synthesize smallCircle = smallCircle_;
@synthesize largeCircle = largeCircle_;
-(id)init{
    self  = [super init];
    if ( nil != self){
        referenceDegree_ = ZERO_DEGREE;
        referenceDegree_ = ZERO_DEGREE;
    }
    return self;
}
-(CGFloat)referenceDegree{
    return referenceDegree_ - ZERO_DEGREE;
}

-(void)setReferenceDegree:(CGFloat)referenceDegree{
    referenceDegree_ = referenceDegree + ZERO_DEGREE;
}

-(void)setCurrentDegree:(CGFloat)currentDegree{
    currentDegree_ = currentDegree + ZERO_DEGREE;
}

-(CGFloat)currentDegree{
    return currentDegree_ - ZERO_DEGREE;
}

-(CGMutablePathRef)GetPathForMode:(Path_Type)pathType{
    switch (pathType) {
        case PT_DONE:
            return [self GetPathForMode_DONE];
        case PT_UNDONE:
            return [self GetPathForMode_UNDONE];
        default:
            return NULL;
    }
}
-(BOOL)PointInPathWithPoint:(CGPoint)point BetweenDegree:(CGFloat)start And:(CGFloat)end{
    CGFloat distance = DistanceBetweenPoints( point, largeCircle_.center );
    if ( distance > largeCircle_.radius || distance < smallCircle_.radius )
        return NO;
    CGFloat base_degree = 0.0f;
    NSInteger flag = 0;
    CGPoint base_point = CGPointMake( point.x - largeCircle_.center.x, largeCircle_.center.y - point.y );
    if ( base_point.x >= 0.0f && base_point.y >= 0.0f ){ //第一象限
        base_degree = 0.0f;
        flag = 1;
    }
    else if ( base_point.x < 0 && base_point.y >= 0 ){  //第二象限
        base_degree = 360.0;
        flag = 2;
    }
    else if ( base_point.x <0 && base_point.y < 0 ){   //第三象限
        base_degree = 180.0f;
        flag = 3;
    }
    else{                                              //第四象限
        base_degree = 180.0f;
        flag = 4;
    }
//
    CGFloat x = ABS( base_point.x );
    double temp_rad = asin( x / distance );
    CGFloat result = 0.0f;
    if ( 1 == flag || 3 == flag )
        result = ToDeg( temp_rad ) + base_degree;
    else
        result = base_degree - ToDeg( temp_rad );
    if ( result >= start  && result <= end )
        return YES;
    else
        return NO;
}
@end

圆环,扇形控件基本算法一种实现 - 代码库 - CocoaChina_让移动开发更简单的更多相关文章

  1. 屏蔽webbrowser控件右键的一种方法

    原文:屏蔽webbrowser控件右键的一种方法 Option ExplicitPrivate Declare Sub ZeroMemory Lib "KERNEL32" Alia ...

  2. WPF编程,通过Double Animation动态更改控件属性的一种方法。

    原文:WPF编程,通过Double Animation动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/a ...

  3. WPF编程,通过【帧】动态更改控件属性的一种方法。

    原文:WPF编程,通过[帧]动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detail ...

  4. [转]MFC子线程中更新控件内容的两种办法

    一.概述 每个系统中都有线程(至少都有一个主线程),而线程最重要的作用就是并行处理,提高软件的并发率.针对界面来说,还能提高界面的响应能力.一般的,为了应用的稳定性,在数据处理等耗时操作会单独在一个线 ...

  5. C# WinForm中 让控件全屏显示的实现代码

    夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...

  6. Devexpress treelist 树形控件 实现带三种状态的CheckBox

    树形控件是使用频率很高的一种控件.对于属性控件往往需要下面两个功能 1.TreeList带有CheckBox,并且节点要有三种状态(所有的子节点都选中,所有的子节点都没选择,一部分子节点选中).使用 ...

  7. VC 对话框背景颜色、控件颜色(三种方法)

    系统环境:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为对话框设置背景颜色.控件颜色 既然MFC对话框不好开发,那么现在我们来开始美化我们的对话框.为对话框设置背景颜色 ...

  8. C#自动实现Dll(OCX)控件注册的两种方法

    尽管MS为我们提供了丰富的.net framework库,我们的程序C#开发带来了极大的便利,但是有时候,一些特定功能的控件库还是需要由第三方提供或是自己编写.当需要用到Dll引用的时候,我们通常会通 ...

  9. 【Winform-自定义控件】可以使用2种半透明的颜色来填充Button

    制作一个自定义按钮,使用2种半透明的颜色来填充Button 1.添加一个自定义控件类,并改变基类,继承自Button public partial class CustomControl1 : But ...

随机推荐

  1. C#发送GET与POST请求

    ////////HTTPGET   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = ...

  2. Silverlight & Blend动画设计系列四:倾斜动画(SkewTransform)

    Silverlight中的倾斜变化动画(SkewTransform)能够实现对象元素的水平.垂直方向的倾斜变化动画效果.我们现实生活中的倾斜变化效果是非常常见的,比如翻书的纸张效果,关门开门的时候门缝 ...

  3. .net core 填坑记之—格式转换问题

    最近在将项目从.net 迁移到.net core环境中,迁移完成后,发布于Windows平台上进行测试,所有功能均能正常运行. 为了项目能够在正式环境也能正常运行,提前进行Linux环境部署(Cent ...

  4. C Primer Plus note6

    error: invalid preprocessing directive #difine| 无效的宏定义处理 宏定义define 写成了 difine.

  5. Tomcat Post请求大小限制

    理论上讲,POST是没有大小限制的.HTTP协议规范也没有进行大小限制,起限制作用的是服务器的处理程序的处理能力. 如:在Tomcat下取消POST大小的限制(Tomcat默认2M): 打开tomca ...

  6. PHPStorm-Mintfy-And-Color-Schema

    美化Php-storm 1.隐藏一些工具条 打开一个项目后我习惯把一些工具条隐藏,在view菜单中把Tool buttons,Status bar,Navigation bar. CTRL+E 切换当 ...

  7. bzoj2119 股市的预测

    传送门 感觉智商莫名其妙的就变低了……写这题的时候死活想不出来…… 做法其实不难…… 题目要求形如ABA的串的个数,我们可以枚举A的长度,利用标记关键点的方法统计答案.设枚举到的答案为k,每k个点标记 ...

  8. BZOJ2882: 工艺(后缀数组)

    题意 题目链接 Sol 直接把序列复制一遍 后缀数组即可 在前\(N\)个位置中取\(rak\)最小的输出 #include<bits/stdc++.h> using namespace ...

  9. <Android 应用 之路> MPAndroidChart~LineChart

    简介 MPAndroidChart是PhilJay大神给Android开发者带来的福利.MPAndroidChart是一个功能强大并且使用灵活的图表开源库,支持Android和IOS两种,这里我们暂时 ...

  10. 求解2的N次幂的问题(多种方法)

    #include <iostream> using namespace std; //计算2的N次幂 //一般方法,时间复杂度为2^n __int64 pow2(int n) { __in ...