Skip to content
Closed
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 @@ -39,7 +39,7 @@ public void setUp() {

@Test
public void testImageDataForDifferentFractionalZoomsShouldBeDifferent() {
Image image = new Image(display, 10, 10);
Image image = new Image(display, (gc, width, height) -> {}, 10, 10);
int zoom1 = 125;
int zoom2 = 150;
ImageData imageDataAtZoom1 = image.getImageData(zoom1);
Expand All @@ -54,7 +54,7 @@ public void testImageDataForDifferentFractionalZoomsShouldBeDifferent() {
public void testImageShouldHaveDimesionAsPerZoomLevel() {
int zoom = DPIUtil.getDeviceZoom();
int scalingFactor = 2;
Image image = new Image(display, 10, 10);
Image image = new Image(display, (gc, width, height) -> {}, 10, 10);
try {
ImageData baseImageData = image.getImageData(zoom);
assertEquals("Width should equal the initial width on the same zoom", 10, baseImageData.width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.URLTransfer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.RowLayout;
Expand Down Expand Up @@ -239,18 +239,17 @@ public void testUrlTransfer() throws InterruptedException {
* Creates a DDB test image with a uniform color applied to all pixels.
*/
private Image createTestImage() {
final Image image = new Image(shell.getDisplay(), 16, 16);
try {
Color color = shell.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE);
GC gc = new GC(image);
gc.setBackground(color);
gc.fillRectangle(image.getBounds());
gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setBackground(color);
gc.fillRectangle(0, 0, width, height);
};
return new Image(shell.getDisplay(), imageGcDrawer, 16, 16);
} catch (Exception e) {
image.dispose();
fail("test image could not be initialized: " + e);
}
return image;
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
Expand All @@ -16,16 +16,15 @@ public static void main(String[] args) {
Shell shell = new Shell(disp);
shell.setSize(400, 300);
shell.setText("Pattern with alpha");
Image image = new Image(disp, 50, 50);
{
GC gc = new GC(image);
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setForeground(new Color(null, 255, 0, 0));
gc.drawLine(0, 0, 49, 49);
gc.drawLine(0, 49, 49, 0);
gc.setForeground(new Color(null, 0, 0, 200));
gc.drawString("Pat", 5, 5);
gc.dispose();
}
};
Image image = new Image(disp, imageGcDrawer, 50, 50);

final Pattern pat = new Pattern(disp, image);
shell.addPaintListener(e -> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@
*******************************************************************************/
package org.eclipse.swt.tests.win32.snippets;

import java.util.function.Consumer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;

import java.util.function.Consumer;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class Bug536008_DarkDisabledLabel {
static void moveControl(Control control, Point point) {
Expand Down Expand Up @@ -73,17 +82,13 @@ public static void main (String [] args) {
int cx = 60;
int cy = 60;
int nRow = 0;

Image image = new Image(display, cx / 2, cy / 2);
{
GC gc = new GC(image);
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setBackground(backColor);
gc.setForeground(foreColor);

Rectangle imageBounds = image.getBounds();
gc.fillRectangle(imageBounds);
gc.drawOval(imageBounds.x, imageBounds.y, imageBounds.width - 1, imageBounds.height - 1);
}
gc.fillRectangle(0, 0, width, height);
gc.drawOval(0, 0, width - 1, height - 1);
};
Image image = new Image(display, imageGcDrawer, cx / 2, cy / 2);

FillLayout fillLayout = new FillLayout();
fillLayout.marginWidth = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,28 @@
package org.eclipse.swt.tests.win32.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Bug560358_DarkMenuBar {
static Image createMenuImage(Device a_Device) {
Image result = new Image(a_Device, 16, 16);
GC gc = new GC(result);
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setBackground(a_Device.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(0, 0, width, height);

gc.setBackground(a_Device.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(0, 0, 16, 16);
gc.setForeground(a_Device.getSystemColor(SWT.COLOR_RED));
gc.drawOval(4, 4, 8, 8);
};
Image result = new Image(a_Device, imageGcDrawer, 16, 16);

gc.setForeground(a_Device.getSystemColor(SWT.COLOR_RED));
gc.drawOval(4, 4, 8, 8);

gc.dispose();
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
*******************************************************************************/
package org.eclipse.swt.tests.win32.snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class Bug560546_GC_drawString_vs_GC_drawText {
static Font fontSegoeUI;
Expand Down Expand Up @@ -73,39 +80,37 @@ void function(GC gc, int x, int y, String string) {

static void testSpeeds(Shell shell) {
final int finalIterations = 20 * 1000;
String report = "";

Image image = new Image(shell.getDisplay(), 2000, 100);
GC gc = new GC(image);
for (int isFinalCalc = 0; isFinalCalc < 2; isFinalCalc++) {
for (int iTestString = 0; iTestString < testStrings.length; iTestString++) {
for (int iTestFunction = 0; iTestFunction < testFunctions.length; iTestFunction++) {
TestString testString = testStrings[iTestString];
TestFunction testFunction = testFunctions[iTestFunction];

// Warm up before measuring
final int iterations = (isFinalCalc != 0) ? finalIterations : 10;

final long time1 = System.nanoTime();
for (int iIteration = 0; iIteration < iterations; iIteration++) {
testFunction.function(gc, 0, 0, testString.string);
}
final long time2 = System.nanoTime();

if (isFinalCalc != 0) {
final double elapsed = (time2 - time1) / 1000000000.0;
report += String.format("%s, %s - %.3f sec\n", testString.caption, testFunction.caption, elapsed);
ImageGcDrawer gcDrawer = (gc, width, height) -> {
String report = "";
for (int isFinalCalc = 0; isFinalCalc < 2; isFinalCalc++) {
for (int iTestString = 0; iTestString < testStrings.length; iTestString++) {
for (int iTestFunction = 0; iTestFunction < testFunctions.length; iTestFunction++) {
TestString testString = testStrings[iTestString];
TestFunction testFunction = testFunctions[iTestFunction];

// Warm up before measuring
final int iterations = (isFinalCalc != 0) ? finalIterations : 10;

final long time1 = System.nanoTime();
for (int iIteration = 0; iIteration < iterations; iIteration++) {
testFunction.function(gc, 0, 0, testString.string);
}
final long time2 = System.nanoTime();

if (isFinalCalc != 0) {
final double elapsed = (time2 - time1) / 1000000000.0;
report += String.format("%s, %s - %.3f sec\n", testString.caption, testFunction.caption, elapsed);
}
}
}
}
}

gc.dispose();
MessageBox messageBox = new MessageBox(shell);
messageBox.setMessage(report);
messageBox.open();
};
Image image = new Image(shell.getDisplay(), gcDrawer, 2000, 100);
image.getImageData();
image.dispose();

MessageBox messageBox = new MessageBox(shell);
messageBox.setMessage(report);
messageBox.open();
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand Down Expand Up @@ -52,14 +52,13 @@ static void setColors(Control control, Color backColor, Color foreColor) {
static Image createImage(Display display) {
Color transparentColor = display.getSystemColor(SWT.COLOR_BLACK);

Image image = new Image(display, 16, 16);

GC gc = new GC(image);
gc.setBackground(transparentColor);
gc.fillRectangle(image.getBounds());
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(6, 6, 4, 4);
gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setBackground(transparentColor);
gc.fillRectangle(0, 0, width, height);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(6, 6, 4, 4);
};
Image image = new Image(display, imageGcDrawer, 16, 16);

return image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public static boolean hasPixel(Control control, Color expectedColor) {
*/
public static boolean hasPixel(Control control, Color expectedColor, Rectangle rect) {
GC gc = new GC(control);
final Image image = new Image(control.getDisplay(), control.getSize().x, control.getSize().y);
final Image image = new Image(control.getDisplay(), (iGc, width, height) -> {}, control.getSize().x, control.getSize().y);
gc.copyArea(image, 0, 0);
gc.dispose();
boolean result = hasPixel(image, expectedColor, rect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.LineAttributes;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -849,20 +850,16 @@ public void test_bug1288_createGCFromImageFromNonDisplayThread() throws Interrup
* (16bpp or less).
*/
RGB getRealRGB(Color color) {
Image colorImage = new Image(display, 10, 10);
GC imageGc = new GC(colorImage);
ImageData imageData;
PaletteData palette;
int pixel;

imageGc.setBackground(color);
imageGc.setForeground(color);
imageGc.fillRectangle(0, 0, 10, 10);
imageData = colorImage.getImageData();
palette = imageData.palette;
imageGc.dispose();
ImageGcDrawer gcDrawer = (imageGc, width, height) -> {
imageGc.setBackground(color);
imageGc.setForeground(color);
imageGc.fillRectangle(0, 0, width, height);
};
Image colorImage = new Image(display, gcDrawer, 10, 10);
ImageData imageData = colorImage.getImageData();
PaletteData palette = imageData.palette;
colorImage.dispose();
pixel = imageData.getPixel(0, 0);
int pixel = imageData.getPixel(0, 0);
return palette.getRGB(pixel);
}

Expand Down
Loading
Loading