8000 修正画圆弧API · newcoderzhang/LuaViewSDK@ca8e8a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca8e8a3

Browse files
author
城西
committed
修正画圆弧API
1 parent 329bcaa commit ca8e8a3

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

IOS/LuaViewSDK/Classes/lvsdk/LVCanvas.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#import "LVData.h"
1313
#import "LVImage.h"
1414

15+
#define LV_ANGLE_RADIANS(angle) (M_PI*angle/180)
16+
1517
@interface LVCanvas ()
1618
@property(nonatomic,strong) UIColor* color;
1719
@property(nonatomic,assign) CGFloat strokeWidth;
@@ -418,9 +420,31 @@ static int canvas_drawOval (lv_State *L) {
418420
return canvas_drawEllipse(L);
419421
}
420422

423+
-(void) drawArc:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h :(CGFloat)startAngle :(CGFloat)endAngle :(BOOL) includeCenter{
424+
if( _contentRef ) {
425+
x += w/2;
426+
y += h/2;
427+
if( includeCenter ) {
428+
CGContextMoveToPoint(_contentRef, x, y);
429+
}
430+
CGContextAddArc(_contentRef, x, y, w/2, LV_ANGLE_RADIANS(startAngle), LV_ANGLE_RADIANS(endAngle), NO);
431+
CGContextClosePath(_contentRef);
432+
CGContextDrawPath(_contentRef, self.drawingMode);
433+
}
434+
}
435+
421436
static int canvas_drawArc (lv_State *L) {
422437
LVUserDataInfo * user = (LVUserDataInfo *)lv_touserdata(L, 1);
423438
if( user ){
439+
CGFloat x = lv_tonumber(L, 2);
440+
CGFloat y = lv_tonumber(L, 3);
441+
CGFloat w = lv_tonumber(L, 4);
442+
CGFloat h = lv_tonumber(L, 5);
443+
CGFloat startAngle = lv_tonumber(L, 6);
444+
CGFloat endAngle = lv_tonumber(L, 7);
445+
BOOL includeCenter = lv_toboolean(L, 8);
446+
LVCanvas* canvas = (__bridge LVCanvas *)(user->object);
447+
[canvas drawArc:x :y :w :h :startAngle :endAngle :includeCenter];
424448
}
425449
return 0;
426450
}
@@ -501,7 +525,7 @@ static int canvas_restore (lv_State *L) {
501525
-(void) rotate:(CGFloat) angle :(CGFloat)x :(CGFloat) y{
502526
if( _contentRef ) {
503527
CGContextTranslateCTM(_contentRef, x, y);
504-
CGContextRotateCTM(_contentRef,M_PI*angle/180);
528+
CGContextRotateCTM(_contentRef,LV_ANGLE_RADIANS(angle) );
505529
CGContextTranslateCTM(_contentRef, -x, -y);
506530
}
507531
}

0 commit comments

Comments
 (0)
0