Skip to content

Commit 9e1dc4c

Browse files
committed
figure drawing method
1 parent d5f03af commit 9e1dc4c

File tree

4 files changed

+126
-57
lines changed

4 files changed

+126
-57
lines changed

com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/EllipseFigureDelegate.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.eclipse.draw2d.Graphics;
99
import org.eclipse.draw2d.geometry.Rectangle;
10+
import org.eclipse.swt.graphics.Path;
1011
import org.eclipse.swt.graphics.Pattern;
1112

1213
import com.archimatetool.model.IDiagramModelObject;
@@ -33,33 +34,29 @@ public void drawFigure(Graphics graphics) {
3334
// Reduce width and height by 1 pixel
3435
rect.resize(-1, -1);
3536

36-
boolean drawOutline = getLineStyle() != IDiagramModelObject.LINE_STYLE_NONE;
37-
38-
if(drawOutline) {
39-
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
40-
setLineWidth(graphics, rect);
41-
setLineStyle(graphics);
42-
}
43-
4437
graphics.setAlpha(getAlpha());
4538

4639
if(!isEnabled()) {
4740
setDisabledState(graphics);
4841
}
4942

43+
// Fill
44+
Path path = createPath(rect, false);
5045
graphics.setBackgroundColor(getFillColor());
51-
5246
Pattern gradient = applyGradientPattern(graphics, rect);
53-
54-
graphics.fillOval(rect);
55-
47+
graphics.fillPath(path);
5648
disposeGradientPattern(graphics, gradient);
57-
49+
path.dispose();
50+
5851
// Outline
59-
if(drawOutline) {
52+
if(getLineStyle() != IDiagramModelObject.LINE_STYLE_NONE) {
53+
graphics.setLineWidth(getLineWidth());
54+
setLineStyle(graphics);
6055
graphics.setAlpha(getLineAlpha());
6156
graphics.setForegroundColor(getLineColor());
62-
graphics.drawOval(rect);
57+
path = createPath(rect, true);
58+
graphics.drawPath(path);
59+
path.dispose();
6360
}
6461

6562
// Image Icon
@@ -69,4 +66,20 @@ public void drawFigure(Graphics graphics) {
6966

7067
graphics.popState();
7168
}
69+
70+
protected Path createPath(Rectangle rect, boolean drawingOutline) {
71+
Path path = new Path(null);
72+
73+
float inset = drawingOutline ? getLineWidth() / 2.0f : 0;
74+
75+
float x = rect.x + inset;
76+
float y = rect.y + inset;
77+
float width = rect.width - inset * 2;
78+
float height = rect.height - inset * 2;
79+
80+
path.addArc(x, y, width, height, 0, 360);
81+
82+
return path;
83+
}
84+
7285
}

com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/RectangleFigureDelegate.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.eclipse.draw2d.Graphics;
99
import org.eclipse.draw2d.geometry.Rectangle;
10+
import org.eclipse.swt.graphics.Path;
1011
import org.eclipse.swt.graphics.Pattern;
1112

1213
import com.archimatetool.model.IDiagramModelObject;
@@ -33,34 +34,29 @@ public void drawFigure(Graphics graphics) {
3334
// Reduce width and height by 1 pixel
3435
rect.resize(-1, -1);
3536

36-
boolean drawOutline = getLineStyle() != IDiagramModelObject.LINE_STYLE_NONE;
37-
38-
if(drawOutline) {
39-
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
40-
setLineWidth(graphics, rect);
41-
setLineStyle(graphics);
42-
}
43-
4437
graphics.setAlpha(getAlpha());
4538

4639
if(!isEnabled()) {
4740
setDisabledState(graphics);
4841
}
49-
42+
5043
// Fill
44+
Path path = createPath(rect, false);
5145
graphics.setBackgroundColor(getFillColor());
52-
5346
Pattern gradient = applyGradientPattern(graphics, rect);
54-
55-
graphics.fillRectangle(rect);
56-
47+
graphics.fillPath(path);
5748
disposeGradientPattern(graphics, gradient);
49+
path.dispose();
5850

5951
// Outline
60-
if(drawOutline) {
52+
if(getLineStyle() != IDiagramModelObject.LINE_STYLE_NONE) {
53+
graphics.setLineWidth(getLineWidth());
54+
setLineStyle(graphics);
6155
graphics.setAlpha(getLineAlpha());
6256
graphics.setForegroundColor(getLineColor());
63-
graphics.drawRectangle(rect);
57+
path = createPath(rect, true);
58+
graphics.drawPath(path);
59+
path.dispose();
6460
}
6561

6662
// Icon
@@ -69,4 +65,19 @@ public void drawFigure(Graphics graphics) {
6965

7066
graphics.popState();
7167
}
68+
69+
protected Path createPath(Rectangle rect, boolean drawingOutline) {
70+
Path path = new Path(null);
71+
72+
float inset = drawingOutline ? getLineWidth() / 2.0f : 0;
73+
74+
float x = rect.x + inset;
75+
float y = rect.y + inset;
76+
float width = rect.width - inset * 2;
77+
float height = rect.height - inset * 2;
78+
79+
path.addRectangle(x, y, width, height);
80+
81+
return path;
82+
}
7283
}

com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/RoundedRectangleFigureDelegate.java

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.eclipse.draw2d.Graphics;
99
import org.eclipse.draw2d.geometry.Dimension;
1010
import org.eclipse.draw2d.geometry.Rectangle;
11+
import org.eclipse.swt.graphics.Path;
1112
import org.eclipse.swt.graphics.Pattern;
1213

1314
import com.archimatetool.model.IDiagramModelObject;
@@ -20,10 +21,10 @@
2021
*
2122
* @author Phillip Beauvoir
2223
*/
23-
public class RoundedRectangleFigureDelegate extends RectangleFigureDelegate
24+
public class RoundedRectangleFigureDelegate extends AbstractFigureDelegate
2425
implements IRoundedRectangleFigure {
2526

26-
private Dimension fArc = new Dimension(20, 20);
27+
private Dimension arc = new Dimension(20, 20);
2728

2829
public RoundedRectangleFigureDelegate(AbstractDiagramModelObjectFigure owner) {
2930
super(owner);
@@ -34,17 +35,9 @@ public void drawFigure(Graphics graphics) {
3435
graphics.pushState();
3536

3637
Rectangle rect = getBounds();
37-
38+
3839
// Reduce width and height by 1 pixel
3940
rect.resize(-1, -1);
40-
41-
boolean drawOutline = getLineStyle() != IDiagramModelObject.LINE_STYLE_NONE;
42-
43-
if(drawOutline) {
44-
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
45-
setLineWidth(graphics, rect);
46-
setLineStyle(graphics);
47-
}
4841

4942
graphics.setAlpha(getAlpha());
5043

@@ -53,19 +46,22 @@ public void drawFigure(Graphics graphics) {
5346
}
5447

5548
// Fill
49+
Path path = createPath(rect, false);
5650
graphics.setBackgroundColor(getFillColor());
57-
5851
Pattern gradient = applyGradientPattern(graphics, rect);
59-
60-
graphics.fillRoundRectangle(rect, fArc.width, fArc.height);
61-
52+
graphics.fillPath(path);
6253
disposeGradientPattern(graphics, gradient);
54+
path.dispose();
6355

6456
// Outline
65-
if(drawOutline) {
57+
if(getLineStyle() != IDiagramModelObject.LINE_STYLE_NONE) {
58+
graphics.setLineWidth(getLineWidth());
59+
setLineStyle(graphics);
6660
graphics.setAlpha(getLineAlpha());
6761
graphics.setForegroundColor(getLineColor());
68-
graphics.drawRoundRectangle(rect, fArc.width, fArc.height);
62+
path = createPath(rect, true);
63+
graphics.drawPath(path);
64+
path.dispose();
6965
}
7066

7167
// Image Icon
@@ -75,15 +71,67 @@ public void drawFigure(Graphics graphics) {
7571
graphics.popState();
7672
}
7773

74+
protected Path createPath(Rectangle rect, boolean drawingOutline) {
75+
Path path = new Path(null);
76+
77+
float inset = drawingOutline ? getLineWidth() / 2.0f : 0;
78+
79+
int arcW = arc.width;
80+
int arcH = arc.height;
81+
82+
// Reduce arc by line width
83+
if(drawingOutline) {
84+
arcW -= getLineWidth();
85+
arcH -= getLineWidth();
86+
}
87+
88+
float rx = arcW / 2f;
89+
float ry = arcH / 2f;
90+
91+
float x = rect.x + inset;
92+
float y = rect.y + inset;
93+
float width = rect.width - inset * 2;
94+
float height = rect.height - inset * 2;
95+
96+
// Start at top side, after top-left corner arc
97+
path.moveTo(x + rx, y);
98+
99+
// Top line
100+
path.lineTo(x + width - rx, y);
101+
102+
// Top-right arc (quarter circle)
103+
path.addArc(x + width - arcW, y, arcW, arcH, 90, -90);
104+
105+
// Right line
106+
path.lineTo(x + width, y + height - ry);
107+
108+
// Bottom-right arc
109+
path.addArc(x + width - arcW, y + height - arcH, arcW, arcH, 0, -90);
110+
111+
// Bottom line
112+
path.lineTo(x + rx, y + height);
113+
114+
// Bottom-left arc
115+
path.addArc(x, y + height - arcH, arcW, arcH, 270, -90);
116+
117+
// Left line
118+
path.lineTo(x, y + ry);
119+
120+
// Top-left arc — closes the path
121+
path.addArc(x, y, arcW, arcH, 180, -90);
122+
123+
return path;
124+
}
125+
78126
@Override
79127
public void setArc(Dimension arc) {
80-
fArc.width = arc.width;
81-
fArc.height = arc.height;
128+
arc.width = arc.width;
129+
arc.height = arc.height;
82130
}
83131

84132
@Override
85133
public Dimension getArc() {
86-
return fArc.getCopy();
134+
return arc.getCopy();
87135
}
88136

89137
}

com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/elements/CollaborationFigure.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ protected void drawFigure(Graphics graphics) {
4343
graphics.pushState();
4444

4545
Rectangle rect = getBounds().getCopy();
46+
Rectangle imageBounds = rect.getCopy().resize(-1, -1);
4647

47-
// Reduce width and height by 1 pixel
48-
rect.resize(-1, -1);
48+
graphics.setLineWidth(getLineWidth());
4949

50-
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
51-
setLineWidth(graphics, rect);
52-
53-
// Get this *after* setLineWidth
54-
Rectangle imageBounds = rect.getCopy();
50+
int x = (getLineWidth() <= 2) ? 1 : getLineWidth() - 1;
51+
rect.shrink(x, x);
5552

5653
setFigurePositionFromTextPosition(rect, 1.5); // Should match 'diameter'
5754

0 commit comments

Comments
 (0)