mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
introduce another clip rect for the cache
This commit is contained in:
@@ -26,6 +26,7 @@ import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -193,8 +194,9 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
* @param drawOptions specific drawing options
|
||||
* @param filter
|
||||
* @param externalZoom
|
||||
* @param visibleRect
|
||||
*/
|
||||
void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter, Double externalZoom);
|
||||
void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter, Double externalZoom, Rectangle2D visibleRect);
|
||||
|
||||
Double[] getAvailableZoomLevels();
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public class DrawingCache {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void draw(IDIYComponent<?> component, G2DWrapper g2d, ComponentState componentState,
|
||||
boolean outlineMode, Project project, double zoom) {
|
||||
boolean outlineMode, Project project, double zoom, Rectangle2D visibleRect) {
|
||||
ComponentType type = ComponentProcessor.getInstance()
|
||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
|
||||
@@ -99,17 +99,20 @@ public class DrawingCache {
|
||||
|
||||
long componentStart = System.nanoTime();
|
||||
|
||||
// temporarily scale the graphic to compensate for the zoom, since we are rendering an image with the zoom appled
|
||||
if (Math.abs(1.0 - zoom) > 1e-4) {
|
||||
g2d.getCanvasGraphics().scale(1 / zoom, 1 / zoom);
|
||||
}
|
||||
try {
|
||||
// draw cached image
|
||||
g2d.getCanvasGraphics().drawImage(value.getImage(), (int) ((firstPoint.x - value.getDx()) * zoom),
|
||||
(int) ((firstPoint.y - value.getDy())* zoom), null);
|
||||
} finally {
|
||||
// only render the cached image if it's within the clipping region
|
||||
if (visibleRect == null || visibleRect.intersects(value.getCacheBounds())) {
|
||||
// temporarily scale the graphic to compensate for the zoom, since we are rendering an image with the zoom appled
|
||||
if (Math.abs(1.0 - zoom) > 1e-4) {
|
||||
g2d.getCanvasGraphics().scale(zoom, zoom);
|
||||
g2d.getCanvasGraphics().scale(1 / zoom, 1 / zoom);
|
||||
}
|
||||
try {
|
||||
// draw cached image
|
||||
g2d.getCanvasGraphics().drawImage(value.getImage(), (int) ((firstPoint.x - value.getDx()) * zoom),
|
||||
(int) ((firstPoint.y - value.getDy())* zoom), null);
|
||||
} finally {
|
||||
if (Math.abs(1.0 - zoom) > 1e-4) {
|
||||
g2d.getCanvasGraphics().scale(zoom, zoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +128,7 @@ public class DrawingCache {
|
||||
}
|
||||
stats.getSecond().add(componentEnd - componentStart);
|
||||
|
||||
// copy over tracking area from the cache
|
||||
// copy over tracking area from the cache, regardless if we rendered or not
|
||||
g2d.merge(value.getCurrentArea(), value.getContinuityPositiveAreas(), value.getContinuityNegativeAreas());
|
||||
} else {
|
||||
// no caching, just draw as usual
|
||||
@@ -233,7 +236,7 @@ public class DrawingCache {
|
||||
|
||||
// add to the cache
|
||||
value = new CacheValue(component, image, wrapper.getCurrentArea(), wrapper.getContinuityPositiveAreas(),
|
||||
wrapper.getContinuityNegativeAreas(), componentState, zoom, dx, dy);
|
||||
wrapper.getContinuityNegativeAreas(), componentState, zoom, dx, dy, rect);
|
||||
imageCache.put(component, value);
|
||||
}
|
||||
|
||||
@@ -250,11 +253,13 @@ public class DrawingCache {
|
||||
double zoom;
|
||||
int dx;
|
||||
int dy;
|
||||
Rectangle2D cacheBounds;
|
||||
|
||||
public CacheValue(IDIYComponent<?> component, BufferedImage image, Area currentArea,
|
||||
Map<String, Area> continuityPositiveAreas, Map<String, Area> continuityNegativeAreas,
|
||||
ComponentState state, double zoom, int dx, int dy) {
|
||||
ComponentState state, double zoom, int dx, int dy, Rectangle2D cacheBounds) {
|
||||
super();
|
||||
this.cacheBounds = cacheBounds;
|
||||
// take a copy of the component, so we can check if it changed in the meantime
|
||||
try {
|
||||
this.component = component.clone();
|
||||
@@ -306,6 +311,10 @@ public class DrawingCache {
|
||||
return dy;
|
||||
}
|
||||
|
||||
public Rectangle2D getCacheBounds() {
|
||||
return cacheBounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return component.getName() + ":" + state + ":" + zoom;
|
||||
|
||||
@@ -139,12 +139,13 @@ public class DrawingManager {
|
||||
* @param componentSlot
|
||||
* @param dragInProgress
|
||||
* @param externalZoom
|
||||
* @param visibleRect
|
||||
* @return
|
||||
*/
|
||||
public List<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
|
||||
IComponentFiler filter, Rectangle selectionRect, Collection<IDIYComponent<?>> selectedComponents,
|
||||
Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
||||
List<IDIYComponent<?>> componentSlot, boolean dragInProgress, Double externalZoom) {
|
||||
List<IDIYComponent<?>> componentSlot, boolean dragInProgress, Double externalZoom, Rectangle2D visibleRect) {
|
||||
long totalStartTime = System.nanoTime();
|
||||
failedComponents.clear();
|
||||
if (project == null) {
|
||||
@@ -242,11 +243,16 @@ public class DrawingManager {
|
||||
|
||||
// translate to the new (0, 0)
|
||||
g2d.transform(AffineTransform.getTranslateInstance(extraSpace, extraSpace));
|
||||
if (visibleRect != null)
|
||||
visibleRect.setRect(visibleRect.getX() - extraSpace, visibleRect.getY() - extraSpace,
|
||||
visibleRect.getWidth(), visibleRect.getHeight());
|
||||
}
|
||||
|
||||
// apply zoom
|
||||
if (Math.abs(1.0 - zoom) > 1e-4) {
|
||||
g2dWrapper.scale(zoom, zoom);
|
||||
visibleRect.setRect(visibleRect.getX() / zoom, visibleRect.getY() / zoom,
|
||||
visibleRect.getWidth() / zoom, visibleRect.getHeight() / zoom);
|
||||
}
|
||||
|
||||
// Composite mainComposite = g2d.getComposite();
|
||||
@@ -301,7 +307,7 @@ public class DrawingManager {
|
||||
try {
|
||||
|
||||
if (drawOptions.contains(DrawOption.ENABLE_CACHING)) // go through the DrawingCache
|
||||
DrawingCache.Instance.draw(component, g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, zoom);
|
||||
DrawingCache.Instance.draw(component, g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, zoom, visibleRect);
|
||||
else // go stragiht to the wrapper
|
||||
component.draw(g2dWrapper, state, outlineMode, project, g2dWrapper);
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, Set<DrawOption> drawOptions, final IComponentFiler filter, Double externalZoom) {
|
||||
public void draw(Graphics2D g2d, Set<DrawOption> drawOptions, final IComponentFiler filter, Double externalZoom, Rectangle2D visibleRect) {
|
||||
if (currentProject == null) {
|
||||
return;
|
||||
}
|
||||
@@ -501,7 +501,8 @@ public class Presenter implements IPlugInPort {
|
||||
getLockedComponents(),
|
||||
groupedComponents,
|
||||
Arrays.asList(instantiationManager.getFirstControlPoint(),
|
||||
instantiationManager.getPotentialControlPoint()), componentSlotToDraw, dragInProgress, externalZoom);
|
||||
instantiationManager.getPotentialControlPoint()), componentSlotToDraw, dragInProgress, externalZoom,
|
||||
visibleRect);
|
||||
List<String> failedComponentNames = new ArrayList<String>();
|
||||
for (IDIYComponent<?> component : failedComponents) {
|
||||
failedComponentNames.add(component.getName());
|
||||
|
||||
@@ -2902,6 +2902,10 @@
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Improved performance math calculations used to model "Twisted Wires"</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Improved performance of "Highlight Connected Areas" feature</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Older files that contain "Open Jack 1/4" components sometimes open with the jacks rotated the wrong way</description>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -159,6 +159,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.ABNORMAL_EXIT_KEY, false);
|
||||
dispose();
|
||||
presenter.dispose();
|
||||
LOG.info("Closing the app");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ public class TemplateDialog extends JDialog {
|
||||
super.paint(g);
|
||||
// Graphics2D g2d = (Graphics2D) g;
|
||||
// AffineTransform transform = g2d.getTransform();
|
||||
presenter.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING), null, null);
|
||||
presenter.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING), null, null, null);
|
||||
// g2d.setTransform(transform);
|
||||
// Rectangle rect = canvasPanel.getBounds();
|
||||
// BorderFactory.createEtchedBorder().paintBorder(canvasPanel,
|
||||
|
||||
@@ -270,7 +270,7 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
drawOptions.add(DrawOption.ENABLE_CACHING);
|
||||
}
|
||||
|
||||
plugInPort.draw(g2d, drawOptions, null, null);
|
||||
plugInPort.draw(g2d, drawOptions, null, null, visibleRect);
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||
|
||||
@@ -319,7 +319,7 @@ public class UploadDialog extends ButtonDialog {
|
||||
}
|
||||
|
||||
// g2d.scale(zoomRatio, zoomRatio);
|
||||
UploadDialog.this.plugInPort.draw(g2d, EnumSet.of(DrawOption.ANTIALIASING), null, zoomRatio);
|
||||
UploadDialog.this.plugInPort.draw(g2d, EnumSet.of(DrawOption.ANTIALIASING), null, zoomRatio, null);
|
||||
}
|
||||
|
||||
public String getKeywords() {
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ProjectDrawingProvider implements IDrawingProvider {
|
||||
if (includeExtraSpace) {
|
||||
drawOptions.add(DrawOption.EXTRA_SPACE);
|
||||
}
|
||||
plugInPort.draw((Graphics2D) g, drawOptions, null, zoomFactor);
|
||||
plugInPort.draw((Graphics2D) g, drawOptions, null, zoomFactor, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -148,7 +148,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
|
||||
// g2d.translate(x, y);
|
||||
// g2d.scale(zoomRatio, zoomRatio);
|
||||
presenter.draw(g2d, EnumSet.noneOf(DrawOption.class), null, zoomRatio);
|
||||
presenter.draw(g2d, EnumSet.noneOf(DrawOption.class), null, zoomRatio, null);
|
||||
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height - (int) (1 / zoomRatio));
|
||||
|
||||
@@ -60,7 +60,7 @@ public class TraceMaskDrawingProvider implements IDrawingProvider {
|
||||
|
||||
@Override
|
||||
public void draw(int page, Graphics g, double zoomFactor) {
|
||||
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ANTIALIASING), new PCBLayerFiler(getUsedLayers()[page]), zoomFactor);
|
||||
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ANTIALIASING), new PCBLayerFiler(getUsedLayers()[page]), zoomFactor, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user