Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Added transparency and improved dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
oppahansi committed Dec 9, 2019
1 parent 8f51f50 commit 95b0ef5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ Doesn't work with YT videos which have embedded playback disabled.
Execute start.bat on Windows / ./start.sh in Terminal on Mac

## How To
Get a YouTube video Link like: https://www.youtube.com/watch?v=hH8QeXYjbF8
Take its ID(the part after "v="): hH8QeXYjbF8

Paste it into the text field.
* Download the latest build from releases. [Here](https://github.com/oppahansi/OOTP/releases)
* Get a YouTube video Link like: https://www.youtube.com/watch?v=hH8QeXYjbF8 Take its ID(the part after "v="): hH8QeXYjbF8
* Paste it into the text field.

## Screenshots
Always on top
![Image of Yaktocat](https://i.vgy.me/OMkoG3.png)

Resizeable
![Image of Yaktocat](https://i.vgy.me/dXXqlc.png)

Transparency
![Image of Yaktocat](https://i.vgy.me/TttnYi.png)
32 changes: 28 additions & 4 deletions res/Main.fxml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
Expand All @@ -10,14 +12,36 @@
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="465.0" prefWidth="792.0" style="-fx-background-color: #000000;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
<children>
<WebView fx:id="webView" layoutY="27.0" onMouseEntered="#onWebViewEntered" onMouseExited="#onWebViewExited" prefHeight="432.0" prefWidth="792.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="35.0" />
<TextField fx:id="youtubeId" layoutX="32.0" layoutY="5.0" onMouseEntered="#onTextFieldEntered" onMouseExited="#onTextFieldExited" text="videoId" AnchorPane.leftAnchor="30.0" AnchorPane.topAnchor="5.0" />
<Button fx:id="closeButton" layoutX="733.0" layoutY="2.0" mnemonicParsing="false" onAction="#onCloseButtonPressed" prefHeight="25.0" text="Close" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="5.0" />
<Button fx:id="resetButton" layoutX="671.0" layoutY="6.0" mnemonicParsing="false" onAction="#onResetButtonPressed" prefHeight="25.0" text="Reset" AnchorPane.rightAnchor="76.0" AnchorPane.topAnchor="5.0" />
<Button fx:id="onTopButton" layoutX="585.0" layoutY="5.0" mnemonicParsing="false" onAction="#onOnTopButtonPressed" prefHeight="25.0" text="Keep On Top" AnchorPane.rightAnchor="130.0" AnchorPane.topAnchor="5.0" />
<TextField fx:id="youtubeId" layoutX="39.0" layoutY="5.0" onMouseEntered="#onTextFieldEntered" onMouseExited="#onTextFieldExited" prefHeight="25.0" prefWidth="140.0" text="videoId" AnchorPane.leftAnchor="30.0" AnchorPane.topAnchor="5.0">
<cursor>
<Cursor fx:constant="TEXT" />
</cursor></TextField>
<Button fx:id="closeButton" layoutX="733.0" layoutY="2.0" mnemonicParsing="false" onAction="#onCloseButtonPressed" prefHeight="25.0" text="Close" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="5.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor></Button>
<Button fx:id="resetButton" layoutX="671.0" layoutY="6.0" mnemonicParsing="false" onAction="#onResetButtonPressed" prefHeight="25.0" text="Reset" AnchorPane.rightAnchor="76.0" AnchorPane.topAnchor="5.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor></Button>
<Button fx:id="onTopButton" layoutX="585.0" layoutY="5.0" mnemonicParsing="false" onAction="#onOnTopButtonPressed" prefHeight="25.0" text="Keep On Top" AnchorPane.rightAnchor="130.0" AnchorPane.topAnchor="5.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor></Button>
<Label layoutX="14.0" layoutY="9.0" text="YT" textFill="WHITE" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="10.0">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<Slider fx:id="opacitySlider" layoutX="186.0" layoutY="11.0" min="5.0" onMouseEntered="#onSliderEntered" onMouseExited="#onSliderExited" value="100.0" AnchorPane.leftAnchor="185.0" AnchorPane.topAnchor="11.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Slider>
<Label layoutX="336.0" layoutY="10.0" text="Opacity" textFill="WHITE" AnchorPane.leftAnchor="335.0" AnchorPane.topAnchor="10.0">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</AnchorPane>
16 changes: 16 additions & 0 deletions src/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.web.WebView;
Expand All @@ -17,6 +18,7 @@ public class Controller {
public Button resetButton;
public Button onTopButton;
public TextField youtubeId;
public Slider opacitySlider;

@FXML
public void initialize() throws NoSuchFieldException, IllegalAccessException {
Expand All @@ -29,6 +31,10 @@ public void initialize() throws NoSuchFieldException, IllegalAccessException {
webView.getEngine().load(baseUrl + youtubeId.getText());
});

opacitySlider.valueProperty().addListener((observable, oldValue, newValue) -> {
opacitySlider.getScene().getWindow().setOpacity((double)newValue / 100.0);
});

clearWebView();
}

Expand Down Expand Up @@ -79,4 +85,14 @@ public void onWebViewExited(MouseEvent mouseEvent) {
Scene scene = (Scene) ((WebView)mouseEvent.getSource()).getScene();
scene.setCursor(Cursor.DEFAULT);
}

public void onSliderEntered(MouseEvent mouseEvent) {
Scene scene = (Scene) ((Slider)mouseEvent.getSource()).getScene();
scene.setCursor(Cursor.HAND);
}

public void onSliderExited(MouseEvent mouseEvent) {
Scene scene = (Scene) ((Slider)mouseEvent.getSource()).getScene();
scene.setCursor(Cursor.DEFAULT);
}
}
13 changes: 11 additions & 2 deletions src/ResizeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ static class ResizeListener implements EventHandler<MouseEvent> {
private double minHeight;
private double maxHeight;

Dimension screenSize;

ResizeListener(Stage stage) {
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.stage = stage;
}

Expand Down Expand Up @@ -161,8 +164,14 @@ public void handle(MouseEvent mouseEvent) {
}
}
} else {
stage.setX(mouseEvent.getScreenX() - sceneWidth / 2);
stage.setY(mouseEvent.getScreenY() - sceneHeight / 2);
double newX = mouseEvent.getScreenX() - sceneWidth / 2;
double newY = mouseEvent.getScreenY() - sceneHeight / 2;

if (newX < 0) stage.setX(0);
else stage.setX(Math.min(newX, screenSize.getWidth() - stage.getWidth()));

if (newY < 0) stage.setY(0);
else stage.setY(Math.min(newY, screenSize.getHeight() - stage.getHeight()));
}
}
}
Expand Down

0 comments on commit 95b0ef5

Please sign in to comment.