mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 06:48:26 +00:00
Tidyup varfont_shader_puzzle (#1629)
* Tidyup `varfont_shader_puzzle` * Add a rebuild script and a test * Simplify fragment shaders * Drop web * Enable `beta` CI * make it `beta` inclusive * Pull out the program loading code
This commit is contained in:
@@ -7,24 +7,30 @@ import 'dart:ui' as ui;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
enum Shader {
|
||||
nothing('nothing'),
|
||||
bwSplit('bw_split'),
|
||||
colorSplit('color_split'),
|
||||
rowOffset('row_offset'),
|
||||
wavyCirc('wavy_circ'),
|
||||
wavy('wavy'),
|
||||
wavy2('wavy2');
|
||||
|
||||
const Shader(this.name);
|
||||
final String name;
|
||||
Future<ui.FragmentProgram> get program =>
|
||||
ui.FragmentProgram.fromAsset('shaders/$name.frag');
|
||||
}
|
||||
|
||||
class FragmentShaded extends StatefulWidget {
|
||||
final Widget child;
|
||||
final String shaderName;
|
||||
final Shader shader;
|
||||
final int shaderDuration;
|
||||
static const int dampenDuration = 1000;
|
||||
static final Map<String, ui.FragmentProgram> fragmentPrograms = {};
|
||||
static const List<String> fragmentProgramNames = [
|
||||
'nothing',
|
||||
'bw_split',
|
||||
'color_split',
|
||||
'row_offset',
|
||||
'wavy_circ',
|
||||
'wavy',
|
||||
'wavy2'
|
||||
];
|
||||
static final Map<Shader, ui.FragmentProgram> _programCache = {};
|
||||
|
||||
const FragmentShaded({
|
||||
required this.shaderName,
|
||||
required this.shader,
|
||||
required this.shaderDuration,
|
||||
required this.child,
|
||||
super.key,
|
||||
@@ -63,15 +69,16 @@ class FragmentShadedState extends State<FragmentShaded>
|
||||
}
|
||||
|
||||
Future<void> initializeFragmentProgramsAndBuilder() async {
|
||||
if (FragmentShaded.fragmentPrograms.isEmpty) {
|
||||
for (String s in FragmentShaded.fragmentProgramNames) {
|
||||
FragmentShaded.fragmentPrograms[s] =
|
||||
await ui.FragmentProgram.fromAsset('shaders/$s.frag');
|
||||
if (FragmentShaded._programCache.isEmpty) {
|
||||
for (final shader in Shader.values) {
|
||||
FragmentShaded._programCache[shader] = await shader.program;
|
||||
}
|
||||
}
|
||||
builder = AnimatingSamplerBuilder(_controller, _dampenAnimation,
|
||||
FragmentShaded.fragmentPrograms[widget.shaderName]!.fragmentShader());
|
||||
setState(() {});
|
||||
|
||||
setState(() {
|
||||
builder = AnimatingSamplerBuilder(_controller, _dampenAnimation,
|
||||
FragmentShaded._programCache[widget.shader]!.fragmentShader());
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -83,7 +90,7 @@ class FragmentShadedState extends State<FragmentShaded>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (null == FragmentShaded.fragmentPrograms[widget.shaderName]) {
|
||||
if (null == FragmentShaded._programCache[widget.shader]) {
|
||||
setState(() {});
|
||||
return const SizedBox(
|
||||
width: 0,
|
||||
|
||||
@@ -16,7 +16,7 @@ class RotatorPuzzle extends StatefulWidget {
|
||||
final PageConfig pageConfig;
|
||||
final int numTiles;
|
||||
final int puzzleNum;
|
||||
final String shaderKey;
|
||||
final Shader shader;
|
||||
final int shaderDuration;
|
||||
|
||||
final String tileShadedString;
|
||||
@@ -31,7 +31,7 @@ class RotatorPuzzle extends StatefulWidget {
|
||||
required this.pageConfig,
|
||||
required this.numTiles,
|
||||
required this.puzzleNum,
|
||||
required this.shaderKey,
|
||||
required this.shader,
|
||||
required this.shaderDuration,
|
||||
required this.tileShadedString,
|
||||
required this.tileShadedStringSize,
|
||||
@@ -97,7 +97,7 @@ class RotatorPuzzleState extends State<RotatorPuzzle>
|
||||
row: (i / dim).floor(),
|
||||
col: i % dim,
|
||||
parentState: this,
|
||||
shaderKey: widget.shaderKey,
|
||||
shader: widget.shader,
|
||||
shaderDuration: widget.shaderDuration,
|
||||
tileShadedString: widget.tileShadedString,
|
||||
tileShadedStringSize: widget.tileShadedStringSize,
|
||||
@@ -213,7 +213,7 @@ class RotatorPuzzleState extends State<RotatorPuzzle>
|
||||
child: Center(
|
||||
child: FragmentShaded(
|
||||
key: shadedWidgetStackHackStateKey,
|
||||
shaderName: widget.shaderKey,
|
||||
shader: widget.shader,
|
||||
shaderDuration: widget.shaderDuration,
|
||||
child: Padding(
|
||||
padding: widget.tileShadedStringPadding,
|
||||
@@ -246,7 +246,7 @@ class RotatorPuzzleState extends State<RotatorPuzzle>
|
||||
class RotatorPuzzleTile extends StatefulWidget {
|
||||
final int tileID;
|
||||
final RotatorPuzzleState parentState;
|
||||
final String shaderKey;
|
||||
final Shader shader;
|
||||
final int shaderDuration;
|
||||
final String tileShadedString;
|
||||
final double tileShadedStringSize;
|
||||
@@ -265,7 +265,7 @@ class RotatorPuzzleTile extends StatefulWidget {
|
||||
required this.row,
|
||||
required this.col,
|
||||
required this.parentState,
|
||||
required this.shaderKey,
|
||||
required this.shader,
|
||||
required this.shaderDuration,
|
||||
required this.tileShadedString,
|
||||
required this.tileShadedStringSize,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../page_content/pages_flow.dart';
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ class _PageAscenderDescenderState extends SinglePageState {
|
||||
pageConfig: widget.pageConfig,
|
||||
numTiles: 9,
|
||||
puzzleNum: 3,
|
||||
shaderKey: 'row_offset',
|
||||
shader: Shader.rowOffset,
|
||||
shaderDuration: 2000,
|
||||
tileShadedString: 'fyd',
|
||||
tileShadedStringPadding: EdgeInsets.only(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../components/components.dart';
|
||||
import '../page_content/pages_flow.dart';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../components/components.dart';
|
||||
import '../page_content/pages_flow.dart';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -178,7 +179,7 @@ class _PageOpticalSizeState extends SinglePageState {
|
||||
pageConfig: widget.pageConfig,
|
||||
numTiles: 16,
|
||||
puzzleNum: 4,
|
||||
shaderKey: 'wavy',
|
||||
shader: Shader.wavy,
|
||||
shaderDuration: 5000,
|
||||
tileShadedString: 'Z',
|
||||
tileShadedStringPadding:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -168,7 +169,7 @@ class _PageWeightState extends SinglePageState {
|
||||
pageConfig: widget.pageConfig,
|
||||
numTiles: 9,
|
||||
puzzleNum: 1,
|
||||
shaderKey: 'wavy2',
|
||||
shader: Shader.wavy2,
|
||||
shaderDuration: 3000,
|
||||
tileShadedString: 'W',
|
||||
tileShadedStringPadding: EdgeInsets.only(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -203,7 +204,7 @@ class _PageWidthState extends SinglePageState {
|
||||
pageConfig: widget.pageConfig,
|
||||
numTiles: 16,
|
||||
puzzleNum: 2,
|
||||
shaderKey: 'bw_split',
|
||||
shader: Shader.bwSplit,
|
||||
shaderDuration: 2000,
|
||||
tileShadedString: 'S',
|
||||
tileShadedStringPadding: EdgeInsets.only(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
export 'page_ascender_descender.dart';
|
||||
export 'page_narrative_post.dart';
|
||||
export 'page_narrative_pre.dart';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2023 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TextStyles {
|
||||
|
||||
Reference in New Issue
Block a user