Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (707)
Games in Android Showcase (208)
games submitted by our members
Games in WIP (781)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Zoom around a Point  (Read 3613 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Devvie

Medals: 2

« Posted 2008-06-02 18:09:45 »

Hi, I'm trying to zoom an image around the current Mouse point (sort of like google craps...err, maps).  So when you have the mouse in the bottom right corner and zoom in (mouse wheel scroll up) it zooms around that point, but then you can move the mouse to the top left corner and continue to zoom in and it will zoom around the new point in the top left corner.  I have this working (in the attached code ... I guess you have to be logged in to see the code and image) but the problem I have is with zooming back out.  Unlike Google maps I don't want to zoom out past the boundary of the map - I want the map to remain in the view.  Right now, if you zoom in the bottom right corner and then move the mouse to the top left corner and start to zoom back out, eventually you will see the corner of the map but in reality I don't want to be able to zoom out past the map extents (...the code eventually snaps back but that's not a solution I want).

sorry for the poor code, but I tried a bunch of things like retrieving the rectangle that represents the current zoomed in portion of the map and using that to determine when to force the zoom to scale of 1.0, etc, etc....there must be a more elegant way to do this.  I don't want to use scroll bars and I don't want to zoom out and see the map edges.
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #1 - Posted 2008-06-03 20:37:44 »

btw, I just found another example of what I'm trying to do...unfortunately this code doesn't limit the zoom out to remain within the bounds of the display/canvas but it does the same zoom in and out that I have (ie around a point).

It is a very cool example and completely functional:
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #2 - Posted 2008-06-09 14:57:04 »

so, no one zooms in on their scenes? 
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #3 - Posted 2008-06-16 18:17:50 »

wow...this message board is quite, is there any better java2d boards where I can go ask questions?  I mean more active boards?
Offline Wildern

Junior Devvie

« Reply #4 - Posted 2008-06-18 15:35:34 »

This is the output from your program when the lower right corner of the map is visible with a white border.

 Screen 2D Point: 163 90
    Screen width: 824 height: 506
    Scale Factor: 0.9
    Scaled Point: 146.70000000000002 height: 81.0
    Scaled width: 741.6 height: 455.40000000000003
at: 2.6861527427269354 2.6861527427269354
CLICK> X: 163.0   Y: 90.0
1: 567 317 308 189
    clickX/getWidth()*rec.width   = 60.92718446601942
    clickY/getHeight()*rec.height = 33.616600790513836

You output the dimensions of your rec, with the width being 308, and the height being 189.
Both of those are less than your screen width and screen height.
I *think* that you need to detect the case where your rec.width is less than screen width and then move your map by the difference to force it to an edge, same would apply for rec.height being less than screen height.
You definitely want to move, and not force the scale to change as this condition could happen at a high zoom.
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #5 - Posted 2008-06-19 18:38:27 »

Thanks for the response, Wildern.  I believe you are right that I need to detect when my width is less and I initially tried doing that and sort of do now and I then snap the map to the bounds of the screen/panel but I'm doing this poorly.  I've completely confused myself on this zooming and I'm having a hard time even explaining my problems so I'm glad you were able to see my problem and could contribute.  I need to review the link I provided in a previous post and I need to map this out on paper once again and then I can find a solution and post here or provide a better explanation for all of you to shoot holes through.

Initially I thought about doing a google maps kind of zoom, but they don't try to force the map within the panel bounds because as you zoom out you eventually zoom outside of the map and they also keep wrapping the image along the X axis which I don't want to do.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Galdo (462 views)
2017-01-12 13:44:09

Archive (616 views)
2017-01-02 05:31:41

0AndrewShepherd0 (1087 views)
2016-12-16 03:58:39

0AndrewShepherd0 (1011 views)
2016-12-15 21:50:57

Lunch (1142 views)
2016-12-06 16:01:40

ral0r2 (1376 views)
2016-11-23 16:08:26

ClaasJG (1471 views)
2016-11-10 17:36:32

CoffeeChemist (1447 views)
2016-11-05 00:46:53

jay4842 (1528 views)
2016-11-01 19:04:52

theagentd (1255 views)
2016-10-24 17:51:53
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!