Skip to content

Commit

Permalink
refactor: rename Image to CommonImage
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsci committed Nov 5, 2024
1 parent 6edefd5 commit c665580
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 175 deletions.
8 changes: 4 additions & 4 deletions OpoLua.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
DBE2917E27932C5400EE824B /* ClockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE2917D27932C5300EE824B /* ClockView.swift */; };
DBE291822795F86200EE824B /* UIKeyModifierFlags.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE291812795F86100EE824B /* UIKeyModifierFlags.swift */; };
DBE91525276D25AA00BDB8F5 /* UIKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE91524276D25A900BDB8F5 /* UIKey.swift */; };
DBEBA4462CCCF039009335CA /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBEBA4452CCCF033009335CA /* Image.swift */; };
DBEBA4462CCCF039009335CA /* CommonImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBEBA4452CCCF033009335CA /* CommonImage.swift */; };
DBEBA4482CCCF7EA009335CA /* ViewBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBEBA4472CCCF7E7009335CA /* ViewBase.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -255,7 +255,7 @@
DBE2917D27932C5300EE824B /* ClockView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClockView.swift; sourceTree = "<group>"; };
DBE291812795F86100EE824B /* UIKeyModifierFlags.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIKeyModifierFlags.swift; sourceTree = "<group>"; };
DBE91524276D25A900BDB8F5 /* UIKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKey.swift; sourceTree = "<group>"; };
DBEBA4452CCCF033009335CA /* Image.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Image.swift; sourceTree = "<group>"; };
DBEBA4452CCCF033009335CA /* CommonImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommonImage.swift; sourceTree = "<group>"; };
DBEBA4472CCCF7E7009335CA /* ViewBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewBase.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -308,7 +308,7 @@
D861E8DC274A81B4003C8D3D /* Directory.swift */,
D884A3D22778E335008954A0 /* FileSystem.swift */,
D80D65A7279DD2060020F994 /* Icon.swift */,
DBEBA4452CCCF033009335CA /* Image.swift */,
DBEBA4452CCCF033009335CA /* CommonImage.swift */,
D884A3D6277914CF008954A0 /* Installer.swift */,
D86724F12771672A009C7246 /* InterpreterThread.swift */,
D8FE6D902C92251B0058CE2E /* Legal.swift */,
Expand Down Expand Up @@ -682,7 +682,7 @@
D85F597127ACB682006AAF3B /* WizardFooterView.swift in Sources */,
D89F8CEA27AEC48B009F25E5 /* UIViewController.swift in Sources */,
D8D6701527A72B2100D12E96 /* DestinationPickerViewController.swift in Sources */,
DBEBA4462CCCF039009335CA /* Image.swift in Sources */,
DBEBA4462CCCF039009335CA /* CommonImage.swift in Sources */,
D8EE4D86279E4D2900F91150 /* ProgramDetector.swift in Sources */,
DBE2917E27932C5400EE824B /* ClockView.swift in Sources */,
D80A9CC227A4B66400E49AD8 /* SourceViewController.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions OpoLua/Model/ApplicationMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct ApplicationMetadata {
return Icon(grayscaleImage: appIcon, colorImage: appIcon)
}

private func image(for size: Graphics.Size) -> Image? {
private func image(for size: Graphics.Size) -> CommonImage? {
var bitmap: Graphics.MaskedBitmap? = nil
for icon in icons {
guard icon.bitmap.size <= size && (icon.mask == nil || icon.bitmap.size == icon.mask?.size) else {
Expand All @@ -82,7 +82,7 @@ struct ApplicationMetadata {
return nil
}
if let cgImg = bitmap.cgImage {
return Image(cgImage: cgImg)
return CommonImage(cgImage: cgImg)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions OpoLua/Model/BitmapFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class BitmapFontRenderer {
init(font: BitmapFontInfo, embolden: Bool = false) {
self.font = font
self.boldWeight = embolden ? 1 : 0
self.img = Image(named: "fonts/\(font.bitmapName)/\(font.bitmapName)")!.cgImage!.inverted()!
self.img = CommonImage(named: "fonts/\(font.bitmapName)/\(font.bitmapName)")!.cgImage!.inverted()!
self.imagew = self.img.width
self.imageh = self.img.height
}
Expand Down Expand Up @@ -145,7 +145,7 @@ class BitmapFontRenderer {

private func individualImageForChar(_ char: Character) -> CGImage? {
let charName = Self.getCharName(char)
return Image(named: "fonts/\(font.bitmapName)/\(charName)")?.cgImage?.inverted()
return CommonImage(named: "fonts/\(font.bitmapName)/\(charName)")?.cgImage?.inverted()
}

func getCharWidth(_ char: Character) -> Int {
Expand Down
4 changes: 2 additions & 2 deletions OpoLua/Model/Border.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension CGContext {
print("No resource found for border type \(type) (\(filename).png)")
return
}
let image = Image(contentsOfFile: url.path)!
let image = CommonImage(contentsOfFile: url.path)!
// I don't really understand why we have to limit the inset size so agressively here, but
// limiting to half the frame size is not sufficient to avoid some weird artifacts
let inset = min(min(frame.width, frame.height) / 3, 10)
Expand All @@ -41,7 +41,7 @@ extension CGContext {
button.capInsets = NSEdgeInsets(top: inset, left: inset, bottom: inset, right: inset)
button.resizingMode = .stretch
#endif
let view = ImageView(image: button)
let view = CommonImageView(image: button)

#if canImport(UIKit)
let layer = view.layer
Expand Down
155 changes: 155 additions & 0 deletions OpoLua/Model/CommonImage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright (c) 2021-2024 Jason Morley, Tom Sutcliffe
//
// 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 the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER 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.

#if canImport(UIKit)

import UIKit
typealias CommonImage = UIImage
typealias CommonImageView = UIImageView

#else

import AppKit
typealias Image = NSImage
typealias ImageView = NSImageView

// Some helpers to make it look more like the UIImage API
extension NSImage {

public convenience init(cgImage: CGImage) {
self.init(cgImage: cgImage, size: .zero)
}

public func pngData() -> Data? {
guard let cgImage = self.cgImage else {
return nil
}

let bitmapRepresentation = NSBitmapImageRep(cgImage: cgImage)
return bitmapRepresentation.representation(using: .png, properties: [:])
}

public var cgImage: CGImage? {
return self.cgImage(forProposedRect: nil, context: nil, hints: nil)
}

}

#endif

extension CommonImage {

static func clockMedium() -> CommonImage {
return CommonImage(named: "ClockMedium")!
}

static func clockMediumC() -> CommonImage {
return CommonImage(named: "ClockMediumC")!
}

static func dataIcon() -> CommonImage {
return CommonImage(named: "DataIcon")!
}

static func dataIconC() -> CommonImage {
return CommonImage(named: "DataIconC")!
}

static func epocLogo() -> CommonImage {
return CommonImage(named: "EpocLogo")!
}

static func epocLogoC() -> CommonImage {
return CommonImage(named: "EpocLogoC")!
}

static func folderIcon() -> CommonImage {
return CommonImage(named: "FolderIcon")!
}

static func folderIconC() -> CommonImage {
return CommonImage(named: "FolderIconC")!
}

static func installerIcon() -> CommonImage {
return CommonImage(named: "InstallerIcon")!
}

static func installerIconC() -> CommonImage {
return CommonImage(named: "InstallerIconC")!
}

static func oplIcon() -> CommonImage {
return CommonImage(named: "OplIcon")!
}

static func oplIconC() -> CommonImage {
return CommonImage(named: "OplIconC")!
}

static func opoIcon() -> CommonImage {
return CommonImage(named: "OpoIcon")!
}

static func opoIconC() -> CommonImage {
return CommonImage(named: "OpoIconC")!
}

static func paintIcon() -> CommonImage {
return CommonImage(named: "PaintIcon")!
}

static func paintIconC() -> CommonImage {
return CommonImage(named: "PaintIconC")!
}

static func recordIcon() -> CommonImage {
return CommonImage(named: "RecordIcon")!
}

static func recordIconC() -> CommonImage {
return CommonImage(named: "RecordIconC")!
}

static func textIcon() -> CommonImage {
return CommonImage(named: "TextIcon")!
}

static func unknownAppIcon() -> CommonImage {
return CommonImage(named: "UnknownAppIcon")!
}

static func unknownAppIconC() -> CommonImage {
return CommonImage(named: "UnknownAppIconC")!
}

static func unknownFileIcon() -> CommonImage {
return CommonImage(named: "UnknownFileIcon")!
}

static func unknownFileIconC() -> CommonImage {
return CommonImage(named: "UnknownFileIconC")!
}

static func ditherPattern() -> CommonImage {
return CommonImage(named: "DitherPattern")!
}

}
2 changes: 1 addition & 1 deletion OpoLua/Model/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension Device {
}
}

var analogClockImage: Image {
var analogClockImage: CommonImage {
switch self {
case .psionSeries3c:
return .clockMedium()
Expand Down
8 changes: 4 additions & 4 deletions OpoLua/Model/Icon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ struct Icon: Hashable {
return true
}

var grayscaleImage: Image
var colorImage: Image
var grayscaleImage: CommonImage
var colorImage: CommonImage
private var grayscaleImagePngData: Data
private var colorImagePngData: Data

init(grayscaleImage: Image, colorImage: Image) {
init(grayscaleImage: CommonImage, colorImage: CommonImage) {
self.grayscaleImage = grayscaleImage
self.colorImage = colorImage
self.grayscaleImagePngData = grayscaleImage.pngData()!
Expand All @@ -53,7 +53,7 @@ struct Icon: Hashable {

extension Icon {

func image(for theme: Settings.Theme) -> Image {
func image(for theme: Settings.Theme) -> CommonImage {
switch theme {
case .series5:
return grayscaleImage
Expand Down
Loading

0 comments on commit c665580

Please sign in to comment.