|
|
@@ -27,7 +27,7 @@ export struct SpectrumView {
|
|
|
@Prop @Watch('onPlayingChange') isPlaying: boolean = false
|
|
|
@StorageProp('themeColor') themeColor: string = '#FF0050'
|
|
|
@Prop @Watch('onVisibilityChange') isVisible: boolean = false
|
|
|
- @State showModePanel: boolean = false
|
|
|
+ private modeCount: number = MODE_NAMES.length
|
|
|
@State canvasWidth: number = 0
|
|
|
@State canvasHeight: number = 0
|
|
|
private renderSettings: RenderingContextSettings = new RenderingContextSettings(true)
|
|
|
@@ -110,11 +110,15 @@ export struct SpectrumView {
|
|
|
this.currentMode = mode
|
|
|
AppStorage.setOrCreate<number>('spectrumMode', mode)
|
|
|
this.fftAnalyzer.reset()
|
|
|
- // 清空 Canvas
|
|
|
this.canvasContext.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
|
|
|
Logger.info(TAG, 'switchMode to ' + MODE_NAMES[mode])
|
|
|
}
|
|
|
|
|
|
+ private nextMode(): void {
|
|
|
+ const next: number = (this.currentMode + 1) % this.modeCount
|
|
|
+ this.switchMode(next)
|
|
|
+ }
|
|
|
+
|
|
|
build() {
|
|
|
Stack({ alignContent: Alignment.TopEnd }) {
|
|
|
Canvas(this.canvasContext)
|
|
|
@@ -130,38 +134,24 @@ export struct SpectrumView {
|
|
|
this.canvasHeight = newVal.height as number
|
|
|
})
|
|
|
|
|
|
- // 特效切换按钮
|
|
|
- Column() {
|
|
|
- Text('🎵')
|
|
|
- .fontSize(22)
|
|
|
- .fontColor('#FFFFFF')
|
|
|
- .opacity(0.7)
|
|
|
- .onClick(() => {
|
|
|
- this.showModePanel = !this.showModePanel
|
|
|
- })
|
|
|
- .padding(8)
|
|
|
-
|
|
|
- if (this.showModePanel) {
|
|
|
- Column() {
|
|
|
- ForEach(MODE_NAMES, (name: string, index: number) => {
|
|
|
- Text(name)
|
|
|
- .fontSize(14)
|
|
|
- .fontColor(index === this.currentMode ? $r('app.color.brand') : '#FFFFFF')
|
|
|
- .fontWeight(index === this.currentMode ? FontWeight.Bold : FontWeight.Normal)
|
|
|
- .opacity(index === this.currentMode ? 1.0 : 0.7)
|
|
|
- .padding({ top: 8, bottom: 8, left: 16, right: 16 })
|
|
|
- .onClick(() => {
|
|
|
- this.switchMode(index)
|
|
|
- this.showModePanel = false
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- // .backgroundColor('rgba(0,0,0,0.6)')
|
|
|
- .borderRadius(12)
|
|
|
- .padding(4)
|
|
|
- }
|
|
|
+ // 特效切换按钮(点击循环切换)
|
|
|
+ Row() {
|
|
|
+ SymbolGlyph($r('sys.symbol.music'))
|
|
|
+ .fontSize(14)
|
|
|
+ .fontColor([$r('app.color.brand')])
|
|
|
+ Text(MODE_NAMES[this.currentMode])
|
|
|
+ .fontSize(12)
|
|
|
+ .fontColor($r('app.color.brand'))
|
|
|
+ .margin({ left: 4 })
|
|
|
}
|
|
|
- .margin({ top: 16, right: 16 })
|
|
|
+ .padding({ top: 5, bottom: 5, left: 10, right: 10 })
|
|
|
+ .borderRadius(16)
|
|
|
+ .backgroundColor(Color.Transparent)
|
|
|
+ .shadow({ radius: 6, color: 'rgba(0, 0, 0, 0.45)', offsetX: 0, offsetY: 0 })
|
|
|
+ .margin({ top: 8, right: 8 })
|
|
|
+ .onClick(() => {
|
|
|
+ this.nextMode()
|
|
|
+ })
|
|
|
}
|
|
|
.width('100%')
|
|
|
.height('100%')
|