1
1
import 'dart:ui' as ui;
2
2
3
+ import 'package:flutter/services.dart' ;
3
4
import 'package:fluent_ui/fluent_ui.dart' ;
4
5
import 'package:rune/utils/query_list.dart' ;
5
6
@@ -13,16 +14,30 @@ import '../../../build_query.dart';
13
14
import '../../../load_and_resize_image.dart' ;
14
15
import '../../../api/query_mix_tracks.dart' ;
15
16
17
+ Future <ui.Image > loadImageFromAsset (String assetPath) async {
18
+ final ByteData data = await rootBundle.load (assetPath);
19
+ final Uint8List bytes = data.buffer.asUint8List ();
20
+ final codec = await ui.instantiateImageCodec (bytes);
21
+ final frame = await codec.getNextFrame ();
22
+ return frame.image;
23
+ }
24
+
16
25
Future <ui.Image > renderCoverWall (
17
26
CollectionType type,
18
27
int id,
28
+ Size size,
29
+ Color background,
30
+ bool frame,
31
+ Color watermarkColor,
19
32
) async {
20
- const sizeDefinition = BoxConstraints (maxWidth: 1920 , maxHeight: 1080 );
33
+ final sizeDefinition =
34
+ BoxConstraints (maxWidth: size.width, maxHeight: size.height);
21
35
final gridSize = calculateCoverWallGridSize (sizeDefinition).ceil ();
22
36
const gap = 4 ;
23
37
24
38
ui.PictureRecorder recorder = ui.PictureRecorder ();
25
39
ui.Canvas canvas = ui.Canvas (recorder);
40
+
26
41
final queries = await buildQuery (type, id);
27
42
final newItems = await queryMixTracks (
28
43
QueryList ([...queries, ('filter::with_cover_art' , 'true' )]),
@@ -48,16 +63,73 @@ Future<ui.Image> renderCoverWall(
48
63
),
49
64
);
50
65
66
+ final backgroundPaint = Paint ()
67
+ ..color = background
68
+ ..style = PaintingStyle .fill;
69
+
70
+ canvas.drawRect (
71
+ Rect .fromLTWH (0 , 0 , size.width, size.height),
72
+ backgroundPaint,
73
+ );
74
+
51
75
final painter = CoverWallBackgroundPainter (
52
76
grid: grid,
53
77
gridSize: gridSize,
54
78
gap: gap,
55
79
images: images,
56
80
);
57
81
58
- final size = ui.Size (1920 , 1080 );
59
82
painter.paint (canvas, size);
60
83
84
+ if (frame) {
85
+ const strokeSize = 16.0 ;
86
+ const bottomSize = 100.0 ;
87
+
88
+ final borderPaint = Paint ()
89
+ ..color = background
90
+ ..style = PaintingStyle .stroke;
91
+
92
+ borderPaint.strokeWidth = strokeSize;
93
+
94
+ final path = Path ();
95
+
96
+ path.moveTo (0 , strokeSize / 2 );
97
+ path.lineTo (size.width, strokeSize / 2 );
98
+ canvas.drawPath (path, borderPaint);
99
+
100
+ path.reset ();
101
+ path.moveTo (size.width - strokeSize / 2 , strokeSize);
102
+ path.lineTo (size.width - strokeSize / 2 , size.height - bottomSize / 2 );
103
+ canvas.drawPath (path, borderPaint);
104
+
105
+ path.reset ();
106
+ path.moveTo (strokeSize / 2 , strokeSize);
107
+ path.lineTo (strokeSize / 2 , size.height - bottomSize / 2 );
108
+ canvas.drawPath (path, borderPaint);
109
+
110
+ borderPaint.strokeWidth = bottomSize;
111
+
112
+ path.reset ();
113
+ path.moveTo (0 , size.height - bottomSize / 2 );
114
+ path.lineTo (size.width, size.height - bottomSize / 2 );
115
+ canvas.drawPath (path, borderPaint);
116
+
117
+ final watermarkPaint = Paint ()
118
+ ..colorFilter = ColorFilter .mode (
119
+ watermarkColor,
120
+ BlendMode .srcATop,
121
+ );
122
+
123
+ final position = Offset (
124
+ 0 ,
125
+ (size.height - 100 ),
126
+ );
127
+
128
+ final watermark = await loadImageFromAsset ('assets/watermark.png' );
129
+
130
+ canvas.drawImage (watermark, position, watermarkPaint);
131
+ }
132
+
61
133
return recorder
62
134
.endRecording ()
63
135
.toImage (size.width.floor (), size.height.floor ());
0 commit comments