Getting More Than One Background Color in Graphics ModeID: Q50411
|
|-----------------------------------------------------------------|
| |
| Light Blue Background |
| |
| |------------------------| |
| | | |
| | Dark Blue | |
| | Background | |
| | | |
| |------------------------| |
| |
| |
|-----------------------------------------------------------------|
This is not difficult. The primary problem is getting around the fact
that, when using _outtext(), the text always outputs on blocks of the
current background color. The result of this is that inside of your
dark blue window, you will have text surrounded by borders of light
blue (not very attractive!).
/* WINDOW.C: A sample program that illustrates changing the */
/* color for a window using _outtext, _floodfill, and _rectangle. */
#include <graph.h> /* for the graphics functions */
#include <conio.h> /* for getch() */
void main(void)
{
_setvideomode(_ERESCOLOR); /* set to graphics mode */
_setbkcolor(_BLUE); /* change background color */
_setcolor(1); /* set drawing color */
_settextcolor(3); /* set text color */
_rectangle(_GFILLINTERIOR,100,100,540,250); /* draw a window */
_setcolor(9); /* change color for fill */
_floodfill(1, 1, 1); /* fill in the background */
_settextposition(14, 35); /* coordinates inside square */
_outtext("scribble"); /* output text inside square */
getch(); /* wait for a key hit */
_setvideomode(_DEFAULTMODE); /* reset the video mode */
}
======================================================================
/* FONTS.C : a slight modification to the "FONTS.C" program from */
/* the QuickC 2.0 online Help system, which outputs the fonted text */
/* onto a "window" of a different color, easily producing the */
/* effect of a secondary, window-area-only background color. */
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graph.h>
#define NFONTS 6
unsigned char *face[NFONTS] =
{
"Courier", "Helvetica", "Times Roman", "Modern", "Script", "Roman"
};
unsigned char *options[NFONTS] =
{
"courier", "helv", "tms rmn", "modern", "script", "roman"
};
main ()
{
unsigned char list[20];
/* modify the following path as necessary!!!!! */
char fondir[_MAX_PATH]="d:\\qc2\\samples\\*.fon";
struct videoconfig vc;
struct _fontinfo fi;
short fontnum, x, y, mode = _VRES16COLOR;
/* Read header info from all .FON files in given directory. */
if (_registerfonts(fondir) <= 0)
{
_outtext("Error: can't register fonts\n");
exit(1);
}
/* Set highest available graphics mode and get configuration. */
while (!_setvideomode(mode))
mode--;
if (mode == _TEXTMONO)
exit(1);
_getvideoconfig(&vc);
/* Display each font name centered on screen. */
for (fontnum = 0; fontnum < NFONTS; fontnum++)
{
/* Build options string. */
strcat(strcat(strcpy(list, "t'"), options[fontnum]), "'");
strcat(list, "h30w24b");
_clearscreen(_GCLEARSCREEN);
if (_setfont(list) >= 0)
{
/* Use length of text and height of font to center text. */
x = (vc.numxpixels / 2)
- (_getgtextextent(face[fontnum]) / 2);
if (_getfontinfo(&fi))
{
_outtext("Error: Can't get font information\n");
break;
}
y = (vc.numypixels / 2) - (fi.ascent / 2);
_moveto(x, y);
if (vc.numcolors > 2)
/* set up the background window & fill before text output
*/
_setcolor(fontnum + 2); /* set window color */
_rectangle(_GFILLINTERIOR, 100, 100, 540, 250);
_setcolor(fontnum + 1); /* set color for text */
_outgtext(face[fontnum]); /* output fonted text */
getch();
}
else
_outtext("Error: Can't set font\n");
}
_unregisterfonts(); /* free up memory used by fonts */
exit(!_setvideomode(_DEFAULTMODE));
}
Additional query words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
Keywords : kb16bitonly
Version :
Platform :
Issue type :
Last Reviewed: July 26, 1999