[m-rev.] Xlib interface for extras
Ian MacLarty
maclarty at cs.mu.OZ.AU
Thu Sep 23 15:52:56 AEST 2004
> I've been writing a little Xlib based graphics library off and on for a
> couple of months and would like to add it to extras.
>
> Feedback gratefully received, as would be flashier applications.
>
This looks neat. It also seems to work fine on Max OS X (I tested it).
> % easyx.m
> % Ralph Becket <rafe at cs.mu.oz.au>
> % Fri Jun 25 17:49:48 EST 2004
> %
> % A simple, easy-to-use wrapper around some of Xlib, good for putting
> % lines and boxes on the screen and writing simple interactive
> graphical
> % applications. This library aims for ease of use over efficiency.
> %
> % All drawing is done to a backing pixmap and the user must explicitly
> call
> % easyx.flush/3 to make visible any changes since the last call to
> % easyx.flush/3. Repainting after exposure events is handled
> automatically,
> % although resizing the window does require the user to redraw.
> %
> % An abstract coordinate space is used, but in keeping with Xlib, the
> % origin of the coordinate space is at the top-left of a window, with
> % coordinates increasing down and to the right. An abstract coordinate
> % value of 1.0 corresponds to the shorter of the current width or
> height
> % of the window.
> %
> % Angles, where used, are measured in radians.
Personally I'd find degrees easier to use. I find 45.0 is easier to
read than math.pi/4.0 - especially for this type of simple library.
> % One must open a display in order to create a window.
> %
> :- type display == xlib.display_ptr.
Why is this not an abstract type?
>
> % open_display(Display, !IO)
> % Open a connection to the default display.
> %
> :- pred open_display(display::out, io::di, io::uo) is det.
>
> % open_display(DisplayName, Display, !IO)
> % Open a connection to the named display.
> %
> :- pred open_display(string::in, display::out, io::di, io::uo) is det.
>
>
> % A window is a target for drawing operations and a source of
> % input events (mouse and keyboard etc.)
> %
> :- type window.
>
> % create_window(Display, Title, Width, Height, Orientation,
> Window, !IO)
> % Create Window on Display, with the given Title, Width, Height and
> % Orientation.
> %
> :- pred create_window(display::in, string::in, int::in, int::in,
> window::out, io::di, io::uo) is det.
>
The orientation argument seems to have been left out here.
> % flush(Window, !IO)
> % Make all rendering to Window since the last call to flush/3
> visible
> % (all rendering is done to a separate drawing area; this predicate
> % updates what is on the screen.)
> %
> :- pred flush(window::in, io::di, io::uo) is det.
>
> % clear_window(Window, !IO)
> % Clear the window using the current colour.
> %
> :- pred clear_window(window::in, io::di, io::uo) is det.
>
>
> :- type font == xlib.font_struct_ptr.
>
Couldn't font be an abstract type?
> % load_font(Window, FontName, Font, !IO)
> % Load a font from the X server.
> %
> :- pred load_font(window::in, string::in, font::out, io::di, io::uo)
> is det.
>
> % Set the font for drawing text.
> %
> :- pred set_font(window::in, font::in, io::di, io::uo) is det.
>
>
> :- type colour == xlib.color_ptr.
Again couldn't this be abstract?
...
>
>
> % The left hand mouse button is usually number 1.
> %
> :- type button == int.
What about making this button1 ; button2 ; button3 or even left ;
middle ; right? This might be useful when constructing switches on
which button was pressed. Also a button variable having the value 999
is pretty meaningless.
...
> xlib.m:
> %----------------------------------------------------------------------
> -------%
> % Copyright (C) 2004 The University of Melbourne.
> % This file may only be copied under the terms of the GNU Library
> General
> % Public License - see the file COPYING.LIB in the Mercury
> distribution.
> % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
> %----------------------------------------------------------------------
> -------%
> % xlib.m
> % Ralph Becket <rafe at cs.mu.oz.au>
> % Mon Jun 21 17:48:24 EST 2004
> %
> % A low-level interface to parts of Xlib (this is very little more
> than a
> % few useful symbol definitions and wrappers around various Xlib
> calls.)
> %
> %----------------------------------------------------------------------
> -------%
>
> :- module xlib.
>
> :- interface.
>
> :- import_module list.
>
>
>
> :- type display_ptr.
>
> :- impure func open_display = (display_ptr::out) is semidet.
>
> :- impure func open_display(string::in) = (display_ptr::out) is
> semidet.
>
> :- impure pred flush(display_ptr::in) is det.
>
> :- impure pred sync(display_ptr::in) is det.
>
Why don't you make these pure and thread the IO state? The semidet
ones you can make det by getting them to return a bool, so you can then
thread the IO state. Same applies to all the other impure preds in
this module.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list