Skip to content

Commit

Permalink
remove SubScene
Browse files Browse the repository at this point in the history
  • Loading branch information
leewyatt committed Dec 29, 2022
1 parent 19e6762 commit 9d6a45e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
>QQ: **9670453** <br />
JavaFX QQ群: **518914410** <br/>
主要变化:
RXCarousel 去掉SubScene (css name: .carousel-subscene)
考虑到一个界面可能有多个轮播图,避免层级过多;
如果想要部分的专场效果,有3D的感觉, 那么可以在Scene里设置;
Main changes:
RXCarousel removes SubScene (css name: .carousel-subscene)
Considering that an interface may have multiple carousels to avoid too many layers;
if you want some special effects and a 3D feeling, Need to set a perspective camera for setting the main scene graph;
```java
scene.setCamera(new PerspectiveCamera());
```


Maven dependency
```xml
<repositories>
Expand All @@ -25,7 +38,7 @@ Maven dependency
<groupId>com.github.leewyatt</groupId>
<artifactId>rxcontrols</artifactId>
<!-- 11.x.y -->
<version>11.0.2</version>
<version>11.0.3</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.github.leewyatt</groupId>
<artifactId>rxcontrols</artifactId>
<version>11.0.2</version>
<version>11.0.3</version>
<packaging>jar</packaging>
<dependencies>

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/leewyatt/rxcontrols/controls/RXCarousel.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,16 @@ public List<RXToggleButton> getNavButtons() {
return skin.getNavButtons();
}

/**
* 之前使用SubScene 然后添加透视相机, 有3D的效果
* 但是考虑到一个页面,或者一个界面可能有多个轮播图,所以取消了SubScene
* 可以自行根据需要跟Scene一个透视相机, 或者自己创建一个SubScene 添加透视相机, 来实现;
* 避免了多个SubScene
* @return null
*/
@Deprecated
public SubScene getSubScene() {
return skin.getSubScene();
return null;
}

/**
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/com/leewyatt/rxcontrols/controls/RXCarouselSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import javafx.geometry.Orientation;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.PerspectiveCamera;
import javafx.scene.SceneAntialiasing;
import javafx.scene.SubScene;
import javafx.scene.control.SkinBase;
import javafx.scene.control.Toggle;
Expand Down Expand Up @@ -76,10 +74,7 @@ public class RXCarouselSkin extends SkinBase<RXCarousel> {

private RXCarousel control;
private ObservableList<RXCarouselPane> paneList;
/**
* 子场景图
*/
private final SubScene subScene;

/**
* 场景图上的根节点(包含内容面板,效果面板,遮挡面板,导航面板)
*/
Expand Down Expand Up @@ -204,9 +199,7 @@ public RXCarouselSkin(RXCarousel control) {

navigationPane.getChildren().setAll(leftButton, rightButton, navBar);
// 裁剪容器(避免显示的部分超出容器的范围)
//SubScene 已经实现了裁剪的效果
// clipRegion(control);
// clipRegion(rootPane);
clipRegion(rootPane);

// 绑定宽高
DoubleProperty dbw = control.prefWidthProperty();
Expand All @@ -221,13 +214,16 @@ public RXCarouselSkin(RXCarousel control) {
clipRegion(pane);
}*/
// 添加底层容器到组件里
subScene = new SubScene(contentPane, dbw.get(), dbh.get(), false, SceneAntialiasing.BALANCED);
subScene.getStyleClass().add("carousel-subscene");
rootPane.getChildren().addAll(subScene, effectPane, navigationPane);
contentPane.backgroundProperty().bind(control.backgroundProperty());
subScene.widthProperty().bind(control.prefWidthProperty());
subScene.heightProperty().bind(control.prefHeightProperty());
subScene.setCamera(new PerspectiveCamera());
rootPane.getChildren().addAll(contentPane, effectPane, navigationPane);
rootPane.backgroundProperty().bind(control.backgroundProperty());

//subScene = new SubScene(contentPane, dbw.get(), dbh.get(), false, SceneAntialiasing.BALANCED);
//subScene.getStyleClass().add("carousel-subscene");
//rootPane.getChildren().addAll(subScene, effectPane, navigationPane);
//contentPane.backgroundProperty().bind(control.backgroundProperty());
//subScene.widthProperty().bind(control.prefWidthProperty());
//subScene.heightProperty().bind(control.prefHeightProperty());
//subScene.setCamera(new PerspectiveCamera());

getChildren().setAll(rootPane);
getSkinnable().requestLayout();
Expand Down Expand Up @@ -677,8 +673,8 @@ public void dispose() {
button.textProperty().unbind();
}
contentPane.backgroundProperty().unbind();
subScene.widthProperty().unbind();
subScene.heightProperty().unbind();
contentPane.prefWidthProperty().unbind();
contentPane.prefHeightProperty().unbind();
rootPane.minWidthProperty().unbind();
rootPane.prefWidthProperty().unbind();
rootPane.minHeightProperty().unbind();
Expand Down Expand Up @@ -706,7 +702,12 @@ public void dispose() {
super.dispose();
}

/**
* 移除SubScene, 要向轮播图有3D效果,请自行给Scene添加透视相机 PerspectiveCamera
* @return null
*/
@Deprecated
public SubScene getSubScene() {
return subScene;
return null;
}
}
2 changes: 2 additions & 0 deletions src/test/java/app/ui/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
Expand All @@ -42,6 +43,7 @@ public void start(Stage primaryStage) throws IOException {
Scene scene = new Scene(root);
scene.setFill(Color.TRANSPARENT);
scene.setUserData(this.getHostServices());
scene.setCamera(new PerspectiveCamera());
primaryStage.setScene(scene);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setTitle("MainTest Window");
Expand Down

0 comments on commit 9d6a45e

Please sign in to comment.