Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » text(-labels) musn't scale - possible?
text(-labels) musn't scale - possible? [message #217144] Thu, 01 June 2006 12:22 Go to next message
Andre Dietisheim is currently offline Andre DietisheimFriend
Messages: 130
Registered: July 2009
Senior Member
I try to have labels that do not scale when zooming in/out. I didn't see
any documentation on it so I dig into the sources and found that the whole
text-scale is done in the graphics class and I can't see any way to tell
it not to scale text. Another approach I tried is to have
Label.setSize()/getSize() set to fixed values. Unfortunately those methods
(inherited from Figure) are final and overridable. Anyone hints how to
achieve this?
Re: text(-labels) musn't scale - possible? [message #217208 is a reply to message #217144] Thu, 01 June 2006 17:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ben.walstrum.gmail.com

The short of this is that it can be done, but I think that the solution
that I have is a bit of a kludge - but it was the best that I could find
and does work.

The problems all come in the paintClientArea() method of
ScalableFreeformLayeredPane. In that method the Graphics are set to be
scaled, and thus all drawing commands from it will in turn be scaled. I
have created a class that extends ScalableFreeformLayeredPane and
overrides paintClientArea().

Next, I extended org.eclipse.draw2d.ScaledGraphics and passed in the
graphics send to paintClientArea(), but keep a copy of it. The graphics
passed in are unscaled. I then expose the graphics through a
getOriginalGraphics() method.

For your figure to paint using these graphics you will need to override
the paint method, cast the graphics and send along the unscaled graphics.

You probably will also need to add your new ScalableFreeformLayeredPane
onto an overridden RootEditPart.

I'm not sure that this would work the way you want for a normal label -
you might need to draw the figures yourself because coordinates become
confusing due to the scaling.

Here's a snapshot of some of the code:

public class ScaledGraphics extends org.eclipse.draw2d.ScaledGraphics {

// these are necessary because the variables are private in
// the superclass

protected Graphics originalGraphics;
protected double scale;

public ScaledGraphics(final Graphics graphics) {
super(graphics);
this.originalGraphics = graphics;
}

public Graphics getOriginalGraphics() {
return originalGraphics;
}

public void scale(final double scale) {
super.scale(scale);
this.scale = scale;
}

public double getScale() {
return scale;
}

// ...

}

public class SemanticScalableFreeformLayeredPane extends
ScalableFreeformLayeredPane {

protected void paintClientArea(final Graphics graphics) {
super.paintClientArea(graphics)
if (!getChildren().isEmpty()) {
ScaledGraphics g = new ScaledGraphics(graphics);

boolean optimizeClip = getBorder() == null ||
getBorder().isOpaque();
if (!optimizeClip) {
g.clipRect(getBounds().getCropped(getInsets()));
}
g.scale(getScale());
g.pushState();
paintChildren(g);
g.dispose();
graphics.restoreState();
}
}

// ...
}

public class MyUnscaledFigure extends Figure

public void paintFigure(final Graphics graphics) {
Graphics original = ((ScaledGraphics)
graphics).getOriginalGraphics();

//-- paint away!! --//
}
}

public class SemanticScalableFreeformRootEditPart extends
ScalableFreeformRootEditPart {

protected ScalableFreeformLayeredPane createScaledLayers() {
pointerLayer = new PointerLayer();

ScalableFreeformLayeredPane layers = new
SemanticScalableFreeformLayeredPane();
layers.add(createGridLayer(), GRID_LAYER);
layers.add(getPrintableLayers(), PRINTABLE_LAYERS);
layers.add(new FeedbackLayer(), SCALED_FEEDBACK_LAYER);
return layers;
}

// ...
}

Again, I am certainly not advocating this as the best or cleanest
solution - but from my searching of the code, it's the best that I could
come up with.

Hope this helps.

Ben

André wrote:
> I try to have labels that do not scale when zooming in/out. I didn't see
> any documentation on it so I dig into the sources and found that the
> whole text-scale is done in the graphics class and I can't see any way
> to tell it not to scale text. Another approach I tried is to have
> Label.setSize()/getSize() set to fixed values. Unfortunately those
> methods (inherited from Figure) are final and overridable. Anyone hints
> how to achieve this?
>
>
Re: text(-labels) musn't scale - possible? [message #217225 is a reply to message #217208] Thu, 01 June 2006 18:55 Go to previous messageGo to next message
Andre Dietisheim is currently offline Andre DietisheimFriend
Messages: 130
Registered: July 2009
Senior Member
Thanks a lot! Looks very promising!
I have to admit that I do see where's the exact problem with the
coordinates without debugging and seeing the exact values. If I remember
right, the font sizes passed to graphics are unscaled and graphics
substitues the font on behalf of the scaling-factor. Shouldn't be of any
problem, shouldn't it?
Re: text(-labels) musn't scale - possible? [message #217231 is a reply to message #217225] Thu, 01 June 2006 19:44 Go to previous message
Eclipse UserFriend
Originally posted by: ben.walstrum.gmail.com

I looked up in my code to figure out what exactly the problem was, and
it is related to the fact that the bounds of the figure will still be
listed in their unscaled coordinates, not their scaled coordinates.

For instance, suppose that you have a figure that has the coordianates
x=10, y=10, w=100, h=100. If you scale at 200% the drawn coordinates
will be x=20, y=20, w=200, h=200, but your figure will still tell you
(when you call getBounds() etc.) that it is x=10, y=10, w=100, h=100
because it has no idea that it is being scaled (that is all handled by
ScaledGraphics). When you use a normal ScaledGraphics this isn't a
problem because everything is scaled.

So basically I just use the scale in my ScaledGraphics class to scale
the bounds rectangle and then use that for any calculations i need
during rendering using the original, unscaled graphics.

Hope this helps.

Ben


André wrote:
> Thanks a lot! Looks very promising!
> I have to admit that I do see where's the exact problem with the
> coordinates without debugging and seeing the exact values. If I remember
> right, the font sizes passed to graphics are unscaled and graphics
> substitues the font on behalf of the scaling-factor. Shouldn't be of any
> problem, shouldn't it?
>
Previous Topic:How to determine size of parent figure based on a child label???
Next Topic:how to add TabbedPropertySheetPage like wtp in my GEF project ?
Goto Forum:
  


Current Time: Wed Nov 26 20:46:10 GMT 2014

Powered by FUDForum. Page generated in 0.01786 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software