Re: Linux gForth/VFX windows
- From: mhx@xxxxxx (Marcel Hendrix)
- Date: Sat, 2 Feb 2008 08:25:43 +0200
Josh Grams <j...@xxxxxxxxxxx> writes Re: Linux gForth/VFX windows
On Jan 31, 9:20 pm, Ian Osgood wrote:
On Jan 31, 12:01 pm, Brad Eckert wrote:
Is there a way to open a graphic window in gForth or Linux-VFX that I
can plot pixels into?
I don't know about these Forths, but bigFORTH does give access to X Windows.
I would also be interested in a simple windowing shim for gforth
(maybe Tk or SDL based).
I usually just write the bits I need when I have a project that needs
graphical stuff. Binding to SDL or X or whatever is pretty simple.
Anything more than a simple binding gets you into issues of what the
interface should look like, and I haven't settled on something that I'm
really happy with. But if you have ideas, I'd consider trying to
implement them...
With the discussion taking this turn, I'd like to mention that iForth's
high-level graphics vocabulary interfaces to the hardware through a set of
vectored words. This 'device driver' concept is used to implement bindings
to HPGL and PostScript devices and files (any OS), the GO32 DOS
extender (MS-DOS), GDI (Windows), SVGALIB (Linux) and X (Linux and OSX).
However, OpenGL functionality does not fit in this framework. (There is
a completely separate driver for that, but it has had insufficient usage.)
A text description of this interface is appended. The words have proven
to be sufficient to implement higher-level concepts (like interactive,
scaled, multi-window, plotting) on all supported platforms, without need
for hardware hacking below this defined interface. The interface has been
used (and fine-tuned) since 1992.
-marcel
== ========================================================================
Graphic driver Interface Description
------------------------------------
_SET-PEN ( n -- )
When drawing dots and lines SET-PEN decides the attributes of the
operation, together with SET-MODE . (These functions overlap in
functionality because of historic reasons).
PEN's minimum required possibilities are:
0 put
1 or
2 and
3 xor
4 random
5 thick ( 3 by 3 pixels)
6 very thick ( 5 by 5 pixels)
Not supported by this driver.
7 horizontal nib ( 3 pixels)
8 vertical nib ( 3 pixels)
9 large horizontal nib (5 pixels)
10 large vertical nib ( 5 pixels)
11 / nib (sw to ne)
12 \ nib (se to nw)
13 // nib (like 11 but 3 pixels wide)
14 \\ nib (like 12 but 3 pixels wide)
_GET-PEN ( -- n )
Report present _SET-PEN
_SET-MODE ( n -- )
When drawing dots and lines SET-MODE decides the attributes of the
operation, together with SET-PEN . (These functions overlap in
functionality because of historic reasons).
MODE's possibilities are:
0 put
1 or
2 and
3 xor
_GET-MODE ( -- n )
Get latest SET-MODE
_SET-DOT ( x y color -- )
Set a dot, checking PEN and MODE . The color value is a symbolic
constant available with a server function. The point (0,0) is the
left-lower corner of the graphic window. The point (Xmax, Ymax)
is the upper right corner (NOT (Xmax-1, Ymax-1). Clipping is
automatic.
_GET-DOT ( x y -- color )
Get the color of the pixel at (x,y). See SET-DOT .
_SET-FONT ( c-addr u -- )
Install a text font. This font is used by TEXT-EMIT , TEXT-TYPE etcetera.
_GET-FONT ( -- c-addr u )
Gets the presently installed text font. Only valid after at least
one call to SET-FONT .
_SET-HLINE ( addr cnt x y -- )
Copy the <cnt> pixels at <addr> to the display, starting at
pixel (x,y), moving horizontally. PEN and MODE are ignored
(always !PUT). Each pixel needs BytesPerPixel bytes to store.
This call is okay when used together with GET-HLINE .
_GET-HLINE ( x y addr cnt -- )
Copy the <cnt> pixels at display position (x,y) to memory address
<addr>, moving horizontally. Use together with SET-HLINE if
hardware independence is wanted.
Each pixel occupies BytesPerPixel bytes.
_OVER-HLINE ( addr cnt x y -- )
Like SET-HLINE, but pixels that have value "0" are not copied.
("stencilling").
_COPY-HLINE ( 'patt cnt x y -- )
Copy <cnt> pixels from the pattern at <'patt> to the display,
starting at pixel (x,y) and moving horizontally.
Internal structure of a pattern:
cell: <xsize>, <ysize> followed by ysize rows of xsize records
with color values (BytesPerPixel bytes).
_DRAW-LINE ( xb yb xe ye color -- )
Draw a line from (xb, yb) to (xe, ye), taking PEN and MODE into
account. Correct clipping is assumed (both points can be outside
of the drawing window).
_ARC ( xm ym x1 y1 x2 y2 r c -- )
Draw a circle segment. Circle is at (xm,ym) with radius r and
color c. The radii m,1 and m,2 define the segment (CCW).
_PIE ( xm ym x1 y1 x2 y2 r c -- )
Draw a circle slice. Circle is at (xm,ym) with radius r and
color c. The radii m,1 and m,2 define the slice (CCW).
_PIEPAT ( xm ym x1 y1 x2 y2 r 'p -- )
Draw a filled circle slice. Circle is at (xm,ym) with radius r and
pattern 'p. The radii m,1 and m,2 define the slice (CCW).
_CIRCLE ( xm ym r c -- )
Draw a circle with radius r and colour c around the point (xm,ym). These are
hardware coordinates.
_FCIRCLE ( xm ym rad col -- )
Draw a filled circle with radius rad and color col around the point (xm,ym).
These are hardware coordinates.
_FCIRCLEPAT ( xm ym rad 'p -- )
Draw a pattern filled circle with radius r around the point (xm,ym). The fill
pattern is found at 'pat.
These are hardware coordinates.
_ELLIPSE ( x1 y1 x2 y2 c -- )
Draw an ellipse bounded by the box indicated by (x1,y1) and (x2,y2). These are
hardware coordinates.
_FELLIPSE ( x1 y1 x2 y2 c -- )
Draw a filled ellipse bounded by the box indicated by (x1,y1) and (x2,y2).
These are hardware coordinates.
_FELLIPSEPAT ( x1 y1 x2 y2 'pattern -- )
Draw a pattern filled ellipse bounded by the box indicated by (x1,y1) and (x2,y2).
The fill pattern is found at 'pat.
These are hardware coordinates.
_POLYGON ( addr #pts c -- )
Draw the polygon described by the array of #pts (x,y) coordinates at addr. These are
hardware coordinates.
_FPOLYGON ( addr #pts c -- )
Draw a filled polygon described by the array of #pts (x,y) coordinates at addr.
These are hardware coordinates.
_FPOLYGONPAT ( addr #pts 'pattern -- )
Draw a pattern filled polygon described by the array of #pts (x,y) coordinates at addr.
The fill pattern is found at 'pat.
These are hardware coordinates.
_RECTANGLE ( xb yb xsize ysize color -- )
Draw a coloured rectangle on the screen.
The left-lower corner of the rectangle is at (xb,yb). It is xsize pixels wide
and ysize pixels tall.
_FBOX ( xb yb xsize ysize color -- )
Draw a filled box on the screen.
The left-lower corner of the rectangle is at (xb,yb). It is xsize pixels wide
and ysize pixels tall.
_FBOXPAT ( xb yb xsize ysize 'pat -- )
Draw a filled box on the screen.
The left-lower corner of the rectangle is at (xb,yb). It is xsize pixels wide
and ysize pixels tall. It is filled with the pattern at 'pat (nxn).
_GRAPHICS ( -- )
Opens a graphic terminal window.
Updates the value of BytesPerPixel according to the latest call
to SELECT-HIRES . Reports the resolution in Xmax, Ymax, and the
number of available colors in PosblColors .
In graphics mode EMIT , TYPE etcetera still work, but now they
are also affected by SET-FONT .
To use a console in the X window use either
SET-CONSOLE-WINDOW ( x y width height -- )
X-CONSOLE
_TEXT ( -- )
Switches (back) to the xterm console mode.
_TEXTMODE? ( -- n )
Reports if in graphics or text mode (lower byte). Also reports if a
cursor is available (byte 2).
_SELECT-HIRES ( mode# -- )
Sets a wanted graphics mode. This comes into effect when GRAPHICS
is executed. See GET-RES . Mode is always 1.
_GET-RESOLUTION ( -- mode# )
Get Graphics mode.
_CLS ( -- )
Clear the console screen (compatibility reasons).
_GCLEAR ( -- )
Clears the graphics window to the default window background.
_SET-MARKUP ( color -- )
Set the color used to mark an outline for FLOOD or FLOODPAT .
_GET-MARKUP ( -- color )
Report the color used to mark outlines for FLOOD or FLOODPAT .
_SET-FILLCOLOR ( color -- )
Set the color used for FLOOD .
_GET-FILLCOLOR ( -- color )
Report the color used by FLOOD .
_FLOOD ( x y -- )
Flood fill the object enclosing the point (x,y). The object boundary must
be drawn in the markup colour.
_FLOODPAT ( 'pat x y -- )
Flood fill the object enclosing the point (x,y), using the pattern
at <'pat>. The object boundary must be drawn in the markup colour.
For details of <'pat> see SET-PATTERN .
_DOTS>HOST ( addr cnt -- )
Plot the <cnt> pixels located at <addr>. The format of the pixels
in memory is a record of three cells: <x>, <y>, <color>. Uses the
same PEN and MODE for all pixels.
_LINES>HOST ( addr cnt -- )
Execute the <cnt> lines descriptors located at <addr>. The format
of the descriptor in memory is a record of five cells:
<xb>, <yb>, <xe> <ye>, <color>. Uses the same PEN and MODE for all
lines.
_name ( -- n )
The following symbolic constants are provided. They
allow setting plot colors by name (Even when (!PALETTE) etc.
is being used).
An important limitation is that these constants are correct only
after the first invocation of GRAPHICS .
_black _blue _green _brown
_red _magenta _cyan _darkgray
_lightgray _lightblue _lightgreen _lightcyan
_lightred _lightmagenta _yellow _white
?OPEN-GPRINTER ( bool -- Xm Ym ) ( doesn't work for X )
Opens the system printing device and redirects all graphic calls there.
The Xm and Ym tell the resolution of the printer. Recommended: <Xm> TO Xmax
<Ym> TO Ymax B-ON-W[ .
When <bool> is TRUE , this word pops up a standard printer dialog box that
allows fine control of the printing process (to file or network printer, to
set Landscape or Portrait mode etc.). When <bool> is FALSE the standard printer
is used.
CLOSE-GPRINTER ( -- ) ( doesn't work for X )
Close the system printer. The graphic calls go where they went before (possibly
nowhere).
OPEN-METAFILE ( -- Xm Ym ) ( doesn't work for X )
Opens a *memory-based* enhanced graphics metafile and redirects all graphic
calls there. (This file can be put on disk, but no program seems to understand
it; it is not a standard EMF file).
The Xm and Ym tell the resolution of the printer. Recommended: <Xm> TO Xmax
<Ym> TO Ymax B-ON-W[ .
CLOSE-METAFILE ( -- ) ( doesn't work for X )
Close the enhanced meta file and put the contents on the clipboard. The graphic
calls go where they went before (possibly nowhere).
B-ON-W[ ( -- )
Convert the standard colors to a palette suitable for black-on-white
printing. Do *NOT* nest B-ON-W[ and ]W-ON-B , this word saves / restores
TextAttr , TextFGColor and TextBGColor and selects the current font plus
attributes in the new context.
]W-ON-B ( -- )
Set the standard colors to the default color palette (display device).
Do *NOT* nest ]W-ON-B and B-ON-W[ , this word saves / restores TextAttr ,
TextFGColor and TextBGColor .
.
- References:
- Re: Linux gForth/VFX windows
- From: Josh Grams
- Re: Linux gForth/VFX windows
- Prev by Date: Re: Linux gForth/VFX windows
- Next by Date: Particle Swarm Optimization
- Previous by thread: Re: Linux gForth/VFX windows
- Next by thread: Re: Linux gForth/VFX windows
- Index(es):
Relevant Pages
|
Loading