home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
EXAMPLES
/
DEMOPCX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-09
|
8KB
|
301 lines
/*
demopcx.c
jmd 8/89
C-scape 3.2 Example Program
Copyright (c) 1989, 1990 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
OVERVIEW:
---------
This program demonstrates how to use graphics and .pcx file
images with C-scape. In particular it shows how to open
a pmap (pixel map graphics) window, load an image into it
from a .pcx file, and attach the window to a sed as a bob.
A .pcx file contains a graphic image. You can create them
with PC Paintbrush(tm) as well as a number of other popular
graphics packages. This program assumes the four .pcx
files:
abc.pcx, art.pcx, face.pcx, graph.pcx
are in the current directory when it is run.
NOTE: THIS PROGRAM MUST BE COMPILED IN LARGE MODEL !!!
(it needs more than 64k of data)
NOTE: This will not work under UNIX as the current UNIX
version has no graphics support.
Revision History:
-----------------
2/03/90 jmd Made it close the pmap when it's done
4/01/90 jmd ansi-fied
6/06/90 jmd changed main to return an int
7/24/90 pmcm/pgo Made it close the pmap when it's done in all cases
9/14/90 bkd changed to use exit(0) instead of return(0).
10/19/90 pmcm included ostdlib.h for exit(), added return(1)
12/01/90 ted added 'void' arg list in demo_pcx() prototype & declaration.
12/01/90 ted prototyped main, except if Turbo C++.
12/04/90 ted added disp_SetColmap() and ocolmap_Close calls.
12/04/90 ted restored "" includes for C-scape headers (not <> includes).
12/19/90 ted added disp_GetColMap() call to init crange before loading
1-plane pcx files.
*/
#include <stdio.h>
#include <string.h>
#include "cscape.h"
#include "ostdlib.h" /* for exit() */
#include "pmwinobj.h" /* for pmwin stuff */
/*** Function prototypes ***/
/* Turbo C++ complains if main is prototyped */
#ifndef TCP
int main(void);
#endif
boolean demo_pcx(void);
void about(sed_type sed);
/*** list of .pcx files ***/
char *pcx_files = "abc.pcx,art.pcx,face.pcx,graph.pcx";
int main(void)
{
boolean success;
/*
Initialize the C-scape device interface:
def_ModeGraphics selects best available graphics mode
*/
if (!disp_Init(def_ModeGraphics, FNULL)) {
printf("\nDEMOPCX: No graphics hardware found.");
printf("\n Or, there is insufficient memory to initialize the OWL ...");
printf("\n (This program requires a large memory model.)\n");
exit(1);
return(1);
}
/* map colors for 2 color video modes */
if (disp_GetColors() <= 2L) {
disp_MapMono(TRUE);
}
/* Turn on the mouse */
hard_InitMouse();
/* Turn on sedwin mouse */
sedwin_ClassInit();
/* Turn on pmap window mouse support */
pmwin_MouseInit();
/* Turn on pmap window .pcx file handling */
pmap_IoInit();
/* call the main part of the program */
success = demo_pcx();
/* close down the display interface */
disp_Close();
if (!success) {
printf("\nDEMOPCX: Unable to open .pcx files; or,\n");
printf("\n Unable to load .pcx image\n");
}
exit(0);
return(0);
}
boolean demo_pcx(void)
/*
Returns FALSE if it can't find the .pcx files
*/
{
menu_type menu;
sed_type sed;
bob_type bob;
boolean quit = FALSE;
boolean ret = TRUE;
win_type win;
ocbox cbox;
pmap_type pmap = NULL;
ocolmap_type crange;
FILE *fp;
char filename[15];
strcpy(filename, "face.pcx");
/*
Create a color range for the pmap; the color range contains the palette
of colors used to create the image.
Initialize it to contain the current system display colors.
*/
crange = ocolmap_Open(0, 16);
disp_GetColMap(crange);
/* Create a pmap window to display the pmap */
/* first define the size of the windows in a ocbox structure: */
cbox.toprow = 0;
cbox.leftcol = 0;
cbox.botrow = 17;
cbox.rightcol = 50;
/*
now create the window with win_Open. We pass win_Open
the class function for the type of window we wish to create,
in this case pmwin_Class, and a pointer to the ocbox structure
defining its initial size and position.
*/
win = win_Open(pmwin_Class, &cbox);
win_SetAttr(win, 0x3f);
win_SetBorder(win, bd_mouse2);
/* Create a bob from the pmap window */
bob = win_CreateBob(win, BOB_DEPENDENT);
/* Create a sed, attach the bob to it */
menu = menu_Open();
menu_Printf(menu, " Picture: @fd2[############]\n",
filename, &list_funcs, NULL, pcx_files);
menu_Printf(menu, " @fd2[New] ", NULL, &gmenu_funcs, NULL, "2");
menu_Printf(menu, " @fd2[Quit] ", NULL, &gmenu_funcs, NULL, "0");
menu_Printf(menu, " @fd2[About] ", NULL, &gmenu_funcs, NULL, "1");
/* attach the pmap bob to a protected field
(it makes no sense to pass control to an image)
*/
menu_Printf(menu, "\n @fpb[]", NULL, &bob_funcs, bob);
sed = sed_Open(menu);
sed_SetColors(sed, 0x34, 0x3f, 0x43);
sed_SetBorder(sed, bd_1);
sed_SetBorderFeature(sed, BD_MOVE | BD_RESIZE);
sed_SetPosition(sed, 0, 1);
sed_SetMouse(sed, sedmou_Track);
/* sit in a loop displaying different pmaps */
while(!quit) {
/* if we haven't already, load a pmap (pixel map) from a .pcx file */
if (pmap == NULL) {
/* first, open the file in binary mode */
if ((fp = fopen(filename, "rb")) == NULL) {
ret = FALSE;
break;
}
/* now, load a pmap from the file and close the file */
if ((pmap = pmap_Load(fp, crange)) == NULL) {
ret = FALSE;
break;
}
disp_SetColMap(crange);
fclose(fp);
/* attach the pmap to the pmap window */
pmwin_SetPmap(win, pmap);
/* paint the sed and the attached pmap window */
sed_Repaint(sed);
}
/* go until Escape is pressed */
switch(sed_Go(sed)) {
case 1:
/* about */
about(sed);
break;
case 0:
/* quit */
quit = TRUE;
/* no break, fall through */
case 2:
default:
/* New: close the old pmap and then load a new one (above) */
pmap_Close(pmap);
pmwin_SetPmap(win, NULL);
pmap = NULL;
break;
}
}
if (pmap != NULL) {
pmap_Close(pmap);
pmwin_SetPmap(win, NULL);
pmap = NULL;
}
/* close the sed and pmap window */
sed_Close(sed);
ocolmap_Close(crange);
return(ret);
}
void about(sed_type sed)
{
menu_type menu;
sed_type popsed;
int row, col;
menu = menu_Open();
menu_Printf(menu, "\n This is demopcx, which demonstrates the use of .pcx files\n");
menu_Printf(menu, " with C-scape. It holds four pictures and you can look at\n");
menu_Printf(menu, " any (or all) of them\n\n");
menu_Printf(menu, " To look at a new picture, either press the Plus key or\n");
menu_Printf(menu, " click the mouse on the `pic' field. This pops up a list\n");
menu_Printf(menu, " of the pictures which you can view. After picking one,\n");
menu_Printf(menu, " either press Enter or click the mouse on the `New'\n");
menu_Printf(menu, " field--this will display the picture you selected.\n\n");
menu_Printf(menu, " If you are using a mouse, you can also scroll the picture\n");
menu_Printf(menu, " by clicking on either arrow in the scroll bar. You can\n");
menu_Printf(menu, " also use the mouse to move this window--click on an edge\n");
menu_Printf(menu, " (not a corner) and drag it wherever you want it to go.\n");
menu_Printf(menu, "\n\n @f[ OK ] ", NULL, &gmenu_funcs);
popsed = sed_Open(menu);
sed_SetHeight(popsed, 20);
sed_SetWidth(popsed, 60);
sed_SetColors(popsed, 0x50, 0x50, 0x05);
sed_GetPosition(sed, &row, &col);
sed_SetPosition(popsed, row + 3, col + 4);
sed_SetBorder(popsed, bd_2);
sed_SetBorderFeature(popsed, BD_MOVE | BD_RESIZE);
sed_SetShadow(popsed, 1);
sed_SetMouse(popsed, sedmou_GreedyClick);
sed_Repaint(popsed);
sed_Go(popsed);
sed_Close(popsed);
}