Java Reference
In-Depth Information
new TexturePaint (
buff,
new Rectangle2D.Double(0,0,64,52)
);
}
}
def w = 400;
def h = 200;
def circle = Circle {
centerX:w/2 centerY:h/2
radius:75
fill: CustomPaint {url:"{__DIR__}texture.png"}
stroke:Color.BLACK
strokeWidth:3
};
When the code is executed, it renders a circle that is painted with the textured paint returned
by the CustomPaint class as shown in the following screenshot:.
How it works...
The previous code snippet shows how to extend the Paint class to create a customized
Paint class that can be used to fill shapes. In this recipe, we will create class CustomPaint
to be used as textured paint. The class takes an arbitrary image file and use its content as the
textured paint applied to the shape object. Let's examine how that is done in the code:
F CustomPaint class —is used to create our customized paint, we extend the abstract
class Paint . Our class exposes the url:String property, which is a value that
contains the URL location of the image to be used as the textured background for
the paint.
F Function impl_getPlatformPaint —this is a required function that must be
implemented when extending the Paint class. It is expected to return an Object
instance that can be used as Paint instance.
 
Search WWH ::




Custom Search