windingRule
パスのくりぬき規則
@property NSWindingRule windingRulevar windingRule: NSWindingRule
解説
ベジエパスのくりぬき規則を返します
【NSWindingRule】
● NSNonZeroWindingRule 重なる塗りオブジェクトの向きが逆ならくりぬきます
● NSEvenOddWindingRule 重なる塗りオブジェクトの向きが同じならくりぬきます
引数
フレームワーク
ApplicationKit
クラス
NSBezierPath
使用可能
10.0
関連記事(外部サイト)
例文
#import "MyView.h" @implementation MyView //NSViewのサブクラス MyViewのDrawRectに上書き -(void)drawRect:(NSRect)rect { NSBezierPath *thePath = [NSBezierPath bezierPath]; [thePath moveToPoint:NSMakePoint(200,200)]; [thePath lineToPoint:NSMakePoint(200,200)]; [thePath appendBezierPathWithArcFromPoint:NSMakePoint(250,250) toPoint:NSMakePoint(0,250) radius:100]; [[NSColor blueColor] set]; [thePath stroke]; if([thePath windingRule] ==NSNonZeroWindingRule){ NSLog(@"NSNonZeroWindingRule"); }else{ NSLog(@"NSEvenOddWindingRule"); } } @end
//NSBezierPath windingRule var aButton022 : NSButton? var aView022 : NSView? //実験用ビューのボタンを押した時に実行されるところ func viewAction022(sender : AnyObject?){ //準備 let aButton = aButton022 let aView = aView022 var theWindow : NSWindow = aButton!.window! //準備ここまで //ビューにフォーカスを当てる aView?.lockFocus() //バックグラウンドカラーを描画 let backgroundColor = NSColor.whiteColor() backgroundColor.setFill() NSRectFill(NSMakeRect(0, 20, 300.0, 178.0)) NSColor.redColor().setStroke() NSColor.magentaColor().setFill() //空のベジェパスを作成 //let aBezier : NSBezierPath = NSBezierPath() //->defaultWindingRule Non Zero let aBezier : NSBezierPath = NSBezierPath(ovalInRect: NSMakeRect(100.0, 100.0, 200.0, 100.0)) let o1Bezier : NSBezierPath = NSBezierPath(ovalInRect: NSMakeRect(120.0, 100.0, 50.0, 50.0)) let o2Bezier : NSBezierPath = NSBezierPath(ovalInRect: NSMakeRect(220.0, 100.0, 50.0, 50.0)) aBezier.windingRule = .NonZeroWindingRule o1Bezier.windingRule = .NonZeroWindingRule o2Bezier.windingRule = .NonZeroWindingRule aBezier.appendBezierPath(o1Bezier) aBezier.appendBezierPath(o2Bezier.bezierPathByReversingPath) switch (aBezier.windingRule ){ case .EvenOddWindingRule: NSLog("windingRule EvenOdd") case .NonZeroWindingRule: NSLog("windingRule Non Zero") default: NSLog("default") } aBezier.fill() aBezier.lineWidth = 2.0 aBezier.stroke() //ビューからフォーカスを外す aView?.unlockFocus() //NSLog("!!! %@",aBezier.description) } @IBAction func function022(sender: AnyObject) { var aWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false, screen: NSScreen.mainScreen()) windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄 aWindow.center()//ウインドウをスクリーンの中心に aWindow.title = "NSBezierPath"//タイトル設定 //ボタン var theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 0.0, 100.0, 30.0)) theButton.title = "Action" theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton.action = Selector("viewAction022:") theButton.target = self aWindow.contentView.addSubview(theButton) //ビュー var theView : NSView = NSView(frame: NSMakeRect(0.0, 20.0, 300.0, 100.0)) //レイヤーバックドにするのだ theView.wantsLayer = true aWindow.contentView.addSubview(theView) //実験ウインドウにUIパーツを渡す self.aButton022 = theButton //ボタン self.aView022 = theView //テストビュー aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }
更新時バージョン
10.10