Skip to content

Commit 645b89d

Browse files
committed
Swap out preview main image when redrawing
Removes blocks with awt thread, allows any size viewport Update preview font Code formatting
1 parent 398351d commit 645b89d

File tree

2 files changed

+54
-61
lines changed

2 files changed

+54
-61
lines changed

Diff for: src/org/jmc/gui/PreviewPanel.java

+53-60
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class PreviewPanel extends JPanel implements MouseMotionListener, MouseWh
7575
/**
7676
* Back buffers used for drawing the preview.
7777
*/
78-
private final BufferedImage main_img, height_img;
78+
private BufferedImage main_img;
7979

8080
/**
8181
* Font used in the preview.
@@ -137,7 +137,6 @@ static class MapMarker {
137137
public PreviewPanel() {
138138

139139
main_img=new BufferedImage(MAX_WIDTH, MAX_HEIGHT, BufferedImage.TYPE_INT_RGB);
140-
height_img=new BufferedImage(MAX_WIDTH, MAX_HEIGHT, BufferedImage.TYPE_BYTE_GRAY);
141140

142141
setMaximumSize(new Dimension(MAX_WIDTH,MAX_HEIGHT));
143142

@@ -152,7 +151,7 @@ public PreviewPanel() {
152151
addMouseMotionListener(this);
153152
addMouseWheelListener(this);
154153

155-
gui_font=new Font("Verdana",Font.BOLD,10);
154+
gui_font=new Font("Noto Sans JMC Combined",Font.BOLD,10);
156155
gui_color=Color.white;
157156
gui_bg_color=Color.black;
158157
gui_bg_alpha=0.3f;
@@ -168,10 +167,9 @@ public void paint(Graphics g) {
168167

169168
Graphics2D g2d = (Graphics2D) g;
170169
g2d.setFont(gui_font);
171-
172-
synchronized (main_img) {
173-
g2d.drawImage(main_img, 0, 0, null);
174-
}
170+
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
171+
172+
g2d.drawImage(main_img, 0, 0, null);
175173

176174
for(MapMarker marker:markers)
177175
{
@@ -234,20 +232,13 @@ public void paint(Graphics g) {
234232
screen_ez=-1;
235233
}
236234

237-
238235
g2d.setComposite(AlphaComposite.getInstance (AlphaComposite.SRC_OVER,gui_bg_alpha));
239236
gui_text.clear();
240237
gui_text.add(zoom_level+"x");
241238
gui_text.add("("+px+","+py+")"); //$NON-NLS-2$ //$NON-NLS-3$
242239
gui_text.add(Messages.getString("PreviewPanel.SELECTION"));
243240
gui_text.add("("+selection_start_x+","+selection_start_z+")"); //$NON-NLS-2$ //$NON-NLS-3$
244241
gui_text.add("("+selection_end_x+","+selection_end_z+")"); //$NON-NLS-2$ //$NON-NLS-3$
245-
246-
//Commented these out because this information is now in a JSpinner on MainPanel
247-
//gui_text.add(Messages.getString("PreviewPanel.FLOOR")+alt_floor);
248-
//gui_text.add(Messages.getString("PreviewPanel.CEILING")+alt_ceil);
249-
250-
251242

252243
g2d.setColor(gui_bg_color);
253244
g2d.fillRect(0, 0, 100, 130+gui_text.size()*(fh+5));
@@ -272,64 +263,69 @@ void redraw(boolean fast)
272263
{
273264
int win_w=getWidth();
274265
int win_h=getHeight();
266+
BufferedImage new_main_img = new BufferedImage(win_w, win_h, BufferedImage.TYPE_INT_RGB);
267+
BufferedImage height_img = new BufferedImage(win_w, win_h, BufferedImage.TYPE_BYTE_GRAY);
275268

276269
Vector<ChunkImage> chunksSnapshot;
277270
synchronized (chunks) {
278271
chunksSnapshot = (Vector<ChunkImage>)chunks.clone();
279272
chunksDirty = false;
280273
}
281274

282-
synchronized (main_img) {
283-
Graphics2D mg=main_img.createGraphics();
284-
if(!fast)
285-
mg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
286-
mg.setColor(Color.black);
287-
mg.clearRect(0, 0, win_w, win_h);
288-
289-
Graphics2D hg=height_img.createGraphics();
290-
if(!fast)
291-
{
292-
hg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
293-
hg.setColor(Color.black);
294-
hg.clearRect(0, 0, win_w, win_h);
295-
}
296-
297-
BufferedImage ckln=new BufferedImage(MAX_WIDTH, MAX_HEIGHT, BufferedImage.TYPE_INT_ARGB);
298-
Graphics2D cklng = ckln.createGraphics();
299-
300-
for (ChunkImage chunk : chunksSnapshot) {
301-
redrawChunk(chunk, fast, cklng);
302-
}
275+
Graphics2D mg=new_main_img.createGraphics();
276+
if(!fast)
277+
mg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
278+
mg.setColor(Color.black);
279+
mg.clearRect(0, 0, win_w, win_h);
280+
281+
Graphics2D hg=height_img.createGraphics();
282+
if(!fast)
283+
{
284+
hg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
285+
hg.setColor(Color.black);
286+
hg.clearRect(0, 0, win_w, win_h);
287+
}
288+
289+
BufferedImage ckln=new BufferedImage(MAX_WIDTH, MAX_HEIGHT, BufferedImage.TYPE_INT_ARGB);
290+
Graphics2D cklng = ckln.createGraphics();
291+
292+
for (ChunkImage chunk : chunksSnapshot) {
293+
redrawChunk(chunk, fast, new_main_img, height_img, cklng);
294+
}
303295

304-
if(!fast) {
305-
WritableRaster height_raster = height_img.getRaster();
306-
int h,oh;
307-
for(int x=0; x<win_w; x++) {
308-
for(int y=0; y<win_h; y++) {
309-
h=height_raster.getSample(x, y, 0);
310-
if(x<(win_w-1) && y<(win_h-1)) oh=height_raster.getSample(x+1, y+1, 0);
311-
else oh=h;
296+
if(!fast) {
297+
WritableRaster height_raster = height_img.getRaster();
298+
int h, oh;
299+
for (int x = 0; x < win_w; x++) {
300+
for (int y = 0; y < win_h; y++) {
301+
h = height_raster.getSample(x, y, 0);
302+
if (x < (win_w - 1) && y < (win_h - 1)) {
303+
oh = height_raster.getSample(x + 1, y + 1, 0);
304+
} else {
305+
oh = h;
306+
}
312307

313-
h=h+50+(oh-h)*20;
314-
if(h<0) h=0;
315-
if (h>255) h=255;
308+
h = h + 50 + (oh - h) * 20;
309+
if (h < 0) h = 0;
310+
if (h > 255) h = 255;
316311

317-
height_raster.setSample(x, y, 0, h);
318-
}
312+
height_raster.setSample(x, y, 0, h);
319313
}
320-
mg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
321-
mg.drawImage(height_img,0,0,null);
322314
}
323-
if (showchunks)
324-
mg.drawImage(ckln, 0, 0, null);
325-
315+
mg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
316+
mg.drawImage(height_img,0,0,null);
326317
}
318+
if (showchunks)
319+
mg.drawImage(ckln, 0, 0, null);
320+
321+
main_img = new_main_img;
322+
327323
}
328324

329325
/**
330326
* Draws a single chunk.
331327
*/
332-
private void redrawChunk(ChunkImage chunk, boolean fast, Graphics2D cklng) {
328+
private void redrawChunk(ChunkImage chunk, boolean fast, BufferedImage color_img, BufferedImage height_img, Graphics2D cklng) {
333329
int win_w=getWidth();
334330
int win_h=getHeight();
335331

@@ -346,12 +342,9 @@ private void redrawChunk(ChunkImage chunk, boolean fast, Graphics2D cklng) {
346342
cklng.drawLine(x+w, y, x+w, y+h);
347343
}
348344

349-
synchronized (main_img) {
350-
Graphics2D mg=main_img.createGraphics();
351-
mg.drawImage(chunk.image, x, y, w, h, null);
352-
if(!fast)
353-
height_img.createGraphics().drawImage(chunk.height_map, x, y, w, h, null);
354-
}
345+
color_img.createGraphics().drawImage(chunk.image, x, y, w, h, null);
346+
if(!fast)
347+
height_img.createGraphics().drawImage(chunk.height_map, x, y, w, h, null);
355348
}
356349

357350
/**

Diff for: src/org/jmc/gui/ViewChunkLoaderRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void run() {
175175
}
176176
}
177177

178-
preview.redraw(true);
178+
preview.redraw(preview.fastrendermode);
179179
preview.repaint();
180180

181181

0 commit comments

Comments
 (0)