Skip to content

Commit

Permalink
Fix resolution shift issues, closes #793
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Feb 9, 2025
1 parent b43d821 commit 335d6ec
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
16 changes: 13 additions & 3 deletions app/lib/cubits/current_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum TemporaryState { allowClick, removeAfterClick, removeAfterRelease }
@Freezed(equal: false)
class CurrentIndex with _$CurrentIndex {
const CurrentIndex._();

const factory CurrentIndex(
int? index,
Handler handler,
Expand Down Expand Up @@ -1073,29 +1074,35 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {
hideUi: state.hideUi == HideState.visible
? HideState.keyboard
: HideState.visible));

void enterTouchHideUI() => emit(state.copyWith(hideUi: HideState.touch));

void exitHideUI() => emit(state.copyWith(hideUi: HideState.visible));

ExternalStorage? getRemoteStorage() => state.location.remote.isEmpty
? null
: state.settingsCubit.state.getRemote(state.location.remote);

bool _currentlySaving = false;

Future<AssetLocation> save(DocumentState blocState,
[AssetLocation? location]) async {
if (state.networkingService.state?.$1 is NetworkerClient) {
return AssetLocation.empty;
}
final storage = getRemoteStorage();
final fileSystem = blocState.fileSystem.buildDocumentSystem(storage);
while (state.saved == SaveState.saving) {}
if (state.saved == SaveState.saved) {
return state.location;
while (_currentlySaving) {
await Future.delayed(const Duration(milliseconds: 100));
}
_currentlySaving = true;
emit(state.copyWith(
saved: SaveState.saving, location: location ?? state.location));
location ??= state.location;
final currentData = await blocState.saveData();
if (currentData == null || blocState.embedding != null) {
emit(state.copyWith(saved: SaveState.saved));
_currentlySaving = false;
return AssetLocation.empty;
}
if (!location.path.endsWith('.bfly') ||
Expand All @@ -1109,6 +1116,7 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {
}
state.settingsCubit.addRecentHistory(location);
emit(state.copyWith(location: location, saved: SaveState.saved));
_currentlySaving = false;
return location;
}

Expand Down Expand Up @@ -1188,8 +1196,10 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {

void setAreaNavigatorCreate(bool value) =>
emit(state.copyWith(areaNavigatorCreate: value));

void setAreaNavigatorExact(bool value) =>
emit(state.copyWith(areaNavigatorExact: value));

void setAreaNavigatorAsk(bool value) =>
emit(state.copyWith(areaNavigatorAsk: value));

Expand Down
4 changes: 2 additions & 2 deletions app/lib/cubits/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ enum RenderResolution {
const RenderResolution(this.multiplier);

Rect getRect(Rect rect) {
final width = rect.width * multiplier;
final height = rect.height * multiplier;
final width = (rect.width * multiplier).ceilToDouble();
final height = (rect.height * multiplier).ceilToDouble();
return Rect.fromCenter(
center: rect.center,
width: width,
Expand Down
5 changes: 4 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -646,5 +646,8 @@
"action": "Action",
"svgText": "SVG Text",
"offset": "Offset",
"positionDependent": "Position dependent"
"positionDependent": "Position dependent",
"flipHorizontal": "Flip horizontal",
"flipVertical": "Flip vertical",
"grayscale": "Grayscale"
}
6 changes: 6 additions & 0 deletions app/lib/renderers/elements/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ class ImageRenderer extends Renderer<ImageElement> {
updateImage(bloc, (cmd) => cmd.invert()),
RendererOperation.background: (bloc, context) =>
updateImage(bloc, (cmd) => cmd.filter(updateImageBackground())),
RendererOperation.grayscale: (bloc, context) =>
updateImage(bloc, (cmd) => cmd.grayscale()),
RendererOperation.flipHorizontal: (bloc, context) =>
updateImage(bloc, (cmd) => cmd.flip(direction: img.FlipDirection.horizontal)),
RendererOperation.flipVertical: (bloc, context) =>
updateImage(bloc, (cmd) => cmd.flip(direction: img.FlipDirection.vertical)),
};
}
}
11 changes: 10 additions & 1 deletion app/lib/renderers/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,28 @@ abstract class HitCalculator {

enum RendererOperation {
invert,
background;
background,
grayscale,
flipHorizontal,
flipVertical;

String getLocalizedName(BuildContext context) {
final loc = AppLocalizations.of(context);
return switch (this) {
RendererOperation.invert => loc.invert,
RendererOperation.background => loc.background,
RendererOperation.grayscale => loc.grayscale,
RendererOperation.flipHorizontal => loc.flipHorizontal,
RendererOperation.flipVertical => loc.flipVertical,
};
}

IconGetter get icon => switch (this) {
RendererOperation.invert => PhosphorIcons.circleHalf,
RendererOperation.background => PhosphorIcons.paintBucket,
RendererOperation.grayscale => PhosphorIcons.palette,
RendererOperation.flipHorizontal => PhosphorIcons.arrowsHorizontal,
RendererOperation.flipVertical => PhosphorIcons.arrowsVertical,
};
}

Expand Down
2 changes: 2 additions & 0 deletions metadata/en-US/changelogs/130.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
* Add option for position and zoom dependent
* Fix snap if size is 0
* Fix offset list tile
* Fix resolution shift issues ([#793](https://github.com/LinwoodDev/Butterfly/issues/793))
* Fix saving issues

Read more here: https://linwood.dev/butterfly/2.3.0-beta.2

0 comments on commit 335d6ec

Please sign in to comment.