我正在为javafx中的音乐可视化程序创建启动管理器。可视化工具是用OpenGL编写的,管理器将信息输入到可视化工具中。在管理器中,我以仅包含画布的阶段的形式为可视化工具提供了某种预览。在画布上,我想用鼠标画一些线,然后将坐标传递给OpenGL。我的问题是,如果我访问mouseEvent.getX()
坐标,则包含装饰,这意味着坐标不准确,或因装饰而移动。以下是一些图片:
第一个屏幕截图显示了管理器。注意,该行从左上角一直到右下角
The second screenshot shows the visualizer. Here, the white line doesnt go all the way to the bottom.
I've fixed the issue and leave this answer just for future reference.
When trying to scale a canvas relatively, you have to be careful which measure to use.
When creating a window, the coordinate system of the Stage
is relative to the top left of the window, including the decoration. When adding a Node
with a fixed size, like a Canvas
to it, the size of the Stage
gets bigger.
So when scaling some thing relative to the Canvas
's size, you have to use the width and height of the Canvas
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句