[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] Cannot layout new widgets on a non rectangular shell
|
Created from snippet 219.
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet219.java?view=co
I changed the image in the above snippet to a bigger 500*200 image which is transparent and use that.
I am trying to create a new composite on the shell created in above
step and put a label on it, but it doesn't work. All that shows up is
shell with the image.
final Display display = new Display ();
final Image image = ImageManager.getImage("info_window.png");
final Shell shell = new Shell (display, SWT.NO_TRIM);
Region region = new Region();
final ImageData imageData = image.getImageData();
if (imageData.alphaData != null) {
Rectangle pixel = new Rectangle(0, 0, 1, 1);
for (int y = 0; y < imageData.height; y++) {
for (int x = 0; x < imageData.width; x++) {
if (imageData.getAlpha(x, y) == 255) {
pixel.x = imageData.x + x;
pixel.y = imageData.y + y;
region.add(pixel);
}
}
}
} else {
ImageData mask = imageData.getTransparencyMask();
Rectangle pixel = new Rectangle(0, 0, 1, 1);
for (int y = 0; y < mask.height; y++) {
for (int x = 0; x < mask.width; x++) {
if (mask.getPixel(x, y) != 0) {
pixel.x = imageData.x + x;
pixel.y = imageData.y + y;
region.add(pixel);
}
}
}
}
shell.setRegion(region);
final Composite comp = new Composite(shell, SWT.NONE);
comp.setBackgroundMode(SWT.INHERIT_FORCE);
GridLayout layout = new GridLayout(1, false);
layout.marginRight = 10;
comp.setLayout(layout);
GridData data = "" GridData(GridData.FILL_BOTH);
comp.setLayoutData(data);
CLabel label = new CLabel(comp, SWT.WRAP);
label.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
final GridData textData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
textData.horizontalIndent = 0;
textData.verticalIndent = 0;
label.setLayoutData(textData);
label.setBackgroundMode(SWT.INHERIT_DEFAULT);
Listener l = new Listener() {
int startX, startY;
public void handleEvent(Event e) {
if (e.type == SWT.KeyDown && e.character == SWT.ESC) {
shell.dispose();
}
if (e.type == SWT.MouseDown && e.button == 1) {
startX = e.x;
startY = e.y;
}
if (e.type == SWT.MouseMove && (e.stateMask & SWT.BUTTON1) != 0) {
Point p = shell.toDisplay(e.x, e.y);
p.x -= startX;
p.y -= startY;
shell.setLocation(p);
}
if (e.type == SWT.Paint) {
e.gc.drawImage(image, imageData.x, imageData.y);
}
}
};
shell.addListener(SWT.KeyDown, l);
shell.addListener(SWT.MouseDown, l);
shell.addListener(SWT.MouseMove, l);
shell.addListener(SWT.Paint, l);
shell.setSize(imageData.x + imageData.width, imageData.y + imageData.height);
shell.layout();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
region.dispose();
image.dispose ();
display.dispose ();
}
Any idea what's wrong?
Thanks,
abhi