mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 20:33:55 +00:00
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.
55 lines
1.7 KiB
Mathematica
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.
|
|
%----------------------------------------------------------------------------%
|