How can I create a layered lens effect?

I want to create a layered lens effect. I am trying to create an effect like this.

I can create a rectangle with a hole in it using mask form = Shape.subtract (backgroundRect, lensRect). The problem is that I want to want to be able to move the lensRect with the mouse. I don't know how to do this. I can use a clip to reveal the background under the lens. The problem with that approach is that is will not let me create a semi-transparent background. Do you know how to update the mask each time, the lenseRect is moved? I tried to use a changelistener on the lenseRect translateX property, but we cannot update the form inside the event. To use the reference of mask in the case where there be declared final.

import javafx.application.Application;
import javafx.beans.value.*;
import javafx.event.EventHandler;
import javafx.geometry.Bounds;
import javafx.scene.*;
import javafx.scene.image.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;

public class WhereIsHe extends Application {
    private static final double VIEWFINDER_WIDTH  = 30;
    private static final double VIEWFINDER_HEIGHT = 80;

    public static final Color LENS_TINT = Color.YELLOW.deriveColor(0, 1, 1, 0.15);
    public static final Color MASK_TINT = Color.GRAY.deriveColor(  0, 1, 1, 0.97);

    @Override public void start(Stage stage) {
        Image image = new Image("http://collider.com/wp-content/uploads/wheres-waldo2.jpg");

        ImageView background = new ImageView(image);
        StackPane layout = applyViewfinder(
                background, image.getWidth(), image.getHeight()
        );

        stage.setScene(new Scene(layout));
        stage.show();
    }

    private StackPane applyViewfinder(Node background, double width, double height) {
        Rectangle mask = new Rectangle(
                width,
                height
        );

        Rectangle viewfinder = new Rectangle(
                VIEWFINDER_WIDTH,
                VIEWFINDER_HEIGHT,
                LENS_TINT
        );
        makeDraggable(viewfinder);

        Pane viewpane = new Pane();
        viewpane.getChildren().addAll(
                new Group(),
                viewfinder
        );

        viewfinder.boundsInParentProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observableValue, Bounds bounds, Bounds bounds2) {
                applyStencil(
                        cutStencil(mask, viewfinder),
                        viewpane
                );
            }
        });

        viewfinder.relocate(
                width  / 2 - VIEWFINDER_WIDTH  / 2,
                height / 2 - VIEWFINDER_HEIGHT / 2
        );

        StackPane layout = new StackPane();
        layout.getChildren().setAll(
                background,
                viewpane
        );
        return layout;
    }

    private void applyStencil(Node stencil, Pane viewpane) {
        viewpane.getChildren().set(0, stencil);
    }

    private Node cutStencil(Rectangle mask, Rectangle viewfinder) {
        Shape stencil = Shape.subtract(mask, viewfinder);
        stencil.setFill(MASK_TINT);

        return stencil;
    }

    public static void makeDraggable(final Node node) {
        final Delta dragDelta = new Delta();
        node.setOnMousePressed(new EventHandler() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                // record a delta distance for the drag and drop operation.
                dragDelta.x = mouseEvent.getX();
                dragDelta.y = mouseEvent.getY();
            }
        });
        node.setOnMouseReleased(new EventHandler() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                node.setCursor(Cursor.MOVE);
            }
        });
        node.setOnMouseDragged(new EventHandler() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                node.relocate(
                        mouseEvent.getSceneX() - dragDelta.x,
                        mouseEvent.getSceneY() - dragDelta.y
                );
                node.setCursor(Cursor.NONE);
            }
        });
        node.setOnMouseEntered(new EventHandler() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if (!mouseEvent.isPrimaryButtonDown()) {
                    node.setCursor(Cursor.MOVE);
                }
            }
        });
        node.setOnMouseExited(new EventHandler() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if (!mouseEvent.isPrimaryButtonDown()) {
                    node.setCursor(Cursor.DEFAULT);
                }
            }
        });
    }

    private static class Delta {
        double x, y;
    }

    public static void main(String[] args) { launch(args); }
}

Tags: Java

Similar Questions

  • How can I create a NoInput rule effectively

    Hello

    My rule script skills are a bit rusty. I have a few accounts that I want to put has no entry, but I don't want to have 1 line per account:

    Noinput ' a L1234 #

    If I put in the account NoInput property in the area of the Usedefined2, could I write a basis of rules no. Input on the scope of Userdefined2?

    Noinput subroutine:

    NoInput "If HS. ACCOUNT. Node2 = NoInput

    End if

    Or should I use the list of accounts?

    You can create a personalized account list that contains all accounts with node2 = "NoInput" like this:

    Void EnumMemberLists()

    "# is a space reserved for when you go to copy the text in your list file, replace you it with the new number of total lists for this dimension
    Dim aAccountLists (1)

    Select HS case. Dimension
    Case 'account '.
    "# is a placeholder for the number correct to list specific when copy you the syntax into your list file aAccountLists (#).
    aAccountLists (1) = "AccountsUD2NoInput".
    GSA SetMemberLists aAccountLists
    Select end

    End Sub

    Void EnumMembersInList()

    Select HS case. Dimension
    Case 'account '.
    Select HS case. MemberListID
    "# is a placeholder for the exact number of the list when you copy this syntax in your file list.
    Case 1
    aLi HS =. Account.List ("", "[Basic]")
    For i = LBound (aLi) to UBound (aLi)
    If HS. Account.UD2 (aLi (i)) = "NoInput" Then
    GSA AddMemberToList aLi (i)
    End If
    Next
    Select end
    Select end
    End Sub

    The above code must appear in a file with the extension .lst and responsible members in HFM using the lists of members of load.

    Then your NoInput routine in your normal rules file would look like this:

    Void NoInput()

    aLi HS =. Account.List ("", "AccountsUD2NoInput")
    For i = LBound (aLi) to UBound (aLi)
    GSA NoInput "A #" & aLi (i)
    Next

    End Sub

    This way you do not check the UD2 during execution of the NoInput rule.

  • How can I create this effect to text and shine?

    I wanted to know how to create this effect of text (there is a gradient on the text and the race seems to be beveled) in Photoshop.

    Image

    Also, how can I create this effect of gloss on this image?

    Image

    Thanks in advance.

    :)

    The text I believe is a simple style using bevel and Emboss. A sample of what I think they did is attached. I used black Ariel for the police.

    The background is a 50% gray

  • How can I create a scroll effect when the manuscripts of user to the bottom of the image will be blurred?

    How can I create a scroll effect when the manuscripts of user to the bottom of the image will be blurred?

    Hello

    You can create a scrolling movement where the image fade out the scroll, you must use the tab opacity under the effects of scroll Panel.

    If you need especially be blur on the image, then you must change this image in any editing program like blurry image to make a copy of this image, then place the two images (real and blurry) on this page and use the scrolling motion or fade option to replace the images.

  • How can I create a fade in/fade out master for a sequence?

    How can I create a fade in/fade out master for a sequence?

    I'm totally new for the first...

    In Final Cut 7 I can take a whole sequence and create a 'nest' out of it, where it becomes an editable object in the timeline panel. I can only apply a fade to the whole sequence, even if there are several clips with transparency immediately above. I can also apply a video effect 'broadcast safe' to make sure that my video is all legal. How to do something similar in the first?

    Thank you!

    -Kurt Cowling

    Nest sequences

    Broadcast colors effect

  • How can I create something like the huggies commercial

    I was wondering how can I create something in the style of the huggies commercial.

    http://www.YouTube.com/watch?v=MfmaRJ8ej2w

    This concept has a name? Can it be created with Adobe products?

    Please let me know or point me where I can go to learn.

    Thank you

    Sometimes called Bullet Time. The key to its type of production is planning and shooting, not the post. While the post is important, if you don't have the right kind of images you can not accomplish the task.

    Here's the right way to do the trick.

    Do a Google search for Bullet Time effect and you will see other ways to kind of fake it without dozens or even hundreds of cameras.

  • How can I create a group through Outlook without the application Outlook email?

    How can I create a group by using Outlook without an application Outlook email?

    Sigmalambda wrote:

    How can I create a group by using Outlook without an application Outlook email?

    It is difficult to understand what you're trying to do. You can create a group and send an email to the group in any mail client. The recipients can use any e-mail provider or an e-mail client to receive e-mail. Please explain in more detail what you are trying to accomplish.

  • How can I create a new folder in Thunderbird

    How can I create a new folder in Thunderbird

    Right-click on the parent folder, a new folder option appears in the menu

  • How can I create a group in my address book?

    I am looking at the help page, and he has "contacts" in the list, but no link to something useful.

    How can I create a group? I want to send something to a group of people, but I don't want them to see all the other people who are part of the group.

    _ http://KB.mozillazine.org/Thunderbird: _FAQs_:_Create_Mailing_List

  • How can I create a trigger e-mail messages sets a phone when Gets an email from particulry?

    Hi team, support
    Customer email thunderbird whit, how can I create a trigger e-mail messages rule a phone dial when comes a word of the body particularly E-mail?

    Kind regards
    Alessandro.

    I don't think you can do this with ordinary Thunderbird. But this add-on

    https://addons.Mozilla.org/en-us/Thunderbird/addon/FiltaQuilla/

    allows you to run javascript or IIRC, launch an external program when a given filter condition is met. So this does not exactly provide an answer to your question, but allows a possible solution. '

  • How can I create a separate address book? I'm not on a mailing list but an address book where addresses are not mixed with my usual address b

    How can I create a separate address book? I'm not on a mailing list but an address book where addresses are not mixed with my address book regularly. I already have three created for me by Thunderbird address books. Add all new addresses to one of those, I'm not afraid to remove the other address books, because some of their addresses are not repeated in my address book "main". So if I delete all the names in one of the existing books, I need to create a blank book that will not mix the addresses with those of an another address book. HOW CAN I CREATE AN ADDRESS BOOK EMPTY? I want to be able to create multiple mailing LISTS using the addresses in this new book, I will eventually have an address book special with a variety of mailing lists, that I can use as I want to.

    In the address book, file | New | Address book.

    No menu showing "file"? F10 or ALT.

  • NB100 - How can I create a recovery on a USB CD?

    Hi friends,

    I recently got a NB100 with XP home. The operating system has been reinstalled and did not have any CD of the operating system.

    Given that I have not an external CD drive how can I create a recovery on a USB CD. I would like to see the function of USB USB just like the CD in case something really goes wrong.

    Can some help me to find a tutorial to do this?

    Thanks for your help.

    SAJ.

    Great! Thanks for sharing this with us!

  • I have problems of space on my iPhone 6. I have only 21 photos and 2 videos on my phone. However, I am on a discussion group on whatsapp. How can I create more space for my phone? I also have very few applications on my phone.

    I have problems of space on my iPhone 6, I have only 21 photos and 2 videos on my phone. However, I am part of a chart group on whatsapp. The problem now is that my storage space is almost full. How can I create more space for photos and everything?

    You cannot create more space for everything.  All you can do is remove apps, photos and especially videos to make room for other pictures and videos.

  • On a flyer, I need to produce black and PMS color. How can I create a PMS color (instead of something on the color wheel).

    On a flyer, I need to produce black and PMS color. How can I create a PMS color (instead of something on the color wheel or RGB)?

    It depends on the application. You use an inDesign application of PAO as Quark XPress, or something else?

    Many consumer apps is not able to output CMYK or specific pantone color combinations.

  • How can I create a full recovery for OS and preinstalled software media?

    Hello
    My son´s accompanying the new Satelite L855-10U preinstalled OS and much other software already installed on the HARD drive, but no installation media, the client is supposed to create a tool from Toshiba.

    I created 6 Swedish recovery for the operating system using the tools Toshiba had installed on the HARD drive.

    To do this 6 Swedish, I created with the Toshiba Recovery tool contain the operating system and all other preinstalled software?

    How can I create the installation media full and usable if not for the operating system and all other preinstalled software?

    I can´t find all the information on the backup software pre-installed with the exception of the BONE. Is there complete information how to do the above, in the manual of the computer, or have you missed this information?

    I would like to know how I can create media backup complete and usable for the operating system as well as for all other preinstalled software, so I can recreate all the facilities of the plant at a new disk if/when the original HARD disk crashes.

    Is there a partition hidden with pre-installed software, and if so, how can I create a backup of this partition, or all the software, so I can reinstall everything if the HARD drive fails, if it is already not with the Swedes 6 Toshiba tool created for me?

    Forward to your response and to complete your customer documentation about the complete instructions for installation and recovery media creation.

    Thank you very much!

    Baltazar

    Hello

    On this forum, you will find a lot of useful comments on the recovery image saved on the HARD drive and its operation to the facility and the creation of recovery disks.
    All this is clearly and simply.

    Front of Toshiba offer new people for laptop in software development create recovery image. This recovery image will be created for each laptop model (specific hardware configuration). Recovery image contains the operating system, all necessary drivers, tools/utilities Toshiba specific and some other software like DVD/Blu-Ray, Microsoft Office test drive and the antivirus application. With this configuration every laptop owner can begin to use the laptop without having to install important applications.

    This package is then saved on the HARD drive and can be used for the installation of HARD drive recovery - http://aps2.toshiba-tro.de/kb0/HTD1303440001R01.htm. In other words, if something is wrong with HARD drive recovery facility you can reset the preinstalled operating system and reinstall recovery imae. After that make you have absolute same settings you had after purchase and first start of the laptop.
    HARD drive recovery image can not be used if:
    -HARD drive is defective
    -you have installed the version of the own BONE
    Structure of the HARD disk partitions - is changed
    Recovery image - HARD drive is deleted or moved to another partition or copied to the external device.

    To avoid all this Toshiba recommends the creation of recovery disks. Using these disks, you will be able to install the OS on the new drive HARD or in any other situation listed above.
    Please note: the use of recovery disks will remove all HARD drive, create the new recovery partition and install image recovery, so you still have the same settings.

    I hope I can help you with my explanation. If you have any other questions you are welcome.

Maybe you are looking for

  • Exec.vi "Wait until completion" system uses a lot of CPU. Help

    I am writing an application that calls parallel instances of an external program. I have the code of work to run the EXE file with the Exec.vi system. When the completion up to wait entry is set to true on Exec.vi LabVIEW system uses all my CPU. The

  • Graph of the Excel data with overlay of dynamic data acquisition

    Hi all I was next to the forum of Labview for about a year, it's the same with my programming so I'm a little rusty. I don't have someone code this for me, but just a quick plan high level to point me in the right direction.  I am able to work throug

  • Upgrade Windows 2003 on-site

    I'm making inplace upgrade of windows 2003 R2 sp2 to windows 2008 32-bit, get error to 68% of windows upgrade below full. It comes to database MS sql server Windows installation encountered an unexpected error. Check that the installation sources are

  • Media center tv set in place IR

    My works of possibility to use IR but when I try to set up the TV he says he can't florent to use Ir, but I use it to make it all up? Help!

  • Printing software blocked installation and uninstall with

    Original title: printer problems My printer was not print if I fooishly put the boot disk to reinstall the siftware without uninstall the old.  Now my scren is stuck not only installing, but uninstalling as well.  Is there anything I can do to solve