summaryrefslogtreecommitdiff
path: root/otherlibs/graph/fill.c
blob: 50b6d32e9d68e38e4de9f41e0e9a5cc6e33bcbb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***********************************************************************/
/*                                                                     */
/*                           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 <memory.h>

value gr_fill_rect(value vx, value vy, value vw, value vh)
{
  int x = Int_val(vx);
  int y = Int_val(vy);
  int w = Int_val(vw);
  int h = Int_val(vh);

  gr_check_open();
  XFillRectangle(grdisplay, grwindow.win, grwindow.gc,
                 x, Wcvt(y) - h + 1, w, h);
  XFillRectangle(grdisplay, grbstore.win, grbstore.gc,
                 x, Bcvt(y) - h + 1, w, h);
  XFlush(grdisplay);
  return Val_unit;
}

value gr_fill_poly(value array)
{
  XPoint * points;
  int npoints, i;

  gr_check_open();
  npoints = Wosize_val(array);
  points = (XPoint *) stat_alloc(npoints * sizeof(XPoint));
  for (i = 0; i < npoints; i++) {
    points[i].x = Int_val(Field(Field(array, i), 0));
    points[i].y = Wcvt(Int_val(Field(Field(array, i), 1)));
  }
  XFillPolygon(grdisplay, grwindow.win, grwindow.gc, points,
               npoints, Complex, CoordModeOrigin);
  for (i = 0; i < npoints; i++) {
    points[i].y = WtoB(points[i].y);
  }
  XFillPolygon(grdisplay, grbstore.win, grbstore.gc, points,
               npoints, Complex, CoordModeOrigin);
  XFlush(grdisplay);
  stat_free((char *) points);
  return Val_unit;
}

value gr_fill_arc_nat(value vx, value vy, value vrx, value vry, value va1, value va2)
{
  int x = Int_val(vx);
  int y = Int_val(vy);
  int rx = Int_val(vrx);
  int ry = Int_val(vry);
  int a1 = Int_val(va1);
  int a2 = Int_val(va2);

  gr_check_open();
  XFillArc(grdisplay, grwindow.win, grwindow.gc,
           x - rx, Wcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64);
  XFillArc(grdisplay, grbstore.win, grbstore.gc,
           x - rx, Bcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64);
  XFlush(grdisplay);
  return Val_unit;
}

value gr_fill_arc(value *argv, int argc)
{
  return gr_fill_arc_nat(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
}