home *** CD-ROM | disk | FTP | other *** search
- /*
- demoswap.c
-
- C-scape 3.2 Example Program
- Copyright (c) 1990 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- This program demonstrates how C-scape programs can swap between
- graphics and text modes.
-
- It places a C-scape window on the display in text mode and asks
- for the name of a .pcx file. If you enter a valid .pcx file
- it switches into graphics mode and displays the image in a
- pmap window. It waits for a keystroke and then goes back into
- text mode.
-
- In general, to swap between text and graphics modes requires the
- contruction of two device interfaces. Each of these interfaces
- are constructed by calling disp_Init(). Only one device interface
- can be current at one time, however. So you must call disp_Init()
- for one mode first, save the current device interface, and then
- call disp_Init() for the other mode. You then swap back and forth
- between the two device interfaces depending on which mode you wish to
- use.
-
- Each device interface has its own window manager and set of windows.
- A window created while one device interface is current does not exist
- under the other device interface. If you wish to have a similar window
- under text and graphics modes, you must create separate copies of
- the windows for each mode.
-
- For example:
-
- 1) open text device interface,
-
- disp_Init(def_ModeText, NULL);
-
- 2) save a pointer to the text interface, (note that disp_GetCurrent
- shuts down the current interface (without closing it) , you
- should call it only when you are about to make another interface
- current),
-
- VOID *textdisp;
-
- textdisp = disp_GetCurrent();
-
- 3) now create a graphics mode interface,
-
- disp_Init(def_ModeGraphics, NULL);
-
- 4) save a pointer to the graphics mode interface and make the
- text mode interface current again,
-
- VOID *grafdisp;
-
- grafdisp = disp_GetCurrent();
- disp_SetCurrent(textdisp);
-
- 5) we can now use C-scape in text mode. If we want to put up
- windows in graphics mode, we shut down the text interaface
- and set the current device interface to the graphics interface,
-
- textdisp = disp_GetCurrent();
- disp_SetCurrent(grafdisp);
-
-
- You can also use this technique to drive two displays at once. If
- your PC has both a graphics and text display, the text interface
- will communicate with the text display and the graphics interface
- will communicate with the graphics display.
-
- Note: THIS PROGRAM MUST BE COMPILED IN LARGE MODEL!
- (it needs more than 64k of data)
-
- Revision History:
- -----------------
- 4/01/90 jmd ansi-fied
- 6/06/90 jmd changed main to return an int
- 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 prototyped main, except if Turbo C++.
- 12/04/90 ted restored "" includes for C-scape headers (not <> includes).
- */
-
- #include <stdio.h>
- #include <string.h>
-
- #include "cscape.h"
- #include "ostdlib.h" /* for exit() */
- #include "popdecl.h"
-
- #include "pmwinobj.h" /* for pmwin stuff */
-
- /*** Function prototypes ***/
-
- /* Turbo C++ complains if main is prototyped */
- #ifndef TCP
- int main(void);
- #endif
-
- void go(void);
- boolean showit(char *fname);
-
- /*** Global data ***/
-
- static VOID *textdisp, *grafdisp;
- static win_type pcxwin;
-
- /* -------------------------------------------------------------------------- */
-
- int main(void)
- {
- ocbox charbox;
-
- /* Set up text display */
- disp_Init(def_ModeText, FNULL);
-
- /* Turn on mouse support */
- hard_InitMouse();
- sedwin_ClassInit();
-
- /* map colors for monochrome displays */
- if (disp_GetColors() <= 2L) {
- disp_MapMono(TRUE);
- }
-
- /* Save a pointer to the text interface and shut it down */
- textdisp = disp_GetCurrent();
-
- /* Init graphics mode display interface, save a pointer to it */
- disp_Init(def_ModeGraphics, FNULL);
- hard_InitMouse();
-
- /* Turn on pmap window mouse support */
- pmwin_MouseInit();
-
- /* Turn on pmap window .pcx file handling */
- pmap_IoInit();
-
- /* create the pmap window in which we'll show the .pcx image */
- /* this window will belong the the graphics device interface */
- charbox.toprow = 1;
- charbox.leftcol = 1;
- charbox.botrow = disp_GetHeight() - 2;
- charbox.rightcol = disp_GetWidth() - 2;
-
- pcxwin = win_Open(pmwin_Class, &charbox);
-
- win_SetBorder(pcxwin, bd_prompt);
- bord_SetTitle(pcxwin, "PCX Image");
-
- /* now go back to text mode (shut down graphics interface and remember it) */
- grafdisp = disp_GetCurrent();
- disp_SetCurrent(textdisp);
-
- /* Now, create a sed to get the name of a .pcx file to view. */
- go();
-
- /* close graphics mode interface */
- textdisp = disp_GetCurrent();
- disp_SetCurrent(grafdisp);
- disp_Close();
-
- /* close text mode interface */
- disp_SetCurrent(textdisp);
- disp_Close();
-
- exit(0);
- return(0);
- }
- /* -------------------------------------------------------------------------- */
-
- void go(void)
- /*
- Create a sed, get the name of a PCX file and show it.
- Quit when the user presses Escape.
- */
- {
- menu_type menu;
- sed_type sed;
- char pcxfname[81];
- pcxfname[0] = '\0';
-
- menu = menu_Open();
-
- menu_Printf(menu, "@[15, ]┌@[12,─]┐\n PCX File name:│@[12, ]│\n@[15, ]└@[12,─]┘\n");
-
- menu_Printf(menu, "@p[1,16]@fdw12[@[80,#]]", pcxfname, &string_funcs,
- "Press Escape to quit");
-
- menu_Flush(menu);
-
- sed = sed_Open(menu);
- sed_SetColors(sed, 0x34, 0x3f, 0x43);
-
- sed_SetBorder(sed, bd_prompt);
- sed_SetBorderTitle(sed, "PCX IMAGE FILE VIEWER");
- sed_SetBorderFeature(sed, BD_MOVE);
- sed_SetPosition(sed, 2, 21);
- sed_SetHeight(sed, 3);
- sed_SetWidth(sed, 30);
-
- sed_Repaint(sed);
-
- for (;;) {
- if (sed_Go(sed) == 0) {
- break;
- }
- else if (!showit(pcxfname)) {
- sed_BorderPrompt(sed, " File Not Found ");
- }
- }
- sed_Close(sed);
- }
-
- boolean showit(char *fname)
- /*
- Open the .pcx file, swap into graphics mode
- and show the image.
-
- return when the user presses a key.
- */
- {
- FILE *fp;
- pmap_type pmap = NULL;
- ocolmap_type crange;
-
- /* Now we'll use the graphics display
- note that we must swap modes before calling
- any display related functions
- */
-
- textdisp = disp_GetCurrent();
- disp_SetCurrent(grafdisp);
-
- /* First, try to open file in binary mode */
- if ((fp = fopen(fname, "rb")) != NULL) {
-
- /* Create a color range for the pmap, the color range defines
- the palette of colors used to create the image.
- */
- crange = ocolmap_Open(0, 16);
-
- /* Load pmap from file and close file */
- pmap = pmap_Load(fp, crange);
- fclose(fp);
-
- /* close the color range */
- ocolmap_Close(crange);
-
- /* attach the pmap to the window */
- pmwin_SetPmap(pcxwin, pmap);
- }
-
- if (pmap != NULL) {
- bord_SetTitle(pcxwin, "Now Showing:");
-
- bord_SetPrompt(pcxwin, fname);
- bord_SetFeature(pcxwin, BD_MOVE | BD_RESIZE);
-
- if (win_IsEmployed(pcxwin)) {
- bord_Paint(pcxwin); /* Paint win contents and new border Title */
- }
- else {
- /* employ the window (first time here) */
- win_Employ(pcxwin);
- }
-
- /* prompt for a keystroke */
- pop_Prompt("Press Enter to return to text mode.", disp_GetHeight() - 6, disp_GetWidth() /2, -1, 26, 0x70, bd_1);
-
- /* close the pmap */
- pmap_Close(pmap);
- pmwin_SetPmap(pcxwin, NULL);
- }
-
- /* Now we go back to using the text display */
- grafdisp = disp_GetCurrent();
- disp_SetCurrent(textdisp);
-
- return(pmap != NULL);
- }
- /* -------------------------------------------------------------------------- */
-
-
- void ModeSwitch(int ToText)
- {
- if (ToText) {
- grafdisp = disp_GetCurrent();
- disp_SetCurrent(textdisp);
- }
- else {
- textdisp = disp_GetCurrent();
- disp_SetCurrent(grafdisp);
- }
-
- return;
- }
-