JavaFX rendering bug with too many ImageViews on screen - javafx

I'm working on a game with JavaFX, and I'm bumping into graphics rendering issues if there are too many entities/ImageViews on the screen.
I'm using a Group as the root node of the scene, where I add an ImageView for each entity; to update the entities' positions, I use the methods setTranslateX and setTranslateY for each ImageView and for a ParallelCamera that keeps the main character centered on the screen. When the main character is not moving (aka the ParallelCamera is stationary) and there are several ImageViews on the screen, the view is not updated as it should.
Can I fix this? Thanks for the help.

Related

JavaFX - imageview node only shows with window resize

I'm using JavaFX. When i add an imageview node to the stack pane and then run the application, I can only see the image after manually resizing the window (dragging the edge of the window with my mouse).
It will also show up if i setTranslateX or setTranslateY the image away from its original location. But if I want it to just stay there, I have to manually resize the window to see it. Has anyone encountered this? Is it a bug I just have to deal with?
Thanks

How do I make content within a JavaFX Scene transparent?

The program below is an example of what I'm actually trying to achieve.
I'm trying to do is recreate the picture above in JavaFX. However I am having difficulties because when I set the content of my stage to transparent it doesn't actually go transparent it still remains white.
#Override
public void start(Stage stage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
root.setStyle("-fx-background-color: rgba(0,0,0,0);");
scene.setFill(Color.TRANSPARENT);
stage.setScene(scene);
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
The stage is visible from this code. I also set the content to transparent and changed the default style of the root pane to transparent.
I don't understand why this doesn't work, I'm setting the content to transparent but the background is still not transparent.
The result from the code I posted shows this, as you can see it's not transparent.
This question is almost a duplicate of:
how to make transparent scene and stage in javafx?
The difference being that it is also asking to retain native window decorations, which is not possible with StageStyle.TRANSPARENT.
If you look closely at the sample windows provided in the question, the decoration areas differ slightly (e.g. one includes a stage icon in the upper left and the other does not). My guess is that the transparent window pictured in the question isn't actually using the OS window decorations at all, but is instead rendering its own decorations which look much like the OS window decorations (that is just a guess though).
Anyway, to achieve a similar effect with JavaFX, it is necessary that JavaFX be used to render the window decorations rather than the OS window manager. To do that, refer to the following question:
JavaFX entirely customized windows?
In particular take a look at the Undecorator library:
https://github.com/in-sideFX/UndecoratorBis
You will never be able to get the window decorations to exactly match the OS Window manager decorations, but you can create something that looks different and provides similar functionality. If you work at it, you might be able to achieve something that matches the OS window decorations pretty closely, similar to the window screenshot in your question. Though, if it were me, I would just go for a different look which was still clean and easily comprehensible by the user, similar to the default look provided by Undecorator.
Do you think this could be pulled off by creating an ImageView and using some sort of stage listener so when the stage is moved the imageview displays a new image of what's behind the application? Or is that overly complicating it?
The background capture to imageView approach is a reasonable alternate approach.
If you do want to use the imageView capture approach, you can use some of the ideas from the following answer:
JavaFX effect on background
Note that the imageView capture type answer linked above won't completely accomplish what you wish and you still need to do some additional custom work to get exactly the effect you need as you move the stage around or as the desktop or windows under your window change. Possibly you may need to resort to logic outside of JavaFX to fully realize your goal, and discussion of how to do that is outside the scope of what I would be prepared (or able) to discuss here.
It's complicated no matter what you do, I don't really have a recommendation between the undecorator or the imageView capture approach.
Maybe if you mix JavaFX and Swing/AWT you may be able to do this by using a JFXPanel and the AWT PERPIXEL_TRANSPARENT feature. I haven't tried this combo, but per pixel settings for AWT are demonstrated in this oracle sample as discussed in How to Implement Per-Pixel Translucency.

ListView scrolling issue in JavaFX2

I'm developing a application which has a ListView which contains items which needs complex cell layouts. The cells are in variable heights and some of the cells tends to be larger than the view port height.
But when the ListView is filled with items the scroll thumb tends to resize its self while scrolling, which makes it hard to hold onto the thumb while scrolling. This happens mainly when passing through different size of cells.
This is not a problem in Swing if I create a same kind of a cell render to be used with the JList. This problem is there in JavaFX 2 and JavaFX8 both.
When looking at the VirtualFlow which is responsible for layout of the ListView and handle scrolling, it seems that the scrollbar thumb side (lenghtbar) is calculated based on the cell count and the visible cell count, which is actually a problem when it comes to lists which has variable heights of cells.
So is this the future of the scroll bar behavior for Java FX list views? or is there any solution available for this problem? Or should I try to hide the scrollbar and provide a different user interaction to scroll?
This problem is already reported under https://javafx-jira.kenai.com/browse/RT-25059 and fixed in Java8 upto some extend. So if this fix is needed on JavaFx2 we have to backport the changes under commit http://hg.openjdk.java.net/openjfx/8/controls/rt/rev/81cc13fe6f96
To get this changes in JavaFX 2.2 you need to apply the required changes on to FX2.2 VirtualFlow.java class and load those changes before the jfxrt.jar is loaded. Another approach is if you don't like to mess up with the jfxrt classes is to have you own ListView which uses your own Skin and the patched VirtualFlow version may be with a different name. But this might require lot of customization compared to first solution.
More approaches are welcome :).

Creating a permanent static overlay for QGraphicsView scene

I am making an app using Qt (currently 4.8) which displays a literal map from a large number of QGraphicsScene items. I would like to annotate the view with a scale. My requirement for the scale is that it is permanently fixed w.r.t the viewport widget. It needs to be updated whenever the view scale changes (zoom in, etc). There are other possible overlay items as well (compass, etc) so I'd prefer a generic solution.
I have looked at earlier questions around this which suggest:
using the ItemIgnoresTransform
using an overlay pixmap.
I tried IgnoresTransform but that way didn't work right: I couldn't figure out how to fix it in place in (say) the bottom corner of the viewport and was having some difficulty getting the text and lines always displaying in the correct size.
I scrapped that and subclassed QGraphicsView, adding an overlay pixmap by reimplementing the paintEvent (calls original one, then paints the overlay pixmap on top), and an alignment option to indicate where it goes. Coding some pixmap paint code produces a usable scale on the view. Yay! ... but it doesn't work with scrolls - I get "shattered" renderings of the scale all over, or sometimes no scale at all. I think this is because QGraphicsView::scrollViewportBy() uses viewport()->scroll() so I wondered if switching to ViewportSmartUpdate would help, but it doesn't help enough. I'd prefer not to switch to ViewportFullUpdate as that would likely slow the app down too much (there are millions of items in the scene and that would require a full repaint just to move around).
So. Any ideas from here? Would adapting my pixmap code to write to a new mostly-transparent Widget that is overlaid on the viewport be a better way?
Thanks for any help...
Though it may not be the best way of doing this, in the past I've added custom widgets to the window that holds the QGraphicsView / QGraphicsScene, which have the same graphic style as the QGraphicObjects in the scene. When the view is then used to move objects in the scene, or the scene itself, the items on the window remain in the same place.
Hope that helps.

Resize image to fit window in Qt

I am using Qt to construct an application. My MainWindow consists of an image of a map which I would like to be resized to the fit the window. This means when the window gets smaller the image gets smaller and vice versa. When the user selects a point on that image I want to remove this feature. I am new to Qt and haven't been able to figure this out. I am using QGraphicsView for this.
QGraphicsView::fitInView

Resources