Fix keyboard input on Mac
This commit is contained in:
parent
9de568cb36
commit
112bca57ce
|
@ -16,14 +16,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
// Create the window and set the content view.
|
// Create the window and set the content view.
|
||||||
window = NSWindow(
|
window = TetrisWindow()
|
||||||
contentRect: NSRect(x: 0, y: 0, width: 634, height: 804),
|
|
||||||
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
|
||||||
backing: .buffered, defer: false)
|
|
||||||
window.center()
|
window.center()
|
||||||
window.setFrameAutosaveName("Main Window")
|
|
||||||
window.contentViewController = TetrisViewController()
|
|
||||||
window.title = "Tetris"
|
|
||||||
window.makeKeyAndOrderFront(nil)
|
window.makeKeyAndOrderFront(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,10 @@ import TetrisKit
|
||||||
|
|
||||||
class TetrisViewController: NSViewController {
|
class TetrisViewController: NSViewController {
|
||||||
|
|
||||||
let gameController = GameController()
|
let gameController: GameController
|
||||||
|
|
||||||
init() {
|
init(gameController: GameController) {
|
||||||
|
self.gameController = gameController
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
preferredContentSize = NSSize(width: 634, height: 804)
|
preferredContentSize = NSSize(width: 634, height: 804)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,7 @@ class TetrisViewController: NSViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
self.view = TetrisHostingView(gameController)
|
self.view = NSHostingView(rootView: ContentView(controller: gameController))
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear() {
|
override func viewDidAppear() {
|
||||||
|
|
|
@ -1,35 +1,28 @@
|
||||||
//
|
//
|
||||||
// TetrisHostingView.swift
|
// TetrisWindow.swift
|
||||||
// Tetris Mac
|
// Tetris Mac
|
||||||
//
|
//
|
||||||
// Created by Shadowfacts on 10/16/19.
|
// Created by Shadowfacts on 4/5/20.
|
||||||
// Copyright © 2019 Shadowfacts. All rights reserved.
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
import SwiftUI
|
|
||||||
import Carbon
|
|
||||||
import TetrisKit
|
import TetrisKit
|
||||||
|
import Carbon
|
||||||
|
|
||||||
class TetrisHostingView: NSHostingView<ContentView> {
|
class TetrisWindow: NSWindow {
|
||||||
|
|
||||||
let gameController: GameController
|
|
||||||
|
|
||||||
override var acceptsFirstResponder: Bool {
|
let gameController = GameController()
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
init(_ gameController: GameController) {
|
init() {
|
||||||
self.gameController = gameController
|
super.init(contentRect: NSRect(x: 0, y: 0, width: 634, height: 804),
|
||||||
super.init(rootView: ContentView(controller: gameController))
|
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||||
}
|
backing: .buffered,
|
||||||
|
defer: false)
|
||||||
required init(rootView: ContentView) {
|
|
||||||
fatalError("init(rootView:) has not been implemented")
|
setFrameAutosaveName("Main Window")
|
||||||
}
|
contentViewController = TetrisViewController(gameController: gameController)
|
||||||
|
title = "Tetris"
|
||||||
required init?(coder aDecoder: NSCoder) {
|
|
||||||
fatalError("init(coder:) has not been implemented")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func keyDown(with event: NSEvent) {
|
override func keyDown(with event: NSEvent) {
|
||||||
|
@ -58,5 +51,5 @@ class TetrisHostingView: NSHostingView<ContentView> {
|
||||||
super.flagsChanged(with: event)
|
super.flagsChanged(with: event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -60,6 +60,7 @@
|
||||||
D608564723551602005BE4BC /* BoardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564523551602005BE4BC /* BoardView.swift */; };
|
D608564723551602005BE4BC /* BoardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564523551602005BE4BC /* BoardView.swift */; };
|
||||||
D608564923551BAC005BE4BC /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564823551BAC005BE4BC /* GridView.swift */; };
|
D608564923551BAC005BE4BC /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564823551BAC005BE4BC /* GridView.swift */; };
|
||||||
D608564A23551BAC005BE4BC /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564823551BAC005BE4BC /* GridView.swift */; };
|
D608564A23551BAC005BE4BC /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564823551BAC005BE4BC /* GridView.swift */; };
|
||||||
|
D640E3E9243A5F15008F9972 /* TetrisWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D640E3E8243A5F14008F9972 /* TetrisWindow.swift */; };
|
||||||
D6AA0AE6235D273E00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
|
D6AA0AE6235D273E00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
|
||||||
D6AA0AE7235D273F00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
|
D6AA0AE7235D273F00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
|
||||||
D6AA0AE8235D273F00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
|
D6AA0AE8235D273F00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
|
||||||
|
@ -93,7 +94,6 @@
|
||||||
D6E560722357D65700BF9ACF /* NextTetrominoesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6DC0E9823579A4D008A0A98 /* NextTetrominoesView.swift */; };
|
D6E560722357D65700BF9ACF /* NextTetrominoesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6DC0E9823579A4D008A0A98 /* NextTetrominoesView.swift */; };
|
||||||
D6E560732357D65700BF9ACF /* Tetromino+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D84DF323567231002968FB /* Tetromino+Color.swift */; };
|
D6E560732357D65700BF9ACF /* Tetromino+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D84DF323567231002968FB /* Tetromino+Color.swift */; };
|
||||||
D6E560772357DF7D00BF9ACF /* TetrisViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */; };
|
D6E560772357DF7D00BF9ACF /* TetrisViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */; };
|
||||||
D6E560792357E1EC00BF9ACF /* TetrisHostingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E560782357E1EC00BF9ACF /* TetrisHostingView.swift */; };
|
|
||||||
D6E5609C2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
|
D6E5609C2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
|
||||||
D6E5609D2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
|
D6E5609D2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
|
||||||
D6E5609E2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
|
D6E5609E2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
|
||||||
|
@ -305,6 +305,7 @@
|
||||||
D608562F23551269005BE4BC /* TilesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TilesView.swift; sourceTree = "<group>"; };
|
D608562F23551269005BE4BC /* TilesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TilesView.swift; sourceTree = "<group>"; };
|
||||||
D608564523551602005BE4BC /* BoardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardView.swift; sourceTree = "<group>"; };
|
D608564523551602005BE4BC /* BoardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardView.swift; sourceTree = "<group>"; };
|
||||||
D608564823551BAC005BE4BC /* GridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridView.swift; sourceTree = "<group>"; };
|
D608564823551BAC005BE4BC /* GridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridView.swift; sourceTree = "<group>"; };
|
||||||
|
D640E3E8243A5F14008F9972 /* TetrisWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisWindow.swift; sourceTree = "<group>"; };
|
||||||
D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GamePieceView.swift; sourceTree = "<group>"; };
|
D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GamePieceView.swift; sourceTree = "<group>"; };
|
||||||
D6D84DF323567231002968FB /* Tetromino+Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Tetromino+Color.swift"; sourceTree = "<group>"; };
|
D6D84DF323567231002968FB /* Tetromino+Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Tetromino+Color.swift"; sourceTree = "<group>"; };
|
||||||
D6D84DF72356B8F0002968FB /* TetrominoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrominoView.swift; sourceTree = "<group>"; };
|
D6D84DF72356B8F0002968FB /* TetrominoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrominoView.swift; sourceTree = "<group>"; };
|
||||||
|
@ -321,7 +322,6 @@
|
||||||
D6E560482357D5D300BF9ACF /* TetrisKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TetrisKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
D6E560482357D5D300BF9ACF /* TetrisKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TetrisKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
D6E560602357D63E00BF9ACF /* TetrisUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TetrisUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
D6E560602357D63E00BF9ACF /* TetrisUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TetrisUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisViewController.swift; sourceTree = "<group>"; };
|
D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisViewController.swift; sourceTree = "<group>"; };
|
||||||
D6E560782357E1EC00BF9ACF /* TetrisHostingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisHostingView.swift; sourceTree = "<group>"; };
|
|
||||||
D6E5609B2358C50A00BF9ACF /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
|
D6E5609B2358C50A00BF9ACF /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
|
||||||
D6E5609F2358C68C00BF9ACF /* BundleHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleHelper.swift; sourceTree = "<group>"; };
|
D6E5609F2358C68C00BF9ACF /* BundleHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleHelper.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
@ -546,8 +546,8 @@
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
D6E560322357C8AF00BF9ACF /* AppDelegate.swift */,
|
D6E560322357C8AF00BF9ACF /* AppDelegate.swift */,
|
||||||
|
D640E3E8243A5F14008F9972 /* TetrisWindow.swift */,
|
||||||
D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */,
|
D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */,
|
||||||
D6E560782357E1EC00BF9ACF /* TetrisHostingView.swift */,
|
|
||||||
D6E560342357C8AF00BF9ACF /* ContentView.swift */,
|
D6E560342357C8AF00BF9ACF /* ContentView.swift */,
|
||||||
D6E560362357C8B100BF9ACF /* Assets.xcassets */,
|
D6E560362357C8B100BF9ACF /* Assets.xcassets */,
|
||||||
D6E5603B2357C8B100BF9ACF /* Main.storyboard */,
|
D6E5603B2357C8B100BF9ACF /* Main.storyboard */,
|
||||||
|
@ -1082,9 +1082,9 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
D6E560792357E1EC00BF9ACF /* TetrisHostingView.swift in Sources */,
|
|
||||||
D6E560352357C8AF00BF9ACF /* ContentView.swift in Sources */,
|
D6E560352357C8AF00BF9ACF /* ContentView.swift in Sources */,
|
||||||
D6E560332357C8AF00BF9ACF /* AppDelegate.swift in Sources */,
|
D6E560332357C8AF00BF9ACF /* AppDelegate.swift in Sources */,
|
||||||
|
D640E3E9243A5F15008F9972 /* TetrisWindow.swift in Sources */,
|
||||||
D6E560772357DF7D00BF9ACF /* TetrisViewController.swift in Sources */,
|
D6E560772357DF7D00BF9ACF /* TetrisViewController.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
|
Loading…
Reference in New Issue