#JavaFX Pannable Scope/Magnifying Glass

131 messages · Page 1 of 1 (latest)

iron fieldBOT
#

@sacred jackal

Yakuza Friend Uploaded Some Code

Okay so I have this game thingy I'm messing around with for a comp sci final, and I can't for the life of me figure out how to implement a scope for it, everything I have tried leaves the game/application buggy in fullscreen. I'll send a video of what it should look like.

The basic requirements are as follows:
Must be able to move by just moving the mouse, no click to drag.
Not affect the scope image.
Be able to be used in full screen and not exceeded the set borders (1920 X1080).

Uploaded these files to a Gist
sacred jackal
#

Complied Screenshot

sharp dock
#

looks like you got a scope, you trying to figure out the zoom?

sacred jackal
#

Yeah, the zoom and panning/movement

sharp dock
#

you wanna mouse listener for the movement, and have the scope move with the panel based on the mouse position

#

what do you use for your scope? Is it on a panel?

sacred jackal
#

Its just a image thats added to the scene atm, I should move it to a panel though eh?

sharp dock
#

oh you use javafx

sacred jackal
#

Mhm

sharp dock
#

i just notice that.. uhmm.. i don't know the javafx lib

#

but I do know if you move it to a panel

#

you can add a mouse listener and have it move with it

#

but with javafx i don't know that part.. but I can try my best to figure out and help you

#

just tight right now cause I got other things i just wanted to give you small amount of help

sacred jackal
#

Okay one of the big things ive run into

#

upon using a listener, it will move the ENTIRE frame, leading to this ugly white space on all sides

#

somethin' like this

sharp dock
#

okay, so you will want the panel to be bigger than the window, just add half if 1920x1080 and that should help that..

#

that black needs to get bigger

sacred jackal
#

thats a manageable fix

#

altough

#

the scope image also gets zoomed in/zoomed out on

sharp dock
#

so when the action between zoomedin and out, you will want something that adjusts the size of everything back and forth

sacred jackal
sharp dock
#

damn, yeah its a lot of work lol

sacred jackal
sharp dock
#

okay so yeah then a mouse listener would be great, I would just toss the scope onto a label or something and have amouse listener that listens to the position of the mouse and moves the container object around creating the moving effect

#

Do you need example code of what it would look like???

sacred jackal
#

one sec just gonna clip somethin for you

sharp dock
#

ok

sacred jackal
#

scope image is locked, and moves with the video

you have to click and drag, you can't mouse the mouse freely, it SHOULD be locked to the midde of the dot, like a FPS game

#

heres all the code that goes with that

iron fieldBOT
#

@sacred jackal

Yakuza Friend Uploaded Some Code
Uploaded these files to a Gist
sharp dock
#

Okay, so you will need a mouse button listener that listens for the mouse clicks, and have a boolean flag that holds if the button is being held or not, and if it is, the window will move, but it wont when it's not bneing held

sacred jackal
#

I should disclamier, this was written by chatgpt as I am insaley new to visual based coding

sharp dock
#

oh so you hardly know what you're doing?

sacred jackal
#

visual coding yes, ui is really new to me, I understand the math and functions but I am 100% new to JavaFX

sharp dock
#

Yeah I hardly worked with javaFX as well, its next to none lol

sacred jackal
#

lol a duel learning experience

sharp dock
#

yup except i don't have the libs for it lmao

sacred jackal
#

drats!

#

anyway anyway

#

so mouse listener

sharp dock
#

where did you get the libs? i will download them and import your code and help you figure it out

sacred jackal
#

scene.setOnMouseDragged(event -> {
double deltaX = event.getSceneX() - mouseX;
double deltaY = event.getSceneY() - mouseY;

        // Update the translation values based on mouse movements
        translateX += deltaX;
        translateY += deltaY;

        // Apply the translation to the root group
        root.setTranslateX(translateX);
        root.setTranslateY(translateY);

        // Update the mouse position
        mouseX = event.getSceneX();
        mouseY = event.getSceneY();
    });

Problem no.1, tips?

sacred jackal
#

you use eclipse?

sharp dock
#

yus

sacred jackal
#

okay one sec

sharp dock
#

okay

sacred jackal
#

--module-path "PUT YOUR PATH HERE" --add-modules javafx.controls,javafx.fxml,javafx.media

#

thats for the vm agruements

sharp dock
#

Alright, I need to finish up this one thing I got right now and then I will be able to get rolling fully with you..

#

okay

sacred jackal
#

Im using javaFX 17.0.7 as my SDK

sharp dock
#

Do you run java 8 or 17 or sooner as your vm?

sacred jackal
#

im using javaSE-11 atm

sharp dock
#

Okay well i use java 20 lol. I will get a java 11 something rolling up in eclipse lol

#

i just didn't want there to be any capatibility issues lol

sacred jackal
#

School pc's use such backwards setups its not you fault LOL

#

and for the sake of capatibility

#

I have to use their settings and configs (ugh.)

sharp dock
#

LOL my school ran on 8 for the longest time, and I had to tell IT how to update it to at least java 17

#

like I emailed and walked the IT guy through everything

sacred jackal
#

bro

#

I tried installing the plugin so I could code

#

it broke eclipse on that pc

sharp dock
#

damn

sacred jackal
#

its fine on my personal PC, but ooooh no how dare a school pc be useable.

sharp dock
#

man I tell my school to screw off and Im doing code on my pc whether they like it or not. Still get 100% every time lmao

sacred jackal
#

framework laptop here I come tho kek

sharp dock
#

My pc is good, its lenovo t480 but I want a framework so bad

sacred jackal
#

there so, ugh mane god bless frame work

#

such a simple idea yet so amazing

sharp dock
#

yes

#

so good

#

but also spendy

#

most laptops are spendy but its worth it

sacred jackal
#

to be fair, its cheap over time

sharp dock
#

right

sacred jackal
#

intial investment is rough tho

sharp dock
#

it reduces ewaste too

sacred jackal
sharp dock
#

lmao you aint the only one. I hate wasting computer parts

#

It's how I got my laptop

#

The company that use to own it had gotten bought out so my mom kept it and I sat there and reset it and reinstalled windows and got everything working again on it. I also then removed any tracing software and everything... So now its ours and the IT didn't care cause they were just gonna throw it out

sacred jackal
#

so i tired making the drag a listener..

sharp dock
#

didn't work out?

#

bruh discord just said nah and crashed lmao

sacred jackal
sharp dock
#

you're adusting the window it'self.. i think

#

what did you write down for it?

#

ss it

sacred jackal
#

wait I noticed its using root

#

root is the main scene so yeah you are right

sharp dock
#

okay lol

#

well fix it, and see what it does lol

#

Alright, i just got finsihed with what I was doin

sacred jackal
#

these lines of code control the scope, removing them allows me to move around the video as wanted, so if I could get these to ALWAYS be on top without being part of the root group then half the problem should be fixed

sharp dock
#

is there no .setAlwaysOnTop()?

#

like in a jframe

#

uhh don't know how itll be able to

sacred jackal
#

I am uhh not sure

sharp dock
#

i dont know

#

what is the root for? the frame? Or the event

sacred jackal
#

Im pretty sure the entire scene based off these lines

sharp dock
#

okay the root is the scene

#

didn't know if it was the root of the jframe lol

sacred jackal
#

Alright well cya you back at some other time I gotta dip

sharp dock
#

alright cya

#

good luck

sacred jackal
#

Hey @sharp dock ! How are ya?

sharp dock
#

I'm good, just got done pressure washing my car

#

What about you?

sacred jackal
#

good good!

sacred jackal
#

So @sharp dock , ive decided to just make it drag for the time being, however I still need that scope to be on the top though, no luck so far

sacred jackal
#

the image dosent stay with the mouse when zoomed in

#

tips?

iron fieldBOT
#

@sacred jackal

Yakuza Friend Uploaded Some Code
Uploaded these files to a Gist
sacred jackal
#

code used for mouse movement

#

these lines spefically though

scene.setOnMouseMoved(event -> {
mouseX = event.getSceneX();
mouseY = event.getSceneY();

            // Calculate the scaled mouse position based on the scale factor and translation
            double scaledMouseX = (mouseX - translateX - (WINDOW_WIDTH / 2)) / scale + (WINDOW_WIDTH / 2);
            double scaledMouseY = (mouseY - translateY - (WINDOW_HEIGHT / 2)) / scale + (WINDOW_HEIGHT / 2);

            // Update the image position to center it on the cursor, taking into account the scale factor and translation
            double imageScaledX = (scaledMouseX - (imageView.getFitWidth() / 2));
            double imageScaledY = (scaledMouseY - (imageView.getFitHeight() / 2));
            imageView.setTranslateX(imageScaledX);
            imageView.setTranslateY(imageScaledY);
    });
sharp dock
#

so you want to get the screen size, and have a border where the mouse can't move into

#

and for the zoom thing, youll want to use some math that determins the size of the scope from the zoom

sacred jackal
#

Hey @sharp dock! Quick question thats pretty simple, can you change the Eclipse Workspace name?

I need it to be EclipseWorkspace not Eclipse Workspace as the space causes errors when importing video