home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / touchup / part06 / touchup.c < prev   
Encoding:
C/C++ Source or Header  |  1988-06-14  |  18.7 KB  |  779 lines

  1.  
  2. /**************************************************************************
  3.    Touchup a bitmap graphics editor for the Sun Workstation running SunView
  4.    Copyright (c) 1988 by Raymond Kreisel
  5.    1/22/88 @ Suny Stony Brook
  6.  
  7.    This program may be redistributed without fee as long as this copyright
  8.    notice is intact.
  9.  
  10. ==> PLEASE send comments and bug reports to one of the following addresses:
  11.  
  12.        Ray Kreisel
  13.        CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  14.  
  15.        UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  16.        ARPA-Internet: rayk@sbcs.sunysb.edu            
  17.        CSnet: rayk@suny-sb
  18.        (If nobody is home at any of the above addresses try:
  19.         S72QKRE@TOWSONVX.BITNET                    )
  20.  
  21.  "If I get home before daylight, I just might get some sleep tonight...."
  22.  
  23. **************************************************************************/
  24. /**************************************************************************
  25.     file: touchup.c
  26.     purpose: this file has misc functions that do different crap
  27.         but mostly the event handler for the main drawing
  28.         area
  29.     modifications:
  30.         date:    Tue Mar 22 22:04:58 EST 1988
  31.         author:    rayk
  32.         changes:add comments
  33. **************************************************************************/
  34.  
  35. #include "header.h"
  36.  
  37. unsigned char red[256],green[256],blue[256];
  38. int image_wid= DEFAULT_IMAGE_WID,image_hgt= DEFAULT_IMAGE_HGT,image_depth=1;
  39. int top_x=0,top_y=0,bottom_x=0,bottom_y=0;
  40. int cur_color=1,grid_size=0;
  41. int magnify_fac=8,fat_x,fat_y,fat_source_x=0-1,fat_source_y=0-1;
  42. int mouse_left=PAINT,undo_flag=TRUE;
  43. int select_pt_x=0-1,select_pt_y=0-1;
  44. int old_x=0; old_y=0;
  45. int start_x=0; start_y=0;
  46. char file_name[MAX_FILE_NAME];
  47. struct pixrect *cut_buffer_pr=NULL,
  48.         *undo_pr=NULL;
  49.  
  50. struct pixfont *main_font=NULL;
  51.  
  52. /*
  53.  * this is the event handler for the special cut/paste command menu
  54.  */
  55. region_handle(item, event)
  56. Panel_item      item;
  57. Event           *event;
  58. {
  59.     switch((int)panel_get_value(region_choice)) {
  60.     case CUT:
  61.         cut_region();
  62.             break;
  63.     case COPY:
  64.         print_msg("Region copied to Cut/Paste buffer. Hold down the RIGHT mouse button to drag the object.");
  65.         panel_set(region_choice,PANEL_VALUE,MOVE,0);
  66.         copy_region();
  67.             break;
  68.     case FLIP_HOR:
  69.         flip_hor_region();
  70.             break;
  71.     case FLIP_VER:
  72.         flip_ver_region();
  73.             break;
  74.     case ROTATE:
  75.         rotate_region();
  76.             break;
  77.     case INVERSE:
  78.         inverse_region();
  79.             break;
  80.     case PASTE:
  81.                 paste_region();
  82.             break;
  83.     case MOVE:
  84.         print_msg("Hold down the RIGHT mouse button and drag the object.");
  85.             break;
  86.     }
  87.  
  88. }
  89.  
  90.  
  91. /*
  92.  * this is the event handler for the main comand menu
  93.  */
  94. command_handle(item, event)
  95. Panel_item      item;
  96. Event           *event;
  97. {
  98.   hide_msg();
  99.   if ((int)panel_get_value(command_choice) != GET_PT)
  100.     {
  101.       (void)window_set(region_panel, WIN_SHOW, FALSE, 0);
  102.       panel_set(region_choice,PANEL_VALUE,5,0);
  103.     }
  104.   (void)window_set(brush_panel, WIN_SHOW, FALSE, 0);
  105.     switch((int)panel_get_value(command_choice)) {
  106.     case TEXT:
  107.           draw_text();
  108.             break;
  109.     case LASO:
  110.           print_msg("Hold down the LEFT mouse button and encircle a object.");
  111.           mouse_parms();
  112.             break;
  113.     case CIRCLE:
  114.           print_msg("Hold down the LEFT mouse button and extend to radius of the circle.");
  115.           mouse_parms();
  116.             break;
  117.     case DRAW:
  118.           print_msg("Press the LEFT mouse button to DRAW.");
  119.           mouse_parms();
  120.             break;
  121.     case LINE:
  122.           print_msg("Hold down the LEFT mouse button and extend to end of the line.");
  123.           mouse_parms();
  124.             break;
  125.     case MAGNIFY:
  126.           print_msg("Use LEFT button to draw, hold down MIDDLE button to move.");
  127.           fat_mode();
  128.             break;
  129.     case FFILL:
  130.           fill_mode(item, event);
  131.           mouse_parms();
  132.             break;
  133.     case OVAL:
  134.              print_msg("Hold down the LEFT mouse button and extend to edge of the oval.");
  135.           mouse_parms();
  136.             break;
  137.     case POLY_F:
  138.     case POLY_H:
  139.           print_msg("Press the LEFT mouse button to select a vertex.");
  140.           mouse_parms();
  141.             break;
  142.     case RECT_F:
  143.     case RECT_H:
  144.           print_msg("Hold down the LEFT mouse button and extend to the opposite corner.");
  145.           mouse_parms();
  146.             break;
  147.     case PAINT:
  148.           print_msg("Press the LEFT mouse button to PAINT.");
  149.           mouse_parms();
  150.           (void)window_set(brush_panel, WIN_SHOW, TRUE, 0);
  151.             break;
  152.     case SEL_REG:
  153.           print_msg("Hold down the LEFT mouse button and extend to the opposite corner.");
  154.           if (mouse_left == SEL_REG)
  155.             {
  156.               clean_region();
  157.               top_x = 0;
  158.               top_y = 0;
  159.                   bottom_x = image_wid;
  160.               bottom_y = image_hgt;
  161.               select_region(pw,top_x,top_y,bottom_x,bottom_y);
  162.             }
  163.           else
  164.             {
  165.               mouse_parms();
  166.             }
  167.           (void)window_set(region_panel, WIN_SHOW, TRUE, 0);
  168.           break;
  169.     case GET_PT:
  170.           print_msg("Press the LEFT mouse button to select a point.");
  171.           mouse_parms();
  172.             break;
  173.     case ERASE:
  174.           print_msg("Press the LEFT MOUSE button to ERASE.");
  175.           if ((mouse_left == ERASE) &&  (confirm("Erase entire drawing area ?")))
  176.             {
  177.             clear_screen();
  178.             (void)window_set(canvas,
  179.                   CANVAS_WIDTH,        DEFAULT_IMAGE_WID,
  180.                   CANVAS_HEIGHT,    DEFAULT_IMAGE_HGT,
  181.                 0);
  182.             }
  183.           else
  184.                     if (top_x || top_y || bottom_x || bottom_y)
  185.                 {
  186.              select_region(pw,top_x,top_y,bottom_x,bottom_y);
  187.                region_fix();
  188.                  pw_rop(pw,top_x,top_y,bottom_x-top_x,bottom_y-top_y,PIX_SRC,0,0,0);
  189.              reset_region();
  190.                 }
  191.           mouse_parms();
  192.             break;
  193.  
  194.     }
  195.  
  196. }     
  197.  
  198.  
  199.  
  200. /*
  201.  * save the screen to a temp bitmap for the undo command
  202.  */
  203. save_screen()
  204. {
  205.   if (undo_flag)
  206.   {
  207.     if (undo_pr == NULL)
  208.       undo_pr =my_mem_create(image_wid,image_hgt,image_depth);
  209.     pr_rop(undo_pr,0,0,image_wid,image_hgt,PIX_SRC,pw->pw_prretained,0,0);
  210.   }
  211. }     
  212.  
  213.  
  214. /*
  215.  * go back to the last saved bitmap
  216.  */
  217. undo_screen(item, event)
  218. Panel_item      item;
  219. Event           *event;
  220. {
  221.   if (undo_flag)
  222.   {
  223.     clean_region();
  224.     clean_point();
  225.     clean_poly();
  226.     fat_done();
  227.     pw_write(pw,0,0, image_wid,image_hgt, PIX_SRC, undo_pr,0,0);
  228.   }
  229. }     
  230.  
  231.  
  232.  
  233. /*
  234.  * clear the drawing area
  235.  */
  236. clear_screen(item, event)
  237. Panel_item      item;
  238. Event           *event;
  239. {
  240.   clean_point();
  241.   clean_region();
  242.   save_screen();
  243.   fat_done();
  244.   pw_write( pw,0,0,1280,1280,PIX_SRC,0,0,0);
  245.   pw_write( fat_pw,0,0,1280,1280,PIX_SRC,0,0,0);
  246. }
  247.  
  248.  
  249. /*
  250.  * if there is a region that is select the deselect it
  251.  */
  252. clean_region()
  253. {
  254.   if (top_x || top_y || bottom_x || bottom_y)
  255.     {
  256.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  257.      reset_region();
  258.     }
  259. }
  260.  
  261.  
  262. /*
  263.  * if there is a point that is selected then deselecte it
  264.  */
  265. clean_point()
  266. {
  267.   if (select_pt_x != -1)
  268.     {
  269.      select_point(select_pt_x,select_pt_y);
  270.      select_pt_x = -1;
  271.      select_pt_y = -1;
  272.     }
  273. }
  274.  
  275.  
  276. /*
  277.  * deselect any points and regions and get the current command mode
  278.  */
  279. mouse_parms(item, event)
  280. Panel_item      item;
  281. Event           *event;
  282. {
  283.   clean_point();
  284.   clean_region();
  285.   fat_done();
  286.   mouse_left = (int)panel_get_value(command_choice);
  287. }
  288.  
  289.  
  290. /*
  291.  * set it to select a point mode
  292.  */
  293. set_select_mode()
  294. {
  295.   panel_set(command_choice,PANEL_VALUE, GET_PT,0);
  296.   mouse_parms();
  297. }
  298.  
  299.  
  300.  
  301. /*
  302.  * this the main event handler that makes the whole thing go
  303.  * this event handle is for that canvas that is the main drawing area
  304.  */
  305. handle_event(canvas_local, event, arg)
  306. Canvas  canvas_local;
  307. Event   *event;
  308. caddr_t arg;
  309. {
  310.     Pixwin      *pw     = canvas_pixwin(canvas_local);
  311.  
  312.     if (grid_size)
  313.      {
  314.     event_set_x(event,event_x(event) + grid_size/2 - (event_x(event)%grid_size));
  315.         event_set_y(event,event_y(event) + grid_size/2 - (event_y(event)%grid_size));
  316.      }
  317.  
  318.     if (event_is_up(event))
  319.     {
  320.         if (event_id(event) == MS_LEFT)
  321.         {
  322.         if ((mouse_left == RECT_H) || (mouse_left == RECT_F))
  323.            draw_rectangle(start_x,start_y,event_x(event), event_y(event));
  324.         if (mouse_left == LINE)
  325.            draw_line(start_x,start_y,event_x(event), event_y(event),PIX_SRC,cur_color);
  326.         if (mouse_left == ERASE)
  327.              {
  328.                    select_region(pw,top_x,top_y,top_x+PATTERN_SIZE,top_y+PATTERN_SIZE);
  329.                reset_region();
  330.              }
  331.  
  332.         if (mouse_left == CIRCLE)
  333.                      {
  334.                  draw_line(start_x,start_y,old_x,old_y,PIX_XOR,1);
  335.                 draw_circle(pw,start_x,start_y,distance(old_x,old_y,start_x,start_y),1,PIX_SET);
  336.              }
  337.  
  338.         if (mouse_left == OVAL)
  339.            draw_oval(pw,start_x,start_y,old_x,old_y,TRUE);
  340.  
  341.                 if (fat_source_x != -1)
  342.                    fat_update(0,0);
  343.         if (mouse_left == GET_PT)
  344.          {
  345.              select_pt_x = event_x(event);
  346.            select_pt_y = event_y(event);
  347.          }
  348.         if (mouse_left == LASO)
  349.         {
  350.            laso_cut_paste();
  351.            panel_set(region_choice,PANEL_VALUE,MOVE,0);
  352.            panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  353.                (void)window_set(brush_panel, WIN_SHOW,FALSE, 0);
  354.                (void)window_set(region_panel, WIN_SHOW,TRUE, 0);
  355.            print_msg("Object copied to Cut/Paste buffer. Hold down the RIGHT mouse button to drag the object.");
  356.            mouse_parms();
  357.         }
  358.           }
  359.         if (event_id(event) == MS_RIGHT)
  360.         {
  361.                   if (((int)panel_get_value(region_choice) == MOVE) && (cut_buffer_pr != NULL))
  362.             {
  363.                  pw_write(pw,old_x- cut_buffer_pr->pr_size.x/2,
  364.                      old_y- cut_buffer_pr->pr_size.y/2,
  365.                      cut_buffer_pr->pr_size.x,
  366.                      cut_buffer_pr->pr_size.y,
  367.                      PIX_XOR, cut_buffer_pr,0,0);
  368.                pw_write(pw,event_x(event)-cut_buffer_pr->pr_size.x/2,
  369.                    event_y(event)-cut_buffer_pr->pr_size.y/2,
  370.                  cut_buffer_pr->pr_size.x,
  371.                  cut_buffer_pr->pr_size.y,
  372.                  PIX_SRC | PIX_DST, cut_buffer_pr,0,0);
  373.             }
  374.         }
  375.          return;
  376.     }
  377.     switch (event_id(event)) {
  378.      case MS_LEFT:
  379.         if ((mouse_left != POLY_H) && (mouse_left != POLY_F) && (mouse_left != GET_PT) && (mouse_left != SEL_REG))
  380.             save_screen();
  381.         old_x = event_x(event);
  382.         old_y = event_y(event);
  383.         start_x = event_x(event);
  384.         start_y = event_y(event);
  385.         switch(mouse_left) {
  386.  
  387.         case LINE:
  388.                draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  389.                break;
  390.         case POLY_F:
  391.         case POLY_H:
  392.                if (poly_points[0].x == -1)
  393.                 save_screen();            
  394.                poly_addpt(poly_points,start_x,start_y);
  395.                print_msg("Press the LEFT button to select a vertex or press the RIGHT mouse button to end the polygon.");
  396.                break;
  397.         case DRAW:
  398.                draw_point(pw,event_x(event), event_y(event));
  399.                break;
  400.         case PAINT:
  401.                draw_brush(pw, event_x(event), event_y(event));
  402.                break;
  403.         case ERASE:
  404.                top_x = event_x(event)-PATTERN_SIZE/2; top_y= event_y(event)-PATTERN_SIZE/2;
  405.                select_region(pw,top_x,top_y,top_x+PATTERN_SIZE,top_y+PATTERN_SIZE);
  406.                erase_brush(pw, event_x(event), event_y(event));
  407.                break;
  408.         case CIRCLE:
  409.                     draw_line(start_x,start_y,old_x,old_y,PIX_XOR,1);
  410.                break;
  411.         case OVAL:
  412.                    draw_oval(pw,start_x,start_y,old_x,old_y,FALSE);
  413.                break;
  414.         case GET_PT:
  415.                     if (select_pt_x != -1)
  416.                     select_point(select_pt_x,select_pt_y);
  417.                       old_x = event_x(event);
  418.                      old_y = event_y(event);
  419.                      select_point(old_x,old_y);
  420.                break;
  421.  
  422.         case SEL_REG:
  423.                  if (top_x || top_y || bottom_x || bottom_y)
  424.                       select_region(pw,top_x,top_y,bottom_x,bottom_y);
  425.                save_screen();
  426.                        top_x = event_x(event);
  427.                 top_y = event_y(event);
  428.                        bottom_x = event_x(event);
  429.                 bottom_y = event_y(event);
  430.                  select_region(pw,top_x,top_y,bottom_x,bottom_y);
  431.                break;
  432.         case LASO:
  433.                ptlist[0].x = -1;
  434.                ptlist[0].y = -1;
  435.                laso_addpt(ptlist,start_x,start_y);
  436.                break;
  437.         }
  438.  
  439.         break;
  440.  
  441.           case MS_MIDDLE:
  442.         switch(mouse_left) {
  443.         case SEL_REG:
  444.             if (top_x || top_y || bottom_x || bottom_y)
  445.             {
  446.               select_region(pw,top_x,top_y,bottom_x,bottom_y);
  447.                     bottom_x = event_x(event);
  448.               bottom_y = event_y(event);
  449.                select_region(pw,top_x,top_y,bottom_x,bottom_y);
  450.             }
  451.             break;
  452.         }      
  453.         break;
  454.           case MS_RIGHT:
  455.         if (((mouse_left==POLY_F) || (mouse_left ==POLY_H))
  456.            && (poly_points[0].x != -1))
  457.          {
  458.                poly_addpt(poly_points,event_x(event),event_y(event));
  459.                draw_poly(poly_points);
  460.          }
  461.                 if (((int)panel_get_value(region_choice) == MOVE) && (cut_buffer_pr != NULL))
  462.             {
  463.             clean_region();
  464.             clean_point();
  465.             save_screen();
  466.             old_x = event_x(event);
  467.             old_y = event_y(event);
  468.             start_x = old_x;
  469.             start_y = old_y;
  470.                 pw_write(pw,old_x - cut_buffer_pr->pr_size.x/2,
  471.                     old_y - cut_buffer_pr->pr_size.y/2,
  472.                     cut_buffer_pr->pr_size.x,
  473.                     cut_buffer_pr->pr_size.y,
  474.                     PIX_XOR, cut_buffer_pr,0,0);
  475.             }
  476.         break;
  477.           case LOC_DRAG:
  478.             if (window_get(canvas_local, WIN_EVENT_STATE, MS_LEFT))
  479.         {
  480.         switch(mouse_left) {
  481.         case PAINT:
  482.             draw_brush(pw, event_x(event), event_y(event));
  483.             break;
  484.         case DRAW:
  485.             draw_point(pw,event_x(event), event_y(event));
  486.             break;
  487.         case ERASE :
  488.             erase_brush(pw, event_x(event), event_y(event));
  489.             break;
  490.         case LINE:
  491.                draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  492.                  old_x = event_x(event);
  493.                old_y = event_y(event);
  494.                draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  495.             break;
  496.         case RECT_F :
  497.         case RECT_H :
  498.                select_region(pw,old_x,old_y,start_x,start_y);
  499.                  old_x = event_x(event);
  500.                old_y = event_y(event);
  501.                select_region(pw,old_x,old_y,start_x,start_y);
  502.             break;
  503.         case CIRCLE:
  504.                draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  505.                  old_x = event_x(event);
  506.                old_y = event_y(event);
  507.                draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  508.             break;
  509.         case OVAL:
  510.                draw_oval(pw,start_x,start_y,old_x,old_y,FALSE);
  511.                  old_x = event_x(event);
  512.                old_y = event_y(event);
  513.                draw_oval(pw,start_x,start_y,old_x,old_y,FALSE);
  514.             break;
  515.         case GET_PT:
  516.                select_point(old_x,old_y);
  517.                     select_pt_x = event_x(event);
  518.                   select_pt_y = event_y(event);
  519.                  old_x = event_x(event);
  520.                old_y = event_y(event);
  521.                select_point(old_x,old_y);
  522.             break;
  523.         case SEL_REG:
  524.               select_region(pw,top_x,top_y,bottom_x,bottom_y);
  525.                     bottom_x = event_x(event);
  526.               bottom_y = event_y(event);
  527.                select_region(pw,top_x,top_y,bottom_x,bottom_y);
  528.             break;
  529.         case LASO:
  530.                laso_addpt(ptlist,event_x(event),event_y(event));
  531.             }
  532.         case POLY_F:
  533.         case POLY_H:
  534.             if (poly_points[0].x != -1)
  535.              {
  536.                draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  537.                  old_x = event_x(event);
  538.                old_y = event_y(event);
  539.                draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  540.             }
  541.           }
  542.             if (window_get(canvas_local, WIN_EVENT_STATE, MS_RIGHT))
  543.         {
  544.                 if ((int)panel_get_value(region_choice) == MOVE)
  545.             {
  546.               move_region(old_x,old_y,event_x(event),event_y(event));
  547.                 old_x = event_x(event);
  548.               old_y = event_y(event);
  549.             }
  550.         }
  551.         break;
  552.           case LOC_MOVE:
  553.         if (((mouse_left == POLY_F) || (mouse_left == POLY_H)) &&
  554.              (poly_points[0].x != -1))
  555.          {
  556.            draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  557.              old_x = event_x(event);
  558.            old_y = event_y(event);
  559.            draw_line(old_x,old_y,start_x,start_y,PIX_XOR,1);
  560.          }
  561.         break;
  562.     }
  563. }
  564.  
  565.  
  566.  
  567. /*
  568.  * we got a "quit" button, say bye bye
  569.  */
  570. quit(item, event)
  571. Panel_item      item;
  572. Event           *event;
  573.  
  574. {
  575.   window_done(base_frame);
  576. }
  577.  
  578.  
  579. /*
  580.  * get all the current values for some stuff
  581.  */
  582. change_parms(item, event)
  583. Panel_item      item;
  584. Event           *event;
  585. {
  586.   if (image_depth == 1)
  587.      cur_color = (int)panel_get_value(mono_cycle);
  588.   magnify_fac = (int)panel_get_value(magnify_cycle) + 1;
  589.   grid_size = (int)panel_get_value(grid_cycle)*5;
  590. }
  591.  
  592.  
  593.  
  594. /*
  595.  * this is the main that start the show and then goes into
  596.  * window main loop
  597.  */
  598. main(argc,argv) int argc; char *argv[];
  599. {
  600. char *s;
  601.  
  602. /*
  603.  * do some agr checking
  604.  */
  605.      while (--argc > 0 && (*++argv)[0] == '-')
  606.     for (s = argv[0]+1;*s != '\0';s++)
  607.                 switch (*s) {
  608.           case 'n':
  609.                 undo_flag = FALSE;
  610.                 break;
  611.           case 'p':
  612.                 image_hgt = DEFAULT_IMAGE_WID;
  613.                 image_wid = DEFAULT_IMAGE_HGT;
  614.                 break;
  615.           case 'y': ++argv; argc--;
  616.                 image_hgt = atoi(argv[0]);
  617.                 break;
  618.           case 'x': ++argv; argc--;
  619.                    image_wid = atoi(argv[0]);
  620.                   break;
  621.           default:  printf("Usage: touchup [-x width] [-y height] [-n] [-p]\n");
  622.                 exit(0);
  623.         }
  624.   if (argc > 0)
  625.     {
  626.       printf("Usage: touchup [-x width] [-y height] [-n] [-p]\n");
  627.       exit(0);
  628.     }
  629.  
  630.   clean_poly();
  631.  
  632.   /*
  633.    * get the font used in all of the panels
  634.    */
  635.   main_font = pf_open(MAIN_FONT);
  636.   if (!main_font)
  637.     {
  638.      printf("ERROR loading the main font !!!!\n");
  639.      exit(1);
  640.     }
  641.  
  642.   init_font();
  643.   getcwd(file_name,MAX_FILE_NAME-2);
  644.   strcat(file_name,"/");
  645.   init_windows(argc,argv);
  646.   /*
  647.    * are we on a color machine ????
  648.    */
  649.   image_depth = pw->pw_pixrect->pr_depth;
  650.   if (image_depth == 8)
  651.     {
  652.     init_colortable();
  653.     my_put_colormap();
  654.     set_color();
  655.     }
  656.   else
  657.     set_mono();
  658.  
  659.   if (undo_flag)
  660.      undo_pr = my_mem_create(image_wid,image_hgt,image_depth);
  661.   else
  662.      panel_set(undo_button,PANEL_SHOW_ITEM, FALSE,0);
  663.  
  664.   init_mag();
  665.   window_main_loop(base_frame);
  666. }
  667.  
  668.  
  669.  
  670. /***************************************************************
  671.         hide_msg
  672.         purpose: To clear the masssage display area.
  673.         parameter:
  674.         returns:
  675.  ***************************************************************/
  676. hide_msg()
  677. {
  678.          panel_set(msg_string,PANEL_LABEL_STRING,"",0);
  679. }
  680.  
  681.  
  682. /***************************************************************
  683.         print_msg
  684.         purpose: To print a message on the window and center it
  685.         parameter:
  686.                 string: The string to be printed.
  687.         returns:
  688.  ***************************************************************/
  689. print_msg(string)
  690. char *string;
  691. {
  692. char temp_space[132];
  693. char *temp_pt;
  694. int i;
  695.   
  696.   if (strlen(string) < 132)
  697.   {
  698.     for(i=0;i<132;i++)
  699.       temp_space[i]= ' ';
  700.     temp_pt = temp_space + (132-strlen(string))/2;
  701.     strcpy(temp_pt,string);
  702.     panel_set(msg_string,PANEL_LABEL_STRING,temp_space,0);
  703.   }
  704.   else
  705.     panel_set(msg_string,PANEL_LABEL_STRING,string,0);
  706. }
  707.  
  708. ERROR(msg)
  709. char *msg;
  710.   print_msg(msg);
  711.   window_bell(panel);
  712. }
  713.  
  714. ERRORstr(msg,str)
  715. char *msg,*str;
  716. {
  717. char temp[200];
  718.   strcpy(temp,msg);
  719.   print_msg(strcat(temp,str));
  720.   window_bell(panel);
  721. }
  722.  
  723.  
  724.  
  725. /***************************************************************
  726.     sqrt_fast
  727.         purpose: To do a fast integer square root
  728.         parameter:
  729.         n :  the int to take the sqrt of
  730.         returns: 
  731.         the integer square root of n
  732.  ***************************************************************/
  733. int sqrt_fast(n)
  734. int n;
  735. {
  736.    int a,b,c;
  737.    a = n;
  738.    b = n;
  739.    if (n>1){
  740.         while (a>0) {
  741.             a = a >> 2;
  742.             b = b >> 1;
  743.     }
  744.         do {
  745.             a = b;
  746.             c = n / b;
  747.             b = (c + a) >> 1;
  748.     } while ( (a-c)<-1 || (a-c)>1 );
  749.    }
  750.     return(b);
  751. }
  752.  
  753. /*
  754.  * find the distance between any two points
  755.  */
  756. distance(x1,y1,x2,y2)
  757. int x1,y1,x2,y2;
  758. {
  759.   return(sqrt_fast((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
  760. }
  761.  
  762.  
  763. /*
  764.  * check if we have enough memory to create those LARGE bitmap
  765.  */
  766. struct pixrect *my_mem_create(wid,hgt,dep)
  767. int wid,hgt,dep;
  768. {
  769. struct pixrect* temp_pr;
  770.  
  771.     temp_pr = mem_create(wid,hgt,dep);
  772.     if (temp_pr== NULL)
  773.         {
  774.       printf("Not enough memory, memory allocation problems!!!\n");
  775.       exit(0);
  776.         }
  777. }
  778.