Controlling Graphics Text Background Color and Size (90424)
The information in this article applies to:
- Microsoft Visual Basic for MS-DOS
- Microsoft Basic Professional Development System for MS-DOS 7.0
- Microsoft Basic Professional Development System for MS-DOS 7.1
- Microsoft QuickBASIC 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBASIC 4.5
This article was previously published under Q90424 SUMMARY
When printing text in graphics mode, the COLOR statement provides
little or no control over the background color. This article describes
a technique for printing graphics text with a foreground and
background color. The routines in this article also allow you to print
with a larger font.
MORE INFORMATION
In many screen modes, the COLOR statement sets the background color of
the entire screen. For example, when you print a line of text in
screen mode 7, Basic prints the text with the background color you
have chosen. However, if you later change the background color, it is
changed everywhere on the screen.
EGA and VGA display adapters contain information for displaying a
number of differently sized fonts on the screen. You can write a
program that reads this font information and uses it to write to the
screen. Some benefits to this are:
- You can set your own foreground and background colors, or you can
leave out the background completely and preserve what is there.
- You can change the size of the printing on the screen.
The following sample program can be used as a template when creating
your own programs to use this technique. It allows you to control
color and font size.
Code Example
' This program demonstrates how to use the font information stored
' in memory to display fonts of different sizes in EGA or VGA
' graphic modes.
' To try this example in VBDOS.EXE:
' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
'
' To run this program in the environment, you must invoke the
' environment with the /L option to load the default Quick library:
' VBDOS.EXE /L for Visual Basic 1.0 for MS-DOS.
' Use the following include file for Visual Basic 1.0 for MS-DOS:
REM $INCLUDE: 'vbdos.bi'
' Use the following include file for QuickBasic for MS-DOS:
REM $INCLUDE: 'qb.bi'
' Use the following include file for Basic PDS for MS-DOS:
REM $INCLUDE: 'qbx.bi'
DECLARE SUB outchar (c$, a%, b%, size%, fore%, back%, offset)
DECLARE FUNCTION powertwo% (n%)
DECLARE SUB outstring (s$, x%, y%, size%, fore%, back%)
DECLARE SUB drawframe (x1!, y1!, x2!, y2!)
SCREEN 12
' format: CALL outstring(message$, x, y, size, forecolor, backcolor).
CALL outstring("Pretty darn cool don't you think?", 0, 16, 2, 14, 1)
END
' This routine outputs one character to the display
' Arguments:
' c$ - Character to print.
' x% - Starting x pixel position.
' y% - Starting y pixel position.
' size% - Size multiplier (1 times, 2 times, etc).
' fore% - Foreground color.
' back% - Background color.
' offset - Offset of character definition table.
SUB outchar (c$, x%, y%, size%, fore%, back%, offset)
CONST mult = 14 ' Height of each character.
addr% = ASC(c$) * mult + offset
FOR j% = 0 TO 13 ' For each pixel row,
temp% = PEEK(addr% + j%) ' Get bit pattern of character.
FOR i% = 0 TO 7 ' For each pixel column:
startx = x% + (i% * size%)
starty = y% + (j% * size%)
endx = x% + ((i% + 1) * size%) - 1
endy = y% + ((j% + 1) * size%) - 1
IF temp% AND powertwo(7 - i%) THEN
LINE (startx, starty)-(endx, endy), fore%, BF ' Display foreground.
ELSE
LINE (startx, starty)-(endx, endy), back%, BF 'Display background.
END IF
NEXT
NEXT
END SUB
' This routine displays a string on the screen.
' Arguments:
' s$ - String to print.
' x% - Starting x pixel position.
' y% - Sstarting y pixel position.
' size% - Size multiplier (1 times, 2 times, etc).
' fore% - Foreground color.
' back% - Background color.
SUB outstring (s$, x%, y%, size%, fore%, back%)
DIM inregs AS RegTypeX, outregs AS RegTypeX
' Get address of font table in video ROM for 8 by 14 font.
inregs.ax = &H1130
inregs.bx = &H200
CALL INTERRUPTX(&H10, inregs, outregs)
DEF SEG = outregs.es
offset = outregs.bp
FOR i% = 1 TO LEN(s$)
c$ = MID$(s$, i%, 1) ' Get character to print.
cx% = x% + (i% - 1) * 8 * size% ' Calculate x position.
outchar c$, cx%, y%, size%, fore%, back%, offset ' Print it.
NEXT
DEF SEG ' Reset Default Segment.
END SUB
' Calculate 2 to the n'th power.
'
FUNCTION powertwo% (n%)
temp% = 1
FOR x% = 1 TO n%
temp% = temp% * 2
NEXT x%
powertwo% = temp%
END FUNCTION
Modification Type: | Minor | Last Reviewed: | 8/16/2005 |
---|
Keywords: | KB90424 |
---|
|