SWT中的自定义窗口小部件形状 [英] Custom widget shapes in SWT

查看:131
本文介绍了SWT中的自定义窗口小部件形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试研究如何使SWT小部件(例如Label,Frame)成为矩形以外的形状。

I'm trying to work out how to make SWT widgets (e.g. Label, Frame) be some shape other than rectangular.

我做了一个定制的形状主窗口使用setRegion()方法。现在我希望窗口中的小部件遵循相同的形状。我尝试在小部件上使用setRegion()方法(它们继承它)但没有任何反应。

I've made a custom shaped main window using the setRegion() method. Now I would like the widgets in the window to follow the same shape. I've tried using the setRegion() method on the widgets themselves (they inherit it) but nothing happens.

如何使SWT小部件具有自定义形状?

How do I make an SWT widget have a custom shape?

推荐答案

我已成功解决了问题。似乎我的困难来自对如何定义自定义区域的误解。 setBounds()方法定义自定义区域的坐标系。我假设区域和setBounds使用相同的坐标系,结果根本没有显示小部件。

I've managed to work it out. It seems my difficulty was arising from a misunderstanding of how to define a custom region. The setBounds() method defines the coordinate system for the custom region. I was assuming the region and setBounds were using the same coordinate system and the result was not displaying the widget at all.

图片显示效果。左边的绿色标签像主窗口一样弯曲,而右下角的灰色框架则不是。

The picture displays the effect. The green label on the left curves like the main window, while the grey frame on the bottom right corner doesn't.

图像出现在预览中但不是已发布的答案,请尝试:
http://img87.imageshack.us/my.php?image=curvecroppedwf8.png

The image appears in the preview but not the posted answer, try: http://img87.imageshack.us/my.php?image=curvecroppedwf8.png

执行此操作的代码片段:

The code fragments to do this:

Display display = Display.getDefault();
Shell shell new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);

// make the region for the main window
// circle is a method that returns a list of points defining a circle
Region region = new Region();
region.add(350, 0, 981, 51);
region.add(circle(380,51,30));
region.add(circle(951,51,30));
region.add(380, 51, 571, 30);
shell.setRegion(region);
Rectangle rsize = region.getBounds();
shell.setSize(rsize.width, rsize.height);

Composite main = new Composite(shell, SWT.NULL);

// make the label
cpyLbl = new Label(main, SWT.NONE);
cpyLbl.setText("Copy");

cpyLbl.setBackground(SWTResourceManager.getColor(38,255,23));

Region cpyRegion = new Region();
cpyRegion.add(0, 0, 161, 51);
cpyRegion.add(circle(28,51,28));
cpyRegion.add(28, 51, 133, 28);
cpyLbl.setRegion(cpyRegion);

// the top left of the bounds is the 0,0 of the region coordinates
// bounds are in screen coordinates (maybe shell coordinates?)
cpyLbl.setBounds(352, 0, 161, 79);
cpyLbl.setVisible(true);

这篇关于SWT中的自定义窗口小部件形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆