-
Notifications
You must be signed in to change notification settings - Fork 1
/
gctx.mli
137 lines (94 loc) · 3.94 KB
/
gctx.mli
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
(** The "Graphics Context" component of the GUI library. *)
(** A graphics context represents a portion of the window to which widgets will
be drawn.
The drawing primitives in this module are all relative to the graphics
context. This means that when a widget needs to draw on the screen, it need
not know its absolute position. The graphics context is responsible for
translating the relative positions passed into the drawing routines into
absolute positions on the screen.
The graphics context also includes other information for basic drawing (such
as the current pen color.)
Note that this module defines a persistent (immutable) data structure. The
operations here use a given graphics context to create a new one with the
specified characteristics. They do not modify their arguments. *)
(** The main (abstract) type of graphics contexts. *)
type gctx
(****************)
(** {1 Colors } *)
(****************)
(** A type for colors, specified by red, green and blue values in
the range [0 .. 255] inclusive *)
type color = {r:int; g:int; b:int}
(* Some predefined colors *)
val black : color
val white : color
val red : color
val green : color
val blue : color
val yellow : color
val cyan : color
val magenta : color
(** Mutable background color, composed of the same r, g and b *)
type background_color = {mutable c: int}
val bg : background_color
(** Thickness type *)
type thickness = {t : int}
val thin : thickness
val thick : thickness
(*******************************)
(** {1 Basic Gctx operations } *)
(*******************************)
(** Open the graphics window *)
val open_graphics : unit -> unit
(** Clear the graphics window *)
val clear_graph : unit -> unit
(** The top-level graphics context *)
val top_level : gctx
(** Produce a new gctx shifted by (dx,dy) *)
val translate : gctx -> int * int -> gctx
(** Produce a new gctx with a different pen color *)
val with_color : gctx -> color -> gctx
(** Produce a new gctx with a different pen thickness *)
val with_thickness : gctx -> thickness -> gctx
(*****************)
(** {1 Drawing } *)
(*****************)
(** A widget-relative position *)
type position = int * int
(** A width and height paired together. *)
type dimension = int * int
(** Various primitive drawing routines. Arguments are widget-local
coordinates. *)
(** Draw a line between the two specified positions *)
val draw_line : gctx -> position -> position -> unit
(** Display text at the given position *)
val draw_string : gctx -> position -> string -> unit
(** Draw a rectangle, with lower-left corner at position of the specified
dimension. *)
val draw_rect : gctx -> position -> dimension -> unit
(** Display a filled rectangle with lower-left corner at position with the
specified dimension. *)
val fill_rect : gctx -> position -> dimension -> unit
(** Draw an elipse, centered at position with given x and y radii. *)
val draw_ellipse : gctx -> position -> int -> int -> unit
(** Calculates the size of text when rendered. *)
val text_size : string -> dimension
(** Draws a point at the specified position. *)
val draw_point : gctx -> position -> unit
(** Draws points from a list of specified positions. *)
val draw_points : gctx -> position list -> unit
(************************)
(** {1 Event Handling } *)
(************************)
type event_type =
| KeyPress of char (* User pressed the following key *)
| MouseDown (* Mouse button pressed, no movement *)
| MouseUp (* Mouse button released, no movement *)
| MouseMove (* Mouse moved with button up *)
| MouseDrag (* Mouse moved with button down *)
(** Events produced by the user-interface. Each event contains a
type and a position. *)
type event = event_type * position
val event_type : event -> event_type
val event_pos : event -> gctx -> position
val make_test_event : event_type -> position -> event