Allow user to resize an undecorated Stage

后端 未结 12 1524
悲&欢浪女
悲&欢浪女 2020-12-24 02:21

I am working on making a screen recorder in JavaFX and one utility that is mandatory in the screen recorder is to let the user define how much area to record.

I m

12条回答
  •  生来不讨喜
    2020-12-24 03:03

    I've looked into some threads where they discuss about it before I tried myself to "solve" it, but in the end there was no Problem.

    I created a button in the bottom-right corner, gave the Button an OnDraggedMethod and simply used the mouseevent and set the Height/Width on MousePosition - stage X/Y position.

        double newX = event.getScreenX() - stage.getX() + 13;
        double newY = event.getScreenY() - stage.getY() + 10;
        if (newX % 5 == 0 || newY % 5 == 0) {
            if (newX > 550) {
                stage.setWidth(newX);
            } else {
                stage.setWidth(550);
            }
    
            if (newY > 200) {
                stage.setHeight(newY);
            } else {
                stage.setHeight(200);
            }
        }
    

    Also I set a minimal Width and Height. And because i think that the laggy resize-animation is annoying i surrounded the statement with the if and just resize the stage every 5th pixel.

    Looks much better!

    PS: The +13 and +10 is just for the MousePosition. Otherweise the Mouse is on the Corner not on the Button^^.

提交回复
热议问题