type melted_type =
string_type of string
| int_type of int
| bitmap_type of image
| float_type of float
| bool_type of bool
;;
melted_type defines a general type that can be used in many
places. It is the union of the classical type: string, int,
boolean, and bitmap (image defined in the windows library). This
type is used here to define the contents of the buttons.
type button_state =
Up
| Down
| Unused
;;
type gr_button =
{ bt_window : gr_window
; mutable bt_top : int
; mutable bt_left : int
; mutable bt_width : int
; mutable bt_height : int
; mutable bt_name : melted_type
; mutable bt_state : button_state
; mutable bt_callback : gr_button -> event -> bool
}
;;
gr_button defines a button. The callback function is only
called when the user presses and releases the mouse button inside
the defined draw button. The sum type stores all the variables needed
to define a button. This variables are:
- the lower left corner's coordinates (bt_left,bt_top),
- the button width in Camlwin coordinates (bt_width),
- the button height (bt_height),
- the attached window (bt_window),
- the button content (bt_name) that can be a string, a bitmap,
an integer or a boolean,
- the present button state (bt_state) which can be:
- released (Up),
- pressed (Down),
- unusable (Unused),
- the function to call when the mouse button is released inside
the draw button (bt_callback). This function takes the button itself
and the event as parameters and returns a boolean that indicates if the
event is used or not.
The other functions linked with the buttons are:
gr_draw_button : gr_button -> unit
- gr_draw_button Button draws the button Button.
gr_draw_unfilled_button : gr_button -> unit
- gr_draw_unfilled_button Button draws only the outline of the
button Button.
gr_button_managed : gr_button -> event -> bool
- its the function used by Camlwin to manage the buttons.