summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--otherlibs/graph/draw.c32
-rw-r--r--otherlibs/graph/graphics.ml7
-rw-r--r--otherlibs/graph/graphics.mli16
3 files changed, 47 insertions, 8 deletions
diff --git a/otherlibs/graph/draw.c b/otherlibs/graph/draw.c
index 8b6efac0d..485e3828b 100644
--- a/otherlibs/graph/draw.c
+++ b/otherlibs/graph/draw.c
@@ -36,13 +36,14 @@ value gr_moveto(value vx, value vy)
return Val_unit;
}
-value gr_current_point(void)
+value gr_current_x(void)
{
- value res;
- res = alloc_small(2, 0);
- Field(res, 0) = Val_int(grx);
- Field(res, 1) = Val_int(gry);
- return res;
+ return Val_int(grx);
+}
+
+value gr_current_y(void)
+{
+ return Val_int(gry);
}
value gr_lineto(value vx, value vy)
@@ -63,6 +64,25 @@ value gr_lineto(value vx, value vy)
return Val_unit;
}
+value gr_draw_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();
+ if(grremember_mode)
+ XDrawRectangle(grdisplay, grbstore.win, grbstore.gc,
+ x, Bcvt(y) - h + 1, w, h);
+ if(grdisplay_mode) {
+ XDrawRectangle(grdisplay, grwindow.win, grwindow.gc,
+ x, Wcvt(y) - h + 1, w, h);
+ XFlush(grdisplay);
+ }
+ return Val_unit;
+}
+
value gr_draw_arc_nat(value vx, value vy, value vrx, value vry, value va1, value va2)
{
int x = Int_val(vx);
diff --git a/otherlibs/graph/graphics.ml b/otherlibs/graph/graphics.ml
index 56b9755a3..3af9466ef 100644
--- a/otherlibs/graph/graphics.ml
+++ b/otherlibs/graph/graphics.ml
@@ -80,8 +80,13 @@ and foreground = black
external plot : int -> int -> unit = "gr_plot"
external point_color : int -> int -> color = "gr_point_color"
external moveto : int -> int -> unit = "gr_moveto"
-external current_point : unit -> int * int = "gr_current_point"
+external current_x : unit -> int = "gr_current_x"
+external current_y : unit -> int = "gr_current_y"
+let current_point () = current_x (), current_y ()
external lineto : int -> int -> unit = "gr_lineto"
+let rlineto x y = lineto (current_x () + x) (current_y () + y)
+let rmoveto x y = moveto (current_x () + x) (current_y () + y)
+external draw_rect : int -> int -> int -> int -> unit = "gr_draw_rect"
external draw_arc : int -> int -> int -> int -> int -> int -> unit
= "gr_draw_arc" "gr_draw_arc_nat"
let draw_ellipse x y rx ry = draw_arc x y rx ry 0 360
diff --git a/otherlibs/graph/graphics.mli b/otherlibs/graph/graphics.mli
index ad6f688d3..de86506c4 100644
--- a/otherlibs/graph/graphics.mli
+++ b/otherlibs/graph/graphics.mli
@@ -113,11 +113,25 @@ external point_color : x:int -> y:int -> color = "gr_point_color"
(* Return the color of the given point. *)
external moveto : x:int -> y:int -> unit = "gr_moveto"
(* Position the current point. *)
-external current_point : unit -> int * int = "gr_current_point"
+val rmoveto : x:int -> y:int -> unit
+ (* [rmoveto x y] translates the current point of the given vector. *)
+external current_x : unit -> int = "gr_current_x"
+ (* Return the abscissa of the current point. *)
+external current_y : unit -> int = "gr_current_y"
+ (* Return the ordinate of the current point. *)
+val current_point : unit -> int * int
(* Return the position of the current point. *)
external lineto : x:int -> y:int -> unit = "gr_lineto"
(* Draw a line with endpoints the current point and the given point,
and move the current point to the given point. *)
+val rlineto : x:int -> y:int -> unit
+ (* Draws a line with endpoints the current point and the
+ current point translated of the given vector,
+ and move the current point to this point. *)
+external draw_rect : x:int -> y:int -> w:int -> h:int -> unit = "gr_draw_rect"
+ (* [fill_rect x y w h] draws the rectangle with lower left corner
+ at [x,y], width [w] and height [h].
+ The current point is unchanged. *)
external draw_arc :
x:int -> y:int -> rx:int -> ry:int -> start:int -> stop:int -> unit
= "gr_draw_arc" "gr_draw_arc_nat"