Skip to content

Commit a250341

Browse files
committed
UI progress
1 parent 763f693 commit a250341

File tree

12 files changed

+485
-28
lines changed

12 files changed

+485
-28
lines changed

Package.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ let package = Package(
5959
"Gravity",
6060
"uFBX",
6161
])
62-
dependencies.append(
63-
.target(name: "Vorbis",
64-
condition: .when(platforms: .any(except: .macOS, .wasi)))
65-
)
62+
// dependencies.append(
63+
// .target(name: "Vorbis",
64+
// condition: .when(platforms: .any(except: .wasi)))
65+
// )
6666

6767
#if os(macOS) || os(Linux)
6868
dependencies.append(
@@ -166,13 +166,13 @@ let package = Package(
166166
settings.append(.define("GATEENGINE_WASI_UNSUPPORTED_HOST", .when(platforms: [.wasi])))
167167
#endif
168168

169-
#if false // Experimental and upcomming language features.
169+
#if true // Experimental and upcomming language features.
170170
// These should be disabled for releases.
171171
// These are to get a headstart on the next Swift versions.
172172
// https://www.swift.org/swift-evolution/#?upcoming=true
173173
settings.append(contentsOf: [
174174
.enableUpcomingFeature("IsolatedDefaultValues"),
175-
.enableUpcomingFeature("InternalImportsByDefault"),
175+
// .enableUpcomingFeature("InternalImportsByDefault"),
176176
.enableUpcomingFeature("DisableOutwardActorInference"),
177177
.enableUpcomingFeature("ImportObjcForwardDeclarations"),
178178
.enableUpcomingFeature("BareSlashRegexLiterals"),
@@ -186,8 +186,8 @@ let package = Package(
186186

187187
.enableExperimentalFeature("AccessLevelOnImport"),
188188
// .enableExperimentalFeature("StrictConcurrency"),
189-
// .enableExperimentalFeature("StrictConcurrency=minimal"),
190-
.enableExperimentalFeature("StrictConcurrency=complete"),
189+
.enableExperimentalFeature("StrictConcurrency=minimal"),
190+
// .enableExperimentalFeature("StrictConcurrency=complete"),
191191
])
192192
#endif
193193

@@ -259,12 +259,12 @@ let package = Package(
259259

260260
targets.append(contentsOf: [
261261
// Vorbis
262-
.target(name: "Vorbis",
263-
path: "Dependencies/Vorbis",
264-
publicHeadersPath: "include",
265-
cSettings: [
266-
.define("extern", to: "__declspec(dllexport) extern", .when(platforms: [.windows]))
267-
]),
262+
// .target(name: "Vorbis",
263+
// path: "Dependencies/Vorbis",
264+
// publicHeadersPath: "include",
265+
// cSettings: [
266+
// .define("extern", to: "__declspec(dllexport) extern", .when(platforms: [.windows]))
267+
// ]),
268268

269269
// miniz
270270
.target(name: "miniz",

Sources/GateEngine/Game.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public final class Game {
9494
@MainActor func willTerminate() {
9595
self.delegate.willTerminate(game: self)
9696
}
97+
98+
@MainActor internal func openURLs(_ urls: [URL]) {
99+
self.delegate.openURLs(urls)
100+
}
97101

98102
@MainActor internal func addPlatformSystems() {
99103
if isHeadless == false {

Sources/GateEngine/GameDelegate.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public protocol GameDelegate: AnyObject {
7575
By default the executablke name is used.
7676
*/
7777
nonisolated func gameIdentifier() -> StaticString?
78+
79+
/**
80+
This is called when the platform host wants you to open something. This can be a user selected file or something else.
81+
*/
82+
func openURLs(_ urls: [URL])
7883

7984
@MainActor
8085
init()
@@ -144,6 +149,10 @@ extension GameDelegate {
144149
}
145150
return identifier
146151
}
152+
153+
public func openURLs(_ urls: [URL]) {
154+
155+
}
147156
}
148157

149158
extension GameDelegate {

Sources/GateEngine/System/Platforms/Apple/AppKit/AppKit/AppKitWindow.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class AppKitWindow: WindowBacking {
4848
var styleMask: NSWindow.StyleMask = [.titled, .resizable, .miniaturizable]
4949

5050
switch window.style {
51-
case .bestForGames:
51+
case .minimalSystemDecorations:
5252
styleMask.insert(.fullSizeContentView)
5353
case .system:
5454
break
@@ -69,7 +69,7 @@ final class AppKitWindow: WindowBacking {
6969
)
7070
self.nsWindowController = NSWindowController(window: nsWindow)
7171
nsWindow.isReleasedWhenClosed = false
72-
if window.style == .bestForGames {
72+
if window.style == .minimalSystemDecorations {
7373
nsWindow.titlebarAppearsTransparent = true
7474
nsWindow.titleVisibility = .hidden
7575
}

Sources/GateEngine/System/Platforms/Apple/AppKit/AppKitPlatform.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ private class AppDelegate: NSObject, NSApplicationDelegate {
9797
func applicationWillTerminate(_ notification: Notification) {
9898
Game.shared.willTerminate()
9999
}
100+
101+
func application(_ application: NSApplication, open urls: [URL]) {
102+
Game.shared.openURLs(urls)
103+
}
100104
}
101105

102106
extension AppKitPlatform {

Sources/GateEngine/System/Platforms/FileSystem.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
#if GATEENGINE_PLATFORM_HAS_FILESYSTEM
88

9+
import Foundation
10+
911
public enum FileSystemSearchPathDomain {
1012
case currentUser
1113
case shared

Sources/GateEngine/System/Platforms/Platform.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import Collections
21
/*
32
* Copyright © 2023-2024 Dustin Collins (Strega's Gate)
43
* All Rights Reserved.
54
*
65
* http://stregasgate.com
76
*/
87
import Foundation
8+
import Collections
99

1010
public protocol Platform: AnyObject {
1111
func locateResource(from path: String) async -> String?

Sources/GateEngine/UI/Layout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public struct Layout {
430430
window.frame.size = windowPointSize
431431
window.setNeedsLayout()
432432
}
433-
guard window.needsLayout else {return}
433+
guard window.needsLayout || window.needsUpdateConstraints else {return}
434434

435435
let layoutStart = Game.shared.platform.systemTime()
436436

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright © 2023-2024 Dustin Collins (Strega's Gate)
3+
* All Rights Reserved.
4+
*
5+
* http://stregasgate.com
6+
*/
7+
8+
open class ScrollView: View {
9+
public var offset: Position2 = .zero {
10+
didSet {
11+
if offset != oldValue {
12+
self.setNeedsUpdateConstraints()
13+
}
14+
}
15+
}
16+
var animationDuration: Float = 0.01
17+
var animationAccumulator: Float = 0
18+
var destinationOffset: Position2 = .zero
19+
20+
public var contentView: View = View()
21+
22+
open override func update(withTimePassed deltaTime: Float) {
23+
super.update(withTimePassed: deltaTime)
24+
animationAccumulator += deltaTime
25+
let factor: Float = .minimum(1, animationAccumulator / animationDuration)
26+
self.offset.interpolate(to: destinationOffset, .linear(factor))
27+
}
28+
29+
override public init() {
30+
super.init()
31+
self.addSubview(contentView)
32+
}
33+
34+
open override func updateLayoutConstraints() {
35+
super.updateLayoutConstraints()
36+
37+
self.contentView.layoutConstraints.removeAllConstraints()
38+
self.contentView.topAnchor.constrain(offset.y, from: self.topAnchor)
39+
self.contentView.leadingAnchor.constrain(offset.x, from: self.leadingAnchor)
40+
self.contentView.bottomAnchor.constrain(offset.x, from: self.bottomAnchor)
41+
self.contentView.trailingAnchor.constrain(to: self.trailingAnchor)
42+
}
43+
44+
open override func canBeHit() -> Bool {
45+
return true
46+
}
47+
48+
open override func scrolled(_ delta: Position2, isPlatformGeneratedMomentum isMomentum: Bool) {
49+
super.scrolled(delta, isPlatformGeneratedMomentum: isMomentum)
50+
if isMomentum == false {
51+
destinationOffset += delta
52+
destinationOffset.x = .maximum(0, destinationOffset.x)
53+
destinationOffset.y = .maximum(0, destinationOffset.y)
54+
}
55+
}
56+
57+
// open override func cursorExited(_ cursor: Mouse) {
58+
// destinationOffset = .zero
59+
// animationDuration = 0.3
60+
// animationAccumulator = 0
61+
// }
62+
// open override func cursorEntered(_ cursor: Mouse) {
63+
// animationAccumulator = 0
64+
// animationDuration = 0.3
65+
// }
66+
// open override func cursorMoved(_ cursor: Mouse) {
67+
// super.cursorMoved(cursor)
68+
// destinationOffset.y = cursor.loactionInView(self)?.y ?? 0
69+
// }
70+
}

0 commit comments

Comments
 (0)