Is there a GridPane lookalike in Gluon? - gluon

I'm making a basic dice app, and I'd like to display dice results in a FlowPane because it automatically adjusts the "columns" as the window is sized/resized horizontally. The problem with this solution is that the results need to be scrollable, and ScrollPane performance seems completely lackluster in Gluon on android.
Currently, for the desktop version (regular JavaFX) I use a FlowPane in a scroll pane, and for the mobile version I use a CharmListView. But I'd like to be able to use a good-performing grid on mobile, too.
I'd like to be able to have the image on the right be more like the one on the left, without destroying scrolling performance on mobile.
Does anyone know of any tools to do this without having to get the width of the window, calculate how many columns of dice I can have, and populating the CharmListView with HBoxes with the number of columns calculated?
Everything in my project is Gluon 3. I wonder if it just has a problem with a bunch of image boxes.
My code is roughly shaped like this:
private Image image1 = new Image("/Dice/one.png");
private Image image2 = new Image("/Dice/two.png");
private Image image3 = new Image("/Dice/three.png");
private Image image4 = new Image("/Dice/four.png");
private Image image5 = new Image("/Dice/five.png");
private Image image6 = new Image("/Dice/six.png");
ArrayList<Image> images = new ArrayList<>();
images.add(image1);
images.add(image2);
images.add(image3);
images.add(image4);
images.add(image5);
images.add(image6);
FlowPane pane = new FlowPane();
pane.prefWidthProperty().bind(widthProperty());
ScrollPane scrollPane = new ScrollPane(pane);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
for(int i = 0; i < 1000; i++) {
pane.getChildren().add(new ImageView(images.get(random.nextInt(6))));
}
setCenter(scrollPane);'
This is all inside my basic view class. Performance is absolutely terrible, even with just around ~100 dice. I'm mostly making this for tabletop war games, and I play a horde army... so more than 100 dice is not uncommon for me. The devices I've done it on are reasonably high-end, too: Samsung Galaxy S7 and a Nexus 9.

Related

How to achieve effect of shrinking picture?

I'd like to hide a picture which is on JavaFX application's stage. I want it disappear by shrinking.
Let's says there are some:
#FXML
private ImageView iv;
private Image img = new Image(...);
real img size is 100x100 pixels
then
iv.setImage(img);
iv.setFitWidth(50);
next I made method like that:
private Timeline shrink(ImageView iv)
{
final Timeline animation = new Timeline();
animation.getKeyFrames().addAll(
new KeyFrame(Duration.ZERO,
new KeyValue(iv.fitWidthProperty(), 50)
),
new KeyFrame(Duration.millis(400),
new KeyValue(iv.fitWidthProperty(), 0)
)
);
animation.setCycleCount(1);
animation.play();
}
so after that, the picture is shrinking, but it doesn't stay with 0 width, even worse, it appears again in its original size: 100.
what should I do to stay it shrinked ? I don't want to hide it by setVisibile cause I need that extra space later to fill it with some text.
ok, my fault...
0 is for default, so that is why picture appears in its original size. It needs to be set to 0.01 for example and then maybe set the visibility to false. But i'm sure there is better and nicer way to do it.

How to use javafx to view cells that wraps horizontally and scrolls vertically

I'm trying to determine how, using javafx, to approach displaying cells (image thumbnails or images) similar to Windows Explorer where images are shown in rows that wrap at horizontal boundaries but scroll in the vertical direction.
Is a tableview the approach to use and then update the column number when the view is resized? A little help would be greatly appreciated. Better yet a simple example code.
I'm pretty new to this forum and I have searched but can't really get started on this.
Thanks
Wrapping a FlowPane inside a ScrollPane would be a much simpler approach to the problem.
Example:
This uses some rectangles with numbers instead of images, but I think it's enough to get an idea how to use the Layouts:
FlowPane contentContainer = new FlowPane();
contentContainer.setVgap(10);
contentContainer.setHgap(10);
ScrollPane scroll = new ScrollPane(contentContainer);
scroll.setFitToWidth(true);
// fill FlowPane with some content
ArrayList<Node> content = new ArrayList<>();
for (int i = 0; i < 15; i++) {
Text text = new Text(Integer.toString(i));
text.setFill(Color.YELLOW);
StackPane pane = new StackPane(text);
pane.setStyle("-fx-background-color: blue;");
pane.setPrefSize(50, 50);
content.add(pane);
}
contentContainer.getChildren().setAll(content);

easeljs splitting an image into pieces

I'm new to easeljs and was wondering how would you split an image into a given number of pieces. From what I've gathered so far, I'm supposed to use SpriteSheets to accomplish this. However, the only tutorials I've seen are ones with multiple images in one Spritesheet, not one image divided into multiple images and put into a SpriteSheet.
This is my code so far (I know that the variable frames is undefined since I cannot properly access the spriteSheet array yet):
var data = {
images: ["/images/teemo.png"],
frames: {width:50, height:50}
};
var spriteSheet = new createjs.SpriteSheet(data);
console.log(spriteSheet);
console.log(spriteSheet[frames]);
var frames = spriteSheet[frames];
console.log(frames);
for (var i=0; i<frames.length; i++){
var bmp = new createjs.Bitmap(SpriteSheet[frames][i]);
}
A spritesheet is an interesting way (although not really the intent of the class). Your usage is wrong though.
Create a Spritesheet
Create Sprite instances (called BitmapAnimation in EaselJS 0.6.1 and earlier), each pointing at the same SpriteSheet instance
Use sprite.gotoAndStop(frame) to have each instance show a different piece
Here is an example:
for (var i=0; i< numberOfImages; i++) {
var sprite = new createsjs.Sprite(spriteSheetData);
sprite.gotoAndStop(i);
stage.addChild(sprite);
// Other stuff
}
You can also crop out a piece of an image using a Bitmap and the sourceRect property, which takes a Rectangle to define the crop area. This ends up being roughly the same as the above approach, but might be more work to determine each Rectangle dimensions.
Cheers.

Starling TouchEvent on Sprite

I have some images/sprites/buttons (i tried them all :)) scrolling/moving on the stage. The user has to tap them to remove them.
The problem is that the touchevent does not match the position of the image.
The faster the touchable sprites move, the further the distance between the touch and the actual image. i.e.:
a image is moving across the screen with 20px/frame:
Touching the image triggers nothing, touching 20 before it triggers a touch on the image.
when image is not moving, this doesn't happen. It seems that the image is already moved internally, but not yet drawn to the screen, but thats just a wild guess. The example below uses a button, but the same goes for an image. I"ll provide a short example of the code, but i guess its pretty straightforward what i'm trying to do.
private var _image:Button;
protected function init():void {
//create pickup image
_image = new Button(assets.getTexture("button"));
_image.scaleWhenDown = 1;
_image.addEventListener(Event.TRIGGERED, onClick_image);
addChild(_image);
//listen to touch event (not used, but example for touch on image instead of button
//touchable = true;
//addEventListener(TouchEvent.TOUCH, onTouch_image);
}
private function onEnter_frame(e:Event):void {
_image.x -= 20;
}

Pinch To Zoom functionality in windows phone 8

From this post i came to know that there exist some platform improvements for
implementing pinch and zoom functionality. By using this new method(ManipulationDeltaEventArgs.PinchManipulation) how i can implement pinch to zoom functionality in windows phone.
Apart from this i need to implement scrolling feature too to the image control. In my current implementation, i am using Toolkit(gesture listener) for pinch and zoom functionality along with scroll viewer, now it seem both scrolling and and pinching events are overlapping and hence it produces a bad user experience.
Can anyone help me to solve this issue in my application. I am looking some code samples that help me to achieve the functionality.
I am not expected to get Multi touch behavior(codeplex) as answer. The assemblies using in the project are quite old and i heard that many of them are facing issues with marketplace submission only because of this.
As I said in my previous answer if you're building a WP8 exclusive app you can use the new ManipulationDeltaEventArgs.PinchManipulation for pinch & zoom effects. Here's a basic example of how to use ManipulationDeltaEventArgs.PinchManipulation data to scale, move and rotate an image.
First, we'll create a basic image hovering in the middle of a grid:
<Grid x:Name="ContentPanel">
<Image Source="Assets\Headset.png"
Width="200" Height="150"
ManipulationDelta="Image_ManipulationDelta"
x:Name="img"
>
<Image.RenderTransform>
<CompositeTransform CenterX="100" CenterY="75" />
</Image.RenderTransform>
</Image>
</Grid>
Next, we'll handle the ManipulationDelta event, check if it's a Pinch Manipulation and apply the correct Silverlight transformations on our UIElement.
private void Image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
if (e.PinchManipulation != null)
{
var transform = (CompositeTransform)img.RenderTransform;
// Scale Manipulation
transform.ScaleX = e.PinchManipulation.CumulativeScale;
transform.ScaleY = e.PinchManipulation.CumulativeScale;
// Translate manipulation
var originalCenter = e.PinchManipulation.Original.Center;
var newCenter = e.PinchManipulation.Current.Center;
transform.TranslateX = newCenter.X - originalCenter.X;
transform.TranslateY = newCenter.Y - originalCenter.Y;
// Rotation manipulation
transform.Rotation = angleBetween2Lines(
e.PinchManipulation.Current,
e.PinchManipulation.Original);
// end
e.Handled = true;
}
}
// copied from http://www.developer.nokia.com/Community/Wiki/Real-time_rotation_of_the_Windows_Phone_8_Map_Control
public static double angleBetween2Lines(PinchContactPoints line1, PinchContactPoints line2)
{
if (line1 != null && line2 != null)
{
double angle1 = Math.Atan2(line1.PrimaryContact.Y - line1.SecondaryContact.Y,
line1.PrimaryContact.X - line1.SecondaryContact.X);
double angle2 = Math.Atan2(line2.PrimaryContact.Y - line2.SecondaryContact.Y,
line2.PrimaryContact.X - line2.SecondaryContact.X);
return (angle1 - angle2) * 180 / Math.PI;
}
else { return 0.0; }
}
Here's what we did:
Scaling: PinchManipulation actually tracks scaling for us, so all we had to do is apply PinchManipulation.CumulativeScale to the scaling factor.
Transform: PinchManipulation tracks the original center and the new center (calculated between the two touch points). By subtracting the new center from the old center we can tell how much the UIElement needs to move and apply that to a translate transform. Note that a better solution here would also account for multiple Manipulation sessions by tracking cumulative original centers which this code doesn't.
Rotation: We figured out the angle between the two touch points and applied it as the rotation transform. More on that in this Nokia wiki article # Real-time rotation of the Windows Phone 8 Map Control
Here's a few print screens showing this code runs just fine:
I found the perfect soultion for smooth pinch to zoom and pan. It is actually a Microsoft Code sample at the following link
http://code.msdn.microsoft.com/wpapps/Image-Recipes-0c0b8fee
I just used it as boiler plate code and it worked wonders.
Cheers
If you're looking to roll your own, you might want to check out this article about pinch zooming in Silverlight: Implementing pinch zoom correctly in Silverlight
Telerik also has an out of the box pan and zoom image control, but it does cost money: Telerik Pan and Zoom Control

Resources