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

@@ -3,9 +3,15 @@
*/
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlate.DrawMode;
import ch.psi.pshell.core.Context;
import ch.psi.pshell.imaging.Data;
import ch.psi.pshell.imaging.ImageListener;
import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import java.awt.Component;
import java.awt.Point;
import java.awt.Dimension;
import java.awt.Graphics;
@@ -14,6 +20,7 @@ import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
@@ -103,11 +110,12 @@ public class BasePlatePanel extends DevicePanel {
Rectangle platePlotRect;
Rectangle puckPlotRect;
Source source;
@Override
public void paint(Graphics g) {
super.paint(g);
if (getDevice() != null) {
if (getDevice() != null) {
Graphics2D g2d = (Graphics2D) g;
Dimension size = getSize();
if ((size.width > 40) && (size.height > 40)) {
@@ -122,38 +130,64 @@ public class BasePlatePanel extends DevicePanel {
case single:
platePlotRect = plotRect;
puckPlotRect = null;
getDevice().draw(g2d, platePlotRect, true, false, true);
getDevice().draw(g2d, platePlotRect, true, false, true, DrawMode.center, img);
break;
case horizontal:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width / 2, plotRect.height);
getDevice().draw(g2d, platePlotRect, false, true, true);
getDevice().draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + plotRect.width / 2 + borderPuck, plotRect.y + borderPuck, plotRect.width / 2 - 2 * borderPuck, plotRect.height - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false, null);
selectedPuck.draw(g2d, puckPlotRect, true, false, true, null);
}
break;
case vertical:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width, plotRect.height / 2);
getDevice().draw(g2d, platePlotRect, false, true, true);
getDevice().draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + borderPuck, plotRect.y + plotRect.height / 2 + borderPuck, plotRect.width - 2 * borderPuck, plotRect.height / 2 - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false, null);
selectedPuck.draw(g2d, puckPlotRect, true, false, true, null);
}
break;
case overlapped:
//getDevice().draw(g2d, plotRect, false, true);
platePlotRect = new Rectangle(plotRect.x - ((int) (plotRect.width * 0.14)), plotRect.y - ((int) (plotRect.height * 0.14)), (int) (plotRect.width * 1.28), (int) (plotRect.height * 1.28));
getDevice().draw(g2d, platePlotRect, false, true, false);
getDevice().draw(g2d, platePlotRect, false, true, false, DrawMode.fill, null);
if (selectedPuck!=null){
int overlappedSize = (int) (1.5 * selectedPuck.getDrawSize());
puckPlotRect = new Rectangle((int) (plotRect.getCenterX() - overlappedSize / 2), (int) (plotRect.getCenterY() - overlappedSize / 2), overlappedSize, overlappedSize);
selectedPuck.draw(g2d, puckPlotRect, true, false, null);
selectedPuck.draw(g2d, puckPlotRect, true, false, true, null);
}
break;
}
}
}
}
BufferedImage img;
ImageListener imageListener = new ImageListener() {
@Override
public void onImage(Object origin, BufferedImage image, Data data) {
img = image;
repaint();
}
@Override
public void onError(Object origin, Exception ex) {
img = null;
repaint();
}
};
void setCameraView(Source source){
img = null;
if (this.source!=null){
this.source.removeListener(imageListener);
}
this.source = source;
if (source!=null){
source.addListener(imageListener);
}
repaint();
}
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override