diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 9da23ce9..ab5540cd 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -150,6 +150,10 @@ public class AppController implements Initializable { private CheckMenuItem useHdCameraResolution; private static final BooleanProperty useHdCameraResolutionProperty = new SimpleBooleanProperty(); + @FXML + private CheckMenuItem mirrorCameraImage; + private static final BooleanProperty mirrorCameraImageProperty = new SimpleBooleanProperty(); + @FXML private CheckMenuItem showLoadingLog; private static final BooleanProperty showLoadingLogProperty = new SimpleBooleanProperty(); @@ -379,6 +383,8 @@ public class AppController implements Initializable { hideEmptyUsedAddresses.selectedProperty().bindBidirectional(hideEmptyUsedAddressesProperty); useHdCameraResolutionProperty.set(Config.get().isHdCapture()); useHdCameraResolution.selectedProperty().bindBidirectional(useHdCameraResolutionProperty); + mirrorCameraImageProperty.set(Config.get().isMirrorCapture()); + mirrorCameraImage.selectedProperty().bindBidirectional(mirrorCameraImageProperty); showTxHexProperty.set(Config.get().isShowTransactionHex()); showTxHex.selectedProperty().bindBidirectional(showTxHexProperty); showLoadingLogProperty.set(Config.get().isShowLoadingLog()); @@ -946,6 +952,11 @@ public class AppController implements Initializable { Config.get().setHdCapture(item.isSelected()); } + public void mirrorCameraImage(ActionEvent event) { + CheckMenuItem item = (CheckMenuItem)event.getSource(); + Config.get().setMirrorCapture(item.isSelected()); + } + public void showLoadingLog(ActionEvent event) { CheckMenuItem item = (CheckMenuItem)event.getSource(); Config.get().setShowLoadingLog(item.isSelected()); @@ -3136,4 +3147,14 @@ public class AppController implements Initializable { } } } + + @Subscribe + public void webcamResolutionChanged(WebcamResolutionChangedEvent event) { + useHdCameraResolutionProperty.set(event.isHdResolution()); + } + + @Subscribe + public void webcamMirroredChanged(WebcamMirroredChangedEvent event) { + mirrorCameraImageProperty.set(event.isMirrored()); + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java index d354a94e..3af75517 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java @@ -25,6 +25,8 @@ import com.sparrowwallet.hummingbird.URDecoder; import com.sparrowwallet.hummingbird.registry.pathcomponent.IndexPathComponent; import com.sparrowwallet.hummingbird.registry.pathcomponent.PathComponent; import com.sparrowwallet.sparrow.AppServices; +import com.sparrowwallet.sparrow.EventManager; +import com.sparrowwallet.sparrow.event.WebcamResolutionChangedEvent; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.io.bbqr.BBQRDecoder; @@ -92,7 +94,7 @@ public class QRScanDialog extends Dialog { this.webcamService = new WebcamService(webcamResolutionProperty.get(), null, new QRScanListener(), new ScanDelayCalculator()); webcamService.setPeriod(Duration.millis(SCAN_PERIOD_MILLIS)); webcamService.setRestartOnFailure(false); - WebcamView webcamView = new WebcamView(webcamService); + WebcamView webcamView = new WebcamView(webcamService, Config.get().isMirrorCapture()); final DialogPane dialogPane = new QRScanDialogPane(); setDialogPane(dialogPane); @@ -150,6 +152,7 @@ public class QRScanDialog extends Dialog { webcamResolutionProperty.addListener((observable, oldValue, newResolution) -> { if(newResolution != null) { setHeight(newResolution == WebcamResolution.HD ? (getHeight() - 100) : (getHeight() + 100)); + EventManager.get().post(new WebcamResolutionChangedEvent(newResolution == WebcamResolution.HD)); } webcamService.cancel(); }); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamView.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamView.java index f5ce9891..acf9626e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamView.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamView.java @@ -1,8 +1,13 @@ package com.sparrowwallet.sparrow.control; +import com.sparrowwallet.sparrow.EventManager; +import com.sparrowwallet.sparrow.event.WebcamMirroredChangedEvent; +import com.sparrowwallet.sparrow.io.Config; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Node; +import javafx.scene.control.CheckMenuItem; +import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -21,12 +26,26 @@ public class WebcamView { private final ObjectProperty imageProperty = new SimpleObjectProperty<>(null); - public WebcamView(WebcamService service) { + public WebcamView(WebcamService service, boolean mirrored) { this.service = service ; this.imageView = new ImageView(); imageView.setPreserveRatio(true); - // make the cam behave like a mirror: - imageView.setScaleX(-1); + if(mirrored) { + setMirrored(true); + } + + ContextMenu contextMenu = new ContextMenu(); + CheckMenuItem mirrorItem = new CheckMenuItem("Mirror Camera"); + mirrorItem.setSelected(mirrored); + mirrorItem.selectedProperty().addListener((observable, oldValue, newValue) -> { + setMirrored(newValue); + Config.get().setMirrorCapture(newValue); + EventManager.get().post(new WebcamMirroredChangedEvent(newValue)); + }); + contextMenu.getItems().add(mirrorItem); + imageView.setOnContextMenuRequested(event -> { + contextMenu.show(imageView, event.getScreenX(), event.getScreenY()); + }); service.valueProperty().addListener((observable, oldValue, newValue) -> { if(newValue != null) { @@ -112,4 +131,8 @@ public class WebcamView { public Node getView() { return view; } + + public void setMirrored(boolean mirrored) { + imageView.setScaleX(mirrored ? -1 : 1); + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WebcamMirroredChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WebcamMirroredChangedEvent.java new file mode 100644 index 00000000..70475f24 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/WebcamMirroredChangedEvent.java @@ -0,0 +1,13 @@ +package com.sparrowwallet.sparrow.event; + +public class WebcamMirroredChangedEvent { + private final boolean mirrored; + + public WebcamMirroredChangedEvent(boolean mirrored) { + this.mirrored = mirrored; + } + + public boolean isMirrored() { + return mirrored; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WebcamResolutionChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WebcamResolutionChangedEvent.java new file mode 100644 index 00000000..6d1f9c80 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/WebcamResolutionChangedEvent.java @@ -0,0 +1,13 @@ +package com.sparrowwallet.sparrow.event; + +public class WebcamResolutionChangedEvent { + private final boolean hdResolution; + + public WebcamResolutionChangedEvent(boolean hdResolution) { + this.hdResolution = hdResolution; + } + + public boolean isHdResolution() { + return hdResolution; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Config.java b/src/main/java/com/sparrowwallet/sparrow/io/Config.java index ce515122..cba610fe 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Config.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Config.java @@ -58,6 +58,7 @@ public class Config { private int enumerateHwPeriod = ENUMERATE_HW_PERIOD_SECS; private QRDensity qrDensity; private Boolean hdCapture; + private boolean mirrorCapture = true; private boolean useZbar = true; private String webcamDevice; private ServerType serverType; @@ -405,6 +406,15 @@ public class Config { flush(); } + public boolean isMirrorCapture() { + return mirrorCapture; + } + + public void setMirrorCapture(boolean mirrorCapture) { + this.mirrorCapture = mirrorCapture; + flush(); + } + public boolean isUseZbar() { return useZbar; } diff --git a/src/main/resources/com/sparrowwallet/sparrow/app.fxml b/src/main/resources/com/sparrowwallet/sparrow/app.fxml index 68123ac5..db1cefae 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/app.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/app.fxml @@ -113,10 +113,13 @@ + + + + -