2009-02-03 4 views
2

SWT 위젯 (예 : 라벨, 프레임)을 직사각형이 아닌 다른 모양으로 만드는 방법을 알아 내려고합니다.SWT의 맞춤 위젯 모양

나는 setRegion() 메서드를 사용하여 사용자 정의 모양의 메인 윈도우를 만들었습니다. 이제 창안의 위젯이 같은 모양을 따르길 바랍니다. 위젯 자체에 setRegion() 메서드를 사용하여 시도했지만 (상속 함) 아무 일도 발생하지 않습니다.

SWT 위젯을 맞춤형으로 만들려면 어떻게해야합니까?

답변

6

나는 그것을 해결할 수있었습니다. 맞춤 영역을 정의하는 방법에 대한 오해에서 생기는 어려움이있는 것 같습니다. setBounds() 메서드는 사용자 정의 영역의 좌표계를 정의합니다. 나는 region과 setBounds가 같은 좌표계를 사용하고 있고 결과가 위젯을 전혀 표시하지 않는다고 가정하고있었습니다.

그림이 효과를 표시합니다. 왼쪽의 녹색 레이블은 메인 윈도우와 같이 곡선을 이루고 오른쪽 하단의 회색 프레임은 그렇지 않습니다.

이미지는 시도 미리보기가 아닌 게시 ​​대답에 나타납니다 http://img87.imageshack.us/my.php?image=curvecroppedwf8.png

코드 조각을이 작업을 수행 :

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);