Skip to content

Commit

Permalink
Merge pull request kristian#1 from baranator/master
Browse files Browse the repository at this point in the history
fixed high cpu-usage while dragging components with grid on
  • Loading branch information
kristian authored Mar 16, 2017
2 parents ac1e36b + 20b8fdc commit 69cc9e2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/lc/kra/jds/Simulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public enum Layer { TOPMOST, BOTTOMMOST; }

private double zoom;
private boolean gridVisible;
private BufferedImage gridBuffer;

protected List<EventListener> listeners;

Expand Down Expand Up @@ -714,12 +715,17 @@ private Graphics2D prepareGraphics(Graphics defaultGraphics) {
return graphics;
}
private void paintGrid(Graphics graphics, Dimension size) {
graphics.setColor(Color.LIGHT_GRAY);
for(int x=0;x<size.width+GRID_STEPS;x+=GRID_STEPS)
for(int y=0;y<size.height+GRID_STEPS;y+=GRID_STEPS) {
graphics.drawLine(x-3, y, x+3, y);
graphics.drawLine(x, y-3, x, y+3);
}
if(gridBuffer==null || gridBuffer.getHeight()!=size.getHeight() || gridBuffer.getWidth()!=size.getWidth()){
gridBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
Graphics gridImage=gridBuffer.getGraphics();
gridImage.setColor(Color.LIGHT_GRAY);
for(int x=0;x<size.width+GRID_STEPS;x+=GRID_STEPS)
for(int y=0;y<size.height+GRID_STEPS;y+=GRID_STEPS) {
gridImage.drawLine(x-3, y, x+3, y);
gridImage.drawLine(x, y-3, x, y+3);
}
}
graphics.drawImage(gridBuffer,0,0,null);
}
@SuppressWarnings("unused") private void paintComponents(Graphics graphics, Collection<Component> components) { paintComponents(graphics, components, null); }
private void paintComponents(Graphics graphics, Collection<Component> components, Collection<?> ignore) {
Expand Down

0 comments on commit 69cc9e2

Please sign in to comment.