Skip to content
Merged
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 @@ -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,38 +80,40 @@ 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);
final StringBuilder[] reportHolder = new StringBuilder[] { new StringBuilder() };

ImageGcDrawer gcDrawer = (gc, width, height) -> {
StringBuilder report = new StringBuilder();
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.append(String.format("%s, %s - %.3f sec\n", testString.caption, testFunction.caption, elapsed));
}
}
}
}
}

gc.dispose();
reportHolder[0] = report;
};
Image image = new Image(shell.getDisplay(), gcDrawer, 2000, 100);
image.getImageData();
image.dispose();

MessageBox messageBox = new MessageBox(shell);
messageBox.setMessage(report);
messageBox.setMessage(reportHolder[0].toString());
messageBox.open();
}

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,22 +52,21 @@ 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;
}

static Image createItemImage(Display display) {
Image image = createImage(display);
ImageData imageData = image.getImageData();
imageData.transparentPixel = imageData.getPixel(0, 0);
imageData.transparentPixel = display.getSystemColor(SWT.COLOR_BLACK).getAlpha();

Image result = new Image(display, imageData);
image.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,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.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
Expand Down Expand Up @@ -55,12 +55,12 @@ public static void main(String[] args) {
Composite container = new Composite(shell, SWT.NONE);
container.setLayout(new RowLayout(SWT.HORIZONTAL));

Image image = new Image(display, 32, 32);
Color color = display.getSystemColor(SWT.COLOR_DARK_GREEN);
GC gc = new GC(image);
gc.setBackground(color);
gc.fillRectangle(image.getBounds());
gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
Color color = display.getSystemColor(SWT.COLOR_DARK_GREEN);
gc.setBackground(color);
gc.fillRectangle(0, 0, width, height);
};
Image image = new Image(display, imageGcDrawer, 32, 32);

Label labelText = new Label(container, SWT.NONE);
Label labelImage = new Label(container, SWT.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
Expand Down Expand Up @@ -96,13 +96,13 @@ public static void main(String[] args) {

private static Image image(Display display, int shapeColor) {
Rectangle bounds = new Rectangle(0, 0, 16, 16);
Image image = new Image(display, bounds.width, bounds.height);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
gc.fillRectangle(bounds);
gc.setBackground(display.getSystemColor(shapeColor));
gc.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
gc.fillRectangle(bounds);
gc.setBackground(display.getSystemColor(shapeColor));
gc.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
};
Image image = new Image(display, imageGcDrawer, bounds.width, bounds.height);
return image;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
Expand Down Expand Up @@ -249,11 +249,11 @@ public static void main(String[] args) {
);

// Make a small image
Image image = new Image (display, 16, 16);
GC gc = new GC(image);
gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE));
gc.fillRectangle (0, 0, 16, 16);
gc.dispose ();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE));
gc.fillRectangle (0, 0, width, height);
};
Image image = new Image (display, imageGcDrawer, 16, 16);

// And a Table to use it
Table table = new Table(shell, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,29 @@

package org.eclipse.swt.tests.manual;

import org.eclipse.swt.*;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.TextTransfer;
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.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;

public final class Bug577878_GTK_TreeTable_NoDragImageWithPaintItem {
static final int NUM_ROWS = 100;
Expand All @@ -31,17 +49,15 @@ static String makeItemText(int iRow, int iCol) {
}

static Image makeItemImage(Device device, int iRow) {
Image image = new Image(device, IMG_CX, IMG_CY);
GC gc = new GC(image);
gc.setBackground(new Color(100,255,100));
gc.fillRectangle(0, 0, IMG_CX-1, IMG_CY-1);
gc.drawRectangle(0, 0, IMG_CX-1, IMG_CY-1);

String text = Integer.toString(iRow);
Point textSize = gc.stringExtent(text);
gc.drawText(text, (IMG_CX - textSize.x) / 2, (IMG_CY - textSize.y) / 2);

gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.setBackground(new Color(100,255,100));
gc.fillRectangle(0, 0, width-1, height-1);
gc.drawRectangle(0, 0, width-1, height-1);
Point textSize = gc.stringExtent(text);
gc.drawText(text, (IMG_CX - textSize.x) / 2, (IMG_CY - textSize.y) / 2);
};
Image image = new Image(device, imageGcDrawer, IMG_CX, IMG_CY);
return image;
}

Expand Down
Loading
Loading