Sign in Join
FPDoc Onlineexperiment

video unit

Screen handling unit.

The Video unit implements a screen access layer which is system independent. It can be used to write on the screen in a system-independent way, which should be optimal on all platforms for which the unit is implemented.

The working of the Video is simple: After calling InitVideo, the array VideoBuf contains a representation of the video screen of size ScreenWidth*ScreenHeight, going from left to right and top to bottom when walking the array elements: VideoBuf[0] contains the character and color code of the top-left character on the screen. VideoBuf[ScreenWidth] contains the data for the character in the first column of the second row on the screen, and so on.

To write to the 'screen', the text to be written should be written to the VideoBuf array. Calling UpdateScreen will then copy the text to the screen in the most optimal way. (an example can be found further on).

The color attribute is a combination of the foreground and background color, plus the blink bit. The bits describe the various color combinations:

bits 0-3
The foreground color. Can be set using all color constants.
bits 4-6
The background color. Can be set using a subset of the color constants.
bit 7
The blinking bit. If this bit is set, the character will appear blinking.

Each possible color has a constant associated with it, see the constants section for a list of constants.

The foreground and background color can be combined to a color attribute with the following code:

Attr:=ForeGroundColor + (BackGroundColor shl 4);

The color attribute can be logically or-ed with the blink attribute to produce a blinking character:

Atrr:=Attr or blink;

But not all drivers may support this.

The contents of the VideoBuf array may be modified: This is 'writing' to the screen. As soon as everything that needs to be written in the array is in the VideoBuf array, calling UpdateScreen will copy the contents of the array screen to the screen, in a manner that is as efficient as possible.

The updating of the screen can be prohibited to optimize performance; To this end, the LockScreenUpdate function can be used: This will increment an internal counter. As long as the counter differs from zero, calling UpdateScreen will not do anything. The counter can be lowered with UnlockScreenUpdate. When it reaches zero, the next call to UpdateScreen will actually update the screen. This is useful when having nested procedures that do a lot of screen writing.

The video unit also presents an interface for custom screen drivers, thus it is possible to override the default screen driver with a custom screen driver, see the SetVideoDriver call. The current video driver can be retrieved using the GetVideoDriver call.

The video unit should not be used together with the crt unit. Doing so will result in very strange behaviour, possibly program crashes.

Classes and records

TEnhancedVideoCellrecord
TVideoDriverrecordVideo driver record.
TVideoModerecordRecord type describing a video mode.

Procedures and functions

ActivateCodePageprocedure
ClearScreenprocedureClear the video screen.
DefaultErrorHandlerfunctionDefault error handling routine.
DoneEnhancedVideoprocedure
DoneVideoprocedureDisable video driver.
equal(TEnhancedVideoCell,TEnhancedVideoCell):Booleanoperator
ExtendedGraphemeClusterDisplayWidthfunction
GetActiveCodePagefunction
GetCapabilitiesfunctionGet current driver capabilities.
GetCursorTypefunctionGet screen cursor type.
GetLegacyCodePagefunction
GetLockScreenCountfunctionGet the screen lock update count.
GetSupportedCodePagefunction
GetSupportedCodePageCountfunction
GetVideoDriverprocedureGet a copy of the current video driver.
GetVideoModeprocedureReturn current video mode.
GetVideoModeCountfunctionGet the number of video modes supported by the driver.
GetVideoModeDatafunctionGet the specifications for a video mode.
InitEnhancedVideoprocedure
InitVideoprocedureInitialize video driver.
LockScreenUpdateprocedurePrevent further screen updates.
SetCursorPosprocedureSet write cursor position.
SetCursorTypeprocedureSet cursor type.
SetVideoDriverfunctionInstall a new video driver.
SetVideoModefunctionSet current video mode.
StringDisplayWidthfunction
UnlockScreenUpdateprocedureUnlock screen update.
UpdateScreenprocedureUpdate physical screen with internal screen image.
UpdateScreenAreaprocedure

Types

PEnhancedVideoCelltype
PVideoBuftypePointer type to .
PVideoCelltypePointer type to .
PVideoModetypePointer to record.
TEnhancedVideoAttributeenumeration
TEnhancedVideoAttributesset
TEnhancedVideoBuftype
TErrorHandlerprocedure typeError handler prototype.
TErrorHandlerReturnValueenumerationType used to report and respond to error conditions.
TVideoBuftypeScreen array type.
TVideoCelltypeOne cell (=screen position) in the video buffer.
TVideoModeSelectorprocedure typeVideo mode selection callback prototype.

Constants

BlackconstantBlack color attribute.
BlinkconstantBlink attribute.
BlueconstantBlue color attribute.
BrownconstantBrown color attribute.
cpBlinkconstantVideo driver supports blink attribute.
cpChangeCursorconstantVideo driver supports changing cursor shape.
cpChangeFontconstantVideo driver supports changing screen font.
cpChangeModeconstantVideo driver supports changing mode.
cpColorconstantVideo driver supports color.
cpUnderLineconstantVideo driver supports underline attribute.
crBlockconstantBlock cursor.
crHalfBlockconstantHalf block cursor.
crHiddenconstantHide cursor.
crUnderLineconstantUnderline cursor.
CyanconstantCyan color attribute.
DarkGrayconstantDark gray color attribute.
errOkconstantNo error.
ErrorCodeconstantError code returned by the last operation.
ErrorHandlerconstantError handler routine.
ErrorInfoconstantPointer to extended error information.
errVioBaseconstantBase value for video errors.
errVioInitconstantVideo driver initialization error.
errVioNoSuchModeconstantInvalid video mode.
errVioNotSupportedconstantUnsupported video function.
FVMaxWidthconstantMaximum screen buffer width.
GreenconstantGreen color attribute.
LightBlueconstantLight Blue color attribute.
LightCyanconstantLight cyan color attribute.
LightGrayconstantLight gray color attribute.
LightGreenconstantLight green color attribute.
LightMagentaconstantLight magenta color attribute.
LightRedconstantLight red color attribute.
LowAsciiconstantLow 32 ASCII character availability.
MagentaconstantMagenta color attribute.
NoExtendedFrameconstantDisable transformation of control characters on Unix terminals.
RedconstantRed color attribute.
ScreenHeightconstantCurrent screen height.
ScreenWidthconstantCurrent screen Width.
vioOKconstantNo errors occurred.
WhiteconstantWhite color attribute.
YellowconstantYellow color attribute.

Variables

CursorLinesvariableCurrently visible scanlines of cursor.
CursorXvariableCurrent write cursor X position.
CursorYvariableCurrent write cursor Y position.
EnhancedVideoBufvariable
OldEnhancedVideoBufvariable
OldVideoBufvariableLast written screen image.
ScreenColorvariableIndicate whether current screen supports colors.
VideoBufvariableCurrent screen image.
VideoBufSizevariableSize of the screen image.

Topics

viddrivertopicWriting a custom video driver.
vidutiltopicExamples utility unit.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.