Custom ImageView disappears during ScaleAnimation/AnimationSet - java

I'm having a problem with an AnimationSet with two ScaleAnimations. Basically I have a custom view that extends an ImageView and am trying to add a "expand"/"shrink" animation to it. The user will press a button and animate the image to fill more or less space basically. I'm trying to do this by scaling the image view.
The animation works but when the animation itself is running it basically makes the Image disappear and when it is finished it reappears, scaled. Once the animation set finishes the image appears again scaled properly.
I'm really out of ideas and was wondering if I need to do something before I start the animation? Any ideas would be greatly appreciated. Code snippet I below:
public void animateImageView(View customImageView) {
...
Animation stretchLeft = new ScaleAnimation(left, newLeft, top, newTop);
Animation stretchRight = new ScaleAnimation(right, newRight, top, newTop);
AnimationSet set = new AnimationSet(true);
set.addAnimation(stretchLeft);
set.addAnimation(stretchRight);
set.setDuration(250);
set.setInterpolator(new AccelerateInterpolator(1.0f));
customImageView.startAnimation(set);
...
}

Related

How To setOnClickListener to a background image at certain cordinates in Javafx

Hey I'm currently creating a back option to my program. I would like it so that when they user clicks the top left of the background image it will bring you back to the last page. I'm not really sure how I would go about doing so. I know that you can create setOnMouseClicked to buttons but can you do it for a background image and can you specify the cordinates aswell?
here is my code
public class Home extends StackPane{
public Home(){
javafx.scene.image.Image sizeBG = new
javafx.scene.image.Image("file:src/Images/Background.jpg");
BackgroundSize bSize = new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, false, false, true, false);
this.setBackground(new Background(new BackgroundImage(sizeBG, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, bSize)));
bSize.setOnMouseClicked(e ->{
MainScene.mainStage.setScene(new IntroScene());
});
}
}
Here is a reference of my background image. the top left arrow is what I would like to click

Is it possible to draw a transparent layer without using Image?-LibGdx

In my game, when I click a button, popup will come out.
At the same time,I want to draw a transparent layer over the screen except popup, to make an impression like while popup is active,background is disabled.
Something like this:
Is it possible to make an existing solid image to create a transparent overlay ?
or
I should use a transparent image itself to make the impression of transparent layer ?
Image is an Actor that can be drawn but you need transparency for your actor, use Actor.
Create an Actor as transparent layer and add in proper order so that you can disable touch for background actor only.
You should maintain order of Actors.
stage=new Stage();
Texture texture=new Texture("badlogic.jpg");
Image image=new Image(texture);
image.addListener(new ClickListener(){
#Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("TouchTest","Clicked on Image");
}
});
stage.addActor(image);
Actor actor=new Actor(); // this is your transparent layer
actor.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
stage.addActor(actor);
// Popup should on the top or your actor(touch layer)
Image image1=new Image(texture);
image.setPosition(100,100);
stage.addActor(image1);
Gdx.input.setInputProcessor(stage);
You can also manage touchability of your touch layer.
actor.setTouchable(Touchable.disabled); // when you want to disable touch on
In my suggestion you should use Dialog for your popup. Dialog is a modal window containing a content table.
EDIT
From your reference image it's seems that you need semi-transparent layer so use semiTL instead of Actor in above code.
Pixmap pixmap = new Pixmap(1,1, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.BLACK);
pixmap.fillRectangle(0, 0, 1, 1);
Texture texture1=new Texture(pixmap);
pixmap.dispose();
Image semiTL=new Image(texture1);
semiTL.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
semiTL.getColor().a=.8f;
stage.addActor(semiTL);
As Abhishek Aryan said, you can use Pixmap to create the sized foundation for your background. But instead of using an image, you can use sprite and sprite drawable like this
private Drawable getStageBackground() {
Pixmap stageBg = new Pixmap(
Gdx.graphics.getWidth(),
Gdx.graphics.getHeight(),
Pixmap.Format.RGB888);
Sprite image = new Sprite(new Texture(stageBg));
image.setColor(1, 1, 1, 0.7f);
return new SpriteDrawable(image);
}
And pass this drawable in your dialog window style with stageBackground property like this
Window.WindowStyle style = new Window.WindowStyle();
style.stageBackground = getStageBackground();

JavaFX ScrollPane - speed up swiping effect on touch device

I found that if I swipe within a ScrollPane in a JavaFX application on a touch device, the scroll-animation is quite slow. I do not swipe over the ScrollBar of the ScrollPane but within the content itself.
How can I speed up the swipe animation?
This is a known problem with touch devices and the ScrollPane ;)
If you want to speedup the animation you have to set the position by your own.
I solved the same problem I while ago on this way, worked well.
You need to do something like this:
ScrollPane scrollPane = new ScrollPane();
final IntegerProperty vValueProperty = new SimpleIntegerProperty(0);
final int steps = 5;
scrollPane.vvalueProperty().bind(vValueProperty);
scrollPane.setOnSwipeDown(new EventHandler<GestureEvent>() {
public void handle(GestureEvent event) {
// calculate the needed value here
vValueProperty.set(vValueProperty.get() + steps);
}
});
If the normal swipe animation disturbes you, just kill the event with
event.consume();
But it could be that you need to use an EventFilter in this case cause the EventFilter is called before the Event is doing anything. Can't remember if a consume() at the end of the EventHandler is enough. If not you need to use something like this:
scrollPane.addEventFilter(SwipeEvent.SWIPE_DOWN,
new EventHandler<SwipeEvent>() {
public void handle(SwipeEvent event) {
vValueProperty.set(vValueProperty.get() - steps);
event.consume();
}
});
Well this is just to speedup the animation. If you want your Pane following your finger, just save the first value, which you get OnTouchDetected and calculate the Offset OnTouchMoved. This is your value you can use to translate the Pane correctly. :)
Hope it is useful. I don't have a touch device here to test it.

How to scroll in horizontal scroll view

I have made a scroll view in my app it works fine. I have some buttons on click of button i want to scroll to desired position. How can i achieve this And one last thing how can i end the spaces between i images in grid view so all the photos sick together.
Thanks In Advance.
Try this:
yourScrollView.post(
new Runnable() {
#Override
public void run() {
yourScrollView.scrollTo(desiredPositionX, desiredPositionY);
}
}
);

SWT drag and drop custom Control displayed next to cursor

How do i display some custom Controls or widgets next to cursor when dragging in SWT?
Like Button or Tree or Table not Image.
If it is not possible - how do i render such a Button into Image?
I've found the way of rendering arbitrary Control (widget) into Image using GC (canvas) class. Here is how:
dragSource.addDragListener(new DragSourceListener() {
#Override
public void dragStart(DragSourceEvent dragSourceEvent) {
// getting control widget - Composite in this case
Composite composite = (Composite) ((DragSource) dragSourceEvent.getSource()).getControl();
// Getting dimensions of this widget
Point compositeSize = composite.getSize();
// creating new GC
GC gc = new GC(composite);
// Creating new Image
Image image = new Image(Display.getCurrent(),compositeSize.x,compositeSize.y);
// Rendering widget to image
gc.copyArea(image,0,0);
// Setting widget to DnD image
dragSourceEvent.image = image;
}
... other overriden methods ...
}
You could use an undecorated Shell that follows the mouse position, and in that Shell have the widget(s) you want to display.

Categories