Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Mirah/SWTSnippets/Snippet10"

(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>/***********************************...)
 
Line 1: Line 1:
Compare with [http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet6.java?view=co the original].
+
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, 2005 IBM Corporation and others.
 
  * Copyright (c) 2000, 2005 IBM Corporation and others.

Revision as of 14:56, 27 March 2011

Compare with the original.

/*******************************************************************************
 * Copyright (c) 2000, 2005 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
 *******************************************************************************/
package org.eclipse.swt.snippets

/*
 * 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 0-30  # https://github.com/mirah/mirah/issues/71
	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

Back to the top