home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 1.ddi / EXAMPLE.EXE / CSCAPE / EXAMPLE / DEMOPCX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-12  |  6.1 KB  |  247 lines

  1. /*
  2.     demopcx.c
  3.  
  4.     jmd 8/89
  5.  
  6.     Copyright (c) 1989, by Oakland Group, Inc.
  7.     ALL RIGHTS RESERVED.
  8.  
  9.     OVERVIEW:
  10.     ---------
  11.  
  12.     This program demonstrates how to use graphics and .pcx file 
  13.     images with C-scape.  In particular it shows how to open
  14.     a pmap (pixel map graphics) window, load an image into it
  15.     from a .pcx file, and attach the window to a sed as a bob.
  16.  
  17.     A .pcx file contains a graphic image.  You can create them
  18.     with PC Paintbrush(tm) as well as a number of other popular
  19.     graphics packages.  This program assumes the three .pcx
  20.     files:     
  21.             abc.pcx, art.pcx, face.pcx, graph.pcx
  22.  
  23.     are in the current directory when it is run.
  24.  
  25.     NOTE:  This will not work under UNIX as the current UNIX 
  26.     version has no graphics support.
  27.  
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <cscape.h>
  33.  
  34. #include <pmwinobj.h>        /* for pmwin stuff */
  35.  
  36. /*** Function Prototypes ***/
  37. boolean demo_pcx(_arg1(void));
  38. void     about(_arg1(sed_type));
  39.  
  40. /*** list of .pcx files ***/
  41.  
  42. char *pcx_files = "abc.pcx,art.pcx,face.pcx,graph.pcx";
  43.  
  44. void main()
  45. {
  46.     boolean success;
  47.  
  48.     /* Initialize device interface */
  49.     disp_Init(def_ModeGraphics, NULL);
  50.  
  51.     if (disp_GetColors() <= 2L) {
  52.         disp_MapMono(TRUE);
  53.     }
  54.  
  55.     /* Turn on the mouse */
  56.     hard_InitMouse();
  57.  
  58.     /* Turn on sedwin mouse */
  59.     sedwin_ClassInit();
  60.  
  61.     /* Turn on pmap window mouse */
  62.     pmwin_MouseInit();
  63.     
  64.     /* Turn on pmap window .pcx file handling */
  65.     pmap_IoInit();
  66.  
  67.     /* call the main part of the program */
  68.     success = demo_pcx();
  69.  
  70.     /* close down the display interface */
  71.     disp_Close();
  72.  
  73.     if (!success) {
  74.         printf("demopcx: unable to find .pcx files\n");
  75.     }
  76. }
  77.  
  78. boolean demo_pcx()
  79. /*
  80.     Returns FALSE if it can't find the .pcx files
  81. */
  82. {
  83.     menu_type menu;
  84.     sed_type sed;
  85.     bob_type bob;
  86.     boolean     quit = FALSE;
  87.     boolean     ret = TRUE;
  88.  
  89.     win_type win;
  90.     ocbox cbox;
  91.     pmap_type pmap = NULL;
  92.     ocolmap_type crange;
  93.  
  94.     FILE *fp;
  95.     char  filename[15];
  96.  
  97.     strcpy(filename, "abc.pcx");
  98.  
  99.     /* Create a color range for the pmap,
  100.        the color range defines the palette of colors used to create the image.
  101.     */
  102.     crange = ocolmap_Open(0, 16);
  103.  
  104.     /* Create a pmap window to display the pmap */
  105.     /* first define the size of the windows in a ocbox structure: */
  106.     cbox.toprow   = 0;
  107.     cbox.leftcol  = 0;
  108.     cbox.botrow   = 17;
  109.     cbox.rightcol = 50;
  110.  
  111.     /* now create the window with win_Open.  We pass win_Open
  112.        the class function for the type of window we wish to create,
  113.        in this case pmwin_Class, and a pointer to the ocbox structure
  114.        defining its initial size and position.
  115.     */    
  116.         
  117.     win = win_Open(pmwin_Class, &cbox);
  118.  
  119.     win_SetAttr(win, 0x3f);
  120.     win_SetBorder(win, bd_mouse);
  121.  
  122.     /* Create a bob from the pmap window */
  123.     bob = win_CreateBob(win, BOB_DEPENDENT);
  124.  
  125.     /* Create a sed, attach the bob to it */
  126.     menu = menu_Open();
  127.  
  128.     menu_Printf(menu, " Picture: @fd2[############]\n", 
  129.         filename, &list_funcs, NULL, pcx_files);
  130.  
  131.     menu_Printf(menu, "          @fd2[New] ", NULL, &gmenu_funcs, NULL, "2");
  132.  
  133.     menu_Printf(menu, " @fd2[Quit] ", NULL, &gmenu_funcs, NULL, "0");
  134.  
  135.     menu_Printf(menu, " @fd2[About] ", NULL, &gmenu_funcs, NULL, "1");
  136.     
  137.     /* attach the pmap bob to a protected field 
  138.        (it makes no sense to pass control to an image)
  139.     */
  140.     menu_Printf(menu, "\n @fpb[]", NULL, &bob_funcs, bob);
  141.  
  142.     sed = sed_Open(menu);
  143.     sed_SetColors(sed, 0x34, 0x3f, 0x43);
  144.  
  145.     sed_SetBorder(sed, bd_1);
  146.     sed_SetBorderFeature(sed, BD_MOVE | BD_RESIZE);
  147.     sed_SetPosition(sed, 0, 1);
  148.  
  149.     sed_SetMouse(sed, sedmou_Track);
  150.  
  151.     /* sit in a loop displaying different pmaps */
  152.     while(!quit) {
  153.  
  154.         /* if we haven't already, load a pmap (pixel map) from a .pcx file */
  155.         if (pmap == NULL) {
  156.             /* first, open the file in binary mode */
  157.             if ((fp = fopen(filename, "rb")) == NULL) {
  158.                 ret = FALSE;
  159.                 break;
  160.             }
  161.  
  162.             /* now, load a pmap from the file and close the file */    
  163.             if ((pmap = pmap_Load(fp, crange)) == NULL) {
  164.                 ret = FALSE;
  165.                 break;
  166.             }
  167.  
  168.             fclose(fp);
  169.  
  170.             /* attach the pmap to the pamp window */
  171.             pmwin_SetPmap(win, pmap);
  172.  
  173.             /* paint the sed and the attached pmap window */
  174.             sed_Repaint(sed);
  175.         }
  176.  
  177.         /* go until Escape is pressed */
  178.         switch(sed_Go(sed)) {
  179.         case 0:
  180.             /* quit */
  181.             quit = TRUE;
  182.             break;
  183.         case 1:
  184.             /* about */
  185.             about(sed);
  186.             break;
  187.  
  188.         case 2:
  189.         default:
  190.             /* New: close the old pmap and then load a new one (above) */
  191.             pmap_Close(pmap);
  192.             pmwin_SetPmap(win, NULL);
  193.             pmap = NULL;
  194.             break;
  195.         }
  196.     }
  197.  
  198.     /* close the sed and pmap window */
  199.     sed_Close(sed);
  200.  
  201.     return(ret);
  202. }
  203.  
  204. void about(sed)
  205.     sed_type sed;
  206. {
  207.     menu_type menu;
  208.     sed_type  popsed;
  209.     int       row, col;
  210.  
  211.     menu = menu_Open();
  212.     menu_Printf(menu, "\n This is demopcx, which demonstrates the use of .pcx files\n");
  213.     menu_Printf(menu, " with C-scape.  It holds four pictures and you can look at\n");
  214.     menu_Printf(menu, " any (or all) of them\n\n");
  215.     menu_Printf(menu, " To look at a new picture, either press the Plus key or\n");
  216.     menu_Printf(menu, " click the mouse on the `pic' field.  This pops up a list\n");
  217.     menu_Printf(menu, " of the pictures which you can view.  After picking one,\n");
  218.     menu_Printf(menu, " either press Enter or click the mouse on the `New'\n");
  219.     menu_Printf(menu, " field--this will display the picture you selected.\n\n");
  220.     menu_Printf(menu, " If you are using a mouse, you can also scroll the picture\n");                             
  221.     menu_Printf(menu, " by clicking on either arrow in the scroll bar.  You can\n");                             
  222.     menu_Printf(menu, " also use the mouse to move this window--click on an edge\n");                             
  223.     menu_Printf(menu, " (not a corner) and drag it wherever you want it to go.\n");                            
  224.  
  225.     menu_Printf(menu, "\n\n                          @f[ OK ]  ", NULL, &gmenu_funcs);
  226.  
  227.     popsed = sed_Open(menu);
  228.     sed_SetHeight(popsed, 20);
  229.     sed_SetWidth(popsed, 60);
  230.  
  231.     sed_SetColors(popsed, 0x50, 0x50, 0x05);
  232.  
  233.     sed_GetPosition(sed, &row, &col);
  234.     sed_SetPosition(popsed, row + 3, col + 4);
  235.  
  236.     sed_SetBorder(popsed, bd_2);
  237.     sed_SetBorderFeature(popsed, BD_MOVE | BD_RESIZE);
  238.     sed_SetShadow(popsed, 1);
  239.  
  240.     sed_SetMouse(popsed, sedmou_GreedyClick);
  241.     sed_Repaint(popsed);
  242.  
  243.     sed_Go(popsed);
  244.  
  245.     sed_Close(popsed);
  246. }
  247.