Use transparency instead of rendering pins on top of transistor body

This commit is contained in:
Branislav Stojkovic
2019-01-14 21:11:12 +01:00
parent 6ce5d305f1
commit 77d038cef9
7 changed files with 122 additions and 107 deletions
Binary file not shown.
@@ -85,6 +85,7 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
public TransistorTO1() { public TransistorTO1() {
super(); super();
updateControlPoints(); updateControlPoints();
alpha = (byte) 100;
} }
@EditableProperty @EditableProperty
@@ -215,6 +216,17 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
return; return;
} }
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
for (Point point : controlPoints) {
if (!outlineMode) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
Area mainArea = getBody(); Area mainArea = getBody();
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
@@ -224,7 +236,7 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
g2d.fill(mainArea); g2d.fill(mainArea);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
Color finalBorderColor; Color finalBorderColor;
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
if (outlineMode) { if (outlineMode) {
finalBorderColor = finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
@@ -238,15 +250,6 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.draw(mainArea); g2d.draw(mainArea);
for (Point point : controlPoints) {
if (!outlineMode) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
// Draw label. // Draw label.
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
Color finalLabelColor; Color finalLabelColor;
@@ -93,6 +93,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
public TransistorTO220() { public TransistorTO220() {
super(); super();
updateControlPoints(); updateControlPoints();
alpha = (byte) 100;
} }
@EditableProperty @EditableProperty
@@ -264,46 +265,8 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
return; return;
} }
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Shape mainArea = getBody()[0];
Shape tabArea = getBody()[1];
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
Color finalTabColor;
if (outlineMode) {
Theme theme =
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalTabColor = theme.getOutlineColor();
} else {
finalTabColor = tabColor;
}
g2d.setColor(finalTabColor);
g2d.fill(tabArea);
g2d.setComposite(oldComposite);
if (!outlineMode) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(tabBorderColor);
g2d.draw(tabArea);
}
Color finalBorderColor;
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
if (outlineMode) {
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
} else {
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
}
g2d.setColor(finalBorderColor);
g2d.draw(mainArea);
if (folded) {
g2d.draw(tabArea);
}
// Draw pins. // Draw pins.
@@ -369,6 +332,46 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
} }
} }
Shape mainArea = getBody()[0];
Shape tabArea = getBody()[1];
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
Color finalTabColor;
if (outlineMode) {
finalTabColor = theme.getOutlineColor();
} else {
finalTabColor = tabColor;
}
g2d.setColor(finalTabColor);
g2d.fill(tabArea);
g2d.setComposite(oldComposite);
if (!outlineMode) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(tabBorderColor);
g2d.draw(tabArea);
}
Color finalBorderColor;
if (outlineMode) {
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
} else {
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
}
g2d.setColor(finalBorderColor);
g2d.draw(mainArea);
if (folded) {
g2d.draw(tabArea);
}
// Draw label. // Draw label.
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
Color finalLabelColor; Color finalLabelColor;
@@ -88,6 +88,7 @@ public class TransistorTO3 extends AbstractTransparentComponent<String> {
public TransistorTO3() { public TransistorTO3() {
super(); super();
updateControlPoints(); updateControlPoints();
alpha = (byte) 100;
} }
@EditableProperty @EditableProperty
@@ -250,6 +251,17 @@ public class TransistorTO3 extends AbstractTransparentComponent<String> {
return; return;
} }
int pinSize = (int) PIN_DIAMETER.convertToPixels() / 2 * 2; int pinSize = (int) PIN_DIAMETER.convertToPixels() / 2 * 2;
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
for (Point point : controlPoints) {
if (!outlineMode) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
Area mainArea = getBody()[0]; Area mainArea = getBody()[0];
Area innerArea = getBody()[1]; Area innerArea = getBody()[1];
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
@@ -260,7 +272,7 @@ public class TransistorTO3 extends AbstractTransparentComponent<String> {
g2d.fill(mainArea); g2d.fill(mainArea);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
Color finalBorderColor; Color finalBorderColor;
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
if (outlineMode) { if (outlineMode) {
finalBorderColor = finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
@@ -275,15 +287,6 @@ public class TransistorTO3 extends AbstractTransparentComponent<String> {
g2d.draw(mainArea); g2d.draw(mainArea);
g2d.draw(innerArea); g2d.draw(innerArea);
for (Point point : controlPoints) {
if (!outlineMode) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
// Draw label. // Draw label.
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
Color finalLabelColor; Color finalLabelColor;
@@ -83,6 +83,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
public TransistorTO92() { public TransistorTO92() {
super(); super();
updateControlPoints(); updateControlPoints();
alpha = (byte) 100;
} }
@EditableProperty @EditableProperty
@@ -249,6 +250,16 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
return; return;
} }
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
if (!outlineMode) {
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
Area mainArea = getBody(); Area mainArea = getBody();
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
@@ -273,15 +284,6 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.draw(mainArea); g2d.draw(mainArea);
if (!outlineMode) {
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
// Draw label. // Draw label.
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
Color finalLabelColor; Color finalLabelColor;
Binary file not shown.
+4
View File
@@ -2226,6 +2226,10 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Use hardware acceleration for rendering to improve performance</description> <description>Use hardware acceleration for rendering to improve performance</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Use transparency instead of rendering pins on top of transistor body</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Leads and wires are rendered better, especially when zoomed in</description> <description>Leads and wires are rendered better, especially when zoomed in</description>