Returns a copy of this matrix.
The result is always writable, which means
currentmatrix
is an easy way to make a copy of a read-only matrix, like
VM.screen.defaultmatrix,
that can be modified by your program.
currentmatrix
and
setmatrix
are sometimes used in pairs when an application describes a path
in a coordinate system that has been scaled or sheared, but wants
to stroke the outline of that path in a way that hides the changes
that were made to the coordinate system.
Incidentally, one very common use of
currentmatrix
and
setmatrix
in PostScript,
namely drawing the outline of an ellipse, can usually be handled
more efficiently by passing horizontal and vertical scaling arguments
directly to the arc drawing built-ins defined in
Graphics
and
Path.
| |
| Example: |
The program,
import yoix.*.*;
JFrame f = {
Color background = Color.white;
Graphics graphics = {
int linewidth = 72/4;
int antialiasing = TRUE;
};
paint(Rectangle rect) {
Matrix mtx;
int n;
graphics { // "named block"
gsave();
rectclip(rect);
translate(size.width/2, size.height/2);
mtx = currentmatrix();
rotate(atan2(size.height, size.width)*180.0/PI);
scale(2, .5);
arc(0, 0, 1.5*72, 0, 360);
gsave(); // save the path
setrgbcolor(0, 1, 0);
fill(.3);
grestore();
setrgbcolor(1, 0, 0);
stroke(.5);
setmatrix(mtx); // too late
grestore();
}
}
};
f.visible = TRUE;
defines a paint function in a frame that fills and outlines an ellipse
that is placed at the center of the frame with its major axis on the
line that connects the frame's upper left and lower right corners.
The fractional arguments used when we fill and stroke the path
are alpha values that let part of the background show through.
We wanted the outline to be drawn in a uniform thickness, so we used
currentmatrix
and
setmatrix,
but our
setmatrix
call was too late.
See if you can figure out where it really belongs.
| | |
| Return: |
Matrix
| | |
| See Also: |
concat,
concatmatrix,
dividematrix,
dtransform,
Graphics,
identmatrix,
idtransform,
initmatrix,
invertmatrix,
itransform,
maptopixel,
rotate,
scale,
setmatrix,
shear,
transform,
translate
|
|