From 6186fb3eb3c00dde36a5ef7b90a15abcb46b5dcf Mon Sep 17 00:00:00 2001 From: Eric Williams Date: Tue, 3 Apr 2018 13:50:54 -0400 Subject: Bug 529431: [GTK3.10+] Snippet294 fails to draw Region Allow GtkWindow (usually Shells) to be shaped using gdk_window_shape_combine_region() instead of cairo_clip. GtkWindow is unaffected by the changes in GTK3.10 so this is fine. A snippet has been added to test this functionality, and to test for the case mentioned in comment 8 of bug 529431. Change-Id: I40c80599e015553576fc8979181577c1170146d2 Signed-off-by: Eric Williams --- .../gtk/snippets/Bug529431_ShellSetRegion.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug529431_ShellSetRegion.java (limited to 'tests') diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug529431_ShellSetRegion.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug529431_ShellSetRegion.java new file mode 100644 index 0000000000..65b0f428eb --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug529431_ShellSetRegion.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/* + * Title: Bug 529431: [GTK3.10+] Snippet294 fails to draw Region + * How to run: launch snippet and look for the resulting Shell + * Bug description: the Shell is a 200 x 200 square with no region set + * Expected results: the Shell is circle with inner circular regions + * GTK Version(s): GTK3.10+ + */ +public class Bug529431_ShellSetRegion { + + static int[] circle(int r, int offsetX, int offsetY) { + int[] polygon = new int[8 * r + 4]; + // x^2 + y^2 = r^2 + for (int i = 0; i < 2 * r + 1; i++) { + int x = i - r; + int y = (int)Math.sqrt(r*r - x*x); + polygon[2*i] = offsetX + x; + polygon[2*i+1] = offsetY + y; + polygon[8*r - 2*i - 2] = offsetX + x; + polygon[8*r - 2*i - 1] = offsetY - y; + } + return polygon; + } + + public static void main(String[] args) { + final Display display = new Display(); + + final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP + | SWT.NO_FOCUS | SWT.TOOL); + + shell.setSize(200,200); + + // define a region that looks like a circle with two holes in it + Region region = new Region(); + region.add(circle(67, 87, 77)); + region.subtract(circle(20, 87, 47)); + region.subtract(circle(20, 87, 113)); + + // define the shape of the shell using setRegion + shell.setRegion(region); + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + region.dispose(); + display.dispose(); + } + +} -- cgit v1.2.3