From 55c66bd59fd02feaa4fc49cf81539cb2893d73f2 Mon Sep 17 00:00:00 2001 From: masakih Date: Mon, 18 Sep 2017 23:30:04 +0900 Subject: [PATCH] =?utf8?q?=E8=89=A6=E9=9A=8A=E8=A1=A8=E7=A4=BA=E9=83=A8?= =?utf8?q?=E3=81=AE=E8=89=A6=E5=A8=98=E5=90=8D=E3=81=8C=E6=9E=A0=E3=81=8B?= =?utf8?q?=E3=82=89=E3=81=AF=E3=81=BF=E5=87=BA=E3=81=9F=E6=99=82=E3=81=AE?= =?utf8?q?=E5=87=A6=E7=90=86=E3=82=92=E8=A1=8C=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD.xcodeproj/project.pbxproj | 8 ++++ KCD/Base.lproj/MediumShipViewController.xib | 30 +++++++------- KCD/Base.lproj/ShipDetailViewController.xib | 10 ++--- KCD/FadeoutTextField.swift | 55 ++++++++++++++++++++++++++ KCD/NSTextFieldExtension.swift | 61 +++++++++++++++++++++++++++++ KCD/SlotItemLevelView.swift | 43 +++++--------------- 6 files changed, 154 insertions(+), 53 deletions(-) create mode 100644 KCD/FadeoutTextField.swift create mode 100644 KCD/NSTextFieldExtension.swift diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index 2bb39143..02a2f65d 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -209,6 +209,8 @@ F4AA594E1E1E4A7C001667AF /* UITestWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA594D1E1E4A7C001667AF /* UITestWindowController.swift */; }; F4AA59501E1E4D18001667AF /* ShipWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA594F1E1E4D18001667AF /* ShipWindowController.swift */; }; F4AA59521E1E607F001667AF /* JSONViewWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA59511E1E607F001667AF /* JSONViewWindowController.swift */; }; + F4AAA1511F6D6DDC00975E87 /* NSTextFieldExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AAA1501F6D6DDC00975E87 /* NSTextFieldExtension.swift */; }; + F4AAA1531F6D706E00975E87 /* FadeoutTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AAA1521F6D706E00975E87 /* FadeoutTextField.swift */; }; F4AC136D1E0802C000851147 /* PreferencePanelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AC136C1E0802C000851147 /* PreferencePanelController.swift */; }; F4AC136F1E0963DB00851147 /* ProgressPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AC136E1E0963DB00851147 /* ProgressPanel.swift */; }; F4AC13711E096A7B00851147 /* HistoryWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AC13701E096A7B00851147 /* HistoryWindowController.swift */; }; @@ -564,6 +566,8 @@ F4AA594D1E1E4A7C001667AF /* UITestWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITestWindowController.swift; sourceTree = ""; }; F4AA594F1E1E4D18001667AF /* ShipWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShipWindowController.swift; sourceTree = ""; }; F4AA59511E1E607F001667AF /* JSONViewWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONViewWindowController.swift; sourceTree = ""; }; + F4AAA1501F6D6DDC00975E87 /* NSTextFieldExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSTextFieldExtension.swift; sourceTree = ""; }; + F4AAA1521F6D706E00975E87 /* FadeoutTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FadeoutTextField.swift; sourceTree = ""; }; F4AC136C1E0802C000851147 /* PreferencePanelController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencePanelController.swift; sourceTree = ""; }; F4AC136E1E0963DB00851147 /* ProgressPanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressPanel.swift; sourceTree = ""; }; F4AC13701E096A7B00851147 /* HistoryWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryWindowController.swift; sourceTree = ""; }; @@ -1053,6 +1057,7 @@ children = ( F40F976C1E6708F300AE81BB /* Graphics.swift */, F40F97721E6989B300AE81BB /* NSViewExtension.swift */, + F4AAA1501F6D6DDC00975E87 /* NSTextFieldExtension.swift */, F4A9E7F21D045B8800F91746 /* ScreenshotList */, F4BDEB5B187252F30069D0CE /* MainMenu.xib */, F4BEEFE31B0CD3C5004702B8 /* MainWindow */, @@ -1194,6 +1199,7 @@ F4BEF00A1B11A5DE004702B8 /* ShipDetailViewController.xib */, F4BEF0011B11A5C2004702B8 /* MediumShipViewController.xib */, F49097841E1A15AF0085A45D /* SlotItemLevelView.swift */, + F4AAA1521F6D706E00975E87 /* FadeoutTextField.swift */, F490978C1E1BA64E0085A45D /* GuardEscapedView.swift */, F45FBB911E129BAE000E72B9 /* FleetViewController.swift */, F4BEF0071B11A5D3004702B8 /* FleetViewController.xib */, @@ -1524,6 +1530,7 @@ F4CF25AA1E338ED000C02A66 /* JSONTracker.swift in Sources */, F44BC6D11E224299004644E3 /* PortCommand.swift in Sources */, F4FC3E901E437E1F00E41228 /* JSONReciever.swift in Sources */, + F4AAA1511F6D6DDC00975E87 /* NSTextFieldExtension.swift in Sources */, F404AF571F2CDD1C00A006B8 /* DefaultKey.swift in Sources */, F45F3BE11E067A870009434E /* HistoryItemCleaner.swift in Sources */, F47C3E981E5DB29300D97449 /* JSONMapper.swift in Sources */, @@ -1622,6 +1629,7 @@ F4AA594A1E1E4863001667AF /* MapWindowController.swift in Sources */, F4FC3E961E46AC3000E41228 /* TSVSupport.swift in Sources */, F42A8FDA1E3DF2230099DC1D /* Ship.swift in Sources */, + F4AAA1531F6D706E00975E87 /* FadeoutTextField.swift in Sources */, F47C3E9A1E5DC90000D97449 /* MasterSTypeMapper.swift in Sources */, F4E5FF101E17A83D0026868C /* ScreenshotListWindowController.swift in Sources */, F44BC7031E252C4F004644E3 /* UpdateSlotItemCommand.swift in Sources */, diff --git a/KCD/Base.lproj/MediumShipViewController.xib b/KCD/Base.lproj/MediumShipViewController.xib index b6896511..3f216006 100644 --- a/KCD/Base.lproj/MediumShipViewController.xib +++ b/KCD/Base.lproj/MediumShipViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -30,7 +30,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -93,7 +93,7 @@ - + @@ -111,7 +111,7 @@ - + @@ -130,7 +130,7 @@ - + @@ -139,7 +139,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -166,7 +166,7 @@ - + @@ -184,7 +184,7 @@ - + @@ -193,7 +193,7 @@ - + @@ -211,7 +211,7 @@ - + @@ -220,7 +220,7 @@ - + diff --git a/KCD/Base.lproj/ShipDetailViewController.xib b/KCD/Base.lproj/ShipDetailViewController.xib index 3e437626..e1c4dab9 100644 --- a/KCD/Base.lproj/ShipDetailViewController.xib +++ b/KCD/Base.lproj/ShipDetailViewController.xib @@ -34,7 +34,7 @@ - + @@ -502,7 +502,6 @@ - @@ -510,6 +509,7 @@ IA + @@ -522,7 +522,6 @@ IA - @@ -530,6 +529,7 @@ IA + @@ -542,7 +542,6 @@ IA - @@ -550,6 +549,7 @@ IA + @@ -562,7 +562,6 @@ IA - @@ -570,6 +569,7 @@ IA + diff --git a/KCD/FadeoutTextField.swift b/KCD/FadeoutTextField.swift new file mode 100644 index 00000000..1d265a4f --- /dev/null +++ b/KCD/FadeoutTextField.swift @@ -0,0 +1,55 @@ +// +// FadeoutTextField.swift +// KCD +// +// Created by Hori,Masaki on 2017/09/16. +// Copyright © 2017年 Hori,Masaki. All rights reserved. +// + +import Cocoa + +class FadeoutTextField: NSTextField { + + var middle1: CGFloat = 0.8 + var middle2: CGFloat = 1.0 + + private var maskImage: CGImage? { + + if !isCharacterProtrude() { + + return nil + } + + if let image = cachMaskImage { + + return image + } + + cachMaskImage = maskImage(middle1: middle1, middle2: middle2) + + return cachMaskImage + } + + private var cachMaskImage: CGImage? + + override func draw(_ dirtyRect: NSRect) { + + guard let context = NSGraphicsContext.current()?.cgContext + else { fatalError("Con not get current CGContext") } + + context.saveGState() + maskImage.map { context.clip(to: bounds, mask: $0) } + + super.draw(dirtyRect) + + context.restoreGState() + } + + override func resizeSubviews(withOldSize oldSize: NSSize) { + + cachMaskImage = nil + + super.resizeSubviews(withOldSize: oldSize) + } + +} diff --git a/KCD/NSTextFieldExtension.swift b/KCD/NSTextFieldExtension.swift new file mode 100644 index 00000000..e0b9b332 --- /dev/null +++ b/KCD/NSTextFieldExtension.swift @@ -0,0 +1,61 @@ +// +// NSTextFieldExtension.swift +// KCD +// +// Created by Hori,Masaki on 2017/09/16. +// Copyright © 2017年 Hori,Masaki. All rights reserved. +// + +import Cocoa + +extension NSTextField { + + func maskImage(middle1: CGFloat, middle2: CGFloat) -> CGImage { + + let colorspace = CGColorSpaceCreateDeviceGray() + + guard let maskContext = CGContext(data: nil, + width: Int(bounds.width), + height: Int(bounds.height), + bitsPerComponent: 8, + bytesPerRow: Int(bounds.width), + space: colorspace, + bitmapInfo: 0) + else { fatalError("Can not create bitmap context") } + + let maskGraphicsContext = NSGraphicsContext(cgContext: maskContext, flipped: false) + + + NSGraphicsContext.saveGraphicsState() + defer { NSGraphicsContext.restoreGraphicsState() } + + NSGraphicsContext.setCurrent(maskGraphicsContext) + + let gradient = NSGradient(colorsAndLocations: (NSColor.white, 0.0), + (NSColor.white, middle1), + (NSColor.black, middle2), + (NSColor.black, 1.0)) + gradient?.draw(in: bounds, angle: 0.0) + + guard let r = maskContext.makeImage() + else { fatalError(" can not create image from context") } + + return r + } + + func isCharacterProtrude(kern: CGFloat = 0) -> Bool { + + guard let currentFont = font else { + + Swift.print("TextField dose not set font") + + return false + } + + let string = stringValue as NSString + let size = string.size(withAttributes: [NSFontAttributeName: currentFont, NSKernAttributeName: kern]) + + return bounds.size.width - size.width < 3 + } + +} diff --git a/KCD/SlotItemLevelView.swift b/KCD/SlotItemLevelView.swift index 7e9061ff..6e536496 100644 --- a/KCD/SlotItemLevelView.swift +++ b/KCD/SlotItemLevelView.swift @@ -12,6 +12,7 @@ final class SlotItemLevelView: NSTextField { private static var sLevelMaskImage: CGImage? private static var sAirLevelMaskImage: CGImage? + private static var sCharacterProtrudeMaskImageMaskImage: CGImage? private let offset: CGFloat = 28 private let padding: CGFloat = 4 @@ -70,6 +71,8 @@ final class SlotItemLevelView: NSTextField { if let alv = slotItemAlv as? Int, alv != 0 { return airLevelMaskImage } if let lv = slotItemLevel as? Int, lv != 0 { return levelMaskImage } + if isCharacterProtrude() { return characterProtrudeMaskImage } + return nil } @@ -88,6 +91,13 @@ final class SlotItemLevelView: NSTextField { return SlotItemLevelView.sAirLevelMaskImage! } + private var characterProtrudeMaskImage: CGImage { + + if let r = SlotItemLevelView.sCharacterProtrudeMaskImageMaskImage { return r } + SlotItemLevelView.sCharacterProtrudeMaskImageMaskImage = maskImage(middle1: 0.9, middle2: 1.0) + + return SlotItemLevelView.sCharacterProtrudeMaskImageMaskImage! + } private var levelOneBezierPath: NSBezierPath? { @@ -257,39 +267,6 @@ final class SlotItemLevelView: NSTextField { drawAirLevel() } - private func maskImage(middle1: CGFloat, middle2: CGFloat) -> CGImage { - - let colorspace = CGColorSpaceCreateDeviceGray() - - guard let maskContext = CGContext(data: nil, - width: Int(bounds.width), - height: Int(bounds.height), - bitsPerComponent: 8, - bytesPerRow: Int(bounds.width), - space: colorspace, - bitmapInfo: 0) - else { fatalError("Can not create bitmap context") } - - let maskGraphicsContext = NSGraphicsContext(cgContext: maskContext, flipped: false) - - - NSGraphicsContext.saveGraphicsState() - defer { NSGraphicsContext.restoreGraphicsState() } - - NSGraphicsContext.setCurrent(maskGraphicsContext) - - let gradient = NSGradient(colorsAndLocations: (NSColor.white, 0.0), - (NSColor.white, middle1), - (NSColor.black, middle2), - (NSColor.black, 1.0)) - gradient?.draw(in: bounds, angle: 0.0) - - guard let r = maskContext.makeImage() - else { fatalError(" can not create image from context") } - - return r - } - private func bezierPathForALevel(level: Int) -> NSBezierPath? { switch level { -- 2.11.0