Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aapis committed Jul 17, 2023
0 parents commit aeac0f0
Show file tree
Hide file tree
Showing 17 changed files with 1,351 additions and 0 deletions.
591 changes: 591 additions & 0 deletions AppIconGenerator.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>AppIconGenerator.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
14 changes: 14 additions & 0 deletions AppIconGenerator/AppIconGenerator.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.assets.pictures.read-write</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
<true/>
</dict>
</plist>
148 changes: 148 additions & 0 deletions AppIconGenerator/AppIconGeneratorApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//
// AppIconGeneratorApp.swift
// AppIconGenerator
//
// Created by Ryan Priebe on 2023-07-15.
//

import Foundation
import SwiftUI

public enum ShapeFillType {
case gradient, solid
}

@main
struct AppIconGeneratorApp: App {
@State public var colours: [Color] = [
Color.random(),
Color.random(),
Color.random()
]
@State public var numberOfLayers: Float = 1.0
@State public var startPoint: UnitPoint = .top
@State public var endPoint: UnitPoint = .bottom
@State public var layers: [any IconLayer] = []
@State public var maskCornerRoundness: Float = 300.0
@State public var constrained: Bool = true
@State public var backgroundColour: Int = 0
@State public var shapeFillType: Int = 0
@State public var uiVisible: Bool = true

var body: some Scene {
let preview = ContentView(
colours: $colours,
gradientLayers: $layers,
startPoint: $startPoint,
endPoint: $endPoint,
numberOfLayers: $numberOfLayers,
maskCornerRoundness: $maskCornerRoundness,
constrained: $constrained,
backgroundColour: $backgroundColour,
shapeFillType: $shapeFillType
)

let interface = Interface(
colours: $colours,
layers: $layers,
startPoint: $startPoint,
endPoint: $endPoint,
numberOfLayers: $numberOfLayers,
maskCornerRoundness: $maskCornerRoundness,
constrained: $constrained,
backgroundColour: $backgroundColour,
shapeFillType: $shapeFillType,
uiVisible: $uiVisible
)

WindowGroup {
VStack(alignment: .leading) {
// HStack(alignment: .top) {
// preview
// .frame(width: 100, height: 100)
// .scaledToFill()
// .background(.clear)
// interface
// }
ZStack(alignment: .top) {
ScrollView {
preview
.frame(width: 1100, height: 1100)
.background(.clear)
}

if uiVisible {
interface
} else {
HStack {
Spacer()
Button {
withAnimation {
uiVisible.toggle()
}
} label: {
ZStack {
Color.accentColor
Image(systemName: "arrow.down.backward.square")
.font(.largeTitle)
}
.frame(width: 50, height: 50)
}
.buttonStyle(.plain)
.onHover { inside in
if inside {
NSCursor.pointingHand.push()
} else {
NSCursor.pop()
}
}
}
}
}
}
}
.commands {
CommandGroup(after: .newItem) {
Button("Save") {
let screenshot = preview.snapshot()
let timestamp = Date.now.timeIntervalSince1970
let exportFolder = "/AIG-Export-\(timestamp)/"
let picturesDir = FileManager.default.urls(for: .picturesDirectory, in: .userDomainMask).first!
let imageURL = picturesDir
.appending(component: exportFolder)

do {
try FileManager.default.createDirectory(atPath: picturesDir.path + exportFolder, withIntermediateDirectories: false)
} catch {
print("Couldn't create folder")
}

saveAtSize(screenshot: screenshot!, h: 1024, w: 1024, path: imageURL)
saveAtSize(screenshot: screenshot!, h: 512, w: 512, path: imageURL)
saveAtSize(screenshot: screenshot!, h: 256, w: 256, path: imageURL)
saveAtSize(screenshot: screenshot!, h: 128, w: 128, path: imageURL)
saveAtSize(screenshot: screenshot!, h: 64, w: 64, path: imageURL)
saveAtSize(screenshot: screenshot!, h: 32, w: 32, path: imageURL)
saveAtSize(screenshot: screenshot!, h: 16, w: 16, path: imageURL)
}
.keyboardShortcut("s", modifiers: .command)
}
}
}

private func saveAtSize(screenshot: NSImage, h: Int, w: Int, path: URL) -> Void {
let image = screenshot.resize(w: w, h: h)
let fileName = "\(h)x\(w).png"

if let png = image.png {
do {
try png.write(to: path.appending(component: fileName))
print("\(fileName) saved")
} catch {
print(error)
}
} else {
print("No PNG data?")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions AppIconGenerator/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"images" : [
{
"filename" : "1024x1024-16.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "1024x1024-32.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions AppIconGenerator/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit aeac0f0

Please sign in to comment.