Need to invert x-value of mouse

L

lannsjo

Hi,
Someone that can figure out a smart way to invert my mousepointer's
x-axis.

I have this function:

doMyFancyStuff(mouseXpos,mouseYpos);

but I want mouseXpos to be inverted... i.e 800 should be 1 and 1 should
be 800 (if my screen resolution is 800..)
 
I

Ingo R. Homann

Hi,

Hi,
Someone that can figure out a smart way to invert my mousepointer's
x-axis.

I have this function:

doMyFancyStuff(mouseXpos,mouseYpos);

but I want mouseXpos to be inverted... i.e 800 should be 1 and 1 should
be 800 (if my screen resolution is 800..)

I'm not sure if I understand your problem correctly, because if I do
understand you correctly, the problem would be trivial and I would
suggest you give up programming when you do not get the solution by
yourself:

doMyFancyStuff(800-mouseXpos+1,mouseYpos);

Or do you want to know how to get the screen-resolution? That should be
something like:

Toolkit.getDefaultToolkit().getScreenResolution();

BTW: Computers start counting with 0, so you have an off-by-1-error.

Ciao,
Ingo
 
T

Thomas Fritsch

Hi,
Someone that can figure out a smart way to invert my mousepointer's
x-axis.

I have this function:

doMyFancyStuff(mouseXpos,mouseYpos);

but I want mouseXpos to be inverted... i.e 800 should be 1 and 1 should
be 800 (if my screen resolution is 800..)
I don't see how a "screen resolution" might come in here. You probably mean
"screen width" (in dots), not "screen resolution" (in dots per inch).
BTW: You can get it with Toolkit.getDefaultToolkit().getScreenSize().width
 
J

jmcgill

Ingo said:
doMyFancyStuff(800-mouseXpos+1,mouseYpos);

Now THAT is a bad idea, putting a magic number in there, where it only
works in one specific case.

This is a job for Graphics2D.transform(). Don't compute the
coordinates, change the origin.
 
I

Ingo R. Homann

Hi,
Now THAT is a bad idea, putting a magic number in there, where it only
works in one specific case.

I know that. That's why I wrote the rest of my posting (that you snipped).
[snipped another good idea ;-]

Ciao,
Ingo
 
O

Oliver Wong

Thomas Fritsch said:
I don't see how a "screen resolution" might come in here. You probably
mean
"screen width" (in dots), not "screen resolution" (in dots per inch).
BTW: You can get it with Toolkit.getDefaultToolkit().getScreenSize().width

I don't know about the etymological correctness of the term, but
nowadays "screen resolution" often refers to the number of pixels a screen
can display. See, for example,
http://en.wikipedia.org/wiki/Screen_resolution

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top