blob: f239b1f0423fd9c2f085e4ef697b6ff8e05e3348 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2010 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.draw2d.test;
import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
public class GraphicsClipping extends AbstractFixtureTestCase {
private Image image;
private GC gc;
private SWTGraphics graphics;
public void testSimpleClip() {
Rectangle rect = new Rectangle(14, 21, 30, 40);
graphics.setClip(rect);
graphics.drawPoint(0, 0);
assertEquals(gcClipping(), rect);
rect.translate(5, 5);
graphics.clipRect(rect);
graphics.drawPoint(0, 0);
rect.resize(-5, -5);
assertEquals(rect, gcClipping());
}
private Rectangle gcClipping() {
return new Rectangle(gc.getClipping());
}
private Rectangle graphicsClip() {
return graphics.getClip(new Rectangle());
}
public void testTranslatedClip() {
Rectangle rect = new Rectangle(14, 21, 300, 400);
graphics.setClip(rect);
graphics.translate(9, 7);
graphics.drawPoint(0, 0);
assertEquals(rect, gcClipping());
rect.translate(-9, -7);
assertEquals(rect, graphicsClip());
Rectangle intersect = new Rectangle(50, 50, 50, 50);
graphics.clipRect(intersect);
rect.intersect(intersect);
graphics.drawPoint(0, 0);
assertEquals(graphicsClip(), rect);
rect.translate(9, 7);
assertEquals(gcClipping(), rect);
}
public void testZoomedClip() {
Rectangle rect = new Rectangle(14, 21, 300, 400);
graphics.setClip(rect);
graphics.scale(2.0);
graphics.translate(90, 0);
graphics.drawPoint(0, 0);
rect.scale(0.5);
rect.translate(-90, 0);
assertEquals(graphicsClip(), rect);
}
protected void setUp() throws Exception {
super.setUp();
image = new Image(display, 800, 600);
gc = new GC(image.getDevice());
graphics = new SWTGraphics(gc);
}
protected void tearDown() throws Exception {
graphics.dispose();
gc.dispose();
image.dispose();
super.tearDown();
}
}