$$include '../../meta/macros.ptl'

import [mix linreg clamp fallback] from "@iosevka/util"

glyph-module

glyph-block Symbol-Pictograph-IEC-Power-And-Playback : for-width-kinds WideWidth1 : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Symbol-Geometric-Shared : GeometricDim GeometricSizes

	define Geom : GeometricDim MosaicUnitWidth MosaicWidth
	define Size : GeometricSizes Geom
	define gap : Math.max (Geom.Size / 8 * MosaicWidthScalar) GeometryStroke

	create-glyph [MangleName 'powerOff'] [MangleUnicode 0x2B58] : glyph-proc
		set-width Geom.Width
		include : RingStrokeAt Geom.MidX Geom.MidY Geom.Size GeometryStroke

	create-glyph [MangleName 'heavyCircledSaltire'] [MangleUnicode 0x2B59] : glyph-proc
		set-width Geom.Width
		include : RingStrokeAt Geom.MidX Geom.MidY Geom.Size GeometryStroke
		include : intersection
			RingAt Geom.MidX Geom.MidY Geom.Size
			union
				dispiro [widths.center GeometryStroke]
					flat Geom.Left Geom.Top
					curl Geom.Right Geom.Bot
				dispiro [widths.center GeometryStroke]
					flat Geom.Left Geom.Bot
					curl Geom.Right Geom.Top

	create-glyph [MangleName 'powerOn'] [MangleUnicode 0x23FD] : glyph-proc
		set-width Geom.Width
		include : Rect
			Geom.MidY + Geom.Size
			Geom.MidY - Geom.Size
			Geom.MidX - [HSwToV : 0.5 * GeometryStroke]
			Geom.MidX + [HSwToV : 0.5 * GeometryStroke]

	create-glyph [MangleName 'powerOnOff'] [MangleUnicode 0x23FC] : glyph-proc
		set-width Geom.Width
		include : refer-glyph [MangleName 'powerOff']
		include : Rect
			Geom.MidY + Geom.Size - GeometryStroke - gap
			Geom.MidY - Geom.Size + GeometryStroke + gap
			Geom.MidX - [HSwToV : 0.5 * GeometryStroke]
			Geom.MidX + [HSwToV : 0.5 * GeometryStroke]

	create-glyph [MangleName 'powerStandby'] [MangleUnicode 0x23FB] : glyph-proc
		set-width Geom.Width
		include : union
			difference
				refer-glyph [MangleName 'powerOff']
				spiro-outline
					corner Geom.MidX Geom.MidY
					corner (Geom.MidX - gap * 4 - [HSwToV GeometryStroke]) (Geom.MidY + Geom.Size * 2)
					corner (Geom.MidX + gap * 4 + [HSwToV GeometryStroke]) (Geom.MidY + Geom.Size * 2)
			Rect
				Geom.MidY + 1.125 * Geom.Size
				Geom.MidY - 0.0 * Geom.Size
				Geom.MidX - [HSwToV : 0.5 * GeometryStroke]
				Geom.MidX + [HSwToV : 0.5 * GeometryStroke]

	create-glyph [MangleName 'powerSleep'] [MangleUnicode 0x23FE] : glyph-proc
		set-width Geom.Width
		include : difference
			Circle.Outline.At Geom.MidX Geom.MidY Geom.Size
			Circle.Outline.At
				Geom.MidX + Geom.Size * 0.5
				Geom.MidY + Geom.Size * 0.35
				Geom.Size * 1.1
		include : Translate (Geom.Size * 0.15) 0

	create-glyph [MangleName 'playback/record'] [MangleUnicode 0x23FA] : glyph-proc
		set-width Geom.Width
		include : RingAt Geom.MidX Geom.MidY Geom.Size GeometryStroke

	create-glyph [MangleName 'playback/stop'] [MangleUnicode 0x23F9] : glyph-proc
		set-width Geom.Width
		include : Rect (Geom.MidY + Geom.Size) (Geom.MidY - Geom.Size) (Geom.MidX - Geom.Size) (Geom.MidX + Geom.Size)

	create-glyph [MangleName 'playback/pause'] [MangleUnicode 0x23F8] : glyph-proc
		set-width Geom.Width
		include : Rect (Geom.MidY + Geom.Size) (Geom.MidY - Geom.Size) (Geom.MidX - Geom.Size) (Geom.MidX - Geom.Size / 3)
		include : Rect (Geom.MidY + Geom.Size) (Geom.MidY - Geom.Size) (Geom.MidX + Geom.Size / 3) (Geom.MidX + Geom.Size)

	local trigRad : Geom.Size - O
	create-glyph [MangleName 'playback/down'] [MangleUnicode 0x23F7] : glyph-proc
		set-width Geom.Width
		include : spiro-outline
			corner (Geom.MidX - trigRad) (Geom.MidY + trigRad / 2)
			corner (Geom.MidX + trigRad) (Geom.MidY + trigRad / 2)
			corner (Geom.MidX)           (Geom.MidY - trigRad / 2)

	create-glyph [MangleName 'playback/up'] [MangleUnicode 0x23F6] : glyph-proc
		set-width Geom.Width
		include : spiro-outline
			corner (Geom.MidX - trigRad) (Geom.MidY - trigRad / 2)
			corner (Geom.MidX + trigRad) (Geom.MidY - trigRad / 2)
			corner (Geom.MidX)           (Geom.MidY + trigRad / 2)

	create-glyph [MangleName 'playback/right'] [MangleUnicode 0x23F5] : glyph-proc
		set-width Geom.Width
		include : spiro-outline
			corner (Geom.MidX - trigRad / 2) (Geom.MidY - trigRad)
			corner (Geom.MidX - trigRad / 2) (Geom.MidY + trigRad)
			corner (Geom.MidX + trigRad / 2) (Geom.MidY)

	create-glyph [MangleName 'playback/left'] [MangleUnicode 0x23F4] : glyph-proc
		set-width Geom.Width
		include : spiro-outline
			corner (Geom.MidX + trigRad / 2) (Geom.MidY - trigRad)
			corner (Geom.MidX + trigRad / 2) (Geom.MidY + trigRad)
			corner (Geom.MidX - trigRad / 2) (Geom.MidY)

	create-glyph [MangleName 'playback/eject'] [MangleUnicode 0x23CF] : glyph-proc
		set-width Geom.Width
		include : Rect (Geom.MidY - Geom.Size / 3) (Geom.MidY - Geom.Size) (Geom.MidX - Geom.Size) (Geom.MidX + Geom.Size)
		include : spiro-outline
			corner (Geom.MidX - trigRad) (Geom.MidY)
			corner (Geom.MidX + trigRad) (Geom.MidY)
			corner (Geom.MidX)           (Geom.MidY + trigRad)

	create-glyph [MangleName 'playback/fastForward'] [MangleUnicode 0x23E9] : glyph-proc
		set-width Geom.Width
		include : spiro-outline
			corner (Geom.MidX - trigRad) (Geom.MidY - trigRad)
			corner (Geom.MidX - trigRad) (Geom.MidY + trigRad)
			corner Geom.MidX Geom.MidY
		include : spiro-outline
			corner Geom.MidX (Geom.MidY - trigRad)
			corner Geom.MidX (Geom.MidY + trigRad)
			corner (Geom.MidX + trigRad) Geom.MidY

	create-glyph [MangleName 'playback/fastForwardToEnd'] [MangleUnicode 0x23ED] : glyph-proc
		set-width Geom.Width
		local sw : Math.max [AdviceStroke (6 * [Math.sqrt Geom.Scalar]) Geom.Scalar] (trigRad / 6)
		local swh : HSwToV sw
		include : spiro-outline
			corner (Geom.MidX - trigRad) (Geom.MidY - trigRad)
			corner (Geom.MidX - trigRad) (Geom.MidY + trigRad)
			corner (Geom.MidX - swh / 2) Geom.MidY
		include : spiro-outline
			corner (Geom.MidX - swh / 2) (Geom.MidY - trigRad)
			corner (Geom.MidX - swh / 2) (Geom.MidY + trigRad)
			corner (Geom.MidX + trigRad - swh) Geom.MidY
		include : VBar.r (Geom.MidX + trigRad) (Geom.MidY - trigRad) (Geom.MidY + trigRad) sw

	create-glyph [MangleName 'playback/playOrStop'] [MangleUnicode 0x23EF] : glyph-proc
		set-width Geom.Width
		local sw : Math.max [AdviceStroke (6 * [Math.sqrt Geom.Scalar]) Geom.Scalar] (trigRad / 6)
		local swh : HSwToV sw
		local gap : Math.max [AdviceStroke (4 * [Math.sqrt Geom.Scalar]) Geom.Scalar] (trigRad / 4)
		local width : trigRad + swh * 2 + gap
		include : spiro-outline
			corner (Geom.MidX - width / 2) (Geom.MidY - trigRad)
			corner (Geom.MidX - width / 2) (Geom.MidY + trigRad)
			corner (Geom.MidX - width / 2 + trigRad) Geom.MidY
		include : VBar.r (Geom.MidX + width / 2 - swh - gap) (Geom.MidY - trigRad) (Geom.MidY + trigRad) sw
		include : VBar.r (Geom.MidX + width / 2) (Geom.MidY - trigRad) (Geom.MidY + trigRad) sw

	create-glyph [MangleName 'playback/fastUpward'] [MangleUnicode 0x23EB] : glyph-proc
		set-width Geom.Width
		include : spiro-outline
			corner (Geom.MidX - trigRad) (Geom.MidY - trigRad)
			corner (Geom.MidX + trigRad) (Geom.MidY - trigRad)
			corner (Geom.MidX)           Geom.MidY
		include : spiro-outline
			corner (Geom.MidX - trigRad) Geom.MidY
			corner (Geom.MidX + trigRad) Geom.MidY
			corner (Geom.MidX)           (Geom.MidY + trigRad)

	turned [MangleName 'playback/fastBackward'] [MangleUnicode 0x23EA] [MangleName 'playback/fastForward'] Geom.MidX Geom.MidY
	turned [MangleName 'playback/fastBackwardToEnd'] [MangleUnicode 0x23EE] [MangleName 'playback/fastForwardToEnd'] Geom.MidX Geom.MidY
	turned [MangleName 'playback/fastDownward'] [MangleUnicode 0x23EC] [MangleName 'playback/fastUpward'] Geom.MidX Geom.MidY
