Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [DRAW2D] Scale child polygon to parent size
[DRAW2D] Scale child polygon to parent size [message #1768949] Tue, 25 July 2017 07:49 Go to next message
Thijs Franck is currently offline Thijs FranckFriend
Messages: 2
Registered: May 2017
Junior Member
Hi Everyone,

I'm working on a plugin for Archi, adding color views to models. You can read about the plugin on the Archi forum here.

To apply coloring, I want to add child shapes to every view object. The child should be transparent so the object below it can still be visible. The goal is to match the size of the parent shape exactly, so the overlay will fit perfectly on top of it. However, this is where I am running into some trouble. Below are two example screenshots of what is going wrong at the moment:

index.php/fa/30106/0/
index.php/fa/30107/0/

The first example shows how the overlay is supposed to work. The leftmost view object (rounded rectangle) is completely covered by the overlay object. I added a regular view object next to it for comparison. However, the arrow (a polygon shape) is not covered. A shape is drawn, but it is not the right size. Furthermore, as can be seen in example 2, the size of the arrow drawn is not always the same. In fact, it is different almost every time I try it.

Below is the code I use to add the overlay object (called 'container') to the parent (called 'owner'):
public void apply(IFigureDelegate delegate) {		
	
        ...
		
	if(colorViewColor != null && container == null){
			
		container = createColorViewFigure(delegate);
			
		Rectangle clientArea = owner.getClientArea();			
		container.setBounds(clientArea.getCopy());
			
		container.setOpaque(false);
		container.setAlpha(150);									
		container.setBackgroundColor(calculateColor(owner.getBackgroundColor(), colorViewColor, container.getAlpha()));
						
		owner.add(container);	
	}
}


And this is the code I use to define my overlay shapes. Note that the 'delegate' parameter defines the shape of the parent. I use that same object to define the type and shape of my overlay object:

private Shape createColorViewFigure(IFigureDelegate delegate){
	Shape result = null;		
	if(AbstractPolygonalFigureDelegate.class.isAssignableFrom(delegate.getClass())){
		ColorViewPolygon polygon = new ColorViewPolygon();
		PointList points = ((AbstractPolygonalFigureDelegate) delegate).getPoints();			
		polygon.setPoints(points);
		result = polygon;
	}
	else
if(RoundedRectangleFigureDelegate.class.isAssignableFrom(delegate.getClass())){
		ColorViewRoundedRectangle roundedRectangle = new ColorViewRoundedRectangle();
		roundedRectangle.setCornerDimensions(((RoundedRectangleFigureDelegate) delegate).getArc());
		result = roundedRectangle;
	}
	else if(EllipseFigureDelegate.class.isAssignableFrom(delegate.getClass())){
		result = new ColorViewEllipse();
	}
	else{
		result = new ColorViewRectangle();
	}
	return result;
}


Finally, these are the definitions of my polygon and rounded rectangle objects:

private class ColorViewRoundedRectangle extends RoundedRectangle implements ColorViewShape{}
	
private class ColorViewPolygon extends ScalablePolygonShape implements ColorViewShape{}


I am at a loss why the polygon variants of my overlay objects are not scaling correctly. Do you have any suggestions? Any help is very much appreciated!

Best regards,
Thijs
  • Attachment: example1.PNG
    (Size: 8.94KB, Downloaded 219 times)
  • Attachment: example2.PNG
    (Size: 6.09KB, Downloaded 222 times)

[Updated on: Wed, 26 July 2017 07:25]

Report message to a moderator

Re: [DRAW2D] Scale child polygon to parent size [message #1769394 is a reply to message #1768949] Mon, 31 July 2017 10:04 Go to previous message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 235
Registered: July 2009
Location: L√ľnen
Senior Member
You should check where the bounds of the ScalablePolygonShape are set. The ScalablePolygonShape will use the bounds and the points (from which template bounds are inferred) to determine what gets painted. The location is taken from the bounds. The scaling is inferred from scaling the template bounds against the bounds.
Previous Topic:Edit node and create new connections GEF/ZEST 5
Next Topic:Documentation about gef4/gef5
Goto Forum:
  


Current Time: Sat Nov 17 00:00:27 GMT 2018

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

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

Back to the top