Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b3e48e8286c6ed77f4f4ceff4c02bc9a0e404fb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 2006 Borland Software Corporation
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Michael Golubev (Borland) - initial API and implementation
 */

«IMPORT "http://www.eclipse.org/gmf/2005/GraphicalDefinition"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»


«DEFINE behaviour FOR gmfgraph::ScalablePolygon-»
	/**
	 * @generated
	 */
	private final org.eclipse.draw2d.geometry.PointList myTemplate = new org.eclipse.draw2d.geometry.PointList();
	/**
	 * @generated
	 */
	private org.eclipse.draw2d.geometry.Rectangle myTemplateBounds;
	
	/**
	 * @generated
	 */
	public void addPoint(org.eclipse.draw2d.geometry.Point point){
		myTemplate.addPoint(point);
		myTemplateBounds = null;
	}
	
	/**
	 * @generated
	 */
	protected void fillShape(org.eclipse.draw2d.Graphics graphics) {
		org.eclipse.draw2d.geometry.Rectangle bounds = getBounds();
		graphics.pushState();
		graphics.translate(bounds.x, bounds.y);
		graphics.fillPolygon(scalePointList());
		graphics.popState();
	}
	
	/**
	 * @generated
	 */
	protected void outlineShape(org.eclipse.draw2d.Graphics graphics) {
		org.eclipse.draw2d.geometry.Rectangle bounds = getBounds();
		graphics.pushState();
		graphics.translate(bounds.x, bounds.y);
		graphics.drawPolygon(scalePointList());
		graphics.popState();
	}
	
	/**
	 * @generated
	 */
	private org.eclipse.draw2d.geometry.Rectangle getTemplateBounds(){
		if (myTemplateBounds == null){
			myTemplateBounds = myTemplate.getBounds().getCopy().union(0, 0);
			//just safety -- we are going to use this as divider 
			if (myTemplateBounds.width < 1){
				myTemplateBounds.width = 1;
			}
			if (myTemplateBounds.height < 1){
				myTemplateBounds.height = 1;
			}
		}
		return myTemplateBounds;
	}
	
	/**
	 * @generated
	 */
	private int[] scalePointList() {
		org.eclipse.draw2d.geometry.Rectangle pointsBounds = getTemplateBounds();
		org.eclipse.draw2d.geometry.Rectangle actualBounds = getBounds();

		float xScale = ((float) actualBounds.width) / pointsBounds.width;
		float yScale = ((float) actualBounds.height) / pointsBounds.height;

		if (xScale == 1 && yScale == 1) {
			return myTemplate.toIntArray();
		}
		int[] scaled = (int[]) myTemplate.toIntArray().clone();
		for (int i = 0; i < scaled.length; i += 2) {
			scaled[i] = (int) Math.floor(scaled[i] * xScale);
			scaled[i + 1] = (int) Math.floor(scaled[i + 1] * yScale);
		}
		return scaled;
	}
«ENDDEFINE»

Back to the top