增加组件的旋转

This commit is contained in:
liujing133
2025-12-06 00:27:43 +08:00
parent 6b31c8051d
commit fb7e360152
6 changed files with 115 additions and 18 deletions
@@ -1,16 +1,22 @@
package dev.bytevibe.hyperpoint;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.Spinner;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
/**
* 属性编辑面板,用于编辑选中对象的属性
* 使用FXML加载UI布局
@@ -38,6 +44,10 @@ public class PropertyPanel extends VBox implements Initializable {
private Spinner<Double> strokeWidthSpinner;
@FXML
private Button deleteButton;
@FXML
private Slider rotationSlider;
@FXML
private Label rotationValueLabel;
private DrawingCanvas canvas;
@@ -80,6 +90,20 @@ public class PropertyPanel extends VBox implements Initializable {
"BOLD_ITALIC"
);
// 初始化旋转控制
rotationSlider.setMin(0);
rotationSlider.setMax(360);
rotationSlider.setValue(0);
rotationSlider.setMajorTickUnit(15);
rotationSlider.setMajorTickUnit(90);
rotationSlider.setShowTickMarks(true);
rotationSlider.setShowTickLabels(true);
rotationSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
updateRotation();
rotationValueLabel.setText(String.format("%.0f°", newVal));
});
// 设置默认值
fontFamilyCombo.setValue("Arial");
fontStyleCombo.setValue("NORMAL");
@@ -112,6 +136,7 @@ public class PropertyPanel extends VBox implements Initializable {
DrawableObject selected = canvas.getSelectedObject();
if (selected == null) {
setEditingVisible(false);
rotationSlider.setDisable(true);
objectTypeLabel.setText("未选中对象");
return;
}
@@ -142,15 +167,31 @@ public class PropertyPanel extends VBox implements Initializable {
showImageControls();
}
rotationSlider.setValue(selected.getRotation());
rotationSlider.setDisable(false);
rotationValueLabel.setText(String.format("%.0f°", selected.getRotation()));
// 重新添加监听
textContentField.setOnKeyReleased(e -> updateTextContent());
}
/**
* 更新旋转
*/
private void updateRotation() {
DrawableObject selected = canvas.getSelectedObject();
if (selected != null) {
selected.setRotation(rotationSlider.getValue());
canvas.redraw();
}
}
/**
* 显示文本控件
*/
private void showTextControls() {
textContentField.setDisable(false);
rotationSlider.setDisable(false);
fontFamilyCombo.setDisable(false);
fontSizeSpinner.setDisable(false);
fontStyleCombo.setDisable(false);
@@ -167,6 +208,7 @@ public class PropertyPanel extends VBox implements Initializable {
*/
private void showShapeControls() {
textContentField.setDisable(true);
rotationSlider.setDisable(false);
fontFamilyCombo.setDisable(true);
fontSizeSpinner.setDisable(true);
fontStyleCombo.setDisable(true);
@@ -183,6 +225,7 @@ public class PropertyPanel extends VBox implements Initializable {
*/
private void showImageControls() {
textContentField.setDisable(true);
rotationSlider.setDisable(false);
fontFamilyCombo.setDisable(true);
fontSizeSpinner.setDisable(true);
fontStyleCombo.setDisable(true);