Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 2877 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Member


Medals: 1



« Posted 2008-06-02 20: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 Member


Medals: 1



« Reply #1 - Posted 2008-06-03 22: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:   http://today.java.net/pub/a/today/2007/03/27/navigable-image-panel.html
Offline Z-Knight

Senior Member


Medals: 1



« Reply #2 - Posted 2008-06-09 16: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 Member


Medals: 1



« Reply #3 - Posted 2008-06-16 20: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 Member





« Reply #4 - Posted 2008-06-18 17: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 Member


Medals: 1



« Reply #5 - Posted 2008-06-19 20: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (19 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org 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‑gaming.org
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!