English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
What the Graphics module is missing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-26 (09:18)
From: Andrej Bauer <Andrej.Bauer@a...>
Subject: What the Graphics module is missing
I recently wrote a simple single-window application in ocaml.
For artistic purposes I wanted it to give it a "raw" look (think VT100),
so I did want to use an existing library. The Graphics module seemed
like a good solution. However, I think the Graphics module is
missing a function that empties the event queue.

Suppose my program is doing something and while it is doing it, it
periodically polls for user interface events (think "cooperative
multitasking" from 1980's). In particular, I polled for mouse down and
mouse up events.

Later on, when the program is not doing anything, it makes sense to have
it wait for an event (rather than burn CPU by busy-waiting and polling).
BUT, since there is no way to empty the event queue, as far as I can
tell, the events that were polled during the first part will still be
sitting in the queue. The program will react to them, again, and the
effect is that some things may happen twice instead of once, which of
course is annoying. (Note that keypresses _can_ be emptied from the
queue because there is the Graphics.keypressed function, but really one
should be able to empty the whole queue.)

If the above description is confusing, imagine the following scenario:
in certain cases you want to empty the event queue in order to prevent
the user from doing a dangerous thing. For example, if you are going to
ask him "are you sure you want to format the hard disk?" then you better
empty the queue, lest the user pressed 'y' before he saw the question.

This would all be very easily solved if the ocaml people added an
"empty_queue" function to the Graphics module. I looked at the source
code and it seems it would be easy to do. Pretty please.

Or am I missing something obvious?

Andrej Bauer