Results 1 to 2 of 2
  1. #1
    Koopa's Avatar
    Koopa is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default Zooming and scaling problem

    I'm trying to scale an Area object according to the zoom level of the mouse but the result i get is bad. Here it is.

    Here's the code too... I think I'm applying bad transformations to my AffineTransform, but I don't know why... I translate to the center of the area, scale the object and then translate back to first place.
    Java Code:
    		
    if (isScaling()) {
        double cx = label.getLabelArea().getBounds2D().getCenterX(); //the x center of the text
        double cy = label.getLabelArea().getBounds2D().getCenterY(); //the y center of the text
        double viewportScale = viewport.getScale(); //the zoom level of the view rectangle
        double scale = 1; //maintain aspect
        scale *= viewportScale;
        transform.translate(cx, cy);
        transform.scale(scale, scale);
        transform.translate(-cx, -cy);
        g.setTransform(transform);
    }		
    		
    g.setColor((Color) f.getAttribute("COLOR"));
    //g.fill(outlineStroke.createStrokedShape(label.getLabelArea()));
    g.draw(label.getLabelBounds());
    g.fill(label.getLabelArea());	
    		
    g.setTransform(originalTransform);
    Last edited by Koopa; 07-07-2011 at 05:38 PM.
    :cool:

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

Similar Threads

  1. Problem with zooming background image
    By LianaN in forum AWT / Swing
    Replies: 0
    Last Post: 01-28-2011, 09:50 PM
  2. The problem with scaling images
    By LianaN in forum AWT / Swing
    Replies: 3
    Last Post: 01-18-2011, 08:52 PM
  3. zooming in a 2D rts game in java
    By masternerdguy in forum Advanced Java
    Replies: 9
    Last Post: 01-04-2010, 06:31 PM
  4. Zooming in on fractal
    By Mr.Beans in forum Java 2D
    Replies: 1
    Last Post: 04-18-2009, 05:00 AM
  5. Zooming Canvas Area
    By Raghavansat in forum AWT / Swing
    Replies: 0
    Last Post: 02-04-2009, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •