project_files/HedgewarsMobile/Classes/MGSplitViewController/MGSplitCornersView.m
changeset 6908 896ed2afcfb8
parent 6659 a6030b32b222
child 8441 a00b0fa0dbd7
equal deleted inserted replaced
6907:a2f9a9a62dc5 6908:896ed2afcfb8
     5 //  Created by Matt Gemmell on 28/07/2010.
     5 //  Created by Matt Gemmell on 28/07/2010.
     6 //  Copyright 2010 Instinctive Code.
     6 //  Copyright 2010 Instinctive Code.
     7 //
     7 //
     8 
     8 
     9 #import "MGSplitCornersView.h"
     9 #import "MGSplitCornersView.h"
    10 
    10 #import "CGPointUtils.h"
    11 
    11 
    12 @implementation MGSplitCornersView
    12 @implementation MGSplitCornersView
    13 
    13 
    14 
    14 
    15 #pragma mark -
    15 #pragma mark -
    34 - (void)dealloc
    34 - (void)dealloc
    35 {
    35 {
    36 	self.cornerBackgroundColor = nil;
    36 	self.cornerBackgroundColor = nil;
    37 	
    37 	
    38 	[super dealloc];
    38 	[super dealloc];
    39 }
       
    40 
       
    41 
       
    42 #pragma mark -
       
    43 #pragma mark Geometry helpers
       
    44 
       
    45 
       
    46 double deg2Rad(double degrees)
       
    47 {
       
    48 	// Converts degrees to radians.
       
    49 	return degrees * (M_PI / 180.0);
       
    50 }
       
    51 
       
    52 
       
    53 double rad2Deg(double radians)
       
    54 {
       
    55 	// Converts radians to degrees.
       
    56 	return radians * (180 / M_PI);
       
    57 }
    39 }
    58 
    40 
    59 
    41 
    60 #pragma mark -
    42 #pragma mark -
    61 #pragma mark Drawing
    43 #pragma mark Drawing
    76 		CGPoint pt = CGPointZero;
    58 		CGPoint pt = CGPointZero;
    77 		switch (cornersPosition) {
    59 		switch (cornersPosition) {
    78 			case MGCornersPositionLeadingVertical: // top of screen for a left/right split
    60 			case MGCornersPositionLeadingVertical: // top of screen for a left/right split
    79 				[path moveToPoint:pt];
    61 				[path moveToPoint:pt];
    80 				pt.y += cornerRadius;
    62 				pt.y += cornerRadius;
    81 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(90) endAngle:0 clockwise:YES]];
    63 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(90) endAngle:0 clockwise:YES]];
    82 				pt.x += cornerRadius;
    64 				pt.x += cornerRadius;
    83 				pt.y -= cornerRadius;
    65 				pt.y -= cornerRadius;
    84 				[path addLineToPoint:pt];
    66 				[path addLineToPoint:pt];
    85 				[path addLineToPoint:CGPointZero];
    67 				[path addLineToPoint:CGPointZero];
    86 				[path closePath];
    68 				[path closePath];
    89 				pt.y = 0;
    71 				pt.y = 0;
    90 				[path moveToPoint:pt];
    72 				[path moveToPoint:pt];
    91 				pt.y = maxY;
    73 				pt.y = maxY;
    92 				[path addLineToPoint:pt];
    74 				[path addLineToPoint:pt];
    93 				pt.x += cornerRadius;
    75 				pt.x += cornerRadius;
    94 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(180) endAngle:deg2Rad(90) clockwise:YES]];
    76 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(180) endAngle:degreesToRadians(90) clockwise:YES]];
    95 				pt.y -= cornerRadius;
    77 				pt.y -= cornerRadius;
    96 				[path addLineToPoint:pt];
    78 				[path addLineToPoint:pt];
    97 				pt.x -= cornerRadius;
    79 				pt.x -= cornerRadius;
    98 				[path addLineToPoint:pt];
    80 				[path addLineToPoint:pt];
    99 				[path closePath];
    81 				[path closePath];
   102 				
    84 				
   103 			case MGCornersPositionTrailingVertical: // bottom of screen for a left/right split
    85 			case MGCornersPositionTrailingVertical: // bottom of screen for a left/right split
   104 				pt.y = maxY;
    86 				pt.y = maxY;
   105 				[path moveToPoint:pt];
    87 				[path moveToPoint:pt];
   106 				pt.y -= cornerRadius;
    88 				pt.y -= cornerRadius;
   107 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(270) endAngle:deg2Rad(360) clockwise:NO]];
    89 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(270) endAngle:degreesToRadians(360) clockwise:NO]];
   108 				pt.x += cornerRadius;
    90 				pt.x += cornerRadius;
   109 				pt.y += cornerRadius;
    91 				pt.y += cornerRadius;
   110 				[path addLineToPoint:pt];
    92 				[path addLineToPoint:pt];
   111 				pt.x -= cornerRadius;
    93 				pt.x -= cornerRadius;
   112 				[path addLineToPoint:pt];
    94 				[path addLineToPoint:pt];
   116 				pt.y = maxY;
    98 				pt.y = maxY;
   117 				[path moveToPoint:pt];
    99 				[path moveToPoint:pt];
   118 				pt.y -= cornerRadius;
   100 				pt.y -= cornerRadius;
   119 				[path addLineToPoint:pt];
   101 				[path addLineToPoint:pt];
   120 				pt.x += cornerRadius;
   102 				pt.x += cornerRadius;
   121 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(180) endAngle:deg2Rad(270) clockwise:NO]];
   103 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(180) endAngle:degreesToRadians(270) clockwise:NO]];
   122 				pt.y += cornerRadius;
   104 				pt.y += cornerRadius;
   123 				[path addLineToPoint:pt];
   105 				[path addLineToPoint:pt];
   124 				pt.x -= cornerRadius;
   106 				pt.x -= cornerRadius;
   125 				[path addLineToPoint:pt];
   107 				[path addLineToPoint:pt];
   126 				[path closePath];
   108 				[path closePath];
   132 				pt.y = cornerRadius;
   114 				pt.y = cornerRadius;
   133 				[path moveToPoint:pt];
   115 				[path moveToPoint:pt];
   134 				pt.y -= cornerRadius;
   116 				pt.y -= cornerRadius;
   135 				[path addLineToPoint:pt];
   117 				[path addLineToPoint:pt];
   136 				pt.x += cornerRadius;
   118 				pt.x += cornerRadius;
   137 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(180) endAngle:deg2Rad(270) clockwise:NO]];
   119 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(180) endAngle:degreesToRadians(270) clockwise:NO]];
   138 				pt.y += cornerRadius;
   120 				pt.y += cornerRadius;
   139 				[path addLineToPoint:pt];
   121 				[path addLineToPoint:pt];
   140 				pt.x -= cornerRadius;
   122 				pt.x -= cornerRadius;
   141 				[path addLineToPoint:pt];
   123 				[path addLineToPoint:pt];
   142 				[path closePath];
   124 				[path closePath];
   145 				pt.y = maxY - cornerRadius;
   127 				pt.y = maxY - cornerRadius;
   146 				[path moveToPoint:pt];
   128 				[path moveToPoint:pt];
   147 				pt.y = maxY;
   129 				pt.y = maxY;
   148 				[path addLineToPoint:pt];
   130 				[path addLineToPoint:pt];
   149 				pt.x += cornerRadius;
   131 				pt.x += cornerRadius;
   150 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(180) endAngle:deg2Rad(90) clockwise:YES]];
   132 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(180) endAngle:degreesToRadians(90) clockwise:YES]];
   151 				pt.y -= cornerRadius;
   133 				pt.y -= cornerRadius;
   152 				[path addLineToPoint:pt];
   134 				[path addLineToPoint:pt];
   153 				pt.x -= cornerRadius;
   135 				pt.x -= cornerRadius;
   154 				[path addLineToPoint:pt];
   136 				[path addLineToPoint:pt];
   155 				[path closePath];
   137 				[path closePath];
   158 				
   140 				
   159 			case MGCornersPositionTrailingHorizontal: // right of screen for a top/bottom split
   141 			case MGCornersPositionTrailingHorizontal: // right of screen for a top/bottom split
   160 				pt.y = cornerRadius;
   142 				pt.y = cornerRadius;
   161 				[path moveToPoint:pt];
   143 				[path moveToPoint:pt];
   162 				pt.y -= cornerRadius;
   144 				pt.y -= cornerRadius;
   163 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(270) endAngle:deg2Rad(360) clockwise:NO]];
   145 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(270) endAngle:degreesToRadians(360) clockwise:NO]];
   164 				pt.x += cornerRadius;
   146 				pt.x += cornerRadius;
   165 				pt.y += cornerRadius;
   147 				pt.y += cornerRadius;
   166 				[path addLineToPoint:pt];
   148 				[path addLineToPoint:pt];
   167 				pt.x -= cornerRadius;
   149 				pt.x -= cornerRadius;
   168 				[path addLineToPoint:pt];
   150 				[path addLineToPoint:pt];
   169 				[path closePath];
   151 				[path closePath];
   170 				
   152 				
   171 				pt.y = maxY - cornerRadius;
   153 				pt.y = maxY - cornerRadius;
   172 				[path moveToPoint:pt];
   154 				[path moveToPoint:pt];
   173 				pt.y += cornerRadius;
   155 				pt.y += cornerRadius;
   174 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:deg2Rad(90) endAngle:0 clockwise:YES]];
   156 				[path appendPath:[UIBezierPath bezierPathWithArcCenter:pt radius:cornerRadius startAngle:degreesToRadians(90) endAngle:0 clockwise:YES]];
   175 				pt.x += cornerRadius;
   157 				pt.x += cornerRadius;
   176 				pt.y -= cornerRadius;
   158 				pt.y -= cornerRadius;
   177 				[path addLineToPoint:pt];
   159 				[path addLineToPoint:pt];
   178 				pt.x -= cornerRadius;
   160 				pt.x -= cornerRadius;
   179 				[path addLineToPoint:pt];
   161 				[path addLineToPoint:pt];