home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / C_DISK5.ZIP / MICROCAD / MICROCAD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-24  |  3.2 KB  |  110 lines

  1. // Copyright 1988 Bruce Eckel
  2. // Permission required to distribute source
  3.  
  4. // file: microcad.cpp
  5. /* The main driver program for the CAD system.
  6.    This includes all the other types I've defined,
  7.    declares some instances, and makes them dance
  8.    around. */
  9. #include        <stdio.h>
  10. #include    <stdlib.h>
  11. #include    <conio.h>
  12. #include    <msmouse.h>
  13. // flash graphics declarations:
  14. #include        <fg.h>      
  15. // (All items starting with "fg" are from
  16. // the flash graphics library)
  17. #include        <string.h>
  18. #include        "msmenu.hpp"  
  19. #include        "circle.hpp"  
  20. #include        "square.hpp"  
  21. #include        "line.hpp"    
  22. #include        "shapelst.hpp"
  23.  
  24. // associate unique integers with the following:
  25. enum { CIRCLE, SQUARE, LINE, MOVE, DELETE, EXIT};
  26.  
  27. struct menu_s my_menu[] = {
  28.   " circle",    CIRCLE,
  29.   " square",    SQUARE,
  30.   " line",      LINE,
  31.   " move",      MOVE,
  32.   " delete",    DELETE,
  33.   " exit",      EXIT,
  34.   "", -1             /* end marker */
  35. };
  36.  
  37.  
  38. main() { 
  39. unsigned x, y;
  40. int quit = 0;  // flag
  41. int result;
  42. shapelist list;
  43. if (fg_init_all () == FG_NULL) {
  44.   fputs ("Unable to open graphics device.\n", 
  45.           stderr);
  46.   exit (1);
  47.   }
  48.  
  49. // create an msmenu and attach our menu:
  50. msmenu mouse(my_menu);
  51.  
  52. while (!quit) {  
  53.     // look for right button press:
  54.     if (msm_getstatus(&x,&y) & 2) { 
  55.         // get a menu selection:
  56.         result = mouse.get_selection(x,y);
  57.         // change from mouse to fg coords:
  58.         mouse.translate_coords(&x,&y);
  59.     mouse.boundary_check(&x,&y);
  60.         switch(result) {
  61.             case CIRCLE:
  62.                 // create an object on the free
  63.                 // store via "new" and add it
  64.                 // to the list:
  65.                 list.insert(new circle(x,y));
  66.                 break;
  67.             case SQUARE:
  68.                 list.insert(new square(x,y));
  69.                 break;
  70.             case LINE:
  71.                 list.insert(new line(x,y));
  72.                 break;
  73.             case MOVE:
  74.                 mouse.cross_cursor();
  75.                 mouse.wait_left_pressed(&x,&y);
  76.                 // you can declare a variable at 
  77.                 // the point of use:
  78.                 cadshape * mv = list.nearest(x,y);
  79.                 // (I think nearest() needs work).
  80.                 // object pointers use arrows 
  81.                 // for de-referencing members:
  82.                 mv->erase(); // pick it up
  83.                 mouse.wait_left_released(&x,&y);
  84.                 mouse.translate_coords(&x,&y);
  85.         mouse.boundary_check(&x,&y);
  86.                 mv->move(x,y); // put it down
  87.                 mouse.default_cursor();
  88.                 break;
  89.             case DELETE:
  90.                 mouse.cross_cursor();
  91.                 mouse.wait_left_pressed(&x,&y);
  92.                 mouse.translate_coords(&x,&y);
  93.                 cadshape * rm = list.nearest(x,y);
  94.                 rm->erase();
  95.                 list.remove(rm);
  96.                 // free the memory created w/ new:
  97.                 delete rm;
  98.                 mouse.default_cursor();
  99.                 break;
  100.             case EXIT: 
  101.                 quit++;
  102.                 break;
  103.             default:
  104.                 break;
  105.         }
  106.     } 
  107. }
  108.     fg_term(); // back to text mode
  109. }
  110.