mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
added transparency
This commit is contained in:
Binary file not shown.
+10
-2
@@ -1,17 +1,19 @@
|
||||
package org.diylc.components.boards;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public abstract class AbstractBoard implements IDIYComponent<String> {
|
||||
public abstract class AbstractBoard extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -29,9 +31,15 @@ public abstract class AbstractBoard implements IDIYComponent<String> {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||
g2d.setStroke(new BasicStroke());
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(getBoardColor());
|
||||
g2d.fillRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
|
||||
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
g2d.setColor(getBorderColor());
|
||||
g2d.drawRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
|
||||
|
||||
+8
@@ -1,7 +1,9 @@
|
||||
package org.diylc.components.boards;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
@@ -43,6 +45,11 @@ public class PerfBoard extends AbstractBoard {
|
||||
super.draw(g2d, componentState, project);
|
||||
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
Point p = new Point(controlPoints[0]);
|
||||
int radius = PAD_SIZE.convertToPixels() / 2;
|
||||
int holeRadius = HOLE_SIZE.convertToPixels() / 2;
|
||||
@@ -61,6 +68,7 @@ public class PerfBoard extends AbstractBoard {
|
||||
holeRadius * 2);
|
||||
}
|
||||
}
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
// System.err.println("OldDraw: " + (System.nanoTime() - t));
|
||||
}
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package org.diylc.components.boards;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.core.ComponentLayer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Vero Board", category = "Boards", author = "Branislav Stojkovic", componentLayer = ComponentLayer.BOARD, instanceNamePrefix = "B", desciption = "Perforated FR4 board with solder pads spaced 0.1 inch apart")
|
||||
public class VeroBoard extends AbstractBoard {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color BOARD_COLOR = Color.decode("#BCED91");
|
||||
public static Color COPPER_COLOR = Color.decode("#B87333");
|
||||
public static Color BORDER_COLOR = BOARD_COLOR.darker();
|
||||
|
||||
private static Size SPACING = new Size(0.1d, SizeUnit.in);
|
||||
private static Size STRIP_SIZE = new Size(0.085d, SizeUnit.in);
|
||||
private static Size HOLE_SIZE = new Size(0.8d, SizeUnit.mm);
|
||||
|
||||
// private Area copperArea;
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||
// long t = System.nanoTime();
|
||||
// Area copperArea = getCopperArea();
|
||||
// System.err.println("Calc: " + (System.nanoTime() - t));
|
||||
// t = System.nanoTime();
|
||||
// super.draw(g2d, componentState, project);
|
||||
// g2d.setColor(COPPER_COLOR);
|
||||
// g2d.fill(copperArea);
|
||||
// System.err.println(" Draw: " + (System.nanoTime() - t));
|
||||
|
||||
// long t = System.nanoTime();
|
||||
super.draw(g2d, componentState, project);
|
||||
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
Point p = new Point(controlPoints[0]);
|
||||
int stripSize = STRIP_SIZE.convertToPixels();
|
||||
int holeRadius = HOLE_SIZE.convertToPixels() / 2;
|
||||
|
||||
while (p.y < controlPoints[1].y - SPACING.convertToPixels()) {
|
||||
p.x = controlPoints[0].x;
|
||||
p.y += SPACING.convertToPixels();
|
||||
g2d.setColor(COPPER_COLOR);
|
||||
g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
|
||||
controlPoints[1].x - SPACING.convertToPixels() - p.x, stripSize);
|
||||
while (p.x < controlPoints[1].x - SPACING.convertToPixels()) {
|
||||
p.x += SPACING.convertToPixels();
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d
|
||||
.fillOval(p.x - holeRadius, p.y - holeRadius, holeRadius * 2,
|
||||
holeRadius * 2);
|
||||
}
|
||||
}
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
// System.err.println("OldDraw: " + (System.nanoTime() - t));
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void setControlPoint(Point point, int index) {
|
||||
// // Reset copper area if a control point is changed.
|
||||
// if (!point.equals(getControlPoint(index))) {
|
||||
// copperArea = null;
|
||||
// }
|
||||
// super.setControlPoint(point, index);
|
||||
// }
|
||||
//
|
||||
// public Area getCopperArea() {
|
||||
// if (copperArea == null) {
|
||||
// copperArea = new Area();
|
||||
//
|
||||
// int holeRadius = HOLE_SIZE.convertToPixels() / 2;
|
||||
// int radius = PAD_SIZE.convertToPixels() / 2;
|
||||
// int spacing = SPACING.convertToPixels();
|
||||
//
|
||||
// // Create a pad.
|
||||
// Area pad = new Area(new Ellipse2D.Double(-radius, -radius, radius * 2,
|
||||
// radius * 2));
|
||||
// pad.subtract(new Area(new Ellipse2D.Double(-holeRadius, -holeRadius,
|
||||
// holeRadius * 2,
|
||||
// holeRadius * 2)));
|
||||
//
|
||||
// // Create a row duplicating the pad.
|
||||
// Area row = new Area();
|
||||
// int columnCount = (controlPoints[1].x - controlPoints[0].x) / spacing -
|
||||
// 1;
|
||||
// int rowCount = (controlPoints[1].y - controlPoints[0].y) / spacing - 1;
|
||||
//
|
||||
// AffineTransform xTransform =
|
||||
// AffineTransform.getTranslateInstance(spacing, 0);
|
||||
// for (int i = 0; i < columnCount; i++) {
|
||||
// pad.transform(xTransform);
|
||||
// row.add(pad);
|
||||
// }
|
||||
//
|
||||
// // Create the whole matrix duplicating the row.
|
||||
// AffineTransform yTransform = AffineTransform.getTranslateInstance(0,
|
||||
// spacing);
|
||||
// for (int i = 0; i < rowCount; i++) {
|
||||
// row.transform(yTransform);
|
||||
// copperArea.add(row);
|
||||
// }
|
||||
//
|
||||
// copperArea.transform(AffineTransform.getTranslateInstance(controlPoints[0].x,
|
||||
// controlPoints[0].y));
|
||||
// }
|
||||
// return copperArea;
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected Color getBoardColor() {
|
||||
return BOARD_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getBorderColor() {
|
||||
return BORDER_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -1,14 +1,16 @@
|
||||
package org.diylc.components.electromechanical;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.ComponentLayer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
@@ -16,7 +18,7 @@ import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic", desciption = "", stretchable = false, componentLayer = ComponentLayer.COMPONENT, instanceNamePrefix = "SW")
|
||||
public class MiniToggleSwitch implements IDIYComponent<ToggleSwitchType> {
|
||||
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -163,8 +165,14 @@ public class MiniToggleSwitch implements IDIYComponent<ToggleSwitchType> {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||
if (body != null) {
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
1f * alpha / MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fill(body);
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
g2d.setStroke(new BasicStroke());
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
|
||||
+10
-2
@@ -1,15 +1,17 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
@@ -18,7 +20,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "DIL IC", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "IC", desciption = "test", stretchable = false)
|
||||
public class DIL_IC implements IDIYComponent<String> {
|
||||
public class DIL_IC extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -166,8 +168,14 @@ public class DIL_IC implements IDIYComponent<String> {
|
||||
y -= height - Constants.GRID;
|
||||
}
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
1f * alpha / MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRoundRect(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS);
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.setStroke(new BasicStroke());
|
||||
|
||||
Reference in New Issue
Block a user