DISCARD

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

For use with drawn graphic elements in graphics windows and graphicboxes, DISCARD "throws away" all graphics drawn since the last flush command, or since the program started if a flush was not issued. These would be all the graphics items contained in a segment that has not been flushed.
Some additional commands used with the display of graphics:
segment
delsegment
cls
redraw
flush

Syntax

This command is NOT case sensitive.
  1. #handle "discard" - a graphics window
  2. #handle.ext "discard" - a graphicbox

Hints

Updating Display. Discard does NOT affect the display of the graphics. The discarded graphics will remain displayed until a redraw command is issued.
Freeing Memory. Discard also frees the memory used by the discarded graphics. Other commands that free memory used by graphics are cls and delsegment.
Bitmaps & Discard. Discard works with bitmaps also. See examples.

Example

An example of the command using a graphics window.

nomainwin

    WindowWidth=400
    WindowHeight=300

    open "Discard Demo" for graphics_nsb_nf as #g
    #g "trapclose [quit]"
    'put the pen down
    #g "down"

    'draw two lines
    #g "line 10 50 10 250"
    #g "color yellow; size 4"
    #g "line 10 50 300 50"
    'save work so far
    #g "flush"

    'add another line
    'change color and size
    #g "color red; size 2"
    #g "line 10 250 300 50"
    confirm "Do you want to save this line?"; yn$
    if yn$="no" then #g "discard; redraw; flush"
    if yn$="yes" then #g "flush"
    wait

[quit]
    close #g
    end

An example of the command using a graphicbox.

nomainwin

    WindowWidth=400
    WindowHeight=300

    graphicbox #g.gb 2, 2, 390, 270
    open "Discard Demo" for graphics_nsb_nf as #g
    #g "trapclose [quit]"
    'put the pen down
    #g.gb "down"

    'draw two lines
    #g.gb "line 10 50 10 250"
    #g.gb "color yellow; size 4"
    #g.gb "line 10 50 300 50"
    'save work so far
    #g.gb "flush"

    'add another line
    'change color and size
    #g.gb "color red; size 2"
    #g.gb "line 10 250 300 50"
    confirm "Do you want to save this line?"; yn$
    if yn$="no" then #g.gb "discard; redraw; flush"
    if yn$="yes" then #g.gb "flush"
    wait

[quit]
    close #g
    end

This example shows how a bitmap can be discarded, if DISCARD and REDRAW are issued before a FLUSH command.

    'Run this example from the main JustBASIC program folder so
    'the bmp\subfolder and bmp image are accessible.
    loadbmp "copyimage", "bmp\copy.bmp"

    open "Loadbmp Test" for graphics as #main
    #main "trapclose [quit]"

    print #main, "drawbmp copyimage 10 10"

    timer 1750, [clearit]

    wait

[clearit]
    timer 0
    #main "discard"
    #main "redraw"

'remove the apostrophe to uncomment the next line and run the program again.
'    #main "flush"
    wait

[quit]
    unloadbmp "copyimage"
    close #main
    end

Useful Procedures

' Place a useful function using this keyword here