1 /*******************************************************************************
2  * Copyright (c) 2006, 2013 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 
15 package org.eclipse.swt.examples.graphics;
16 
17 import org.eclipse.swt.graphics.*;
18 
19 /**
20  * This tab demonstrates how an image can be scaled.
21  */
22 public class ImageScaleTab extends GraphicsTab {
23 
ImageScaleTab(GraphicsExample example)24 public ImageScaleTab(GraphicsExample example) {
25 	super(example);
26 }
27 
28 @Override
getCategory()29 public String getCategory() {
30 	return GraphicsExample.getResourceString("Image"); //$NON-NLS-1$
31 }
32 
33 @Override
getText()34 public String getText() {
35 	return GraphicsExample.getResourceString("Scale"); //$NON-NLS-1$
36 }
37 
38 @Override
getDescription()39 public String getDescription() {
40 	return GraphicsExample.getResourceString("ScaleDescription"); //$NON-NLS-1$
41 }
42 
43 @Override
paint(GC gc, int width, int height)44 public void paint(GC gc, int width, int height) {
45 	Device device = gc.getDevice();
46 	Image image = GraphicsExample.loadImage(device, GraphicsExample.class, "houses.png");
47 
48 	Rectangle bounds = image.getBounds();
49 	Rectangle canvasBounds = example.canvas.getBounds();
50 	gc.drawImage(image, 0, 0, bounds.width, bounds.height, 0, 0, canvasBounds.width, canvasBounds.height);
51 
52 	image.dispose();
53 }
54 }
55 
56