Skip to content

Commit

Permalink
Fix pattern background rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 13, 2023
1 parent c84bcb6 commit 47b4047
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion FLUTTER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.16.0-0.1.pre
3.16.0-0.2.pre
18 changes: 6 additions & 12 deletions app/lib/renderers/textures/pattern.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ void drawPatternTextureOnCanvas(PatternTexture texture, Canvas canvas,
if (texture.boxWidth > 0 && texture.boxXCount > 0) {
var relativeWidth = texture.boxWidth * scale;
var relativeSpace = texture.boxXSpace * scale;
int xCount =
(offset.dx / (texture.boxWidth * texture.boxXCount + texture.boxXSpace))
.floor();
double x =
-xCount * (texture.boxWidth * texture.boxXCount + texture.boxXSpace) +
offset.dx;
final part = texture.boxWidth * texture.boxXCount + texture.boxXSpace;
int xCount = (offset.dx / part).floor() + 1;
double x = -xCount * part + offset.dx;
x *= scale;

int count = 0;
Expand All @@ -38,12 +35,9 @@ void drawPatternTextureOnCanvas(PatternTexture texture, Canvas canvas,
if (texture.boxHeight > 0 && texture.boxYCount > 0) {
var relativeHeight = texture.boxHeight * scale;
var relativeSpace = texture.boxYSpace * scale;
int yCount = (offset.dy /
(texture.boxHeight * texture.boxYCount + texture.boxYSpace))
.floor();
double y =
-yCount * (texture.boxHeight * texture.boxYCount + texture.boxYSpace) +
offset.dy;
final part = texture.boxHeight * texture.boxYCount + texture.boxYSpace;
int yCount = (offset.dy / part).floor() + 1;
double y = -yCount * part + offset.dy;
y *= scale;

int count = 0;
Expand Down
4 changes: 2 additions & 2 deletions app/lib/views/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const minSize = 500.0;
class _PropertyViewState extends State<PropertyView>
with SingleTickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
duration: const Duration(milliseconds: 300),
duration: const Duration(milliseconds: 200),
vsync: this,
);
late final Animation<Offset> _offsetAnimation = Tween<Offset>(
begin: Offset.zero,
end: const Offset(1.5, 0.0),
).animate(CurvedAnimation(parent: _controller, curve: Curves.bounceInOut));
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOutCubic));
final _scrollController = ScrollController();

double _size = minSize;
Expand Down
87 changes: 45 additions & 42 deletions app/lib/views/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class _MainViewViewportState extends State<MainViewViewport>
double size = 1.0;
GlobalKey paintKey = GlobalKey();
_MouseState _mouseState = _MouseState.normal;
bool _isShiftPressed = false,
_isAltPressed = false,
_isCtrlPressed = false,
_isScalingDisabled = false;
bool _isShiftPressed = false, _isAltPressed = false, _isCtrlPressed = false;
bool? _isScalingDisabled;

@override
void initState() {
Expand Down Expand Up @@ -93,7 +91,7 @@ class _MainViewViewportState extends State<MainViewViewport>
@override
Widget build(BuildContext context) {
return SizedBox.expand(
child: ClipRRect(child: LayoutBuilder(builder: (context, constraints) {
child: LayoutBuilder(builder: (context, constraints) {
void bake() {
context.read<DocumentBloc>().bake(
viewportSize: constraints.biggest,
Expand Down Expand Up @@ -171,6 +169,7 @@ class _MainViewViewportState extends State<MainViewViewport>
}

var openView = false;
var point = Offset.zero;
final CurrentIndexCubit cubit = context.read<CurrentIndexCubit>();

Handler getHandler() {
Expand Down Expand Up @@ -208,7 +207,7 @@ class _MainViewViewportState extends State<MainViewViewport>
onScaleUpdate: (details) {
final handler = getHandler();
handler.onScaleUpdate(details, getEventContext());
if (_isScalingDisabled) return;
if (_isScalingDisabled ?? true) return;
final cubit = context.read<CurrentIndexCubit>();
if (details.scale == 1) {
return;
Expand All @@ -223,21 +222,21 @@ class _MainViewViewportState extends State<MainViewViewport>
.read<SettingsCubit>()
.state
.touchSensitivity;
cubit.zoom(current / sensitivity + 1,
details.localFocalPoint);
cubit.zoom(current / sensitivity + 1, point);
size = details.scale;
},
onLongPressEnd: (details) => getHandler()
.onLongPressEnd(details, getEventContext()),
onScaleEnd: (details) {
getHandler().onScaleEnd(details, getEventContext());
if (!_isScalingDisabled) delayBake();
_isScalingDisabled = false;
if (!(_isScalingDisabled ?? true)) delayBake();
_isScalingDisabled = null;
},
onScaleStart: (details) {
_isScalingDisabled = cubit
.getHandler()
.onScaleStart(details, getEventContext());
point = details.localFocalPoint;
size = 1;
},
onDoubleTapDown: (details) => getHandler()
Expand Down Expand Up @@ -322,37 +321,41 @@ class _MainViewViewportState extends State<MainViewViewport>
child: BlocBuilder<TransformCubit, CameraTransform>(
builder: (context, transform) => MouseRegion(
cursor: currentIndex.currentCursor,
child: Stack(children: [
Container(color: Colors.white),
CustomPaint(
size: Size.infinite,
foregroundPainter: ForegroundPainter(
[
...cubit.foregrounds,
],
state.data,
state.page,
state.info,
Theme.of(context).colorScheme,
transform,
cubit.state.selection,
currentIndex.cameraViewport.utilities,
),
painter: ViewPainter(
state.data,
state.page,
state.info,
cameraViewport: currentIndex.cameraViewport,
transform: transform,
invisibleLayers: state.invisibleLayers,
states: currentIndex.allRendererStates,
currentArea: state.currentArea,
colorScheme: Theme.of(context).colorScheme,
),
isComplex: true,
willChange: true,
)
]),
child: ClipRRect(
child: Stack(children: [
Container(color: Colors.white),
CustomPaint(
size: Size.infinite,
foregroundPainter: ForegroundPainter(
[
...cubit.foregrounds,
],
state.data,
state.page,
state.info,
Theme.of(context).colorScheme,
transform,
cubit.state.selection,
currentIndex.cameraViewport.utilities,
),
painter: ViewPainter(
state.data,
state.page,
state.info,
cameraViewport:
currentIndex.cameraViewport,
transform: transform,
invisibleLayers: state.invisibleLayers,
states: currentIndex.allRendererStates,
currentArea: state.currentArea,
colorScheme:
Theme.of(context).colorScheme,
),
isComplex: true,
willChange: true,
)
]),
),
),
),
),
Expand All @@ -361,6 +364,6 @@ class _MainViewViewportState extends State<MainViewViewport>
),
)));
});
})));
}));
}
}
8 changes: 4 additions & 4 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_linux
sha256: c2eb5bf57a2fe9ad6988121609e47d3e07bb3bdca5b6f8444e4cf302428a128a
sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa"
url: "https://pub.dev"
source: hosted
version: "2.3.1"
version: "2.3.2"
shared_preferences_platform_interface:
dependency: transitive
description:
Expand All @@ -1071,10 +1071,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_windows
sha256: f763a101313bd3be87edffe0560037500967de9c394a714cd598d945517f694f
sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59"
url: "https://pub.dev"
source: hosted
version: "2.3.1"
version: "2.3.2"
shelf:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/74.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
* Fix unnessesary baking of canvas on every change ([#503](https://github.com/LinwoodDev/Butterfly/issues/503))
* Fix performance of pen tool
* Fix tool reordering
* Fix pattern background rendering
* Improve default pattern templates values
* Improve documentation
* Improve file name validator to support -, (, ), comma and space
* Improve open animation in property view
* Switch back to flutter beta

View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.10

0 comments on commit 47b4047

Please sign in to comment.