Last active
August 29, 2015 13:57
-
-
Save jeeeyul/9798697 to your computer and use it in GitHub Desktop.
Bug430846.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.eclipse.bugs.snippet; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.graphics.GC; | |
import org.eclipse.swt.graphics.Image; | |
import org.eclipse.swt.widgets.Display; | |
import org.eclipse.swt.widgets.Event; | |
import org.eclipse.swt.widgets.Listener; | |
import org.eclipse.swt.widgets.Shell; | |
public class Bug430846 { | |
public static void main(String[] args) { | |
Display display = Display.getDefault(); | |
Shell shell = new Shell(display); | |
// each separated area size for source image | |
final int srcBlockSize = 40; | |
// each separated area size for destination | |
final int destBlockSize = 80; | |
final int destBlockGap = 10; | |
final int srcAndDestGap = 10; | |
final int gridSize = 5; | |
final int srcSize = srcBlockSize*3; | |
final Image srcImage = new Image(display, srcBlockSize * 3, srcBlockSize * 3); | |
GC gc = new GC(srcImage); | |
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); | |
gc.fillRectangle(0, 0, srcSize, srcSize); | |
// grid | |
gc.setForeground(display.getSystemColor(SWT.COLOR_GRAY)); | |
for(int x = 0; x<srcSize; x+=gridSize){ | |
gc.drawLine(x, 0, x, srcSize); | |
gc.drawLine(0, x, srcSize, x); | |
} | |
// area text | |
gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); | |
for (int row = 0; row < 3; row++) { | |
for (int col = 0; col < 3; col++) { | |
gc.drawText(row + "," + col, col * srcBlockSize, row * srcBlockSize, true); | |
} | |
} | |
gc.dispose(); | |
shell.addListener(SWT.Paint, new Listener() { | |
@Override | |
public void handleEvent(Event e) { | |
e.gc.drawImage(srcImage, 0, 0); | |
for (int row = 0; row < 3; row++) { | |
for (int col = 0; col < 3; col++) { | |
e.gc.drawImage( | |
srcImage, | |
col * srcBlockSize, row * srcBlockSize, srcBlockSize, srcBlockSize, | |
col * (destBlockSize+destBlockGap) + srcBlockSize * 3 + srcAndDestGap, row * (destBlockSize+destBlockGap), destBlockSize, destBlockSize | |
); | |
} | |
} | |
} | |
}); | |
shell.open(); | |
while (!shell.isDisposed()) { | |
if (!display.readAndDispatch()) { | |
display.sleep(); | |
} | |
} | |
display.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment