|
java-gnome version 4.0.7 | ||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||
java.lang.Objectorg.freedesktop.bindings.Proxy
org.freedesktop.cairo.Context
public class Context
Carry out drawing operations with the Cairo Graphics library. The current Context contains the state of the rendering engine, including the co-ordinates of as yet undrawn elements.
ImageSurface, do your drawing, and then use Surface's writeToPNG()
to output your image.
EXPOSE_EVENT, and do your
drawing there.
It is somewhat traditional to call your Context cr.
All of the methods on Context take arguments of type double
to represent co-ordinates, angles, colours, transparency levels, etc.
Colours are represented as values between 0.0 and
0.1, for example:
cr.setSourceRGB(1.0, 0.0, 0.0);for solid red. In the case of co-ordinates, you can simply specify the pixel address you wish to move to or draw to:
cr.moveTo(10, 10); cr.lineTo(90, 50); cr.stroke();where stroke draws the current path with the current line thickness.
Various other drawing operations are done by creating a shape and then
filling it in:
cr.rectangle(30, 20, 60, 60); cr.fill();and so on.
Obviously this is only the beginning of our documentation for Cairo.
| Constructor Summary | |
|---|---|
Context(Drawable drawable)
Construct a new "Cairo Context" related to a Drawable. |
|
Context(Surface target)
Construct a new "Cairo Context". |
|
| Method Summary | |
|---|---|
void |
arc(double xc,
double yc,
double radius,
double angle1,
double angle2)
Adds a circular arc of the given radius to the current path. |
void |
arcNegative(double xc,
double yc,
double radius,
double angle1,
double angle2)
Adds a circular arc of the given radius to the current path. |
void |
fill()
Fill the current path, implicitly closing sub-paths first. |
void |
fillPreserve()
|
Pattern |
getSource()
Get the current source Pattern for this Context. |
Surface |
getTarget()
Get the Surface that this Context is drawing on. |
void |
lineTo(double x,
double y)
Add a line from the current location to x,y. |
void |
mask(Pattern pattern)
Paint the current source using the alpha channel of pattern as a mask. |
void |
moveTo(double x,
double y)
Move to a new location without drawing, beginning a new sub-path. |
void |
paint()
Paint the current source everywhere within the current clip region. |
void |
rectangle(double x,
double y,
double width,
double height)
Draw a (closed) rectangular sub-path. |
void |
setAntialias(Antialias antialias)
Set the antialiasing mode of the rasterizer used for drawing shapes. |
void |
setLineWidth(double width)
Set the line width for this Context. |
void |
setOperator(Operator op)
Set the operation that will govern forthcoming compositing actions. |
void |
setSource(Pattern pattern)
Set a Pattern to be the source of this Context. |
void |
setSourceRGB(double red,
double green,
double blue)
Set the source pattern within this Context to an opaque colour. |
void |
setSourceRGBA(double red,
double green,
double blue,
double alpha)
Set the source pattern within this Context to a translucent colour. |
void |
setSourceSurface(Surface surface,
double x,
double y)
Create a Pattern from a Surface, and then use it in this Context. |
void |
stroke()
Draw the current path as a line. |
| Methods inherited from class org.freedesktop.bindings.Proxy |
|---|
toString |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Context(Drawable drawable)
You may find yourself needing to get at the Surface that is being drawn
on. Use getTarget().
Strictly speaking, this method is a part of GDK. We expose it here as we are, from the Java bindings' perspective, constructing a Cairo Context. So a constructor it is.
public Context(Surface target)
| Method Detail |
|---|
public void arc(double xc,
double yc,
double radius,
double angle1,
double angle2)
xc,yc, begins at angle1 and
proceeds in the direction of increasing angles to end at
angle2. If angle2 is less than
angle1 it will be progressively increased by
2π until it is greater than angle1.
If there is a current point, an initial line segment will be added to the path to connect the current point to the beginning of the arc.
Angles are measured in radians. An angle of 0.0 is in
the direction of the positive x axis. An angle of
π/2 radians (90°) is in the direction of the
positive y axis. Angles increase in the direction from the
positive x axis toward the positive axis, increasing in a
clockwise direction.
This function gives the arc in the direction of increasing angles; see
arcNegative()
to go the other direction.
public void arcNegative(double xc,
double yc,
double radius,
double angle1,
double angle2)
xc,yc, begins at angle1 and
proceeds in the direction of decreasing angles to end at
angle2. If angle2 is greater than
angle1 it will be progressively decreased by
2π until it is less than angle1.
See arc() for
drawing in the positive direction.
public void fill()
fill(); if you want to keep it
use fillPreserve() instead.
public void fillPreserve()
public Pattern getSource()
public Surface getTarget()
Yes, this method has a stupid name. It really should be
getSurface(). So many people have a hard time finding
the generic method that allows you to get to the Surface that they're
considering renaming this to cairo_get_surface in Cairo
itself, but until they do, we'll stick with the algorithmic mapping of
cairo_get_target.
public void lineTo(double x,
double y)
x,y.
After the call the current point will be x,y.
public void mask(Pattern pattern)
pattern as a mask. This means "opaque areas of the mask
will be painted with the source, whereas transparent areas will not be
painted"
public void moveTo(double x,
double y)
x,y.
public void paint()
public void rectangle(double x,
double y,
double width,
double height)
x,y in user-space coordinates of the
given width and height.
public void setAntialias(Antialias antialias)
public void setLineWidth(double width)
stroke(). Default value is 2.0.
public void setOperator(Operator op)
One particularly useful sequence is clearing the Surface to all transparent pixels:
cr.setOperator(Operator.CLEAR); cr.paint();
public void setSource(Pattern pattern)
public void setSourceRGB(double red,
double green,
double blue)
0.0 to 1.0.
public void setSourceRGBA(double red,
double green,
double blue,
double alpha)
0.0 to 1.0.
For the alpha parameter, a value of 0.0
indicates full transparency, and 1.0 is full opacity
(ie, normal).
public void setSourceSurface(Surface surface,
double x,
double y)
x,y define where, in user-space
coordinates, that the Pattern should appear.
You can get the Pattern that was created internally by calling this
with getSource() and manipulate it further if you
need to change the defaults.
public void stroke()
|
![]() java-gnome |
||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||