2

I'm making a ScalaFX (but use of Scala is irrelevant here) application with a user interface similar to i.e. Google maps. There's panning and zooming.

For each such change of the user's viewpoint, I add a transform into a Group's .transforms.

transforms += new Translate( dx, dy )

or

transforms += new Scale( 1/f,1/f, cx, cy )

This seems like the only way to affect transformations (apart from translateXYZ, layoutXYZ, which I'm ignoring), and it works.

The docs say this:

Multiple transformations may be applied to a node by specifying an ordered chain of transforms. The order in which the transforms are applied is defined by the ObservableList specified in the transforms variable.

Doesn't this imply that there's a list (even, an observable list) of potentially hundreds or thousands of entries long?

If so, I would like to flatten the list occasionally. Tried calling .localToSceneTransoform and .localToParentTransform for this (thinking I'd then set the .transforms with the received overall affine matrix). That crashed the JVM.

Am I doing something wrong here, or should I just stop caring about the list growing, well, indefinately?

Can provide a short ScalaFX sample code to highlight all this (including the crash). Please ask.

System: OS X, JVM 7u10

4

1 回答 1

1

JavaFX 转换的“思考”需要一段时间。这个想法是制作一个转换列表,并更改这些转换的 Observable 参数。这消除了不断向列表添加越来越多转换的需要。

这实际上是一种非常可爱的处理方式。可悲的是,从我读过的任何文档中都看不到这一点(我认为将这个条目留在 SO 中的原因)。

必要的代码类似于:

private val panTrans = new Translate(0,0)

transforms = 
  panTrans ::
  Nil

...

panTrans.x = panTrans.x() + dx
panTrans.y = panTrans.y() + dy

我认为从这里会很明显。

于 2013-01-03T14:32:38.137 回答