diff --git a/AUTHORS b/AUTHORS index cb04c967..fd7435bb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,7 +2,7 @@ $ Main contributors and volunteers of this repository (vChewing for macOS): - Shiki Suen // Main developer of vChewing for macOS, Megrez language engine, and Tekkon syllable composer engine. - Hiraku Wang // Technical reinforcement in Cocoa during the Object-Cpp dev period of this project. -- Isaac Xen // Technical reinforcement in Swift: SFX Module and StringView Ranges Extension. +- Isaac Xen // Technical reinforcement in Swift: SFX Module (NSSound ver.) and StringView Ranges Extension. $ Contributors and volunteeres of the upstream repo, having no responsibility in discussing anything in the current repo: diff --git a/Source/Data b/Source/Data index 06d16d8a..65d4da95 160000 --- a/Source/Data +++ b/Source/Data @@ -1 +1 @@ -Subproject commit 06d16d8a468668278ad9f50cc8629983c490fa42 +Subproject commit 65d4da952b2f2a52501b7d690073742ce3e7993c diff --git a/Source/Modules/ControllerModules/KeyHandler_Core.swift b/Source/Modules/ControllerModules/KeyHandler_Core.swift index 3374829c..447da1a2 100644 --- a/Source/Modules/ControllerModules/KeyHandler_Core.swift +++ b/Source/Modules/ControllerModules/KeyHandler_Core.swift @@ -162,36 +162,38 @@ class KeyHandler { func fixNode(value: String, respectCursorPushing: Bool = true) { let cursorIndex = min(actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), builderLength) - let selectedNode: Megrez.NodeAnchor = _builder.grid.fixNodeSelectedCandidate( - location: cursorIndex, value: value - ) - // 不要針對逐字選字模式啟用臨時半衰記憶模型。 - if !mgrPrefs.useSCPCTypingMode { - // If the length of the readings and the characters do not match, - // it often means it is a special symbol and it should not be stored - // in the user override model. - var addToUserOverrideModel = true - if selectedNode.spanningLength != value.count { - IME.prtDebugIntel("UOM: SpanningLength != value.count, dismissing.") - addToUserOverrideModel = false - } - if addToUserOverrideModel { - if let theNode = selectedNode.node { - // 威注音的 SymbolLM 的 Score 是 -12。 - if theNode.scoreFor(candidate: value) <= -12 { - IME.prtDebugIntel("UOM: Score <= -12, dismissing.") - addToUserOverrideModel = false - } - } - } - if addToUserOverrideModel { - IME.prtDebugIntel("UOM: Start Observation.") - _userOverrideModel.observe( - walkedNodes: _walkedNodes, cursorIndex: cursorIndex, candidate: value, - timestamp: NSDate().timeIntervalSince1970 - ) - } - } + _builder.grid.fixNodeSelectedCandidate(location: cursorIndex, value: value) + // // 因半衰模組失能,故禁用之。 + // let selectedNode: Megrez.NodeAnchor = _builder.grid.fixNodeSelectedCandidate( + // location: cursorIndex, value: value + // ) + // // 不要針對逐字選字模式啟用臨時半衰記憶模型。 + // if !mgrPrefs.useSCPCTypingMode { + // // If the length of the readings and the characters do not match, + // // it often means it is a special symbol and it should not be stored + // // in the user override model. + // var addToUserOverrideModel = true + // if selectedNode.spanningLength != value.count { + // IME.prtDebugIntel("UOM: SpanningLength != value.count, dismissing.") + // addToUserOverrideModel = false + // } + // if addToUserOverrideModel { + // if let theNode = selectedNode.node { + // // 威注音的 SymbolLM 的 Score 是 -12。 + // if theNode.scoreFor(candidate: value) <= -12 { + // IME.prtDebugIntel("UOM: Score <= -12, dismissing.") + // addToUserOverrideModel = false + // } + // } + // } + // if addToUserOverrideModel { + // IME.prtDebugIntel("UOM: Start Observation.") + // _userOverrideModel.observe( + // walkedNodes: _walkedNodes, cursorIndex: cursorIndex, candidate: value, + // timestamp: NSDate().timeIntervalSince1970 + // ) + // } + // } walk() if mgrPrefs.moveCursorAfterSelectingCandidate, respectCursorPushing { diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index 5e51dad9..a0895d56 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -188,7 +188,7 @@ extension KeyHandler { let poppedText = popOverflowComposingTextAndWalk // ... get and tweak override model suggestion if possible... - dealWithOverrideModelSuggestions() + // dealWithOverrideModelSuggestions() // 暫時禁用,因為無法使其生效。 // ... then update the text. _composer.clear() diff --git a/Source/Modules/SFX/clsSFX.swift b/Source/Modules/SFX/clsSFX.swift index 3fc43f7b..6a6b4e04 100644 --- a/Source/Modules/SFX/clsSFX.swift +++ b/Source/Modules/SFX/clsSFX.swift @@ -1,6 +1,4 @@ -// Copyright (c) 2022 and onwards Isaac Xen (MIT License). -// All possible vChewing-specific modifications are of: -// (c) 2021 and onwards The vChewing Project (MIT-NTL License). +// Copyright (c) 2021 and onwards The vChewing Project (MIT-NTL License). /* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -24,52 +22,15 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import Cocoa - -public class clsSFX: NSObject, NSSoundDelegate { - private static let shared = clsSFX() - override private init() { - super.init() - } - - private var currentBeep: NSSound? - private func beep() { - let defaultVolume: Float = 0.4 - // Stop existing beep - if let beep = currentBeep { - if beep.isPlaying { - for i in 1..<30 { - beep.volume = (defaultVolume / Float(i)) - usleep(1000) - } - beep.stop() - beep.volume = defaultVolume - } - } - // Create a new beep sound if possible - var sndBeep: String - if mgrPrefs.shouldNotFartInLieuOfBeep == false { - sndBeep = "Fart" - } else { - sndBeep = "Beep" - } - guard - let beep = NSSound(named: sndBeep) - else { - NSSound.beep() - return - } - beep.delegate = self - beep.volume = defaultVolume - beep.play() - currentBeep = beep - } - - public func sound(_: NSSound, didFinishPlaying _: Bool) { - currentBeep = nil - } +import AVFoundation +import Foundation +public class clsSFX { static func beep() { - shared.beep() + let filePath = Bundle.main.path(forResource: mgrPrefs.shouldNotFartInLieuOfBeep ? "Beep" : "Fart", ofType: "m4a")! + let fileURL = URL(fileURLWithPath: filePath) + var soundID: SystemSoundID = 0 + AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID) + AudioServicesPlaySystemSound(soundID) } } diff --git a/Source/Resources/SoundFiles/Beep.m4a b/Source/Resources/SoundFiles/Beep.m4a index 6972662d..16d382f7 100644 Binary files a/Source/Resources/SoundFiles/Beep.m4a and b/Source/Resources/SoundFiles/Beep.m4a differ diff --git a/Source/Resources/SoundFiles/Fart.m4a b/Source/Resources/SoundFiles/Fart.m4a index c945f649..b27b9552 100644 Binary files a/Source/Resources/SoundFiles/Fart.m4a and b/Source/Resources/SoundFiles/Fart.m4a differ diff --git a/Source/UI/CandidateUI/ctlCandidateUniversal.swift b/Source/UI/CandidateUI/ctlCandidateUniversal.swift index 7447cd16..568f5f03 100644 --- a/Source/UI/CandidateUI/ctlCandidateUniversal.swift +++ b/Source/UI/CandidateUI/ctlCandidateUniversal.swift @@ -409,8 +409,6 @@ public class ctlCandidateUniversal: ctlCandidate { let buttonAttribute: [NSAttributedString.Key: Any] = [.font: NSFont.systemFont(ofSize: 9.0)] nextPageButton = .init(frame: contentRect) - NSColor.controlBackgroundColor.setFill() - NSBezierPath.fill(nextPageButton.bounds) nextPageButton.wantsLayer = true nextPageButton.layer?.masksToBounds = true nextPageButton.layer?.borderColor = NSColor.clear.cgColor @@ -422,8 +420,6 @@ public class ctlCandidateUniversal: ctlCandidate { string: " ", attributes: buttonAttribute ) // Next Page Arrow prevPageButton = .init(frame: contentRect) - NSColor.controlBackgroundColor.setFill() - NSBezierPath.fill(prevPageButton.bounds) prevPageButton.wantsLayer = true prevPageButton.layer?.masksToBounds = true prevPageButton.layer?.borderColor = NSColor.clear.cgColor @@ -439,17 +435,13 @@ public class ctlCandidateUniversal: ctlCandidate { // MARK: Add Page Counter - contentRect.size = NSSize(width: 40.0, height: 20.0) + contentRect = NSRect(x: 128.0, y: 128.0, width: 48.0, height: 20.0) pageCounterLabel = .init(frame: contentRect) pageCounterLabel.isEditable = false pageCounterLabel.isSelectable = false pageCounterLabel.isBezeled = false - pageCounterLabel.textColor = NSColor( - red: 0.86, green: 0.86, blue: 0.86, alpha: 1.00 - ) - pageCounterLabel.drawsBackground = true - pageCounterLabel.backgroundColor = NSColor( - red: 0.18, green: 0.18, blue: 0.18, alpha: 1.00 + pageCounterLabel.attributedStringValue = NSMutableAttributedString( + string: " ", attributes: buttonAttribute ) panel.contentView?.addSubview(pageCounterLabel) @@ -466,8 +458,6 @@ public class ctlCandidateUniversal: ctlCandidate { prevPageButton.target = self prevPageButton.action = #selector(pageButtonAction(_:)) - - pageCounterLabel.font = pageCounterFont } @available(*, unavailable) @@ -554,30 +544,6 @@ extension ctlCandidateUniversal { return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0) } - // 用來顯示頁面計數器的 NSFont。因為結果可 nil,所以最好 guard-let 再用。 - private var pageCounterFont: NSFont? { - var pointSize: CGFloat { candidateView.fractionFontSize } - let systemFontDesc = NSFont.systemFont(ofSize: pointSize, weight: .light).fontDescriptor - let fractionFontDesc = systemFontDesc.addingAttributes( - [ - NSFontDescriptor.AttributeName.traits: [ - [ - NSFontDescriptor.FeatureKey.typeIdentifier: kFractionsType, - NSFontDescriptor.FeatureKey.selectorIdentifier: kDiagonalFractionsSelector, - ] - ] - ] - ) - return NSFont(descriptor: fractionFontDesc, size: pointSize) ?? nil - } - - // 用來生成拿給頁面計數器用的顯示字串。 - // TODO: 這衰洨的 pageCount 總是返回空字串,需要調查。 - private var pageCounterText: String { - if pageCount < 2 { return .init() } - return "\(currentPageIndex + 1)/" - } - private func layoutCandidateView() { guard let delegate = delegate else { return @@ -627,11 +593,11 @@ extension ctlCandidateUniversal { prevPageButton.isHidden = true } - if !pageCounterText.isEmpty { - let attrString = NSAttributedString( - string: pageCounterText.appending(String(pageCount)), + if pageCount >= 2 { + let attrString = NSMutableAttributedString( + string: "\(currentPageIndex + 1)/\(pageCount)", attributes: [ - .font: pageCounterFont as AnyObject + .font: NSFont.systemFont(ofSize: candidateView.fractionFontSize) ] ) pageCounterLabel.attributedStringValue = attrString @@ -641,6 +607,7 @@ extension ctlCandidateUniversal { ) rect.size.height += 3 + rect.size.width += 4 let rectOriginY: CGFloat = (currentLayout == .horizontal) ? (newSize.height - rect.height) / 2