Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Mirah/SWTSnippets/Snippet10"
< Mirah | SWTSnippets
(New page: Compare with [http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet6.java?view=co the original]. <pre>/***********************************...) |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | Compare with [http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/ | + | Compare with [http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet10.java?view=co the original]. |
<pre>/******************************************************************************* | <pre>/******************************************************************************* | ||
− | * Copyright (c) 2000, | + | * Copyright (c) 2000, 2011 IBM Corporation and others. |
* All rights reserved. This program and the accompanying materials | * All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | * are made available under the terms of the Eclipse Public License v1.0 | ||
Line 10: | Line 10: | ||
* IBM Corporation - initial API and implementation | * IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | *******************************************************************************/ | ||
− | |||
/* | /* | ||
Line 39: | Line 38: | ||
tr = Transform.new display | tr = Transform.new display | ||
tr.translate 50, 120 | tr.translate 50, 120 | ||
− | tr.rotate | + | tr.rotate(-30) |
gc.drawImage image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2 | gc.drawImage image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2 | ||
gc.setAlpha 100 | gc.setAlpha 100 |
Latest revision as of 16:47, 28 March 2011
Compare with the original.
/******************************************************************************* * Copyright (c) 2000, 2011 IBM Corporation 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: * IBM Corporation - initial API and implementation *******************************************************************************/ /* * Draw using transformations, paths and alpha blending * * For a list of SWT example snippets ported to Mirah, see * http://wiki.eclipse.org/Mirah/SWTSnippets * * @since 3.1 */ import org.eclipse.swt.* import org.eclipse.swt.graphics.* import org.eclipse.swt.widgets.* display = Display.new shell = Shell.new display shell.setText "Advanced Graphics" fd = shell.getFont.getFontData[0] font = Font.new display, fd.getName, 60, SWT.BOLD | SWT.ITALIC image = Image.new display, 640, 480 rect = image.getBounds gc = GC.new image gc.setBackground display.getSystemColor(SWT.COLOR_RED) gc.fillOval rect.x, rect.y, rect.width, rect.height gc.dispose shell.addListener(SWT.Paint) do |event| gc = event.gc tr = Transform.new display tr.translate 50, 120 tr.rotate(-30) gc.drawImage image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2 gc.setAlpha 100 gc.setTransform tr path = Path.new display path.addString "SWT", 0, 0, font gc.setBackground display.getSystemColor(SWT.COLOR_GREEN) gc.setForeground display.getSystemColor(SWT.COLOR_BLUE) gc.fillPath path gc.drawPath path tr.dispose path.dispose end shell.setSize shell.computeSize(rect.width / 2, rect.height / 2) shell.open until shell.isDisposed unless display.readAndDispatch display.sleep end end image.dispose font.dispose display.dispose