|
12 | 12 | #import "LVData.h"
|
13 | 13 | #import "LVImage.h"
|
14 | 14 |
|
| 15 | +#define LV_ANGLE_RADIANS(angle) (M_PI*angle/180) |
| 16 | + |
15 | 17 | @interface LVCanvas ()
|
16 | 18 | @property(nonatomic,strong) UIColor* color;
|
17 | 19 | @property(nonatomic,assign) CGFloat strokeWidth;
|
@@ -418,9 +420,31 @@ static int canvas_drawOval (lv_State *L) {
|
418 | 420 | return canvas_drawEllipse(L);
|
419 | 421 | }
|
420 | 422 |
|
| 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 | + |
421 | 436 | static int canvas_drawArc (lv_State *L) {
|
422 | 437 | LVUserDataInfo * user = (LVUserDataInfo *)lv_touserdata(L, 1);
|
423 | 438 | 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]; |
424 | 448 | }
|
425 | 449 | return 0;
|
426 | 450 | }
|
@@ -501,7 +525,7 @@ static int canvas_restore (lv_State *L) {
|
501 | 525 | -(void) rotate:(CGFloat) angle :(CGFloat)x :(CGFloat) y{
|
502 | 526 | if( _contentRef ) {
|
503 | 527 | CGContextTranslateCTM(_contentRef, x, y);
|
504 |
| - CGContextRotateCTM(_contentRef,M_PI*angle/180); |
| 528 | + CGContextRotateCTM(_contentRef,LV_ANGLE_RADIANS(angle) ); |
505 | 529 | CGContextTranslateCTM(_contentRef, -x, -y);
|
506 | 530 | }
|
507 | 531 | }
|
|
0 commit comments