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