Files
mercury/extras/graphics/mercury_cairo/samples/imagepattern.m
Julien Fischer 7a85f13389 Add a Mercury binding to the cairo 2D graphics library to the extras
distribution.  (For further information see, <http://www.cairographics.org/>.)
The binding is currently fairly complete (enough for the cairo sample and
tutorial programs to be work in Mercury).  The main things missing are:

   * scaled fonts
   * a few operations on patterns (grep for NYI)
   * support for X, Quartz, or Win32 surfaces
   * font backends other than the builtin toy one

TODO: I'll add README files, Makefiles, update the NEWS file, etc
in a separate change.

extras/graphics/mercury_cairo/*.m:
extras/graphics/mercury_cairo/tutorial/*.m:
extras/graphics/mercury_cairo/samples/*.m:
extras/graphics/mercury_cairo/samples/data/*.png:
	Add the Mercury cairo binding.
2010-09-05 14:31:46 +00:00

55 lines
1.7 KiB
Mathematica

:- module imagepattern.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%----------------------------------------------------------------------------%
%----------------------------------------------------------------------------%
:- implementation.
:- import_module cairo.
:- import_module cairo.image.
:- import_module cairo.matrix.
:- import_module cairo.path.
:- import_module cairo.pattern.
:- import_module cairo.png.
:- import_module cairo.transformations.
:- import_module float.
:- import_module math.
%----------------------------------------------------------------------------%
main(!IO) :-
cairo.image.create_surface(format_argb32, 256, 256, Surface, !IO),
cairo.create_context(Surface, Context, !IO),
image_surface_create_from_png("data/romedalen.png", Image, !IO),
image.get_width(Image, W, !IO),
image.get_height(Image, H, !IO),
pattern.create_for_surface(Image, Pattern, !IO),
pattern.set_extend(Pattern, extend_repeat, !IO),
transformations.translate(Context, 128.0, 128.0, !IO),
transformations.rotate(Context, pi / 4.0, !IO),
transformations.scale(Context, 1.0 / sqrt(2.0), 1.0 / sqrt(2.0), !IO),
transformations.translate(Context, -128.0, -128.0, !IO),
matrix.init_scale(float(W) / 256.0 * 5.0, float(H) / 256.0 * 5.0, Matrix, !IO),
pattern.set_matrix(Pattern, Matrix, !IO),
cairo.set_source(Context, Pattern, !IO),
path.rectangle(Context, 0.0, 0.0, 256.0, 256.0, !IO),
cairo.fill(Context, !IO),
write_surface_to_png(Surface, "imagepattern.png", !IO).
%----------------------------------------------------------------------------%
:- end_module imagepattern.
%----------------------------------------------------------------------------%