From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie)
Newsgroups: comp.lang.forth
Subject: Graphics, GUIs, and Events
Date: 11 Apr 92 16:01:52 GMT
Organization: (n.) to be organized.  But that's not important right now.

Category 10,  Topic 33
Message 1         Mon Mar 30, 1992
B.DUNN5 [Brian]              at 05:18 EST
 
 
 Could graphics, windows, mice, and events be standardized?  Some ideas for a
least common denominator across many systems:

 Typical graphic operations such as dot, line, circle, rectangle, filled or
hollow, with names such as DRAW_DOT ( x y -- ).

 Coordinates given in a 16K X 16K space, 0,0 in upper left, to be scaled to
your current screen display.

 For colors, a program may declare the colors it would like to use:
 NEW_COLORS   0 0 0 ADD_COLOR  255 255 255 ADD_COLOR  255 0 0  ADD_COLOR
 RGB values are loaded into a color pallette if one exists.   The most desired
colors are requested first.  If the pallette fills the leftover color requests
are ignored.  Background and foreground are the first two colors given.  Fixed
color systems or 24 bit color systems ignore all this.  From then on,  r g b
DRAWING_COLOR  selects the closest actual available color to use.  Greyscale
systems select the closest intensity, monochrome systems use a fill pattern of
some density.

 Simple generic windows are declared, added, titled, opened, moved, sized,
updated, closed, and deleted, and 'evented' with:
 WINDOW mywindow   ( mywindow returns a window_id )
 ( The below could be in a : definition. )
 mywindow ADD_WINDOW  ( default size, position, no title, no redraw )
 ' update_mywindow  mywindow  UPDATES_WINDOW  ( what performs redraws )
 ' handles_keypresses  mywindow  TAKES_WINDOW_KEYS    ( what takes keys )
 ' handles_mousepresses  mywindow  TAKES_WINDOW_MOUSE ( mouse... )
 0 0 8192 8192  mywindow  MOVE_WINDOW
 8192  8192  mywindow  SIZE_WINDOW
 S" A Title"  mywindow  TITLE_WINDOW
 mywindow  OPEN_WINDOW
 ( and CLOSE_WINDOW and DELETE_WINDOW, possibly a forced UPDATE_WINDOW )

 The user provides some event service routines:
 : update_mywindow  ( address_of_event -- )   ( redraw the entire window ) ;
 : handles_keypresses  ( address_of_event -- )  ( take one keypress ) ;
 : handles_mousepresses  ( address_of_event -- )   ( take mouseclick ) ;
 These may be different for every window, or general and more complex.

 The service routines are given addresses of events of the following form:
 structure update_event
   cell: ..ue_time         ( there is some kind of timestamp )
   cell: ..ue_window_id    ( and there is a window_id )
   end-structure
 ( ex:   addr_of_event ..ue_time @   is the timestamp of the event )

 structure keypress_event
   cell: ..ke_time
   cell: ..ke_window_id
   cell: ..ke_key          ( the EKEY code )
   end-structure

 structure mousepress_event
   cell: ..me_time
   cell: ..me_window_id
   cell: ..me_x            ( the mouse coordinates )
   cell: ..me_y
   cell: ..me_buttons      ( a bitpattern of the mouse buttons )
   end-structure

 Also, simple stuff such as MOUSE_XY and MOUSE_BUTTONS for current status.

 For easy text in windows, with automatic memory of text for updates:
 80 25 TEXT_WINDOW  mywindow  ( memory for an 80X25 character display )

 The update routine for this window may call the provided word:
   UPDATE_TEXT_WINDOW ( window_id -- )  ( redraws all text in window )
 followed by additional graphics to be displayed in the same window.

 The redraw routines may call WINDOW_I/O and NORMAL_I/O to change the vectored
actions of KEY, TYPE, CR, PAGE, etc.

 Finally there must be some main event loop command to trigger it all:
 : main_loop  begin  PERFORM_EVENTS  quit? until  ;
 If possible, PAUSE should be called by PERFORM_EVENTS if no events are
waiting.

 I make no mention of menus and dialog boxes because not all GUIs have them.
These plus file selectors might be faked with additional windows on those
systems.  There is also no mention of nested windows or window gadgets such as
close boxes, scroll bars, size boxes, etc.  Perhaps some additional event
types should be added.

 The question is whether the above or a similar wordset could be implimented
on a variety of platforms including Macintosh, Windows, XWindows, GEM, Amiga,
and whether it would be worth attempting.

 This will probably have nothing to do with ANS Forth, but FIG might be able
to make a pseudo-official standard wordset, the way FVG did for floating point
operations a few years ago.


-----
This message came from GEnie via willett.  You *cannot* reply to the author
using e-mail.  Please post a follow-up article, or use any instructions
the author may have included (USMail addresses, telephone #, etc.).
Report problems to: dwp@willett.pgh.pa.us