Primitive Graphics

Top  Previous  Next

Emergence BASIC has graphic functions for lines, rectangles, ellipses, points, images, icons and cursors. Primitive graphic elements are drawn in the current foreground and background colors.

LINE and LINETO statements

The LINE statement draws a solid line between the start and end points specified. The LINETO statement draws a line between the last pen position and the end point specified. The line will be drawn in the current foreground color unless changed by the optional color parameter. The syntax of the line statements are:

LINE window startx, starty, endx, endy {, color}

LINETO window endx, endy {,color}

For the LINETO statement the last pen position is updated by any other graphic primitive or the MOVE statement
 

DEF w as WINDOW
OPENWINDOW w,0,0,640,220,@SIZE|@MINBOX|@MAXBOX,0,"Lines",&main
CENTERWINDOW w
LINE w,4,20,620,20,RGB(255,0,0)
LINETO w,620,180,RGB(0,0,255)
LINETO w,4,180,RGB(0,255,0)
LINETO w,4,20,RGB(255,255,0)
run = 1
 
WAITUNTIL run = 0
CLOSEWINDOW w
END
 
SUB main
SELECT @MESSAGE
     CASE @IDCLOSEWINDOW
                run = 0
ENDSELECT
RETURN
ENDSUB

RECT statement

The RECT statement is used to draw rectangles in the window. Rectangles can be filled with an optional fill color. The rectangle is drawn in the current foreground color unless a border color is specified. The syntax of the RECT statement is:

RECT window, left, top, width, height {, border {, fill}}

ELLIPSE statement

The ELLIPSE statement is used to draw ellipses in the window. The ellipse will be bound by the rectangle specified in the left,top,width and height parameters. The ellipse drawn in the current foreground color unless a border color is specified. The ellipse may be filled with an optional fill color. The syntax of the ellipse statement is:

ELLIPSE window, left, top, width, height {, border {, fill}}

CIRCLE statement

The CIRCLE statement is used to draw device independent circles. The circle will be drawn at the starting point specified with the radius specified. The circle will be drawn in the current foreground color unless a border color is specified. The circle may be filled with an optional fill color.  The syntax of the CIRCLE statement is:

CIRCLE window, centerx, centery, radius {, border {, fill}}

Example:

DEF w as WINDOW
OPENWINDOW w,0,0,640,220,@SIZE|@MINBOX|@MAXBOX,0,"Demo",&main
CENTERWINDOW w
RECT w,20,20,50,100,RGB(0,0,255),RGB(0,255,0)
ELLIPSE w,90,20,100,50,RGB(255,0,0),RGB(255,255,0)
CIRCLE w,250,75,50,RGB(0,255,0),RGB(0,0,255)
run = 1
 
WAITUNTIL run = 0
CLOSEWINDOW w
END
 
SUB main
SELECT @MESSAGE
     CASE @IDCLOSEWINDOW
                run = 0
ENDSELECT
RETURN
ENDSUB 

PSET statement

The PSET statement changes one pixel of the window to the foreground color or the optional specified color. The syntax of PSET is:

PSET window, x, y {, color}

GETPIXEL function

GETPIXEL retrieves the color of a pixel in the window at the coordinates specified. The syntax of GETPIXEL is:

color = GETPIXEL( window, x ,y )

 

Drawing Modes

The DRAWMODE statement sets the background mode. The background mode defines whether the system removes existing background colors on the drawing surface before drawing text. The syntax of the DRAWMODE statement is

DRAWMODE window, flags

Flags can be either @TRANSPARENT or @OPAQUE. If the mode is set to @TRANSPARENT then the background color is not changed when printing text.

Raster operations

The RASTERMODE statement sets the current drawing mode. The drawing mode specifies how the colors of the pen and the interior of filled objects are combined with the color already on the display surface. The syntax of RASTERMODE is:

RASTERMODE window, flags

Flags can be any one of the rastermode flags listed in the appendix.

Example:

DEF w as WINDOW
OPENWINDOW w,0,0,640,220,@SIZE|@MINBOX|@MAXBOX,0,"Demo",&main
CENTERWINDOW w
RASTERMODE w, @RMXORPEN
RECT w,20,20,50,100,RGB(0,0,255),RGB(0,255,0)
ELLIPSE w,20,20,100,50,RGB(255,0,0),RGB(255,255,0)
CIRCLE w,50,50,25,RGB(0,255,0),RGB(0,0,255)
run = 1
 
WAITUNTIL run = 0
CLOSEWINDOW w
END
 
SUB main
SELECT @MESSAGE
     CASE @IDCLOSEWINDOW
                run = 0
ENDSELECT
RETURN
ENDSUB

Advanced graphics statements

For advanced users Emergence BASIC allows using WIN32 (WINAPI) functions to draw in a window. In order to use any of the WIN32 graphics functions you must first obtain a handle to a device context. While you could use the GetDC/ReleaseDC API functions, it is more convenient and compatible to use the built-in GetHDC and ReleaseHDC functions. The syntax of the GetHDC and ReleaseHDC functions are:

handle = GetHDC(window)

ReleaseHDC window, handle

The handle returned is an unsigned integer value and is a valid HDC. The advantages in using the built in functions is they are integrated with Emergence BASIC's auto drawing windows and will retain the current font, color and drawing mode settings.

The @NOAUTODRAW flag

To handle WM_PAINT messages directly in your program specify the @NOAUTODRAW flag when creating a window. Your windows handler subroutine will receive @IDPAINT messages whenever the window needs updating. A window created with @NOAUTODRAW uses less memory and will update faster. You must redraw the window every time in response to the @IDPAINT messages.

@NOAUTODRAW should also be used if your creating a window where another control covers the entire client area of the window. The editor.eba sample uses this method to embed an edit control into a window.

Example code fragment:

'...
OPENWINDOW w,0,0,350,350@SIZE|@NOAUTODRAW,0,"Test",&mainwindow
'...
SUB mainwindow
SELECT @MESSAGE
                CASE @IDCLOSEWINDOW
                                run=0
                CASE @IDPAINT
                        IF(bitmap)
                                ShowImage w1,bitmap,0,x,y,w,h
                        ENDIF
ENDSELECT
RETURN
ENDSUB 

See Also: Images, icons and cursors