Skip to content

Commit 57b9244

Browse files
authored
Merge pull request #2 from PlugFox/feature/shaders-hello-world
Feature/shaders hello world
2 parents 8da1af5 + 31cf11e commit 57b9244

36 files changed

+1203
-111
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
"dart-code.dart-code",
44
"Dart-Code.flutter",
55
"github.vscode-github-actions",
6+
"raczzalan.webgl-glsl-editor",
7+
"circledev.glsl-canvas"
68
]
79
}

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
"--dart-define-from-file=config/development.json",
1313
],
1414
"env": {}
15+
},
16+
{
17+
"name": "Example (Release)",
18+
"type": "dart",
19+
"program": "lib/main.dart",
20+
"request": "launch",
21+
"flutterMode": "release",
22+
"cwd": "${workspaceFolder}/example",
23+
"args": [
24+
"--dart-define-from-file=config/development.json",
25+
],
26+
"env": {}
1527
}
1628
]
1729
}

.vscode/settings.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
".gitignore": ".gitattributes, .gitmodules, .gitmessage, .mailmap, .git-blame*",
6565
"readme.*": "authors, backers.md, changelog*, citation*, code_of_conduct.md, codeowners, contributing.md, contributors, copying, credits, governance.md, history.md, license*, maintainers, readme*, security.md, sponsors.md",
6666
"*.dart": "$(capture).g.dart, $(capture).freezed.dart, $(capture).config.dart"
67-
}
67+
},
6868
/* "files.associations": {
6969
"*.drift": "sql"
7070
}, */
@@ -80,5 +80,19 @@
8080
}
8181
]
8282
}
83-
} */
83+
}, */
84+
// -- Shaders -- //
85+
"glsl-canvas.refreshOnChange": false,
86+
"glsl-canvas.refreshOnSave": true,
87+
"[glsl]": {
88+
"editor.defaultFormatter": "raczzalan.webgl-glsl-editor"
89+
},
90+
"[frag]": {
91+
"editor.defaultFormatter": "raczzalan.webgl-glsl-editor"
92+
},
93+
"[vert]": {
94+
"editor.defaultFormatter": "raczzalan.webgl-glsl-editor"
95+
},
96+
"editor.defaultFormatter": "raczzalan.webgl-glsl-editor",
97+
"notebook.defaultFormatter": "raczzalan.webgl-glsl-editor",
8498
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.3
2+
3+
- Updated Frame Limiter logic
4+
15
## 0.0.2
26

37
- Added example project

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ deploy-check: publish-check
4646

4747
.PHONY: publish
4848
publish: ## Publish the package
49-
@yes | flutter pub publish
49+
@flutter pub publish
5050

5151
.PHONY: deploy
5252
deploy: publish

example/ios/Flutter/Debug.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Generated.xcconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Generated.xcconfig"

example/ios/Podfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Uncomment this line to define a global platform for your project
2+
# platform :ios, '12.0'
3+
4+
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5+
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6+
7+
project 'Runner', {
8+
'Debug' => :debug,
9+
'Profile' => :release,
10+
'Release' => :release,
11+
}
12+
13+
def flutter_root
14+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15+
unless File.exist?(generated_xcode_build_settings_path)
16+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17+
end
18+
19+
File.foreach(generated_xcode_build_settings_path) do |line|
20+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
21+
return matches[1].strip if matches
22+
end
23+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24+
end
25+
26+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27+
28+
flutter_ios_podfile_setup
29+
30+
target 'Runner' do
31+
use_frameworks!
32+
use_modular_headers!
33+
34+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35+
target 'RunnerTests' do
36+
inherit! :search_paths
37+
end
38+
end
39+
40+
post_install do |installer|
41+
installer.pods_project.targets.each do |target|
42+
flutter_additional_ios_build_settings(target)
43+
end
44+
end

example/lib/src/common/widget/routes.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:flutter/material.dart';
22
import 'package:repaintexample/src/feature/clock/clock_screen.dart';
3+
import 'package:repaintexample/src/feature/fps/fps_screen.dart';
34
import 'package:repaintexample/src/feature/home/home_screen.dart';
5+
import 'package:repaintexample/src/feature/shaders/fragment_shaders_screen.dart';
46

57
/// The routes to navigate to.
68
final Map<String, Page<void> Function(Map<String, Object?>?)> $routes =
@@ -15,4 +17,14 @@ final Map<String, Page<void> Function(Map<String, Object?>?)> $routes =
1517
child: const ClockScreen(),
1618
arguments: arguments,
1719
),
20+
'fragment-shaders': (arguments) => MaterialPage<void>(
21+
name: 'fragment-shaders',
22+
child: const FragmentShadersScreen(),
23+
arguments: arguments,
24+
),
25+
'fps': (arguments) => MaterialPage<void>(
26+
name: 'fps',
27+
child: const FpsScreen(),
28+
arguments: arguments,
29+
),
1830
};

example/lib/src/feature/clock/clock_screen.dart

Lines changed: 95 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -18,100 +18,110 @@ class ClockScreen extends StatelessWidget {
1818
),
1919
),
2020
body: SafeArea(
21-
child: Center(
22-
child: RePaint.inline<Paint>(
23-
frameRate: 1,
24-
setUp: (box) => Paint()
25-
..color = Colors.black
26-
..style = PaintingStyle.stroke
27-
..strokeWidth = 2,
28-
render: (box, paint, canvas) {
29-
final size = box.size; // Get the size of the box
30-
final now = DateTime.now(); // Get the current time
21+
child: Padding(
22+
padding: const EdgeInsets.all(16),
23+
child: Center(
24+
child: AspectRatio(
25+
aspectRatio: 1,
26+
child: RePaint.inline<Paint>(
27+
frameRate: 6,
28+
setUp: (box) => Paint()..style = PaintingStyle.stroke,
29+
render: (box, paint, canvas) {
30+
final size = box.size; // Get the size of the box
31+
final now = DateTime.now(); // Get the current time
3132

32-
final center = size.center(Offset.zero);
33-
final radius = size.shortestSide / 3;
33+
final center = size.center(Offset.zero);
34+
final radius = size.shortestSide / 2 - 8;
3435

35-
// Draw the clock face
36-
canvas.drawCircle(center, radius, paint);
36+
// Draw the clock face
37+
canvas.drawCircle(
38+
center,
39+
radius,
40+
paint
41+
..color = Colors.black
42+
..strokeWidth = 2,
43+
);
44+
45+
final textPainter = TextPainter(
46+
textAlign: TextAlign.center,
47+
textDirection: TextDirection.ltr,
48+
);
3749

38-
final textPainter = TextPainter(
39-
textAlign: TextAlign.center,
40-
textDirection: TextDirection.ltr,
41-
);
50+
// Draw the clock numbers
51+
for (int i = 1; i <= 12; i++) {
52+
final angle =
53+
math.pi / 6 * (i - 3); // Positioning the numbers
54+
final numberPosition = Offset(
55+
center.dx + radius * 0.8 * math.cos(angle),
56+
center.dy + radius * 0.8 * math.sin(angle),
57+
);
4258

43-
// Draw the clock numbers
44-
for (int i = 1; i <= 12; i++) {
45-
final angle =
46-
math.pi / 6 * (i - 3); // Positioning the numbers
47-
final numberPosition = Offset(
48-
center.dx + radius * 0.8 * math.cos(angle),
49-
center.dy + radius * 0.8 * math.sin(angle),
50-
);
59+
textPainter
60+
..text = TextSpan(
61+
text: '$i',
62+
style: TextStyle(
63+
color: Colors.black,
64+
fontSize: radius * 0.15,
65+
),
66+
)
67+
..layout()
68+
..paint(
69+
canvas,
70+
numberPosition -
71+
Offset(textPainter.width / 2,
72+
textPainter.height / 2),
73+
);
74+
}
5175

52-
textPainter
53-
..text = TextSpan(
54-
text: '$i',
55-
style: TextStyle(
56-
color: Colors.black,
57-
fontSize: radius * 0.15,
76+
// Draw the hour hand
77+
final hourAngle =
78+
math.pi / 6 * (now.hour % 12 + now.minute / 60) -
79+
math.pi / 2;
80+
final hourHandLength = radius * 0.5;
81+
paint
82+
..color = Colors.black
83+
..strokeWidth = 4;
84+
canvas.drawLine(
85+
center,
86+
Offset(
87+
center.dx + hourHandLength * math.cos(hourAngle),
88+
center.dy + hourHandLength * math.sin(hourAngle),
5889
),
59-
)
60-
..layout()
61-
..paint(
62-
canvas,
63-
numberPosition -
64-
Offset(textPainter.width / 2, textPainter.height / 2),
90+
paint,
6591
);
66-
}
67-
68-
// Draw the hour hand
69-
final hourAngle =
70-
math.pi / 6 * (now.hour % 12 + now.minute / 60) -
71-
math.pi / 2;
72-
final hourHandLength = radius * 0.5;
73-
paint
74-
..color = Colors.black
75-
..strokeWidth = 4;
76-
canvas.drawLine(
77-
center,
78-
Offset(
79-
center.dx + hourHandLength * math.cos(hourAngle),
80-
center.dy + hourHandLength * math.sin(hourAngle),
81-
),
82-
paint,
83-
);
8492

85-
// Draw the minute hand
86-
final minuteAngle = math.pi / 30 * now.minute - math.pi / 2;
87-
final minuteHandLength = radius * 0.7;
88-
paint
89-
..color = Colors.blue
90-
..strokeWidth = 3;
91-
canvas.drawLine(
92-
center,
93-
Offset(
94-
center.dx + minuteHandLength * math.cos(minuteAngle),
95-
center.dy + minuteHandLength * math.sin(minuteAngle),
96-
),
97-
paint,
98-
);
93+
// Draw the minute hand
94+
final minuteAngle = math.pi / 30 * now.minute - math.pi / 2;
95+
final minuteHandLength = radius * 0.7;
96+
paint
97+
..color = Colors.blue
98+
..strokeWidth = 3;
99+
canvas.drawLine(
100+
center,
101+
Offset(
102+
center.dx + minuteHandLength * math.cos(minuteAngle),
103+
center.dy + minuteHandLength * math.sin(minuteAngle),
104+
),
105+
paint,
106+
);
99107

100-
// Draw the second hand
101-
final secondAngle = math.pi / 30 * now.second - math.pi / 2;
102-
final secondHandLength = radius * 0.9;
103-
paint
104-
..color = Colors.red
105-
..strokeWidth = 2;
106-
canvas.drawLine(
107-
center,
108-
Offset(
109-
center.dx + secondHandLength * math.cos(secondAngle),
110-
center.dy + secondHandLength * math.sin(secondAngle),
111-
),
112-
paint,
113-
);
114-
},
108+
// Draw the second hand
109+
final secondAngle = math.pi / 30 * now.second - math.pi / 2;
110+
final secondHandLength = radius * 0.9;
111+
paint
112+
..color = Colors.red
113+
..strokeWidth = 2;
114+
canvas.drawLine(
115+
center,
116+
Offset(
117+
center.dx + secondHandLength * math.cos(secondAngle),
118+
center.dy + secondHandLength * math.sin(secondAngle),
119+
),
120+
paint,
121+
);
122+
},
123+
),
124+
),
115125
),
116126
),
117127
),

0 commit comments

Comments
 (0)