[Commit]
CairoJava/test/org/cairographics/cairo/test TestCairo.java,
NONE, 1.1 TestCairoImage.java, NONE, 1.1
Soorya Kuloor
commit at keithp.com
Wed Aug 6 12:54:05 PDT 2003
Committed by: skuloor
Update of /local/src/CVS/CairoJava/test/org/cairographics/cairo/test
In directory home.keithp.com:/tmp/cvs-serv20525/test/org/cairographics/cairo/test
Added Files:
TestCairo.java TestCairoImage.java
Log Message:
Initial checkin
--- NEW FILE: TestCairo.java ---
/*
* $Id: TestCairo.java,v 1.1 2003/08/06 18:54:02 skuloor Exp $
*
* Copyright (C) 2003 Verano
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* Verano not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
* Verano makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* VERANO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* VERANO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package org.cairographics.cairo.test;
import org.cairographics.cairo.Cairo;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* This class tests Xr by doing some basic drawings
*/
public class TestCairo extends Shell {
public TestCairo() {
super();
this.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
TestCairo.this.repaint(e);
}
});
}
public void repaint(PaintEvent e) {
org.eclipse.swt.graphics.Rectangle size = getBounds();
Image img = new Image(getDisplay(), size.width, size.height);
Cairo cairo = new Cairo(img);
//cairo.save();
cairo.setColor(1, 0, 0.5);
cairo.setTolerance(0.4);
cairo.setLineWidth(1);
cairo.rect(110, 110, 300, 300, 0, 0);
cairo.stroke();
//cairo.clip();
cairo.setAlpha(0.3);
cairo.ellipse(200, 200, 70, 75);
cairo.fill();
cairo.save();
cairo.setAlpha(1.0);
cairo.moveTo(200, 200);
cairo.setColor(0.0, 0.5, 0.3);
cairo.selectFont("Bitstream Vera Serif:normal:normal");
cairo.scaleFont(15.0);
cairo.showText("Hello how are you?");
//cairo.rect(200, 200-20, 400, 20, 0, 0);
//Xr.TextExtents ext = cairo.getTextExtents("Hello how are you?");
cairo.stroke();
cairo.restore();
cairo.setAlpha(1);
cairo.rect(280, 220, 50, 65, 10, 10);
cairo.stroke();
cairo.restore();
cairo.dispose();
e.gc.drawImage(img, 0, 0);
img.dispose();
}
public static void main(String[] args) {
Display display = Display.getDefault();
TestCairo shell = new TestCairo();
shell.open();
shell.setText("Cairo Test");
shell.setSize(500, 500);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
--- NEW FILE: TestCairoImage.java ---
/*
* $Id: TestCairoImage.java,v 1.1 2003/08/06 18:54:02 skuloor Exp $
*
* Copyright (C) 2003 Verano
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* Verano not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
* Verano makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* VERANO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* VERANO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package org.cairographics.cairo.test;
import org.cairographics.cairo.Cairo;
import org.cairographics.cairo.CairoImage;
import org.cairographics.cairo.CairoSurface;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* This class tests Xr by doing some basic drawings
*/
public class TestCairoImage extends Shell {
public TestCairoImage() {
super();
this.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
TestCairoImage.this.paintWithCairoImage(e);
}
});
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if ((e.character == 'q') || (e.character == 'Q')) {
TestCairoImage.this.close();
}
}
});
}
void draw_stuff(Cairo cairo) {
org.eclipse.swt.graphics.Rectangle size = getBounds();
/*
* First group
*/
cairo.save();
cairo.setColor(1., 1., 1.);
cairo.rect(0, 0, size.width, size.height, 0, 0);
cairo.fill();
/*
* Second level group
*/
cairo.save();
/*
* First rectangle
*/
cairo.save();
cairo.setColor(123.0 / 255.0, 23.0 / 255.0, 250.0 / 255.0);
cairo.rotate(Math.PI / 4.0);
cairo.rect(430, 30, 100, 50, 0.0, 0.0);
cairo.fill();
cairo.restore();
/*
* Second rectangle
*/
cairo.save();
cairo.setLineWidth(4.0);
cairo.setColor(1.0, 0.0, 0.0);
cairo.rect(100, 100, 65, 100, 0.0, 0.0);
cairo.stroke();
cairo.restore();
/*
* Third level group
*/
cairo.save();
cairo.setColor(0.0, 1.0, 0.0);
/*
* Circle
*/
cairo.save();
cairo.setColor(128.0 / 255.0, 0.0, 128.0 / 255.0);
cairo.ellipse(300, 100, 50, 50);
cairo.fill();
cairo.setColor(0.0, 1.0, 0.0);
cairo.stroke();
cairo.setColor(128.0 / 255.0, 0.0, 128.0 / 255.0);
cairo.restore();
/*
* Ellipse
*/
cairo.save();
cairo.setLineWidth(2.0);
cairo.ellipse(300, 200, 50, 75);
cairo.stroke();
cairo.restore();
cairo.restore();
/*
* Polyline
*/
double dashes[] = {3.0, 2.0};
cairo.save();
cairo.setLineWidth(1.0);
cairo.setDash(dashes, 0.0);
cairo.setColor(178.0 / 255.0, 34.0 / 255.0, 34.0 / 255.0);
cairo.moveTo(100.0, 100);
cairo.lineTo(150, 145);
cairo.lineTo(130, 300);
cairo.lineTo(250, 200);
cairo.stroke();
cairo.restore();
/*
* Polygon
*/
cairo.save();
cairo.setColor(1.0, 0, 1);
cairo.moveTo(320, 170);
cairo.lineTo(395, 280);
cairo.lineTo(500, 300);
cairo.lineTo(400, 400);
cairo.lineTo(350, 450);
cairo.closePath();
cairo.fill();
cairo.restore();
cairo.restore();
cairo.restore();
}
/**
* Paints using a local image buffer. Does not use the Render extension, uses libic.
*
* @param e The paint event object.
*/
public void paintWithCairoImage(PaintEvent e) {
org.eclipse.swt.graphics.Rectangle size = getBounds();
long t1 = System.currentTimeMillis();
CairoImage img = new CairoImage(e.width, e.height);
CairoSurface sf = new CairoSurface(img);
Cairo cairo = new Cairo(sf);
cairo.translate(-e.x, -e.y);
long t2 = System.currentTimeMillis();
draw_stuff(cairo);
cairo.dispose();
img.drawOn(e.widget, e.gc, e.x, e.y);
long t3 = System.currentTimeMillis();
sf.dispose();
img.dispose();
System.out.println("CairoImage drawing time: " + (t3 - t1) + " msecs");
}
/**
* Paints on a pixmap. Required Render extension.
*
* @param e The paint event object
*/
public void paintWithImage(PaintEvent e) {
org.eclipse.swt.graphics.Rectangle size = getBounds();
Image img = new Image(getDisplay(), e.width, e.height);
long t1 = System.currentTimeMillis();
Cairo cairo = new Cairo(img);
cairo.translate(-e.x, -e.y);
long t2 = System.currentTimeMillis();
draw_stuff(cairo);
cairo.dispose();
long t3 = System.currentTimeMillis();
e.gc.drawImage(img, e.x, e.y);
img.dispose();
System.out.println("Image drawing time: " + (t3 - t1) + " msecs");
}
public static void main(String[] args) {
System.out.println("Inside main...");
Display display = Display.getDefault();
TestCairoImage shell = new TestCairoImage();
shell.open();
shell.setText("Xr/Image Test");
shell.setSize(600, 550);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
System.out.println("Main done...");
}
}
More information about the Commit
mailing list