Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
Expand Down Expand Up @@ -1294,60 +1294,58 @@ void disposeExampleWidgets () {
}

Image colorImage (Color color) {
Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
GC gc = new GC(image);
gc.setBackground(color);
Rectangle bounds = image.getBounds();
gc.fillRectangle(0, 0, bounds.width, bounds.height);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, iwidth, iheight) -> {
gc.setBackground(color);
gc.fillRectangle(0, 0, iwidth, iheight);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawRectangle(0, 0, iwidth - 1, iheight - 1);
};
Image image = new Image (display, imageGcDrawer, IMAGE_SIZE, IMAGE_SIZE);
return image;
}

Image fontImage (Font font) {
Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
GC gc = new GC(image);
Rectangle bounds = image.getBounds();
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
gc.fillRectangle(0, 0, bounds.width, bounds.height);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
FontData data[] = font.getFontData();
int style = data[0].getStyle();
switch (style) {
case SWT.NORMAL:
gc.drawLine(3, 3, 3, 8);
gc.drawLine(4, 3, 7, 8);
gc.drawLine(8, 3, 8, 8);
break;
case SWT.BOLD:
gc.drawLine(3, 2, 3, 9);
gc.drawLine(4, 2, 4, 9);
gc.drawLine(5, 2, 7, 2);
gc.drawLine(5, 3, 8, 3);
gc.drawLine(5, 5, 7, 5);
gc.drawLine(5, 6, 7, 6);
gc.drawLine(5, 8, 8, 8);
gc.drawLine(5, 9, 7, 9);
gc.drawLine(7, 4, 8, 4);
gc.drawLine(7, 7, 8, 7);
break;
case SWT.ITALIC:
gc.drawLine(6, 2, 8, 2);
gc.drawLine(7, 3, 4, 8);
gc.drawLine(3, 9, 5, 9);
break;
case SWT.BOLD | SWT.ITALIC:
gc.drawLine(5, 2, 8, 2);
gc.drawLine(5, 3, 8, 3);
gc.drawLine(6, 4, 4, 7);
gc.drawLine(7, 4, 5, 7);
gc.drawLine(3, 8, 6, 8);
gc.drawLine(3, 9, 6, 9);
break;
}
gc.dispose();
ImageGcDrawer igc = (gc, iwidth, iheight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
gc.fillRectangle(0, 0, iwidth, iheight);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawRectangle(0, 0, iwidth - 1, iheight - 1);
FontData data[] = font.getFontData();
int style = data[0].getStyle();
switch (style) {
case SWT.NORMAL:
gc.drawLine(3, 3, 3, 8);
gc.drawLine(4, 3, 7, 8);
gc.drawLine(8, 3, 8, 8);
break;
case SWT.BOLD:
gc.drawLine(3, 2, 3, 9);
gc.drawLine(4, 2, 4, 9);
gc.drawLine(5, 2, 7, 2);
gc.drawLine(5, 3, 8, 3);
gc.drawLine(5, 5, 7, 5);
gc.drawLine(5, 6, 7, 6);
gc.drawLine(5, 8, 8, 8);
gc.drawLine(5, 9, 7, 9);
gc.drawLine(7, 4, 8, 4);
gc.drawLine(7, 7, 8, 7);
break;
case SWT.ITALIC:
gc.drawLine(6, 2, 8, 2);
gc.drawLine(7, 3, 4, 8);
gc.drawLine(3, 9, 5, 9);
break;
case SWT.BOLD | SWT.ITALIC:
gc.drawLine(5, 2, 8, 2);
gc.drawLine(5, 3, 8, 3);
gc.drawLine(6, 4, 4, 7);
gc.drawLine(7, 4, 5, 7);
gc.drawLine(3, 8, 6, 8);
gc.drawLine(3, 9, 6, 9);
break;
}
};
Image image = new Image (display, igc, IMAGE_SIZE, IMAGE_SIZE);
return image;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -177,29 +178,26 @@ public void paint(GC gc, int width, int height) {
* Height of the drawing surface
*/
Image createImage(Device device, Color color1, Color color2, int width, int height) {
Image image = new Image(device, width/2, height/2);
GC gc = new GC(image);
Rectangle rect = image.getBounds();

Pattern pattern1 = new Pattern(device, rect.x, rect.y, rect.width/2f, rect.height/2f, color1, color2);
gc.setBackgroundPattern(pattern1);
Path path = new Path(device);
path.addRectangle(0, 0, width/4f, height/4f);
path.addRectangle(width/4f, height/4f, width/4f, height/4f);
gc.fillPath(path);
path.dispose();

Pattern pattern2 = new Pattern(device, rect.width, 0, rect.width/2f, rect.height/2f, color1, color2);
gc.setBackgroundPattern(pattern2);
path = new Path(device);
path.addRectangle(width/4f, 0, width/4f, height/4f);
path.addRectangle(0, height/4f, width/4f, height/4f);
gc.fillPath(path);
path.dispose();

gc.dispose();
pattern1.dispose();
pattern2.dispose();
ImageGcDrawer igc = (gc, iwidth, iheight) -> {
Pattern pattern1 = new Pattern(device, 0, 0, iwidth/2f, iheight/2f, color1, color2);
gc.setBackgroundPattern(pattern1);
Path path = new Path(device);
path.addRectangle(0, 0, width/4f, height/4f);
path.addRectangle(width/4f, height/4f, width/4f, height/4f);
gc.fillPath(path);
path.dispose();

Pattern pattern2 = new Pattern(device, iwidth, 0, iwidth/2f, iheight/2f, color1, color2);
gc.setBackgroundPattern(pattern2);
path = new Path(device);
path.addRectangle(width/4f, 0, width/4f, height/4f);
path.addRectangle(0, height/4f, width/4f, height/4f);
gc.fillPath(path);
path.dispose();
pattern1.dispose();
pattern2.dispose();
};
Image image = new Image(device, igc, width/2, height/2);
return image;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -325,11 +326,10 @@ static Image createThumbnail(Device device, String name) {
Rectangle src = image.getBounds();
Image result = null;
if (src.width != 16 || src.height != 16) {
result = new Image(device, 16, 16);
GC gc = new GC(result);
Rectangle dest = result.getBounds();
gc.drawImage(image, src.x, src.y, src.width, src.height, dest.x, dest.y, dest.width, dest.height);
gc.dispose();
ImageGcDrawer igc = (gc, iwidth, iheight) -> {
gc.drawImage(image, src.x, src.y, src.width, src.height, 0, 0, iwidth, iheight);
};
result = new Image(device, igc, 16, 16);
}
if (result != null) {
image.dispose();
Expand All @@ -347,16 +347,15 @@ static Image createThumbnail(Device device, String name) {
*
* */
static Image createImage(Device device, Color color1, Color color2, int width, int height) {
Image image = new Image(device, width, height);
GC gc = new GC(image);
Rectangle rect = image.getBounds();
Pattern pattern = new Pattern(device, rect.x, rect.y, rect.width - 1,
rect.height - 1, color1, color2);
gc.setBackgroundPattern(pattern);
gc.fillRectangle(rect);
gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
gc.dispose();
pattern.dispose();
ImageGcDrawer igc = (gc, iwidth, iheight) -> {
Pattern pattern = new Pattern(device, 0, 0, iwidth - 1,
iheight - 1, color1, color2);
gc.setBackgroundPattern(pattern);
gc.fillRectangle(0,0,iwidth,iheight);
gc.drawRectangle(0, 0, iwidth - 1, iheight - 1);
pattern.dispose();
};
Image image = new Image(device, igc, width, height);
return image;
}

Expand All @@ -368,16 +367,15 @@ static Image createImage(Device device, Color color1, Color color2, int width, i
*
* */
static Image createImage(Device device, Color color) {
Image image = new Image(device, 16, 16);
GC gc = new GC(image);
gc.setBackground(color);
Rectangle rect = image.getBounds();
gc.fillRectangle(rect);
if (color.equals(device.getSystemColor(SWT.COLOR_BLACK))) {
gc.setForeground(device.getSystemColor(SWT.COLOR_WHITE));
}
gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
gc.dispose();
ImageGcDrawer igc = (gc, iwidth, iheight) -> {
gc.setBackground(color);
gc.fillRectangle(0,0,iwidth,iheight);
if (color.equals(device.getSystemColor(SWT.COLOR_BLACK))) {
gc.setForeground(device.getSystemColor(SWT.COLOR_WHITE));
}
gc.drawRectangle(0, 0, iwidth - 1, iheight - 1);
};
Image image = new Image(device, igc, 16, 16);
return image;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public static void main(String[] args) {
shell.setText("Advanced Graphics");
FontData fd = shell.getFont().getFontData()[0];
final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC);
final Image image = new Image(display, 640, 480);
final ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(0, 0, imageWidth, imageHeight);
};
final Image image = new Image(display,imageGcDrawer, 640, 480);
final Rectangle rect = image.getBounds();
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(rect.x, rect.y, rect.width, rect.height);
gc.dispose();

shell.addListener(SWT.Paint, event -> {
GC gc1 = event.gc;
Transform tr = new Transform(display);
Expand All @@ -61,6 +62,7 @@ public static void main(String[] args) {
if (!display.readAndDispatch())
display.sleep();
}

image.dispose();
font.dispose();
display.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,63 @@

public class Snippet104 {

public static void main(String[] args) {
final Display display = new Display();
final int [] count = new int [] {4};
final Image image = new Image(display, 300, 300);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillRectangle(image.getBounds());
gc.drawText("Splash Screen", 10, 10);
gc.dispose();
final Shell splash = new Shell(SWT.ON_TOP);
final ProgressBar bar = new ProgressBar(splash, SWT.NONE);
bar.setMaximum(count[0]);
Label label = new Label(splash, SWT.NONE);
label.setImage(image);
FormLayout layout = new FormLayout();
splash.setLayout(layout);
FormData labelData = new FormData ();
labelData.right = new FormAttachment (100, 0);
labelData.bottom = new FormAttachment (100, 0);
label.setLayoutData(labelData);
FormData progressData = new FormData ();
progressData.left = new FormAttachment (0, 5);
progressData.right = new FormAttachment (100, -5);
progressData.bottom = new FormAttachment (100, -5);
bar.setLayoutData(progressData);
splash.pack();
Rectangle splashRect = splash.getBounds();
Rectangle displayRect = display.getBounds();
int x = (displayRect.width - splashRect.width) / 2;
int y = (displayRect.height - splashRect.height) / 2;
splash.setLocation(x, y);
splash.open();
display.asyncExec(() -> {
Shell [] shells = new Shell[count[0]];
for (int i1=0; i1<count[0]; i1++) {
shells [i1] = new Shell(display);
shells [i1].setSize (300, 300);
shells [i1].addListener(SWT.Close, e -> --count[0]);
bar.setSelection(i1+1);
try {Thread.sleep(1000);} catch (Throwable e) {}
}
splash.close();
image.dispose();
for (int i2=0; i2<count[0]; i2++) {
shells [i2].setText("SWT Snippet 104 - " + (i2+1));
shells [i2].open();
public static void main(String[] args) {
final Display display = new Display();
final int[] count = new int[] { 4 };

ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillRectangle(0, 0, imageWidth, imageHeight);
gc.drawText("Splash Screen", 10, 10);
};
final Image image = new Image(display, imageGcDrawer, 300, 300);
final Shell splash = new Shell(SWT.ON_TOP);
final ProgressBar bar = new ProgressBar(splash, SWT.NONE);
bar.setMaximum(count[0]);
Label label = new Label(splash, SWT.NONE);
label.setImage(image);
FormLayout layout = new FormLayout();
splash.setLayout(layout);
FormData labelData = new FormData();
labelData.right = new FormAttachment(100, 0);
labelData.bottom = new FormAttachment(100, 0);
label.setLayoutData(labelData);
FormData progressData = new FormData();
progressData.left = new FormAttachment(0, 5);
progressData.right = new FormAttachment(100, -5);
progressData.bottom = new FormAttachment(100, -5);
bar.setLayoutData(progressData);
splash.pack();
Rectangle splashRect = splash.getBounds();
Rectangle displayRect = display.getBounds();
int x = (displayRect.width - splashRect.width) / 2;
int y = (displayRect.height - splashRect.height) / 2;
splash.setLocation(x, y);
splash.open();
display.asyncExec(() -> {
Shell[] shells = new Shell[count[0]];
for (int i1 = 0; i1 < count[0]; i1++) {
shells[i1] = new Shell(display);
shells[i1].setSize(300, 300);
shells[i1].addListener(SWT.Close, e -> --count[0]);
bar.setSelection(i1 + 1);
try {
Thread.sleep(1000);
} catch (Throwable e) {
}
}
splash.close();
image.dispose();
for (int i2 = 0; i2 < count[0]; i2++) {
shells[i2].setText("SWT Snippet 104 - " + (i2 + 1));
shells[i2].open();
}
});
while (count[0] != 0) {
if (!display.readAndDispatch())
display.sleep();
}
});
while (count [0] != 0) {
if (!display.readAndDispatch ()) display.sleep ();
display.dispose();
}
display.dispose();
}

}
Loading
Loading