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

Mirah/SWTSnippets/Snippet10

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
 *******************************************************************************/
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(-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

Back to the top