|
java-gnome version 4.0.19 | ||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectorg.freedesktop.bindings.Pointer
org.freedesktop.bindings.Proxy
org.freedesktop.cairo.Matrix
public class Matrix
A matrix describing an affine transformation.
You can apply this transformation to a Cairo Context with its
transform()
method as follows:
matrix = new Matrix(); matrix.rotate(...); // and/or matrix.scale(...); // and/or matrix.translate(...); cr.transform(matrix);Calls to the
rotate()
, scale()
, and
translate
methods are cumulative on a given Matrix.
Applying a transformation is what take you from device co-ordinates to user-space co-ordinates; you are in fact always working in the later but we tend not to focus on this as the default is naturally no transformation.
In each of the illustrations below, we draw a box as follows:
cr.setSource(0.7, 0.8, 0.8); cr.rectangle(5, 5, 25, 15); cr.stroke();We then apply the transform shown, change colour to blue, and then draw the exact same rectangle again:
cr.setSource(0.0, 0.0, 1.0); cr.rectangle(5, 5, 25, 15); cr.stroke();Thus both the original rectangle and the result of the matrix operation are shown.
Constructor Summary | |
---|---|
Matrix()
Construct a new transformation matrix with the identity (no-op) transform. |
Method Summary | |
---|---|
void |
rotate(double angle)
Rotate the transformation by the given angle. |
void |
scale(double sx,
double sy)
Scale by sx horizontally and sy vertically. |
void |
translate(double tx,
double ty)
Translate by tx horizontally and ty
vertically. |
Methods inherited from class org.freedesktop.bindings.Pointer |
---|
toString |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Matrix()
Method Detail |
---|
public void rotate(double angle)
angle
is in radians. matrix.rotate(-Math.PI / 4.0); cr.transform(matrix);
A negative angle is used in this example for the same reason as
discussed in
arc()
.
public void scale(double sx, double sy)
sx
horizontally and sy
vertically.
matrix.scale(-0.8, 1.6); cr.transform(matrix);Note that in this example the
sx
argument being negative
results in a reflection through the y axis. Note also that the
line widths are not the same as the original image's were; only
scaling by 1.0
would have left the widths alone.
Don't scale by 0
.
public void translate(double tx, double ty)
tx
horizontally and ty
vertically. matrix.translate(5, 10); cr.transform(matrix);
|
![]() java-gnome |
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |