增加鼠标滚轮控制页面切换
This commit is contained in:
@@ -1,20 +1,25 @@
|
|||||||
package dev.bytevibe.hyperpoint;
|
package dev.bytevibe.hyperpoint;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import dev.bytevibe.hyperpoint.Utils.MyAlert;
|
import dev.bytevibe.hyperpoint.Utils.MyAlert;
|
||||||
import dev.bytevibe.hyperpoint.Utils.MyTextInputDialog;
|
import dev.bytevibe.hyperpoint.Utils.MyTextInputDialog;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
|
import javafx.scene.control.TextInputDialog;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
public class Controller implements Initializable {
|
public class Controller implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<SlidePage> pageListView;
|
private ListView<SlidePage> pageListView;
|
||||||
@@ -51,6 +56,25 @@ public class Controller implements Initializable {
|
|||||||
displayPageContent(newVal);
|
displayPageContent(newVal);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 为页面列表添加鼠标滚轮事件
|
||||||
|
pageListView.setOnScroll(event -> {
|
||||||
|
if (currentSlide == null || currentSlide.getPages().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int currentIndex = pageListView.getSelectionModel().getSelectedIndex();
|
||||||
|
if (event.getDeltaY() < 0) {
|
||||||
|
if (currentIndex < currentSlide.getPages().size() - 1) {
|
||||||
|
pageListView.getSelectionModel().select(currentIndex + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (currentIndex > 0) {
|
||||||
|
pageListView.getSelectionModel().select(currentIndex - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.consume();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
package dev.bytevibe.hyperpoint;
|
package dev.bytevibe.hyperpoint;
|
||||||
|
|
||||||
import javafx.animation.*;
|
import javafx.animation.Animation;
|
||||||
import javafx.geometry.Bounds;
|
import javafx.animation.AnimationTimer;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import javafx.scene.input.ScrollEvent;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.transform.Rotate;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
import javafx.util.Duration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全屏演示窗口,支持翻页和动画效果
|
* 全屏演示窗口,支持翻页和动画效果
|
||||||
@@ -54,6 +53,7 @@ public class PresentationWindow {
|
|||||||
// 添加键盘和鼠标事件处理
|
// 添加键盘和鼠标事件处理
|
||||||
root.setOnKeyPressed(this::handleKeyEvent);
|
root.setOnKeyPressed(this::handleKeyEvent);
|
||||||
root.setOnMouseClicked(this::handleMouseClick);
|
root.setOnMouseClicked(this::handleMouseClick);
|
||||||
|
root.setOnScroll(this::handleMouseScroll);
|
||||||
|
|
||||||
root.getChildren().add(canvas);
|
root.getChildren().add(canvas);
|
||||||
root.setStyle("-fx-background-color: #000000;");
|
root.setStyle("-fx-background-color: #000000;");
|
||||||
@@ -100,6 +100,18 @@ public class PresentationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理鼠标滚轮事件
|
||||||
|
*/
|
||||||
|
private void handleMouseScroll(ScrollEvent event) {
|
||||||
|
if (event.getDeltaY() < 0) {
|
||||||
|
nextPage();
|
||||||
|
} else {
|
||||||
|
previousPage();
|
||||||
|
}
|
||||||
|
event.consume();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下一页
|
* 下一页
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user