Created
March 17, 2016 05:43
-
-
Save codenameone/3f2f8cdaabb7780eae6f to your computer and use it in GitHub Desktop.
Usage of the Shape drawing API in Codename One and GeneralPath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Form hi = new Form("Shape"); | |
// We create a 50 x 100 shape, this is arbitrary since we can scale it easily | |
GeneralPath path = new GeneralPath(); | |
path.moveTo(20,0); | |
path.lineTo(30, 0); | |
path.lineTo(30, 100); | |
path.lineTo(20, 100); | |
path.lineTo(20, 15); | |
path.lineTo(5, 40); | |
path.lineTo(5, 25); | |
path.lineTo(20,0); | |
hi.getContentPane().getUnselectedStyle().setBgPainter((Graphics g, Rectangle rect) -> { | |
g.setColor(0xff); | |
float widthRatio = ((float)rect.getWidth()) / 50f; | |
float heightRatio = ((float)rect.getHeight()) / 100f; | |
g.scale(widthRatio, heightRatio); | |
g.translate((int)(((float)rect.getX()) / widthRatio), (int)(((float)rect.getY()) / heightRatio)); | |
g.fillShape(path); | |
g.resetAffine(); | |
}); | |
hi.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of Shape & GeneralPath.
From the Codename One project