home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
p
/
prbgi097.zip
/
C.ZIP
/
BGIDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-15
|
12KB
|
408 lines
/* This program is not mine.
It was included with Turbo/Borland C(++)
and I only modified it a little to demonstrate
features of my PRINTBGI library.
It is included here for demonstration only
and cannot be used for any other purposes. ( Could it? ).
Original Copyright notice follows.
*/
/*
GRAPHICS DEMO FOR TURBO C 2.0
Copyright (c) 1987,88,90 Borland International. All rights reserved.
From the command line, use:
tcc bgidemo graphics.lib
*/
#define CRTtextmode1 0 // set to 1 if you don't want to use InterBGI driver
#ifdef __TINY__
#error BGIDEMO will not run in the tiny model.
#endif
#include <dos.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <graphics.h>
#include "prtgraph.h"
#include "BGIDEMO.H"
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
static unsigned picwidth=4000,picheight=3000;
static int leftmargin=0,topmargin=0,
PicRotate=0, PicInverse=1;
static int PRTno;
static int mode;
static char OutName[MAXPATH]="PRN";
struct palettetype palette; /* Used to read palette info */
int static printing=0,asking=0;
int PRT_drv;
int PCXmode=0;
int ScreenPreview=1;
#define ESC 0x1b /* Define the escape key */
#include <assert.h>
#include <alloc.h>
#include "userprtf.c"
#include "harderrh.c"
/*-------------------*/
void grErrorTest(void)
/*-------------------*/
{ int ErrorCode;
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode == grOk ) return;
/* Error occurred */
#if CRTtextmode1
closegraph();
#else
BGI_closegraph();
#endif
printf(" Graphics System Error: %s\n", PRT_grapherrormsg( ErrorCode ) );
PRT_End();
exit( 16 );
}
#ifdef __cplusplus
#define min(x,y) ((x)<=(y)? (x):(y))
#endif
/* */
/* CHANGETEXTSTYLE: similar to settextstyle, but checks for */
/* errors that might occur whil loading the font file. */
/* */
void changetextstyle(int font, int direction, int charsize)
{
int m;
int x,y;
graphresult(); /* clear error code */
if ( printing && font == DEFAULT_FONT )
{
PRT_Resolution ( &x,&y );
m = min ( y+60/120, getmaxx()/600+1 );
if (m>1) charsize *=m;
}
settextstyle(font, direction, charsize);
grErrorTest();
}
int _scanf( const char * format, ... )
{ va_list ap;
int c,r;
c=getchar();
if ( c=='\n' ) return 0;
va_start(ap,format);
ungetc(c,stdin);
r = vscanf (format,ap); (void)getchar();
va_end(ap);
return r;
}
/*-----------------------*/
void AskOfParameters(void)
/*-----------------------*/
{ int c,MAXmode;
const char *modename;
char s[MAXPATH];
clrscr();
cprintf ( "\n\r Output device name [%s]", OutName );
gets ( s ); if (*s!=0) strcpy(OutName,s);
cputs("\r\n");
PRT_SetOutName ( OutName );
cputs ( "\r\n Choose printer mode operation\r\n" );
PRT_MaxMode ( PRTno, &MAXmode );
for ( mode=0; mode<=MAXmode; mode++ )
{
PRT_ModeName(PRTno,mode,&modename );
cprintf ( " %2d - %s\r\n", mode, modename );
}
mode=MAXmode+1;
do
{
c=getch();
if (c==0) getch();
else if ((unsigned)c-'0'<=(unsigned)MAXmode) mode=c-'0';
}
while ( mode>MAXmode);
cprintf ( "\n\r Picture width in 1/1000 inch [%d] ", picwidth );
_scanf ( "%d", &picwidth );
cprintf ( " Picture height in 1/1000 inch [%d] ", picheight );
_scanf ( "%d", &picheight );
cprintf ( " Top margin in 1/1000 inch [%d] ", topmargin );
_scanf ( "%d", &topmargin );
cprintf ( " Left margin in 1/1000 inch [%d] ", leftmargin );
_scanf ( "%d", &leftmargin );
cprintf ( " Rotate picture [%d] ", PicRotate );
_scanf ( "%d", &PicRotate );
cprintf ( " Inverse picture [%d] ", PicInverse );
_scanf ( "%d", &PicInverse );
cprintf ( " Screen Preview [%d] ", ScreenPreview );
_scanf ( "%d", &ScreenPreview );
cprintf ( " PCX mode [%d] ", PCXmode );
_scanf ( "%d", &PCXmode );
}
/*---------------------------------*/
void DrawAndPrint ( int far func(void far * UserPointer), void far* UserPointer )
/*---------------------------------*/
{ int rc;
int PRT_mode=0;
do
{
asking=0;
printing=0;
func(UserPointer);
if ( asking )
{ int mode;
mode = BGI_getgraphmode(Scrn_BGIgroup);
restorecrtmode();
AskOfParameters();
BGI_setgraphmode( mode );
}
if ( printing ) /* Have user pressed Ctrl-P ? */
{
PRT_SetUserBeforeBuildFunc( BuildingMsg );
// PRT_SetDriver ( PRTno, mode,picwidth,picheight,
// ( PicRotate ? PRT_ROTATE:0 ) | ( PicInverse ? PRT_INVERSE:0 ) );
PRT_SetPrinterDrv ( PRTno, mode );
PRT_SetPictureInch ( picwidth,picheight,
( PicRotate ? PRT_ROTATE:0 ) |
( PicInverse ? PRT_INVERSE:0 ) );
PRT_SetMargins ( leftmargin, topmargin );
PRT_HaltPrinting = 0; // reset break indicator
rc=PRT_PrintBGI ( &PRT_drv, &PRT_mode, getenv("BGIPATH"), func, UserPointer );
#if CRTtextmode1
BGI_setgraphmode(mode);
#endif
if ( rc )
{ int mode;
mode=BGI_getgraphmode(Scrn_BGIgroup);
restorecrtmode();
cprintf ("\r\n error code %d (%s) from PRT_PrintBGI \r\n", rc,
PRT_grapherrormsg(rc) );
getch();
BGI_setgraphmode(mode);
}
}
}
while ( asking || printing );
}
/*-----------------*/
void InitPBGI(void)
/*-----------------*/
{
const char *PRTname;
int MaxPrinterNo;
int rc;
rc=PRT_ReadDrivers(getenv("BGIPATH"),"Printers.Def");
// rc=PRT_LinkDrivers();
if ( rc!=0 )
{
cputs ("\r\nSorry - I can't find drivers defintion file\r\n" );
exit(8);
}
clrscr();
cputs ( "\r\n\n\n"
"\n\rThis is a sample program (developed from Borland's BGIDEMO.C)"
"\n\rdemonstrating some of the features of PrintBGI toolkit"
"\n\rHope you'll find it usefull (the whole package not this program,"
"\n\rof course).\n\r"
"\n\rSince this is only an example program for demonstrating purposes"
"\n\rit uses standard C scanf function to input data with all"
"\n\rconsequences of it." );
cputs ( "\r\n"
"\r\nPlease, let me know if this program does not work with your printer."
"\r\nTo contact me write to RESZTAK@PLUMCS11.bitnet " );
cputs ( "\n\r \n\r Press any key to continue");
if ( getch()==0 ) getch();
clrscr();
MaxPrinterNo = PRT_MaxDriver();
cputs ( "\r\n Choose printer type\r\n" );
for ( PRTno=1; PRTno<=MaxPrinterNo; PRTno++ )
{
PRT_DriverName(PRTno,&PRTname );
cprintf ( " %2d - %s \r\n", PRTno, PRTname );
}
do
{
scanf( "%d",&PRTno);
(void)getchar();
}
while ( PRTno>MaxPrinterNo || PRTno<=0 );
clrscr();
PRT_drv = DETECT; /* <-- needed if you don't want link BitImage BGI driver */
PRT_drv = PRT_installuserdriver ( "BitImage", NULL );
rc = PRT_registerfarbgidriver ( BitImage );
AskOfParameters();
cputs ( "\r\n\r\n You will be able to change above parameters by pressing Ctrl-C." );
cputs ( "\n\r \n\r Press any key to continue");
if ( getch()==0 ) getch();
PRT_SetUserPrintFunc(StdUserPrtFunc);
}
#ifdef __cplusplus
void interrupt (*old_0x1b)(...);
#else
void interrupt (*old_0x1b)(void);
#endif
void restore_0x1b(void)
{
setvect(0x1b,old_0x1b);
}
/* */
/* Begin main function */
/* */
int main()
{ float f,g;
assert ( heapfillfree(0x12f7) > 0 );
assert ( heapcheckfree(0x12f7) > 0 );
assert ( heapcheck() > 0 );
harderr(harderr_handler);
old_0x1b = getvect(0x1b);
atexit(restore_0x1b);
setvect(0x1b,CtrlBreak_handler);
f=14; g=12;
f = f+g; g=f*g;
InitPBGI();
Initialize(); /* Set system into Graphics mode */
DrawAndPrint ( ReportStatus, &GraphDriver ); /* Report results of the initialization */
DrawAndPrint ( ColorDemo, NULL ); /* Begin actual demonstration */
// if( GraphDriver==EGA || GraphDriver==EGALO || GraphDriver==VGA )
// PaletteDemo();
DrawAndPrint ( PutPixelDemo, NULL );
DrawAndPrint ( PutImageDemo, NULL );
DrawAndPrint ( Bar3DDemo, NULL );
DrawAndPrint ( BarDemo, NULL );
DrawAndPrint ( RandomBars, NULL );
DrawAndPrint ( ArcDemo, NULL );
DrawAndPrint ( CircleDemo, NULL );
DrawAndPrint ( PieDemo, NULL );
DrawAndPrint ( LineRelDemo, NULL );
DrawAndPrint ( LineToDemo, NULL );
DrawAndPrint ( LineStyleDemo, NULL );
DrawAndPrint ( UserLineStyleDemo, NULL );
TextDump();
TextDemo();
/* CRTModeDemo(); */
DrawAndPrint ( FillStyleDemo, NULL );
DrawAndPrint ( FillPatternDemo, NULL);
DrawAndPrint ( PolyDemo, NULL );
DrawAndPrint ( SayGoodbye, NULL ); /* Give user the closing screen */
#if CRTtextmode1
closegraph();
#else
BGI_closegraph(); /* Return the system to text mode */
#endif
PRT_End();
return(0);
}
/* */
/* INITIALIZE: Initializes the graphics system and reports */
/* any errors which occured. */
/* */
void Initialize(void)
{
/* int xasp, yasp; */ /* Used to read the aspect ratio*/
GraphDriver = DETECT; /* Request auto-detection */
#if CRTtextmode1
initgraph( &GraphDriver, &GraphMode, getenv("BGIPATH") );
#else
BGI_initgraph( &GraphDriver, &GraphMode, getenv("BGIPATH"), Scrn_BGIgroup );
#endif
grErrorTest();
getpalette( &palette ); /* Read the palette from board */
/* MaxColors = getmaxcolor() + 1; */ /* Read maximum number of colors*/
/* MaxX = getmaxx(); */
/* MaxY = getmaxy(); */ /* Read size of screen */
/* getaspectratio( &xasp, &yasp ); */ /* read the hardware aspect */
/* AspectRatio = (double)xasp / (double)yasp; */ /* Get correction factor */
}
/* */
/* PAUSE: Pause until the user enters a keystroke. If the */
/* key is an ESC, then exit program, else simply return. */
/* */
void Pause(void)
{
static char msg[] = "Esc aborts, Ctrl-P prints, other key continue ...";
int c;
// if ( !printing )
StatusLine( msg ); /* Put msg at bottom of screen */
if ( !printing )
{
c = getch(); /* Read a character from kbd */
if( 0 == c ) /* Did use hit a non-ASCII key? */
c = getch(); /* Read scan code for keyboard */
else
{
if( ESC == c ){ /* Does user wish to leave? */
#if CRTtextmode1
closegraph();
#else
BGI_closegraph(); /* Change to text mode */
#endif
PRT_End();
exit( 1 ); /* Return to OS */
}
if ( c == 16 ) /* Ctrl-P ? */
printing=1;
if ( c == 3 ) /* Ctrl-C ? */
asking=1;
}
// cleardevice(); /* Clear the screen */
}
}
#include "BGIDEMO.INC"