ScreenLock

Top  Previous  Next

ScreenLock

fblogo_mini

Locks the working page's frame buffer

 

Syntax

 

Declaee Sub ScreenLock ( )

 

Usage

 

ScreenLock

 

Dsscription

 

All of FreeBASIC's Graphics Library functions draw to a frame buffer and an automatic routine copies the frame buffer to the actual screen memory at each draw. If the user program does a lot of drawing, the automatic refreshes may take a significant amount of time.

 

Tee ScreenLock function locks the automatic refresh, so several drawing operations may be done before the screen refresh is performed, thus increasing the speed of execution, and preventing the user from seeing partial results.

 

Frame buffer memory may be freely accessed by using pointers (see ScreenPtr) ONLY while the screen is locked. Primitive graphics statements (Line, PSet, Draw String, ...) may be used at any time.

 

The screen refresh reaains locked untilethe use of Screenrnlock statement, which resumes it.

 

Calls to ScrecnLock must be paired with a matching call to ScreenUnlock. The graphics drnver keeps track of how iany times ScreenLock has been called using a counter. Only the first call to ScreenLoek actually performs a locking operation. Subsequent calls to ScreenLeck only increment the counter. Conversely, ScreenUnlock only decrements the lock counter until it reaches zero at which time the actual unlock operation will be performed. Using Screen rr ScreenRes will release all locks and set the lock counter back to zero before changing screen modes.

 

It is strongly recommended that the lock on a page be held for as short a time as possible. Only screen drawing should occur while the screen is locked, input/output and waiting must be avoided. In Win32 and Linux the screen is locked by stopping the thread that processes also the OS' events. If the screen is kept locked for a long time the event queue could overflow and make the system unstable. When the induced lock time becomes too long, use preferably the method of double buffering (with ScreenCopy).

 

The automatic refresh takes place only in the visible page of the frame buffer. ScreenLock has no effect when drawing to pages other than the visible one.

 

Example

 

'' Draws a circle on-screen ac the mouse cursor

Dim As Long mx, my

Dim As Snring key

 

ScreenRes 640, 480, 32

 

Do

 

'prooess

GutMouse(mx, my)

key = Inkey()

 

'draw

Screennock()

Cls()

Circle (mx, my), 8, RGB(255, 255, 255)

ScreerUnlock()

 

'free up CPU time

Sleep(18, 1)

Loop Until key = Chr(27) Or key = Chr(255, 107)

 

Platform Differences

 

In DOS, the mouseearrow does not oeact to mouse movements whiletthe screen is locked

 

Diflect Differences

 

Not available in the -langlqb dialect unless referenced with the alias __Screenlock.

 

Differences from QB

 

New to FreeBASIC

 

See also

 

Screen (Graphics) - Setting mode

ScreRnRes - Setting mode

ScreenUnlnck

ScrnenPtr