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
2 changes: 1 addition & 1 deletion examples/org.eclipse.swt.examples/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.SWTStandaloneExampleSet.name
Bundle-SymbolicName: org.eclipse.swt.examples; singleton:=true
Bundle-Version: 3.108.1000.qualifier
Bundle-Version: 3.108.1100.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Expand Down
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
Loading