Referers



JavaFX: Texture Paint

08.01.2008 | 0 Comments

Now that the JavaFX technology preview has hit the streets I'm really starting to get excited about the capabilities of this technology.  I'm building out some JavaFX bits and learning as I go and I'm very impressed with the robustness and stability of the preview.  (Actually I've been pretty impressed for a while now - I've been playing with the daily openJFX compiler builds for a couple of months now).  Kudos to all involved -- very impressive!

 Anyway - now for some code :-)  I wanted to be able to add a texture to a peice of geometry today and I realized that the java.awt.TexturePaint had not yet been included in the javax.scene.paint package.  Well the good news is, it's very easy to integrate it (or any other paint's you might already have) into JavaFX.  Here's how I did it:



package javadojo.fx.paint;

/**
* @author Ian Moore
*/


import javafx.scene.geometry.*;
import javafx.scene.paint.*;
import javafx.scene.image.*;

public class Texture extends Paint {

public attribute image : Image;

public attribute anchorRect : Rectangle;

public function getAWTPaint() : java.awt.Paint {
var rect: java.awt.Rectangle = new java.awt.Rectangle();
rect.x = anchorRect.x as Integer;
rect.y = anchorRect.y as Integer;
rect.width = anchorRect.width as Integer;
rect.height = anchorRect.height as Integer;
return new java.awt.TexturePaint(image.getBufferedImage(), rect);
}
}



 Hope someone finds this useful.  Leave me a comment if you do ;-)

« JavaFX: Using both a... | Main

Comments:

Post a Comment:
Comments are closed for this entry.