forked from Blendman974/faceclaw
iOS porting: Main screen and compositor
This commit is contained in:
1 parent
61b3bf8b7c
commit
99793a37a7
24 files changed
+1124
-70
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { ImageSource } from '@nativescript/core'
|
||||
import { GrayImage } from '../graphics/image'
|
||||
|
||||
declare const FaceclawGraphics: any
|
||||
|
||||
export function previewPixels(pixels: Uint8Array, width: number, height: number, green = false): ImageSource {
|
||||
// NSData copies the buffer; the UIImage owns its pixels after this call.
|
||||
const copy = new Uint8Array(pixels)
|
||||
const data = NSData.dataWithBytesLength(interop.handleof(copy.buffer), copy.byteLength)
|
||||
const native = FaceclawGraphics.previewWidthHeightGreen(data, width, height, green)
|
||||
if (!native) throw new Error('Could not create preview image')
|
||||
return new ImageSource(native)
|
||||
}
|
||||
|
||||
export function rasterizeSvg(svg: string, size: number): GrayImage | null {
|
||||
const data = FaceclawGraphics.renderSVGSize(svg, size)
|
||||
if (!data) return null
|
||||
const image = new GrayImage(size, size, 0)
|
||||
image.pixels.set(new Uint8Array(interop.bufferFromData(data)))
|
||||
return image
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ApplicationSettings } from '@nativescript/core'
|
||||
|
||||
// Main-isolate settings for the initial iOS port. Worker synchronization will
|
||||
// be added when worker-hosted apps are enabled on iOS.
|
||||
const listeners = new Set<(key: string) => void>()
|
||||
function changed(key: string): void {
|
||||
setTimeout(() => { for (const listener of [...listeners]) listener(key) }, 0)
|
||||
}
|
||||
export function getStringSetting(key: string, fallback: string): string {
|
||||
return ApplicationSettings.getString(key, fallback)
|
||||
}
|
||||
export function setStringSetting(key: string, value: string): void {
|
||||
if (getStringSetting(key, '') === value && ApplicationSettings.hasKey(key)) return
|
||||
ApplicationSettings.setString(key, value)
|
||||
changed(key)
|
||||
}
|
||||
export function getBooleanSetting(key: string, fallback: boolean): boolean {
|
||||
return ApplicationSettings.getBoolean(key, fallback)
|
||||
}
|
||||
export function setBooleanSetting(key: string, value: boolean): void {
|
||||
if (getBooleanSetting(key, false) === value && ApplicationSettings.hasKey(key)) return
|
||||
ApplicationSettings.setBoolean(key, value)
|
||||
changed(key)
|
||||
}
|
||||
export function onSettingsStoreChanged(listener: (key: string) => void): () => void {
|
||||
listeners.add(listener)
|
||||
return () => { listeners.delete(listener) }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { rasterizeSvg as render } from './ios-graphics'
|
||||
export function rasterizeSvg(svg: string, size: number, strokeWidth: number) {
|
||||
// Shared icon sources rely on the Android renderer's white, rounded
|
||||
// stroke defaults. Supply those explicitly for a standards SVG renderer.
|
||||
const source = svg.replace(/<svg\b([^>]*)>/, (_tag, attributes: string) => {
|
||||
const defaults = { xmlns: 'http://www.w3.org/2000/svg', width: '24', height: '24',
|
||||
stroke: svg.includes('fill="none"') ? '#ffffff' : 'none', fill: '#ffffff', 'stroke-width': String(strokeWidth),
|
||||
'stroke-linecap': 'round', 'stroke-linejoin': 'round' }
|
||||
const missing = Object.entries(defaults).filter(([key]) => !new RegExp(`\\b${key}=`).test(attributes))
|
||||
.map(([key, value]) => ` ${key}="${value}"`).join('')
|
||||
return `<svg${attributes}${missing}>`
|
||||
})
|
||||
return render(source, size)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { GrayImage } from '../graphics/image'
|
||||
declare const com: any
|
||||
export function rasterizeSvg(svg: string, size: number, strokeWidth: number): GrayImage | null {
|
||||
const bytes = com.faceclaw.app.IconRenderer.renderSvgGray(svg, size, strokeWidth)
|
||||
if (!bytes || bytes.length < size * size) return null
|
||||
const image = new GrayImage(size, size, 0)
|
||||
for (let i = 0; i < size * size; i++) image.pixels[i] = bytes[i] & 0xff
|
||||
return image
|
||||
}
|
||||
Reference in new issue
Block a user