OSDN Git Service

HMMaskSelectViewクラスをSwiftで書き換え
authormasakih <masakih@users.sourceforge.jp>
Tue, 30 Dec 2014 09:09:56 +0000 (18:09 +0900)
committermasakih <masakih@users.sourceforge.jp>
Tue, 30 Dec 2014 09:09:56 +0000 (18:09 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMMaskSelectView.h [deleted file]
KCD/HMMaskSelectView.m [deleted file]
KCD/HMMaskSelectView.swift [new file with mode: 0644]
KCD/HMScreenshotWindowController.m
KCD/KCD-Bridging-Header.h
KCD/ja.lproj/HMScreenshotListWindowController.xib

index 6dd9ede..31b221b 100644 (file)
@@ -64,7 +64,6 @@
                F4A2AF581A0930160024BD9E /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4A2AF571A0930160024BD9E /* Quartz.framework */; };
                F4A3AD82199F529700FDBF80 /* HMCombinedBattleCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A3AD81199F529700FDBF80 /* HMCombinedBattleCommand.m */; };
                F4A3AD8819B6149D00FDBF80 /* HMNyukyoStartCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A3AD8719B6149D00FDBF80 /* HMNyukyoStartCommand.m */; };
-               F4A3AD8B19B9BE7A00FDBF80 /* HMMaskSelectView.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A3AD8A19B9BE7A00FDBF80 /* HMMaskSelectView.m */; };
                F4A3AD9419BDDE5500FDBF80 /* HMPreferencePanelController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4A3AD9619BDDE5500FDBF80 /* HMPreferencePanelController.xib */; };
                F4AA05FB192B92C800844688 /* Temporary.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = F4AA05F9192B92C700844688 /* Temporary.xcdatamodeld */; };
                F4AA05FE192B932E00844688 /* HMTemporaryDataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = F4AA05FD192B932E00844688 /* HMTemporaryDataStore.m */; };
                F4E802071A50F8A100016781 /* HMSuppliesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E802061A50F8A100016781 /* HMSuppliesView.swift */; };
                F4E802091A511F5900016781 /* HMSuppliesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E802081A511F5900016781 /* HMSuppliesCell.swift */; };
                F4E8020B1A51954500016781 /* HMMaskInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E8020A1A51954500016781 /* HMMaskInformation.swift */; };
+               F4E8020F1A5245F700016781 /* HMMaskSelectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E8020E1A5245F700016781 /* HMMaskSelectView.swift */; };
                F4FCFD44191F4C1D000640A1 /* HMKenzoMarkCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4FCFD43191F4C1D000640A1 /* HMKenzoMarkCommand.m */; };
                F4FDF2411A3D50420033E0AD /* HMShipMasterDetailWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4FDF23F1A3D50420033E0AD /* HMShipMasterDetailWindowController.m */; };
                F4FDF2421A3D50420033E0AD /* HMShipMasterDetailWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4FDF2401A3D50420033E0AD /* HMShipMasterDetailWindowController.xib */; };
                F4A3AD81199F529700FDBF80 /* HMCombinedBattleCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCombinedBattleCommand.m; sourceTree = "<group>"; };
                F4A3AD8619B6149D00FDBF80 /* HMNyukyoStartCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMNyukyoStartCommand.h; sourceTree = "<group>"; };
                F4A3AD8719B6149D00FDBF80 /* HMNyukyoStartCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMNyukyoStartCommand.m; sourceTree = "<group>"; };
-               F4A3AD8919B9BE7A00FDBF80 /* HMMaskSelectView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMaskSelectView.h; sourceTree = "<group>"; };
-               F4A3AD8A19B9BE7A00FDBF80 /* HMMaskSelectView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMaskSelectView.m; sourceTree = "<group>"; };
                F4A3AD9519BDDE5500FDBF80 /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMPreferencePanelController.xib; sourceTree = "<group>"; };
                F4AA05FA192B92C800844688 /* Temporary.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Temporary.xcdatamodel; sourceTree = "<group>"; };
                F4AA05FC192B932E00844688 /* HMTemporaryDataStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMTemporaryDataStore.h; sourceTree = "<group>"; };
                F4E802061A50F8A100016781 /* HMSuppliesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSuppliesView.swift; sourceTree = "<group>"; };
                F4E802081A511F5900016781 /* HMSuppliesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSuppliesCell.swift; sourceTree = "<group>"; };
                F4E8020A1A51954500016781 /* HMMaskInformation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMMaskInformation.swift; sourceTree = "<group>"; };
+               F4E8020E1A5245F700016781 /* HMMaskSelectView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMMaskSelectView.swift; sourceTree = "<group>"; };
                F4FCFD42191F4C1D000640A1 /* HMKenzoMarkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKenzoMarkCommand.h; sourceTree = "<group>"; };
                F4FCFD43191F4C1D000640A1 /* HMKenzoMarkCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMKenzoMarkCommand.m; sourceTree = "<group>"; };
                F4FDF23E1A3D50420033E0AD /* HMShipMasterDetailWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMShipMasterDetailWindowController.h; sourceTree = "<group>"; };
                                F4B3DC4F18F150CD0011B4FC /* HMScreenshotWindowController.h */,
                                F4B3DC5018F150CD0011B4FC /* HMScreenshotWindowController.m */,
                                F4B2D02D18F83A2F00542742 /* HMScreenshotWindowController.xib */,
-                               F4A3AD8919B9BE7A00FDBF80 /* HMMaskSelectView.h */,
-                               F4A3AD8A19B9BE7A00FDBF80 /* HMMaskSelectView.m */,
+                               F4E8020E1A5245F700016781 /* HMMaskSelectView.swift */,
                                F4E8020A1A51954500016781 /* HMMaskInformation.swift */,
                                F4551BE31A48379F00BB0235 /* HMDeckViewController.swift */,
                                F4B2D03518F83CC800542742 /* HMDeckViewController.xib */,
                                F4D2CBC518AE2AE2000EBC59 /* HMCompositCommand.m in Sources */,
                                F4C1190218A6FFC2005D5B25 /* HMQueue.m in Sources */,
                                F4513EEB18B7900A00073552 /* HMMemberDeckCommand.m in Sources */,
+                               F4E8020F1A5245F700016781 /* HMMaskSelectView.swift in Sources */,
                                F4B3DC2A18DF31400011B4FC /* HMCreateShipCommand.m in Sources */,
                                F46F103618A7CE310063E503 /* HMJSONViewCommand.m in Sources */,
                                F4B3DC1E18DEB8C70011B4FC /* HMKenzoHistory.m in Sources */,
                                F4B3DBCA18DDB9170011B4FC /* HMCreateSlotItemCommand.m in Sources */,
                                F4131ED8190FA08D004F7F9A /* HMDestroyItem2Command.m in Sources */,
                                F4B3DC2718DF2F360011B4FC /* HMKenzoMark.m in Sources */,
-                               F4A3AD8B19B9BE7A00FDBF80 /* HMMaskSelectView.m in Sources */,
                                F4B414E918B09A4B00468DAF /* HMMasterMapAreaCommand.m in Sources */,
                                F4C3957418CDDFE500A1E918 /* HMKenzoDockStatus.m in Sources */,
                                F4C118FB18A67B1C005D5B25 /* CanonicalRequest.m in Sources */,
diff --git a/KCD/HMMaskSelectView.h b/KCD/HMMaskSelectView.h
deleted file mode 100644 (file)
index b9bae28..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-//
-//  HMMaskSelectView.h
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/09/05.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-@interface HMMaskSelectView : NSView
-
-@property (strong, nonatomic) NSMutableArray *masks;
-
-- (IBAction)disableAllMasks:(id)sender;
-
-@end
diff --git a/KCD/HMMaskSelectView.m b/KCD/HMMaskSelectView.m
deleted file mode 100644 (file)
index 2e8dcc0..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-//
-//  HMMaskSelectView.m
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/09/05.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMMaskSelectView.h"
-
-#import "KCD-Swift.h"
-
-
-const NSInteger kNumberOfMask = 4;
-static NSRect maskRects[kNumberOfMask];
-
-static NSSize originalSize;
-
-@implementation HMMaskSelectView
-
-+ (void)initialize
-{
-       static dispatch_once_t onceToken;
-       dispatch_once(&onceToken, ^{
-               maskRects[0] = NSMakeRect(113, 455, 100, 18);
-               maskRects[1] = NSMakeRect(203, 330, 200, 25);
-               maskRects[2] = NSMakeRect(95, 378, 100, 18);
-               maskRects[3] = NSMakeRect(60, 378, 100, 18);
-               
-               originalSize = NSMakeSize(800, 480);
-       });
-}
-
-- (id)initWithFrame:(NSRect)frame
-{
-    self = [super initWithFrame:frame];
-    if(self) {
-               [self buildMask];
-    }
-    return self;
-}
-
-- (id)initWithCoder:(NSCoder *)aDecoder
-{
-       self = [super initWithCoder:aDecoder];
-       if(self) {
-               [self buildMask];
-       }
-       return self;
-}
-
-- (void)buildMask
-{
-       self.masks = [NSMutableArray new];
-       NSRect frame = self.frame;
-       CGFloat widthRatio = frame.size.width / originalSize.width;
-       CGFloat heightRatio = frame.size.height / originalSize.height;
-       
-       for(NSInteger i = 0; i < kNumberOfMask; i++ ) {
-               HMMaskInformation *info = [HMMaskInformation new];
-               NSRect maskRect = NSMakeRect(
-                                                                        maskRects[i].origin.x * widthRatio,
-                                                                        maskRects[i].origin.y * heightRatio,
-                                                                        maskRects[i].size.width * widthRatio,
-                                                                        maskRects[i].size.height * heightRatio
-                                                                        );
-               info.maskRect = maskRect;
-               [self.masks addObject:info];
-               if(i == 3) {
-                       info.borderColor = [NSColor colorWithCalibratedRed:0.000 green:0.011 blue:1.000 alpha:1.000];
-               } else {
-                       info.borderColor = [NSColor redColor];
-               }
-//             info.maskColor = [NSColor blackColor];
-       }
-}
-
-- (void)drawRect:(NSRect)dirtyRect
-{
-    NSGraphicsContext *context = [NSGraphicsContext currentContext];
-       [context saveGraphicsState];
-       [context setShouldAntialias:NO];
-       
-       CGFloat dashSeed[] = {3.0, 3.0};
-       for(HMMaskInformation *info in self.masks) {
-               NSBezierPath *path = [NSBezierPath bezierPathWithRect:info.maskRect];
-               if(info.enable) {
-                       [info.maskColor set];
-                       [path fill];
-               }
-               [path setLineDash:dashSeed count:2 phase:0];
-               [info.borderColor set];
-               [path stroke];
-               [path setLineDash:dashSeed count:2 phase:3.0];
-               [[NSColor lightGrayColor] set];
-               [path stroke];
-       }
-       
-       [context restoreGraphicsState];
-       
-#if 0
-       NSBezierPath *path = [NSBezierPath bezierPath];
-       for(int i = 0; i < 800; i += 50) {
-               [path moveToPoint:NSMakePoint(i, 0)];
-               [path lineToPoint:NSMakePoint(i, 480)];
-       }
-       for(int j = 0; j < 480; j += 50) {
-               [path moveToPoint:NSMakePoint(0, j)];
-               [path lineToPoint:NSMakePoint(800, j)];
-       }
-       [[NSColor whiteColor] set];
-       [path stroke];
-#endif
-}
-
-- (void)mouseUp:(NSEvent *)event
-{
-       NSPoint mouse = [event locationInWindow];
-       mouse = [self convertPoint:mouse fromView:nil];
-       
-       for(HMMaskInformation *info in [self.masks reverseObjectEnumerator]) {
-               if(NSMouseInRect(mouse, info.maskRect, self.isFlipped)) {
-                       info.enable = !info.enable;
-                       [self setNeedsDisplayInRect:NSInsetRect(info.maskRect, -5, -5)];
-                       break;
-               }
-       }
-}
-
-- (IBAction)disableAllMasks:(id)sender
-{
-       for(HMMaskInformation *info in self.masks) {
-               info.enable = NO;
-       }
-       [self setNeedsDisplay:YES];
-}
-
-@end
diff --git a/KCD/HMMaskSelectView.swift b/KCD/HMMaskSelectView.swift
new file mode 100644 (file)
index 0000000..fd73fc0
--- /dev/null
@@ -0,0 +1,95 @@
+//
+//  HMMaskSelectView.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/12/30.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+class HMMaskSelectView: NSView
+{
+       override init(frame: NSRect) {
+               super.init(frame: frame)
+               masks = makeMask(frame: frame)
+       }
+       required init?(coder: NSCoder) {
+           super.init(coder: coder)
+               masks = makeMask(frame: frame)
+       }
+       
+       let masks: [HMMaskInformation]!
+       
+       private func makeMask(frame frameRect: NSRect) -> [HMMaskInformation] {
+               let originalSize: NSSize = NSSize(width: 800, height: 480)
+               
+               var masks: [HMMaskInformation] = []
+               let widthRatio = frameRect.size.width / originalSize.width
+               let heightRatio = frameRect.size.height / originalSize.height
+               
+               let maskRects: [NSRect] = [
+                       NSRect(x: 113, y: 455, width: 100, height: 18),
+                       NSRect(x: 203, y: 330, width: 200, height: 25),
+                       NSRect(x: 95, y: 378, width: 100, height: 18),
+                       NSRect(x: 60, y: 378, width: 100, height: 18)
+               ]
+               
+               for i in 0..<maskRects.count {
+                       let info = HMMaskInformation()
+                       info.maskRect = NSRect(
+                               x: maskRects[i].origin.x * widthRatio,
+                               y: maskRects[i].origin.y * heightRatio,
+                               width: maskRects[i].size.width * widthRatio,
+                               height: maskRects[i].size.height * heightRatio)
+                       if i == 3 {
+                               info.borderColor = NSColor(calibratedRed: 0.00, green: 0.011, blue: 1.000, alpha: 1.000)
+                       } else {
+                               info.borderColor = NSColor.redColor()
+                       }
+                       masks += [info]
+               }
+               return masks
+       }
+       
+    override func drawRect(dirtyRect: NSRect) {
+               let context = NSGraphicsContext.currentContext()
+               context?.saveGraphicsState()
+               context?.shouldAntialias = false
+               
+               let dashSeed:[CGFloat] = [3.0, 3.0]
+               for info in masks {
+                       let path = NSBezierPath(rect: info.maskRect)
+                       if info.enable {
+                               info.maskColor.set()
+                               path.fill()
+                       }
+                       path.setLineDash(dashSeed, count: dashSeed.count, phase: 0)
+                       info.borderColor?.set()
+                       path.stroke()
+                       path.setLineDash(dashSeed, count: dashSeed.count, phase: 3.0)
+                       NSColor.lightGrayColor().set()
+                       path.stroke()
+               }
+               context?.restoreGraphicsState()
+    }
+       
+       override func mouseUp(theEvent: NSEvent) {
+               var mouse = theEvent.locationInWindow
+               mouse = convertPoint(mouse, fromView: nil)
+               for info in masks.reverse() {
+                       if NSMouseInRect(mouse, info.maskRect, flipped) {
+                               info.enable = !info.enable
+                               setNeedsDisplayInRect(NSInsetRect(info.maskRect, -5, -5))
+                               break
+                       }
+               }
+       }
+       
+       @IBAction func disableAllMasks(sender: AnyObject?) {
+               for info in masks {
+                       info.enable = false
+               }
+               needsDisplay = true
+       }
+}
index 796e168..194d3ba 100644 (file)
@@ -8,7 +8,6 @@
 
 #import "HMScreenshotWindowController.h"
 #import "HMUserDefaults.h"
-#import "HMMaskSelectView.h"
 
 #import "HMAppDelegate.h"
 
index 694e9bc..ee3aa3c 100644 (file)
@@ -16,8 +16,6 @@
 #import "HMKenzoDockStatus.h"
 #import "HMFleetInformation.h"
 
-#import "HMMaskSelectView.h"
-
 
 @interface NSFileManager (KCDExtension)
 - (NSString *)_web_pathWithUniqueFilenameForPath:(NSString *)path;
index b161f75..628dba9 100644 (file)
                 <rect key="frame" x="0.0" y="1" width="853" height="430"/>
                 <autoresizingMask key="autoresizingMask"/>
                 <subviews>
-                    <scrollView horizontalLineScroll="132.75" horizontalPageScroll="10" verticalLineScroll="153" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="uRf-6p-n0n">
+                    <scrollView horizontalLineScroll="145" horizontalPageScroll="10" verticalLineScroll="145" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="uRf-6p-n0n">
                         <rect key="frame" x="-1" y="-1" width="461" height="432"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <clipView key="contentView" copiesOnScroll="NO" id="xHE-4e-HA7">
                             <rect key="frame" x="1" y="1" width="166" height="79"/>
                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                             <subviews>
-                                <ikImageBrowserView autoresizesSubviews="NO" zoomValue="4.5748710632324219" allowsMultipleSelection="NO" allowsEmptySelection="NO" id="FPI-Ma-X6H">
-                                    <rect key="frame" x="0.0" y="0.0" width="10000" height="2534"/>
+                                <ikImageBrowserView autoresizesSubviews="NO" zoomValue="0.5" allowsMultipleSelection="NO" allowsEmptySelection="NO" id="FPI-Ma-X6H">
+                                    <rect key="frame" x="0.0" y="0.0" width="10000" height="2885"/>
                                     <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
                                     <ikCellsStyle key="cellsStyleMask" none="YES" shadowed="YES" titled="YES" subtitled="YES"/>
                                     <autoresizingMask key="contentResizingMask" heightSizable="YES"/>
-                                    <size key="cellSize" width="6867" height="6867"/>
+                                    <size key="cellSize" width="125" height="125"/>
                                     <connections>
                                         <binding destination="mrq-7Y-mHG" name="content" keyPath="arrangedObjects" id="G0M-vZ-Pyi"/>
                                         <binding destination="-2" name="selectionIndexes" keyPath="selectedIndexes" previousBinding="G0M-vZ-Pyi" id="hZm-cJ-NmG"/>
@@ -86,7 +86,7 @@
                             <binding destination="-2" name="value" keyPath="appendKanColleTag" id="COG-Sp-61P"/>
                         </connections>
                     </button>
-                    <customView id="tQA-8E-MmO" customClass="HMMaskSelectView">
+                    <customView id="tQA-8E-MmO" customClass="HMMaskSelectView" customModule="KCD" customModuleProvider="target">
                         <rect key="frame" x="479" y="200" width="354" height="210"/>
                         <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
                         <connections>