use clip to improve performance

This commit is contained in:
bancika
2011-02-06 18:22:30 +00:00
parent de7378c722
commit 4774e97ba2
19 changed files with 66 additions and 18 deletions
@@ -2,6 +2,7 @@ package org.diylc.components;
import java.awt.Color;
import java.awt.Font;
import java.awt.Shape;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.EditableProperty;
@@ -19,7 +20,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
private static final long serialVersionUID = 1L;
protected String name = "";
public static Color SELECTION_COLOR = Color.red;
public static Color LABEL_COLOR = Color.black;
public static Color LABEL_COLOR_SELECTED = Color.red;
@@ -35,7 +36,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public void setName(String name) {
this.name = name;
}
@Override
public boolean canControlPointOverlap(int index) {
return false;
@@ -56,4 +57,17 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
protected int getClosestOdd(double x) {
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;
}
}
@@ -63,6 +63,9 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
// Do not track guidelines.
drawingObserver.stopTracking();
@@ -65,6 +65,9 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
Shape shape = getBodyShape();
// If there's no body, just draw the line connecting the ending points.
if (shape == null) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
: getLeadColor(componentState));
@@ -147,7 +147,7 @@ public class DrawingManager {
g2dWrapper.setColor(Constants.CANVAS_COLOR);
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(
ANTIALIASING_KEY, GridType.LINES);
@@ -107,10 +107,6 @@ class CanvasPanel extends JComponent implements Autoscroll {
} else {
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
@@ -120,12 +116,12 @@ class CanvasPanel extends JComponent implements Autoscroll {
}
if (bufferImage == null) {
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) {
VolatileImage volatileImage = (VolatileImage) bufferImage;
do {