@oxy.so/bloom-lens 0.0.0-bootstrap.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +673 -0
- package/NOTICE +26 -0
- package/android/build.gradle +19 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/assets/fonts/Inter-OFL.txt +93 -0
- package/android/src/main/assets/fonts/Inter-Regular.ttf +0 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/220 +0 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidModule.kt +71 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidView.kt +548 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassBackdrop.kt +215 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassLens.kt +103 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeGeometry.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeIcons.kt +74 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeMaterial.kt +74 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeHost.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeModule.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeView.kt +609 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/StaticGlassCache.kt +73 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceIcons.kt +114 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesHost.kt +71 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesModule.kt +22 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesView.kt +527 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassIcons.kt +68 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassMenuContent.kt +349 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassRow.kt +19 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassFieldTexture.kt +102 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassGaussianField.kt +161 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassShapes.kt +37 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedField.kt +119 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedUnion.kt +81 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassGroup.kt +225 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassJelly.kt +118 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphFrame.kt +22 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphTuning.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMotion.kt +475 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassSpring.kt +78 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassDevGuard.kt +31 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassFeedback.kt +18 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuOverlay.kt +433 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuSession.kt +750 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassScrub.kt +41 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassSubmenuLayer.kt +290 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassAbsorbRecord.kt +9 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMemberRecord.kt +14 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuConfigRecord.kt +24 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuItemRecord.kt +23 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassShrinkRecord.kt +10 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassTriggerConfigRecord.kt +19 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRecipe.kt +18 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRenderer.kt +361 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassShaders.kt +318 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassStill.kt +115 -0
- package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassSurfaceState.kt +38 -0
- package/expo-module.config.json +10 -0
- package/package.json +31 -1
- package/patches/bloom.patch +1908 -0
- package/patches/menu/bloom.patch +148 -0
- package/src/base.tsx +208 -0
- package/src/chrome/compositor-geometry.ts +163 -0
- package/src/chrome/glass-header.tsx +155 -0
- package/src/chrome/glass-search-fab.tsx +113 -0
- package/src/chrome/glass-size-class.tsx +150 -0
- package/src/chrome/glass-toolbar.tsx +45 -0
- package/src/chrome/interface.ts +17 -0
- package/src/chrome/ios-tab-bar.tsx +49 -0
- package/src/chrome/surface-layer.ts +91 -0
- package/src/chrome/surface-nodes.tsx +54 -0
- package/src/index.ts +19 -0
- package/src/menu/components/menu/index.ts +22 -0
- package/src/menu/components/menu/menu.tsx +97 -0
- package/src/menu/components/menu-action-row/index.ts +1 -0
- package/src/menu/components/menu-action-row/menu-action-row.tsx +12 -0
- package/src/menu/components/menu-content/index.ts +2 -0
- package/src/menu/components/menu-content/menu-content.tsx +11 -0
- package/src/menu/components/menu-item/index.ts +13 -0
- package/src/menu/components/menu-item/menu-item-icon.tsx +10 -0
- package/src/menu/components/menu-item/menu-item-subtitle.tsx +14 -0
- package/src/menu/components/menu-item/menu-item-title.tsx +11 -0
- package/src/menu/components/menu-item/menu-item.tsx +11 -0
- package/src/menu/components/menu-label/index.ts +3 -0
- package/src/menu/components/menu-label/menu-label.tsx +11 -0
- package/src/menu/components/menu-separator/index.ts +3 -0
- package/src/menu/components/menu-separator/menu-separator.tsx +7 -0
- package/src/menu/components/menu-submenu/index.ts +1 -0
- package/src/menu/components/menu-submenu/menu-submenu.tsx +12 -0
- package/src/menu/components/menu-trigger/index.ts +3 -0
- package/src/menu/components/menu-trigger/interface.ts +41 -0
- package/src/menu/components/menu-trigger/menu-trigger.android.tsx +97 -0
- package/src/menu/components/menu-trigger/menu-trigger.tsx +15 -0
- package/src/menu/components/menu-trigger/native-menu.android.ts +9 -0
- package/src/menu/components/menu-trigger-button/index.ts +3 -0
- package/src/menu/components/menu-trigger-button/menu-trigger-button.android.tsx +38 -0
- package/src/menu/components/menu-trigger-button/menu-trigger-button.tsx +17 -0
- package/src/menu/constants/interface.ts +6 -0
- package/src/menu/constants/menu.const.ts +11 -0
- package/src/menu/context/interface.ts +63 -0
- package/src/menu/context/menu.context.ts +7 -0
- package/src/menu/index.ts +53 -0
- package/src/menu/interface.ts +229 -0
- package/src/menu/utils/create-compound-component.util.ts +18 -0
- package/src/menu/utils/find-menu-content.util.ts +17 -0
- package/src/menu/utils/flatten-elements.util.ts +18 -0
- package/src/menu/utils/parse-menu-content.util.ts +98 -0
- package/src/menu/utils/parse-menu-item.util.ts +56 -0
- package/src/menu/utils/register-component.util.ts +13 -0
- package/src/menu/utils/to-native-item.util.ts +24 -0
- package/src/rows.tsx +61 -0
- package/README.md +0 -1
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.content
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Canvas
|
|
5
|
+
import android.graphics.Color
|
|
6
|
+
import android.graphics.Matrix
|
|
7
|
+
import android.graphics.Paint
|
|
8
|
+
import android.graphics.Path
|
|
9
|
+
import android.graphics.RadialGradient
|
|
10
|
+
import android.graphics.RectF
|
|
11
|
+
import android.graphics.Shader
|
|
12
|
+
import android.graphics.Typeface
|
|
13
|
+
import android.text.TextPaint
|
|
14
|
+
import android.text.TextUtils
|
|
15
|
+
import android.view.View
|
|
16
|
+
import androidx.core.graphics.PathParser
|
|
17
|
+
import com.facebook.react.common.assets.ReactFontManager
|
|
18
|
+
import so.oxy.bloom.glassmenu.records.GlassMenuItemRecord
|
|
19
|
+
import kotlin.math.ceil
|
|
20
|
+
import kotlin.math.max
|
|
21
|
+
import kotlin.math.min
|
|
22
|
+
|
|
23
|
+
private object Metrics {
|
|
24
|
+
const val MinimumWidth = 250f
|
|
25
|
+
const val ContentInsetY = 10f
|
|
26
|
+
const val PlateInsetX = 8f
|
|
27
|
+
const val RowHeight = 42f
|
|
28
|
+
const val SubtitleExtra = 16f
|
|
29
|
+
const val SeparatorBlock = 21f
|
|
30
|
+
const val SeparatorInset = 24f
|
|
31
|
+
const val HeadingHeight = 30f
|
|
32
|
+
const val CheckCenter = 28f
|
|
33
|
+
const val LeadingWithCheck = 44f
|
|
34
|
+
const val IconCenterWithCheck = 55f
|
|
35
|
+
const val TextAfterIconWithCheck = 80f
|
|
36
|
+
const val LeadingPlain = 28f
|
|
37
|
+
const val IconCenterPlain = 40f
|
|
38
|
+
const val TextAfterIconPlain = 64f
|
|
39
|
+
const val TrailingInset = 24f
|
|
40
|
+
const val TitleSize = 17f
|
|
41
|
+
const val SubtitleSize = 13f
|
|
42
|
+
const val IconSize = 19.5f
|
|
43
|
+
// Action row (the top row of icon actions): row height, icon size and title size, as the web layout.
|
|
44
|
+
const val ActionRowHeight = 64f
|
|
45
|
+
const val ActionIconSize = 22f
|
|
46
|
+
const val ActionTitleSize = 12f
|
|
47
|
+
const val ActionIconTop = 10f
|
|
48
|
+
const val ActionTitleBottom = 10f
|
|
49
|
+
}
|
|
50
|
+
internal class GlassMenuContent(
|
|
51
|
+
private val context: Context,
|
|
52
|
+
private val density: Float,
|
|
53
|
+
private val iconView: (Int) -> View?,
|
|
54
|
+
) {
|
|
55
|
+
private val titlePaint = TextPaint(Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG)
|
|
56
|
+
private val subtitlePaint = TextPaint(Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG)
|
|
57
|
+
private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
58
|
+
style = Paint.Style.STROKE
|
|
59
|
+
strokeCap = Paint.Cap.ROUND
|
|
60
|
+
strokeJoin = Paint.Join.ROUND
|
|
61
|
+
}
|
|
62
|
+
private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
|
63
|
+
private val actionPaint = TextPaint(Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG).apply {
|
|
64
|
+
textAlign = Paint.Align.CENTER
|
|
65
|
+
}
|
|
66
|
+
private val iconMatrix = Matrix()
|
|
67
|
+
private val iconPath = Path()
|
|
68
|
+
private var reservesCheck = false
|
|
69
|
+
|
|
70
|
+
var rows: List<GlassRow> = emptyList()
|
|
71
|
+
private set
|
|
72
|
+
var width = 0f
|
|
73
|
+
private set
|
|
74
|
+
var height = 0f
|
|
75
|
+
private set
|
|
76
|
+
var dark = true
|
|
77
|
+
// The theme's row ink (null channels keep the built-in colours).
|
|
78
|
+
var ink: so.oxy.bloom.glassmenu.records.GlassMenuConfigRecord? = null
|
|
79
|
+
// Alpha of the whole content: the submenu navigation fades the level in (RowsRevealSpring).
|
|
80
|
+
var contentAlpha = 1f
|
|
81
|
+
|
|
82
|
+
// Forces the check column (the parent menu's), so the header row is laid out exactly as the row it came from.
|
|
83
|
+
var forceCheckColumn: Boolean? = null
|
|
84
|
+
val reservesCheckColumn: Boolean get() = reservesCheck
|
|
85
|
+
|
|
86
|
+
// `back`: the submenu being shown (its header row returns to the parent panel), null at the root.
|
|
87
|
+
fun setItems(items: List<GlassMenuItemRecord>, requestedWidth: Float?, maximumWidth: Float, fontFamily: String?, back: GlassMenuItemRecord? = null) {
|
|
88
|
+
val typeface = resolveTypeface(fontFamily)
|
|
89
|
+
val fontScale = min(context.resources.configuration.fontScale, 1.35f)
|
|
90
|
+
titlePaint.typeface = typeface
|
|
91
|
+
subtitlePaint.typeface = typeface
|
|
92
|
+
titlePaint.textSize = Metrics.TitleSize * density * fontScale * FontFit
|
|
93
|
+
subtitlePaint.textSize = Metrics.SubtitleSize * density * fontScale * FontFit
|
|
94
|
+
titlePaint.letterSpacing = TitleTracking
|
|
95
|
+
subtitlePaint.letterSpacing = 0f
|
|
96
|
+
reservesCheck = forceCheckColumn ?: items.any { it.checked != null }
|
|
97
|
+
val flat = ArrayList<GlassRow>()
|
|
98
|
+
if (back != null) flat.add(GlassRow(back, 0, back = true))
|
|
99
|
+
items.forEach { item ->
|
|
100
|
+
val cells = item.actions
|
|
101
|
+
if (cells != null) {
|
|
102
|
+
cells.forEachIndexed { column, action ->
|
|
103
|
+
flat.add(GlassRow(action, flat.size).apply {
|
|
104
|
+
this.column = column
|
|
105
|
+
columns = cells.size
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
flat.add(GlassRow(item, flat.size))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
val built: List<GlassRow> = flat
|
|
113
|
+
actionPaint.typeface = typeface
|
|
114
|
+
actionPaint.textSize = Metrics.ActionTitleSize * density * fontScale * FontFit
|
|
115
|
+
|
|
116
|
+
var widest = Metrics.MinimumWidth * density
|
|
117
|
+
for (row in built) {
|
|
118
|
+
if (row.isSeparator || row.isAction) continue
|
|
119
|
+
val paint = titlePaint
|
|
120
|
+
val text = paint.measureText(row.item.title)
|
|
121
|
+
val reserve = if (row.submenu || row.back) CHEVRON_RESERVE else 0f
|
|
122
|
+
val needed = rowLeading(row) * density + text + (Metrics.TrailingInset + reserve) * density
|
|
123
|
+
widest = max(widest, needed)
|
|
124
|
+
}
|
|
125
|
+
width = min(requestedWidth?.times(density) ?: ceil(widest), maximumWidth)
|
|
126
|
+
|
|
127
|
+
var y = Metrics.ContentInsetY * density
|
|
128
|
+
val rowScale = max(fontScale, 1f)
|
|
129
|
+
var actionTop = y
|
|
130
|
+
for (row in built) {
|
|
131
|
+
if (row.isAction) {
|
|
132
|
+
// The cells of one action row share its band; the band advances after the last cell.
|
|
133
|
+
if (row.column == 0) actionTop = y
|
|
134
|
+
val inset = Metrics.PlateInsetX * density
|
|
135
|
+
val cellWidth = (width - 2 * inset) / row.columns
|
|
136
|
+
val height = Metrics.ActionRowHeight * density
|
|
137
|
+
row.rect.set(inset + row.column * cellWidth, actionTop, inset + (row.column + 1) * cellWidth, actionTop + height)
|
|
138
|
+
if (row.column == row.columns - 1) y += height
|
|
139
|
+
row.title = TextUtils.ellipsize(row.item.title, actionPaint, cellWidth - 8f * density, TextUtils.TruncateAt.END)
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
val rowHeight = when {
|
|
143
|
+
row.isSeparator -> Metrics.SeparatorBlock
|
|
144
|
+
row.isHeading -> Metrics.HeadingHeight * rowScale
|
|
145
|
+
row.item.subtitle != null -> (Metrics.RowHeight + Metrics.SubtitleExtra) * rowScale
|
|
146
|
+
else -> Metrics.RowHeight * rowScale
|
|
147
|
+
} * density
|
|
148
|
+
row.rect.set(Metrics.PlateInsetX * density, y, width - Metrics.PlateInsetX * density, y + rowHeight)
|
|
149
|
+
y += rowHeight
|
|
150
|
+
if (!row.isSeparator) {
|
|
151
|
+
val available = width - rowLeading(row) * density - (Metrics.TrailingInset + (if (row.submenu || row.back) CHEVRON_RESERVE else 0f)) * density
|
|
152
|
+
row.title = TextUtils.ellipsize(row.item.title, titlePaint, available, TextUtils.TruncateAt.END)
|
|
153
|
+
row.subtitle = row.item.subtitle?.let { TextUtils.ellipsize(it, subtitlePaint, available, TextUtils.TruncateAt.END) }
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
height = y + Metrics.ContentInsetY * density
|
|
157
|
+
rows = built
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private fun leading(item: GlassMenuItemRecord): Float = when {
|
|
161
|
+
item.heading -> if (reservesCheck) Metrics.LeadingWithCheck else Metrics.LeadingPlain
|
|
162
|
+
reservesCheck -> if (hasIcon(item)) Metrics.TextAfterIconWithCheck else Metrics.LeadingWithCheck
|
|
163
|
+
else -> if (hasIcon(item)) Metrics.TextAfterIconPlain else Metrics.LeadingPlain
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private fun hasIcon(item: GlassMenuItemRecord) = item.icon != null || item.iconPath != null || item.iconSlot != null
|
|
167
|
+
|
|
168
|
+
private fun resolveTypeface(family: String?): Typeface {
|
|
169
|
+
if (family != null) {
|
|
170
|
+
return ReactFontManager.getInstance().getTypeface(family, Typeface.NORMAL, context.assets)
|
|
171
|
+
}
|
|
172
|
+
return runCatching { Typeface.createFromAsset(context.assets, "fonts/Inter-Regular.ttf") }
|
|
173
|
+
.getOrDefault(Typeface.DEFAULT)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fun rowAt(x: Float, y: Float): GlassRow? =
|
|
177
|
+
rows.firstOrNull {
|
|
178
|
+
it.selectable && y >= it.rect.top && y < it.rect.bottom &&
|
|
179
|
+
// An action cell is hit within its column; every other row spans the layout width.
|
|
180
|
+
(if (it.isAction) x >= it.rect.left && x <= it.rect.right else x >= 0f && x <= width)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
fun nearestRow(x: Float, y: Float, slack: Float): GlassRow? {
|
|
184
|
+
if (x < -slack || x > width + slack || y < -slack || y > height + slack) return null
|
|
185
|
+
var best: GlassRow? = null
|
|
186
|
+
var distance = Float.MAX_VALUE
|
|
187
|
+
for (row in rows) {
|
|
188
|
+
if (!row.selectable) continue
|
|
189
|
+
var gap = when {
|
|
190
|
+
y < row.rect.top -> row.rect.top - y
|
|
191
|
+
y > row.rect.bottom -> y - row.rect.bottom
|
|
192
|
+
else -> 0f
|
|
193
|
+
}
|
|
194
|
+
if (row.isAction) gap += when {
|
|
195
|
+
x < row.rect.left -> row.rect.left - x
|
|
196
|
+
x > row.rect.right -> x - row.rect.right
|
|
197
|
+
else -> 0f
|
|
198
|
+
}
|
|
199
|
+
if (gap < distance) {
|
|
200
|
+
distance = gap
|
|
201
|
+
best = row
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return best
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
fun drawPlate(canvas: Canvas, plate: RectF, alpha: Float, lightX: Float, strength: Float, shine: Float) {
|
|
208
|
+
if (alpha <= .001f) return
|
|
209
|
+
val base = if (dark) PlateDark else PlateLight
|
|
210
|
+
val edge = (base * alpha * strength).coerceIn(0f, 1f)
|
|
211
|
+
val center = ((base + (if (dark) PlateShine else 0f) * shine) * alpha * strength).coerceIn(0f, 1f)
|
|
212
|
+
val tone = if (dark) 235 else 60
|
|
213
|
+
fun shade(opacity: Float) = Color.argb((opacity * 255f).toInt(), tone, tone, if (dark) 245 else 67)
|
|
214
|
+
val radius = plate.height() / 2f
|
|
215
|
+
fillPaint.color = Color.BLACK
|
|
216
|
+
fillPaint.shader = RadialGradient(
|
|
217
|
+
lightX.coerceIn(plate.left, plate.right), plate.centerY(), plate.width() * .62f,
|
|
218
|
+
shade(center), shade(edge), Shader.TileMode.CLAMP,
|
|
219
|
+
)
|
|
220
|
+
canvas.drawRoundRect(plate, radius, radius, fillPaint)
|
|
221
|
+
fillPaint.shader = null
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// All rows, with the rows matching `skip` left out (the submenu's header is drawn by the submenu panel).
|
|
225
|
+
fun draw(canvas: Canvas, scroll: Float, skip: ((GlassRow) -> Boolean)? = null) {
|
|
226
|
+
canvas.save()
|
|
227
|
+
canvas.translate(0f, -scroll)
|
|
228
|
+
for (row in rows) {
|
|
229
|
+
if (skip?.invoke(row) == true) continue
|
|
230
|
+
drawRow(canvas, row, 0f)
|
|
231
|
+
}
|
|
232
|
+
canvas.restore()
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// One row: its separator, text, icon, check and chevron. The same draw for every row, so a row that moves
|
|
236
|
+
// (the submenu header) is drawn by the same code wherever it is. `chevronRotation` turns the trailing chevron
|
|
237
|
+
// around its own centre.
|
|
238
|
+
fun drawRow(canvas: Canvas, row: GlassRow, chevronRotation: Float) {
|
|
239
|
+
val foreground = ink?.textColor?.toArgb() ?: if (dark) Color.argb(245, 255, 255, 255) else Color.argb(235, 0, 0, 0)
|
|
240
|
+
val muted = ink?.mutedColor?.toArgb() ?: if (dark) Color.argb(153, 235, 235, 245) else Color.argb(153, 60, 60, 67)
|
|
241
|
+
val destructive = ink?.destructiveColor?.toArgb() ?: if (dark) Color.rgb(255, 82, 84) else Color.rgb(220, 30, 48)
|
|
242
|
+
if (row.isSeparator) {
|
|
243
|
+
fillPaint.color = ink?.separatorColor?.toArgb() ?: if (dark) Color.argb(17, 255, 255, 255) else Color.argb(26, 0, 0, 0)
|
|
244
|
+
val y = row.rect.centerY()
|
|
245
|
+
val half = density / 2f
|
|
246
|
+
canvas.drawRect(Metrics.SeparatorInset * density, y - half, width - Metrics.SeparatorInset * density, y + half, fillPaint)
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
val alpha = if (row.item.disabled) .38f else 1f
|
|
250
|
+
val base = if (row.item.destructive) destructive else foreground
|
|
251
|
+
val color = withAlpha(base, alpha)
|
|
252
|
+
if (row.isAction) {
|
|
253
|
+
// One cell: the icon above the title, centred in the cell's column.
|
|
254
|
+
val cx = row.rect.centerX()
|
|
255
|
+
drawIcon(canvas, row.item.icon, row.item.iconPath, cx, row.rect.top + (Metrics.ActionIconTop + Metrics.ActionIconSize / 2f) * density, Metrics.ActionIconSize, color, 1.45f)
|
|
256
|
+
actionPaint.color = color
|
|
257
|
+
canvas.drawText(row.title, 0, row.title.length, cx, row.rect.bottom - Metrics.ActionTitleBottom * density, actionPaint)
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
val left = rowLeading(row) * density
|
|
261
|
+
if (row.isHeading) {
|
|
262
|
+
subtitlePaint.color = muted
|
|
263
|
+
val baseline = row.rect.bottom - 8f * density
|
|
264
|
+
canvas.drawText(row.title, 0, row.title.length, left, baseline, subtitlePaint)
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
val centerY = row.rect.centerY()
|
|
268
|
+
if (row.item.checked == true) {
|
|
269
|
+
drawIcon(canvas, "check", null, Metrics.CheckCenter * density, centerY, 13.5f, color, 1.9f)
|
|
270
|
+
}
|
|
271
|
+
if (hasIcon(row.item)) {
|
|
272
|
+
val center = (if (reservesCheck) Metrics.IconCenterWithCheck else Metrics.IconCenterPlain) * density
|
|
273
|
+
val slot = row.item.iconSlot
|
|
274
|
+
if (slot != null) {
|
|
275
|
+
drawIconView(canvas, slot, center, centerY, alpha)
|
|
276
|
+
} else {
|
|
277
|
+
drawIcon(canvas, row.item.icon, row.item.iconPath, center, centerY, Metrics.IconSize, color, 1.45f)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (row.submenu || row.back) {
|
|
281
|
+
drawIcon(canvas, "chevron", null, width - (Metrics.TrailingInset + 3f) * density, centerY, 18f, color, 1.6f, chevronRotation)
|
|
282
|
+
}
|
|
283
|
+
titlePaint.color = color
|
|
284
|
+
val metrics = titlePaint.fontMetrics
|
|
285
|
+
val subtitle = row.subtitle
|
|
286
|
+
if (subtitle == null) {
|
|
287
|
+
val baseline = centerY - (metrics.ascent + metrics.descent) / 2f
|
|
288
|
+
canvas.drawText(row.title, 0, row.title.length, left, baseline, titlePaint)
|
|
289
|
+
} else {
|
|
290
|
+
canvas.drawText(row.title, 0, row.title.length, left, centerY - 2f * density, titlePaint)
|
|
291
|
+
subtitlePaint.color = withAlpha(muted, alpha)
|
|
292
|
+
canvas.drawText(subtitle, 0, subtitle.length, left, centerY + 16f * density, subtitlePaint)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// The header row's title starts after its chevron column.
|
|
297
|
+
private fun rowLeading(row: GlassRow): Float = leading(row.item)
|
|
298
|
+
|
|
299
|
+
private fun withAlpha(color: Int, alpha: Float): Int =
|
|
300
|
+
Color.argb((Color.alpha(color) * alpha * contentAlpha).toInt(), Color.red(color), Color.green(color), Color.blue(color))
|
|
301
|
+
|
|
302
|
+
private fun drawIconView(canvas: Canvas, slot: Int, centerX: Float, centerY: Float, alpha: Float) {
|
|
303
|
+
val view = iconView(slot) ?: return
|
|
304
|
+
if (view.width == 0 || view.height == 0) return
|
|
305
|
+
val save = if (alpha < 1f) {
|
|
306
|
+
canvas.saveLayerAlpha(
|
|
307
|
+
centerX - view.width / 2f, centerY - view.height / 2f,
|
|
308
|
+
centerX + view.width / 2f, centerY + view.height / 2f, (alpha * 255f).toInt(),
|
|
309
|
+
)
|
|
310
|
+
} else canvas.save()
|
|
311
|
+
canvas.translate(centerX - view.width / 2f, centerY - view.height / 2f)
|
|
312
|
+
view.draw(canvas)
|
|
313
|
+
canvas.restoreToCount(save)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private fun drawIcon(
|
|
317
|
+
canvas: Canvas, name: String?, customPath: String?, centerX: Float, centerY: Float,
|
|
318
|
+
size: Float, color: Int, weight: Float, rotation: Float = 0f,
|
|
319
|
+
) {
|
|
320
|
+
val pixels = size * density
|
|
321
|
+
val scale = pixels / 24f
|
|
322
|
+
iconMatrix.setScale(scale, scale)
|
|
323
|
+
iconMatrix.postTranslate(centerX - pixels / 2f, centerY - pixels / 2f)
|
|
324
|
+
if (rotation != 0f) iconMatrix.postRotate(rotation, centerX, centerY)
|
|
325
|
+
iconPath.reset()
|
|
326
|
+
if (customPath != null) {
|
|
327
|
+
val parsed = runCatching { PathParser.createPathFromPathData(customPath) }.getOrNull() ?: return
|
|
328
|
+
parsed.transform(iconMatrix, iconPath)
|
|
329
|
+
fillPaint.color = color
|
|
330
|
+
canvas.drawPath(iconPath, fillPaint)
|
|
331
|
+
return
|
|
332
|
+
}
|
|
333
|
+
val shape = GlassIcons.path(name ?: return) ?: return
|
|
334
|
+
shape.transform(iconMatrix, iconPath)
|
|
335
|
+
strokePaint.color = color
|
|
336
|
+
strokePaint.strokeWidth = weight * density
|
|
337
|
+
canvas.drawPath(iconPath, strokePaint)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private companion object {
|
|
341
|
+
// Chevron column reserved at the trailing edge of a submenu row (dp).
|
|
342
|
+
const val CHEVRON_RESERVE = 24f
|
|
343
|
+
const val FontFit = .978f
|
|
344
|
+
const val TitleTracking = -.012f
|
|
345
|
+
const val PlateDark = .155f
|
|
346
|
+
const val PlateShine = .03f
|
|
347
|
+
const val PlateLight = .09f
|
|
348
|
+
}
|
|
349
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.content
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
import so.oxy.bloom.glassmenu.records.GlassMenuItemRecord
|
|
5
|
+
|
|
6
|
+
internal class GlassRow(val item: GlassMenuItemRecord, val index: Int, val back: Boolean = false) {
|
|
7
|
+
val rect = RectF()
|
|
8
|
+
// A submenu row: chevron; a tap enters the submenu panel (navigation).
|
|
9
|
+
val submenu: Boolean get() = !back && item.items != null
|
|
10
|
+
var title: CharSequence = ""
|
|
11
|
+
var subtitle: CharSequence? = null
|
|
12
|
+
val isSeparator get() = item.separator
|
|
13
|
+
val isHeading get() = item.heading
|
|
14
|
+
val selectable get() = !item.separator && !item.heading && !item.disabled
|
|
15
|
+
// Action row cell: its column (0-based) of `columns`; -1 for every other row.
|
|
16
|
+
var column = -1
|
|
17
|
+
var columns = 1
|
|
18
|
+
val isAction: Boolean get() = column >= 0
|
|
19
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.field
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import android.graphics.BitmapShader
|
|
5
|
+
import android.graphics.ColorSpace
|
|
6
|
+
import android.graphics.RuntimeShader
|
|
7
|
+
import android.graphics.Shader
|
|
8
|
+
import android.os.Build
|
|
9
|
+
import android.util.Half
|
|
10
|
+
import androidx.annotation.RequiresApi
|
|
11
|
+
import java.nio.ByteBuffer
|
|
12
|
+
import java.nio.ByteOrder
|
|
13
|
+
|
|
14
|
+
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
15
|
+
internal class GlassFieldTexture {
|
|
16
|
+
private class Buffer(val bitmap: Bitmap) {
|
|
17
|
+
val shader = BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP).apply {
|
|
18
|
+
filterMode = BitmapShader.FILTER_MODE_LINEAR
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private val buffers = ArrayList<Buffer>(RingSize)
|
|
23
|
+
private var slot = -1
|
|
24
|
+
private var current: Buffer? = null
|
|
25
|
+
private var field: GlassGaussianField? = null
|
|
26
|
+
private var generation = Long.MIN_VALUE
|
|
27
|
+
private var upload: ByteBuffer? = null
|
|
28
|
+
private val empty = BitmapShader(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
|
|
29
|
+
|
|
30
|
+
fun preallocate() {
|
|
31
|
+
while (buffers.size < RingSize) buffers.add(createBuffer(PreparedSize, PreparedSize))
|
|
32
|
+
if (upload == null) {
|
|
33
|
+
upload = ByteBuffer.allocateDirect(buffers[0].bitmap.byteCount).order(ByteOrder.nativeOrder())
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private fun createBuffer(width: Int, height: Int): Buffer = Buffer(
|
|
38
|
+
Bitmap.createBitmap(
|
|
39
|
+
width, height, Bitmap.Config.RGBA_F16, false,
|
|
40
|
+
ColorSpace.get(ColorSpace.Named.LINEAR_EXTENDED_SRGB),
|
|
41
|
+
).apply { isPremultiplied = false },
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
fun update(value: GlassGaussianField?) {
|
|
45
|
+
field = value
|
|
46
|
+
if (value == null) {
|
|
47
|
+
current = null
|
|
48
|
+
generation = Long.MIN_VALUE
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
if (generation == value.generation) return
|
|
52
|
+
generation = value.generation
|
|
53
|
+
slot = (slot + 1) % RingSize
|
|
54
|
+
var buffer = buffers.getOrNull(slot)
|
|
55
|
+
if (buffer == null || buffer.bitmap.width < value.width || buffer.bitmap.height < value.height) {
|
|
56
|
+
buffer = createBuffer((value.width + 63) / 64 * 64, (value.height + 63) / 64 * 64)
|
|
57
|
+
if (slot < buffers.size) buffers[slot] = buffer else buffers.add(buffer)
|
|
58
|
+
}
|
|
59
|
+
current = buffer
|
|
60
|
+
val size = buffer.bitmap.byteCount
|
|
61
|
+
val bytes = upload?.takeIf { it.capacity() >= size }
|
|
62
|
+
?: ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).also { upload = it }
|
|
63
|
+
bytes.clear()
|
|
64
|
+
val stride = buffer.bitmap.rowBytes
|
|
65
|
+
val source = value.rgba
|
|
66
|
+
for (row in 0 until value.height) {
|
|
67
|
+
bytes.position(row * stride)
|
|
68
|
+
val start = row * value.width * 4
|
|
69
|
+
for (index in start until start + value.width * 4) bytes.putShort(Half.toHalf(source[index]))
|
|
70
|
+
}
|
|
71
|
+
bytes.rewind()
|
|
72
|
+
buffer.bitmap.copyPixelsFromBuffer(bytes)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fun bindPrepared(shader: RuntimeShader) {
|
|
76
|
+
shader.setInputBuffer("smoothedField", buffers[0].shader)
|
|
77
|
+
shader.setFloatUniform("smoothedFieldEnabled", 1f)
|
|
78
|
+
shader.setFloatUniform("fieldCoordinateScale", 1f, 1f)
|
|
79
|
+
shader.setFloatUniform("fieldCoordinateOffset", .5f, .5f)
|
|
80
|
+
shader.setFloatUniform("fieldExtent", PreparedSize.toFloat(), PreparedSize.toFloat())
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fun bind(shader: RuntimeShader) {
|
|
84
|
+
val value = field
|
|
85
|
+
val input = if (value != null) current?.shader else null
|
|
86
|
+
shader.setInputBuffer("smoothedField", input ?: empty)
|
|
87
|
+
shader.setFloatUniform("smoothedFieldEnabled", if (input != null) 1f else 0f)
|
|
88
|
+
val step = value?.step ?: 1f
|
|
89
|
+
shader.setFloatUniform("fieldCoordinateScale", 1f / step, 1f / step)
|
|
90
|
+
shader.setFloatUniform(
|
|
91
|
+
"fieldCoordinateOffset",
|
|
92
|
+
-(value?.originX ?: 0f) / step + 0.5f,
|
|
93
|
+
-(value?.originY ?: 0f) / step + 0.5f,
|
|
94
|
+
)
|
|
95
|
+
shader.setFloatUniform("fieldExtent", (value?.width ?: 1).toFloat(), (value?.height ?: 1).toFloat())
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private companion object {
|
|
99
|
+
const val RingSize = 4
|
|
100
|
+
const val PreparedSize = 128
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.field
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
import kotlin.math.ceil
|
|
5
|
+
import kotlin.math.exp
|
|
6
|
+
import kotlin.math.floor
|
|
7
|
+
import kotlin.math.max
|
|
8
|
+
import kotlin.math.min
|
|
9
|
+
import kotlin.math.sqrt
|
|
10
|
+
|
|
11
|
+
internal class GlassGaussianField(private val minimumStep: Float) {
|
|
12
|
+
var originX = 0f
|
|
13
|
+
private set
|
|
14
|
+
var originY = 0f
|
|
15
|
+
private set
|
|
16
|
+
var step = 1f
|
|
17
|
+
private set
|
|
18
|
+
var width = 0
|
|
19
|
+
private set
|
|
20
|
+
var height = 0
|
|
21
|
+
private set
|
|
22
|
+
var rgba = FloatArray(0)
|
|
23
|
+
private set
|
|
24
|
+
var generation = 0L
|
|
25
|
+
private set
|
|
26
|
+
|
|
27
|
+
private var raw = FloatArray(0)
|
|
28
|
+
private var horizontal = FloatArray(0)
|
|
29
|
+
private val weights = FloatArray(17)
|
|
30
|
+
private val incoming = RoundedUnion()
|
|
31
|
+
private val outgoing = RoundedUnion()
|
|
32
|
+
private var hasOutgoing = false
|
|
33
|
+
private var blend = 0f
|
|
34
|
+
|
|
35
|
+
// [members], when it has shapes, is the trigger drawn as several (a group of glasses): they take the trigger's
|
|
36
|
+
// place, the outgoing shape in a morph, else the incoming one.
|
|
37
|
+
fun update(
|
|
38
|
+
incomingRect: RectF, radiusX: Float, radiusY: Float,
|
|
39
|
+
outgoingRect: RectF?, outgoingRadius: Float, smoothing: Float, lockedStep: Float = 0f,
|
|
40
|
+
members: GlassShapes? = null,
|
|
41
|
+
): Boolean {
|
|
42
|
+
val sigma = max(smoothing, 0f)
|
|
43
|
+
if (sigma <= 0.000001f) return false
|
|
44
|
+
incoming.set(incomingRect, radiusX, radiusY)
|
|
45
|
+
hasOutgoing = outgoingRect != null
|
|
46
|
+
if (outgoingRect != null) outgoing.set(outgoingRect, outgoingRadius, outgoingRadius)
|
|
47
|
+
if (members != null && members.count > 0) (if (hasOutgoing) outgoing else incoming).set(members)
|
|
48
|
+
var left = incoming.bounds.left
|
|
49
|
+
var top = incoming.bounds.top
|
|
50
|
+
var right = incoming.bounds.right
|
|
51
|
+
var bottom = incoming.bounds.bottom
|
|
52
|
+
if (hasOutgoing) {
|
|
53
|
+
left = min(left, outgoing.bounds.left)
|
|
54
|
+
top = min(top, outgoing.bounds.top)
|
|
55
|
+
right = max(right, outgoing.bounds.right)
|
|
56
|
+
bottom = max(bottom, outgoing.bounds.bottom)
|
|
57
|
+
}
|
|
58
|
+
val grow = if (outgoingRect != null) sigma * 0.25f * max(radiusX, radiusY) / max(min(radiusX, radiusY), 0.01f) else 0f
|
|
59
|
+
left -= grow
|
|
60
|
+
top -= grow
|
|
61
|
+
right += grow
|
|
62
|
+
bottom += grow
|
|
63
|
+
step = if (lockedStep > 0f) {
|
|
64
|
+
max(lockedStep, minimumStep)
|
|
65
|
+
} else {
|
|
66
|
+
max(max(minimumStep, sigma / 4f), max(right - left, bottom - top) / MaximumCells)
|
|
67
|
+
}
|
|
68
|
+
val localSigma = sigma / step
|
|
69
|
+
val maximumRadius = min(ceil(localSigma * 4f).toInt(), weights.lastIndex)
|
|
70
|
+
var sum = 0f
|
|
71
|
+
for (index in 0..maximumRadius) {
|
|
72
|
+
val value = exp(-index * index / (2f * localSigma * localSigma))
|
|
73
|
+
weights[index] = value
|
|
74
|
+
sum += if (index == 0) value else value * 2f
|
|
75
|
+
}
|
|
76
|
+
for (index in 0..maximumRadius) weights[index] /= sum
|
|
77
|
+
var radius = maximumRadius
|
|
78
|
+
while (radius > 0 && weights[radius] < 0.002f) radius--
|
|
79
|
+
if (radius == 0) return false
|
|
80
|
+
sum = weights[0]
|
|
81
|
+
for (index in 1..radius) sum += weights[index] * 2f
|
|
82
|
+
for (index in 0..radius) weights[index] /= sum
|
|
83
|
+
|
|
84
|
+
blend = sigma
|
|
85
|
+
originX = floor(left / step) * step - step
|
|
86
|
+
originY = floor(top / step) * step - step
|
|
87
|
+
width = max(2, ceil((right - originX) / step).toInt() + 2)
|
|
88
|
+
height = max(2, ceil((bottom - originY) / step).toInt() + 2)
|
|
89
|
+
val paddedWidth = width + radius * 2
|
|
90
|
+
val paddedHeight = height + radius * 2
|
|
91
|
+
if (rgba.size < width * height * 4) rgba = FloatArray(width * height * 4 + 4096)
|
|
92
|
+
if (raw.size < paddedWidth * paddedHeight * 3) raw = FloatArray(paddedWidth * paddedHeight * 3 + 4096)
|
|
93
|
+
if (horizontal.size < width * paddedHeight * 3) horizontal = FloatArray(width * paddedHeight * 3 + 4096)
|
|
94
|
+
|
|
95
|
+
for (row in 0 until paddedHeight) {
|
|
96
|
+
val y = originY + (row - radius) * step
|
|
97
|
+
for (column in 0 until paddedWidth) {
|
|
98
|
+
sample(originX + (column - radius) * step, y, (row * paddedWidth + column) * 3)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
for (row in 0 until paddedHeight) {
|
|
102
|
+
for (column in 0 until width) {
|
|
103
|
+
val center = (row * paddedWidth + column + radius) * 3
|
|
104
|
+
var distance = raw[center] * weights[0]
|
|
105
|
+
var nx = raw[center + 1] * weights[0]
|
|
106
|
+
var ny = raw[center + 2] * weights[0]
|
|
107
|
+
for (offset in 1..radius) {
|
|
108
|
+
val a = center - offset * 3
|
|
109
|
+
val b = center + offset * 3
|
|
110
|
+
val weight = weights[offset]
|
|
111
|
+
distance += (raw[a] + raw[b]) * weight
|
|
112
|
+
nx += (raw[a + 1] + raw[b + 1]) * weight
|
|
113
|
+
ny += (raw[a + 2] + raw[b + 2]) * weight
|
|
114
|
+
}
|
|
115
|
+
val output = (row * width + column) * 3
|
|
116
|
+
horizontal[output] = distance
|
|
117
|
+
horizontal[output + 1] = nx
|
|
118
|
+
horizontal[output + 2] = ny
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (row in 0 until height) {
|
|
122
|
+
for (column in 0 until width) {
|
|
123
|
+
val center = ((row + radius) * width + column) * 3
|
|
124
|
+
var distance = horizontal[center] * weights[0]
|
|
125
|
+
var nx = horizontal[center + 1] * weights[0]
|
|
126
|
+
var ny = horizontal[center + 2] * weights[0]
|
|
127
|
+
for (offset in 1..radius) {
|
|
128
|
+
val a = center - offset * width * 3
|
|
129
|
+
val b = center + offset * width * 3
|
|
130
|
+
val weight = weights[offset]
|
|
131
|
+
distance += (horizontal[a] + horizontal[b]) * weight
|
|
132
|
+
nx += (horizontal[a + 1] + horizontal[b + 1]) * weight
|
|
133
|
+
ny += (horizontal[a + 2] + horizontal[b + 2]) * weight
|
|
134
|
+
}
|
|
135
|
+
val length = sqrt(nx * nx + ny * ny)
|
|
136
|
+
val output = (row * width + column) * 4
|
|
137
|
+
rgba[output] = distance
|
|
138
|
+
rgba[output + 1] = if (length > 0.000001f) nx / length else 0f
|
|
139
|
+
rgba[output + 2] = if (length > 0.000001f) ny / length else 0f
|
|
140
|
+
rgba[output + 3] = 1f
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
generation++
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private companion object {
|
|
148
|
+
const val MaximumCells = 64f
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private fun sample(x: Float, y: Float, index: Int) {
|
|
152
|
+
incoming.sample(x, y)
|
|
153
|
+
if (hasOutgoing) {
|
|
154
|
+
outgoing.sample(x, y)
|
|
155
|
+
incoming.blendWith(outgoing.distance, outgoing.gradientX, outgoing.gradientY, blend)
|
|
156
|
+
}
|
|
157
|
+
raw[index] = incoming.distance
|
|
158
|
+
raw[index + 1] = incoming.gradientX
|
|
159
|
+
raw[index + 2] = incoming.gradientY
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package so.oxy.bloom.glassmenu.field
|
|
2
|
+
|
|
3
|
+
import android.graphics.RectF
|
|
4
|
+
import kotlin.math.min
|
|
5
|
+
|
|
6
|
+
// A glass that is several shapes (a group of glasses on one base): each shape's rect and corner radius, in the
|
|
7
|
+
// surface's pixels, blended into one another within [blend] px (a smooth union: shapes closer than it flow together,
|
|
8
|
+
// and 0 joins them only where they overlap). Empty, the glass is its one rect, as every glass but a group's is.
|
|
9
|
+
internal class GlassShapes {
|
|
10
|
+
val rects = Array(Capacity) { RectF() }
|
|
11
|
+
val radii = FloatArray(Capacity)
|
|
12
|
+
var count = 0
|
|
13
|
+
private set
|
|
14
|
+
var blend = 0f
|
|
15
|
+
|
|
16
|
+
fun clear() {
|
|
17
|
+
count = 0
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// A shape; its radius is capped at a capsule's. Shapes past Capacity are not drawn.
|
|
21
|
+
fun add(rect: RectF, radius: Float) {
|
|
22
|
+
if (count == Capacity) return
|
|
23
|
+
rects[count].set(rect)
|
|
24
|
+
radii[count] = min(radius, min(rect.width(), rect.height()) / 2f)
|
|
25
|
+
count += 1
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fun bounds(out: RectF) {
|
|
29
|
+
out.setEmpty()
|
|
30
|
+
for (index in 0 until count) out.union(rects[index])
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
companion object {
|
|
34
|
+
// The shader's: its first shape and seven more (GlassShaders, MemberCapacity).
|
|
35
|
+
const val Capacity = 8
|
|
36
|
+
}
|
|
37
|
+
}
|