La partie C de draw_poly et des traces multiples.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3529 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Pierre Weis 2001-06-15 14:31:37 +00:00
parent b40b5c1c73
commit 9b65e594d7
2 changed files with 143 additions and 1 deletions

View File

@ -24,7 +24,7 @@ CAMLOPT=../../boot/ocamlrun ../../ocamlopt -I ../../stdlib
OBJS=open.o draw.o fill.o color.o text.o \
image.o make_img.o dump_img.o point_col.o sound.o events.o \
subwindow.o extend.o
subwindow.o draws.o
all: libgraphics.a graphics.cmi graphics.cma

142
otherlibs/graph/draws.c Normal file
View File

@ -0,0 +1,142 @@
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* en Automatique. All rights reserved. This file is distributed */
/* under the terms of the GNU Library General Public License. */
/* */
/***********************************************************************/
/* $Id $ */
#include "libgraph.h"
#include <alloc.h>
#include <memory.h>
/* Convert an array of points (represented as pairs of integers) into
a C array of points for X. */
XPoint * make_XPoints (value pts, int npoints)
{
XPoint *points;
int i;
points = (XPoint *) stat_alloc(npoints * sizeof(XPoint));
for (i = 0; i < npoints; i++) {
points[i].x = Int_val(Field(Field(pts, i), 0));
points[i].y = Bcvt(Int_val(Field(Field(pts, i), 1)));
};
return (points);
}
/* Convert an array of points (represented as pairs of integers) into
a closed path for X (an array of points with identical first and
last points). */
XPoint * make_XClosedPath (value pts, int npoints, int *pathlen)
{
XPoint *points;
int i, to_close;
to_close = 0;
if(npoints > 1) {
int x1, y1, x2, y2;
x1 = Int_val(Field(Field(pts, 0), 0));
y1 = Bcvt(Int_val(Field(Field(pts, 0), 1)));
x2 = Int_val(Field(Field(pts, (npoints - 1)), 0));
y2 = Bcvt(Int_val(Field(Field(pts, (npoints - 1)), 1)));
if((x1 != x2) || (y1 != y2)) {
to_close = 1;
}
}
*pathlen = npoints + to_close;
points = (XPoint *) stat_alloc(*pathlen * sizeof(XPoint));
for (i = 0; i < npoints; i++) {
points[i].x = Int_val(Field(Field(pts, i), 0));
points[i].y = Bcvt(Int_val(Field(Field(pts, i), 1)));
};
if(to_close == 1) {
points[npoints].x = Int_val(Field(Field(pts, 0), 0));
points[npoints].y = Bcvt(Int_val(Field(Field(pts, 0), 1)));
}
return (points);
}
value gr_plots(value pts)
{
XPoint *points;
int npoints;
gr_check_open();
npoints = Wosize_val(pts);
points = make_XPoints (pts, npoints);
if(grremember_mode)
XDrawPoints(grdisplay, grbstore.win, grbstore.gc,
points, npoints, CoordModeOrigin);
if(grdisplay_mode) {
XDrawPoints(grdisplay, grwindow.win, grwindow.gc,
points, npoints, CoordModeOrigin);
XFlush(grdisplay);
}
return Val_unit;
}
value gr_draw_poly(value pts)
{
XPoint *points;
int npoints;
gr_check_open();
npoints = Wosize_val(pts);
points = make_XClosedPath(pts, npoints, &npoints);
if(grremember_mode)
XDrawLines(grdisplay, grbstore.win, grbstore.gc,
points, npoints, CoordModeOrigin);
if(grdisplay_mode) {
XDrawLines(grdisplay, grwindow.win, grwindow.gc,
points, npoints, CoordModeOrigin);
XFlush(grdisplay);
}
return Val_unit;
}
XSegment * make_XSegments (value segs, int nsegments)
{
XSegment *segments;
int i;
segments = (XSegment *) stat_alloc(nsegments * sizeof(XSegment));
for (i = 0; i < nsegments; i++) {
segments[i].x1 = Int_val(Field(Field(segs, i), 0));
segments[i].y1 = Bcvt(Int_val(Field(Field(segs, i), 1)));
segments[i].x2 = Int_val(Field(Field(segs, i), 2));
segments[i].y2 = Bcvt(Int_val(Field(Field(segs, i), 3)));
};
return (segments);
}
value gr_draw_lines(value segs)
{
XSegment *segments;
int nsegments;
gr_check_open();
nsegments = Wosize_val(segs);
segments = make_XSegments(segs, nsegments);
if(grremember_mode)
XDrawSegments(grdisplay, grbstore.win, grbstore.gc,
segments, nsegments);
if(grdisplay_mode) {
XDrawSegments(grdisplay, grwindow.win, grwindow.gc,
segments, nsegments);
XFlush(grdisplay);
}
return Val_unit;
}