mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
use clip to improve performance
This commit is contained in:
@@ -9,11 +9,11 @@
|
|||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>lastPath</string>
|
<string>lastPath</string>
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>antiAliasing</string>
|
<string>antiAliasing</string>
|
||||||
<boolean>false</boolean>
|
<boolean>true</boolean>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>hiQualityRender</string>
|
<string>hiQualityRender</string>
|
||||||
|
|||||||
Binary file not shown.
+14
@@ -2,6 +2,7 @@ package org.diylc.components;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.Shape;
|
||||||
|
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
@@ -56,4 +57,17 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
|||||||
protected int getClosestOdd(double x) {
|
protected int getClosestOdd(double x) {
|
||||||
return ((int) x / 2) * 2 + 1;
|
return ((int) x / 2) * 2 + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clip
|
||||||
|
* @return true if none of the control points lie in the clip rectangle.
|
||||||
|
*/
|
||||||
|
protected boolean checkPointsClipped(Shape clip) {
|
||||||
|
for (int i = 0; i < getControlPointCount(); i++) {
|
||||||
|
if (clip.contains(getControlPoint(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -63,6 +63,9 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
|
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
|
||||||
// Do not track guidelines.
|
// Do not track guidelines.
|
||||||
drawingObserver.stopTracking();
|
drawingObserver.stopTracking();
|
||||||
|
|||||||
+3
@@ -65,6 +65,9 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
Shape shape = getBodyShape();
|
Shape shape = getBodyShape();
|
||||||
// If there's no body, just draw the line connecting the ending points.
|
// If there's no body, just draw the line connecting the ending points.
|
||||||
if (shape == null) {
|
if (shape == null) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
|
||||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||||
: getLeadColor(componentState));
|
: getLeadColor(componentState));
|
||||||
|
|||||||
+1
-1
@@ -147,7 +147,7 @@ public class DrawingManager {
|
|||||||
|
|
||||||
g2dWrapper.setColor(Constants.CANVAS_COLOR);
|
g2dWrapper.setColor(Constants.CANVAS_COLOR);
|
||||||
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
||||||
g2d.setClip(new Rectangle(new Point(0, 0), d));
|
g2d.clip(new Rectangle(new Point(0, 0), d));
|
||||||
|
|
||||||
GridType gridType = (GridType) ConfigurationManager.getInstance().readObject(
|
GridType gridType = (GridType) ConfigurationManager.getInstance().readObject(
|
||||||
ANTIALIASING_KEY, GridType.LINES);
|
ANTIALIASING_KEY, GridType.LINES);
|
||||||
|
|||||||
+5
-9
@@ -107,10 +107,6 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
} else {
|
} else {
|
||||||
bufferImage = createImage(getWidth(), getHeight());
|
bufferImage = createImage(getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
|
||||||
plugInPort.draw(g2d, ConfigurationManager.getInstance().readBoolean(
|
|
||||||
IPlugInPort.ANTI_ALIASING_KEY, true) ? DRAW_OPTIONS_ANTI_ALIASING : DRAW_OPTIONS,
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,12 +116,12 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
}
|
}
|
||||||
if (bufferImage == null) {
|
if (bufferImage == null) {
|
||||||
createBufferImage();
|
createBufferImage();
|
||||||
} else {
|
|
||||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
|
||||||
plugInPort.draw(g2d, ConfigurationManager.getInstance().readBoolean(
|
|
||||||
IPlugInPort.ANTI_ALIASING_KEY, true) ? DRAW_OPTIONS_ANTI_ALIASING
|
|
||||||
: DRAW_OPTIONS, null);
|
|
||||||
}
|
}
|
||||||
|
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||||
|
g2d.setClip(getVisibleRect());
|
||||||
|
plugInPort.draw(g2d, ConfigurationManager.getInstance().readBoolean(
|
||||||
|
IPlugInPort.ANTI_ALIASING_KEY, true) ? DRAW_OPTIONS_ANTI_ALIASING : DRAW_OPTIONS,
|
||||||
|
null);
|
||||||
if (USE_HARDWARE_ACCELLERATION) {
|
if (USE_HARDWARE_ACCELLERATION) {
|
||||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||||
do {
|
do {
|
||||||
|
|||||||
Binary file not shown.
+3
@@ -37,6 +37,9 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||||
if (componentState != ComponentState.DRAGGING) {
|
if (componentState != ComponentState.DRAGGING) {
|
||||||
Composite oldComposite = g2d.getComposite();
|
Composite oldComposite = g2d.getComposite();
|
||||||
|
|||||||
+3
@@ -34,6 +34,9 @@ public class Eyelet extends AbstractComponent<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int diameter = getClosestOdd((int) size.convertToPixels());
|
int diameter = getClosestOdd((int) size.convertToPixels());
|
||||||
int holeDiameter = getClosestOdd((int) holeSize.convertToPixels());
|
int holeDiameter = getClosestOdd((int) holeSize.convertToPixels());
|
||||||
g2d.setColor(color);
|
g2d.setColor(color);
|
||||||
|
|||||||
+3
@@ -33,6 +33,9 @@ public class SolderPad extends AbstractComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int diameter = getClosestOdd((int) size.convertToPixels());
|
int diameter = getClosestOdd((int) size.convertToPixels());
|
||||||
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
|
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
|
||||||
g2d.setColor(componentState == ComponentState.SELECTED
|
g2d.setColor(componentState == ComponentState.SELECTED
|
||||||
|
|||||||
+3
@@ -35,6 +35,9 @@ public class TraceCut extends AbstractComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int size = getClosestOdd((int) this.size.convertToPixels());
|
int size = getClosestOdd((int) this.size.convertToPixels());
|
||||||
int dotDiameter = size - 6;
|
int dotDiameter = size - 6;
|
||||||
g2d.setColor(fillColor);
|
g2d.setColor(fillColor);
|
||||||
|
|||||||
+3
@@ -167,6 +167,9 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Shape body = getBody();
|
Shape body = getBody();
|
||||||
// Draw body if available.
|
// Draw body if available.
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
|
|||||||
+8
-3
@@ -42,20 +42,25 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
double s = 1d * scale / DEFAULT_SCALE;
|
||||||
|
Point endPoint = new Point((int) (image.getIconWidth() * s),
|
||||||
|
(int) (image.getIconHeight() * s));
|
||||||
|
if (!g2d.getClip().contains(point) && !g2d.getClip().contains(endPoint)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Composite oldComposite = g2d.getComposite();
|
Composite oldComposite = g2d.getComposite();
|
||||||
if (alpha < MAX_ALPHA) {
|
if (alpha < MAX_ALPHA) {
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||||
/ MAX_ALPHA));
|
/ MAX_ALPHA));
|
||||||
}
|
}
|
||||||
double s = 1d * scale / DEFAULT_SCALE;
|
|
||||||
g2d.scale(s, s);
|
g2d.scale(s, s);
|
||||||
g2d.drawImage(image.getImage(), (int) (point.x / s), (int) (point.y / s), null);
|
g2d.drawImage(image.getImage(), (int) (point.x / s), (int) (point.y / s), null);
|
||||||
if (componentState == ComponentState.SELECTED) {
|
if (componentState == ComponentState.SELECTED) {
|
||||||
g2d.setComposite(oldComposite);
|
g2d.setComposite(oldComposite);
|
||||||
g2d.scale(1 / s, 1 / s);
|
g2d.scale(1 / s, 1 / s);
|
||||||
g2d.setColor(SELECTION_COLOR);
|
g2d.setColor(SELECTION_COLOR);
|
||||||
g2d.drawRect(point.x, point.y, (int) (image.getIconWidth() * s), (int) (image
|
g2d.drawRect(point.x, point.y, endPoint.x, endPoint.y);
|
||||||
.getIconHeight() * s));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -23,6 +23,6 @@ public class ResistorValue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return resistance.toString() + " " + power.toString();
|
return resistance.toString() + power.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -243,6 +243,9 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||||
Shape mainShape = getBody()[0];
|
Shape mainShape = getBody()[0];
|
||||||
Shape shaftShape = getBody()[1];
|
Shape shaftShape = getBody()[1];
|
||||||
|
|||||||
+3
@@ -249,6 +249,9 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||||
Area mainArea = getBody()[0];
|
Area mainArea = getBody()[0];
|
||||||
for (Point point : controlPoints) {
|
for (Point point : controlPoints) {
|
||||||
|
|||||||
+3
@@ -174,6 +174,9 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||||
Shape mainArea = getBody()[0];
|
Shape mainArea = getBody()[0];
|
||||||
Shape tabArea = getBody()[1];
|
Shape tabArea = getBody()[1];
|
||||||
|
|||||||
+3
@@ -166,6 +166,9 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
if (checkPointsClipped(g2d.getClip())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||||
Area mainArea = getBody();
|
Area mainArea = getBody();
|
||||||
Composite oldComposite = g2d.getComposite();
|
Composite oldComposite = g2d.getComposite();
|
||||||
|
|||||||
Reference in New Issue
Block a user