Drawing over image

This commit is contained in:
2018-04-09 16:14:22 +02:00
parent ee310ea7bd
commit fd15d2cf48
6 changed files with 191 additions and 70 deletions

View File

@@ -7,10 +7,14 @@ import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceBase;
import ch.psi.pshell.imaging.DimensionDouble;
import ch.psi.pshell.imaging.PointDouble;
import ch.psi.utils.swing.MainFrame;
import ch.psi.pshell.imaging.Utils;
import ch.psi.utils.swing.MainFrame;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
@@ -155,19 +159,57 @@ public class BasePlate extends DeviceBase {
}
boolean drawContour;
enum DrawMode{
fill,
center,
left,
right,
top,
bottom
}
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour) {
this.plotRect = plotRect;
this.drawContour = drawContour;
if (drawContour){
g.setColor(getColor());
g.fillOval((int)(plotRect.width*0.05), (int)(plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90));
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour, DrawMode mode, BufferedImage img) {
if (mode != DrawMode.fill){
int length = Math.min(plotRect.width, plotRect.height);
Point center= new Point(plotRect.x + plotRect.width/2, plotRect.y + plotRect.height/2); //center;
switch (mode){
case left:
center.setLocation(length/2, center.y);
break;
case right:
center.setLocation(plotRect.width - length/2, center.y);
break;
case top:
center.setLocation(center.x, length/2);
break;
case bottom:
center.setLocation(center.x, plotRect.height - length/2);
break;
}
plotRect = new Rectangle(center.x - length/2, center.y - length/2, length, length);
}
this.plotRect = plotRect;
this.drawContour = drawContour;
Rectangle boundingBox = new Rectangle((int)(plotRect.x+plotRect.width*0.05), (int)(plotRect.y+plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90));
if (img!=null){
img = Utils.stretch(img, boundingBox.width, boundingBox.height);
g.drawImage(img, boundingBox.x, boundingBox.y, null);
}
boolean drawBackground = (img==null);
if (drawContour){
if (drawBackground){
g.setColor(getColor());
g.fillOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}
g.setColor(getBorderColor());
g.drawOval((int)(plotRect.width*0.05), (int)(plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90));
g.drawOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}
for (Puck puck : getPucks()) {
puck.draw(g, null, drawSamples, drawIds, this) ;
puck.draw(g, null, drawSamples, drawIds, drawBackground, this) ;
}
}