我想创建一个“选择区域”工具.
此工具应允许使用鼠标在屏幕上绘制矩形区域.
我使用全屏,半透明,变暗的swt Shell作为我的背景,我在其上绘制一个白色矩形来表示所选区域.
我的问题是我没有找到一种刷新矩形区域的有效方法.
到目前为止,我已经使用了重绘方法,但视觉效果非常难看,甚至以为我只想重绘他需要的区域:
public ManualScreenAreaSelector(final Display display) {
shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
shell.setBounds(display.getClientArea());
// shell.setFullScreen(true);
shell.setAlpha(180);
shell.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
shell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
}
@Override
public void mouseMove(final MouseEvent e) {
if (editionMode) {
// retrieve the rectangular area corresponding to mouse selection
final Rectangle r = makeRectangleFromSelection(clickCoordinates, new Point(e.x, e.y));
// make the ugly 'tint' effect