home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / touchup / part05 / drawing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-14  |  15.7 KB  |  692 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: drawing.c
  26.     purpose: This file has most of the functions that draw stuff
  27.     on the screen.
  28.  
  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. struct pr_pos poly_points[MAX_POLY];
  38.  
  39. struct pixrect *brush_temp_pr = NULL;
  40.  
  41. /*
  42.  * What we do that someone selects a new pattern
  43.  */
  44. select_pattern(item, event)
  45. Panel_item      item;
  46. Event           *event;
  47. {
  48.   panel_set(current_pattern,PANEL_LABEL_IMAGE,pattern[(int)panel_get_value(pattern_choice)],0);
  49.  
  50. }
  51.  
  52.  
  53. /*
  54.  * let the user define his own patterns to paint with
  55.  * works for color and mono
  56.  */
  57. pattern_define(item, event)
  58. Panel_item      item;
  59. Event           *event;
  60. {
  61.  
  62.   if (select_pt_x == -1)
  63.      {
  64.     ERROR("Select a point first, then select Define Pattern.");
  65.     set_select_mode();
  66.     return(0);
  67.      }
  68.   select_point(select_pt_x,select_pt_y);
  69.   if (image_depth > 1)
  70.    {
  71.       pattern[39]  = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,image_depth);
  72.       pattern40_pr = *(pattern[39]);
  73.    }
  74.   pr_rop(pattern[39],0,0,PATTERN_SIZE,PATTERN_SIZE,
  75.         PIX_SRC,pw->pw_prretained,select_pt_x-PATTERN_SIZE/2,
  76.         select_pt_y-PATTERN_SIZE/2);
  77.  
  78.   panel_paint(pattern_choice,PANEL_NO_CLEAR);
  79.   reset_point();
  80.   print_msg("The user defined pattern is now stored in the last pattern element.");
  81. }
  82.  
  83.  
  84. /*
  85.  * Take the current text string and put that Baby up on the bitmap
  86.  * in the right font
  87.  */
  88. draw_text()
  89. {
  90. int x,y;
  91.  
  92.   if (select_pt_x != -1)
  93.     {
  94.       x = select_pt_x;
  95.       y = select_pt_y;
  96.       clean_point();
  97.       save_screen();
  98.       pw_text(pw,x,y,PIX_COLOR(cur_color) | PIX_SRC,font_array[(int)panel_get_value(text_size_item)],
  99.         (char*)panel_get_value(text_panel));
  100.     }
  101.   else
  102.     {
  103.       ERROR("Select a point first, fill in TEXT STRING, then select ABC.");
  104.       window_set(panel,PANEL_CARET_ITEM,text_panel,0);
  105.       set_select_mode();
  106.     }
  107. }
  108.  
  109.  
  110. /*
  111.  * draw a line on the bitmap
  112.  */
  113. draw_line(x1,y1,x2,y2,ROP,color)
  114. int x1,y1,x2,y2,ROP,color;
  115. {
  116.   pw_vector(pw,x1,y1,x2,y2,ROP,color);
  117. }
  118.  
  119.  
  120. /*
  121.  * draw a rectangle on the bitmap
  122.  */
  123. draw_rectangle(x1,y1,x2,y2)
  124. int x1,y1,x2,y2;
  125. {
  126.   top_x = x1;
  127.   top_y = y1;
  128.   bottom_x = x2;
  129.   bottom_y = y2;
  130.   if ((int)panel_get_value(command_choice)==RECT_F)
  131.     fill_region();
  132.   else
  133.     reset_region();
  134.   if ((int)panel_get_value(border_cycle))
  135.   {
  136.     pw_vector(pw,x1,y1,x2,y1,PIX_SRC,cur_color);
  137.     pw_vector(pw,x2,y1,x2,y2,PIX_SRC,cur_color);
  138.     pw_vector(pw,x2,y2,x1,y2,PIX_SRC,cur_color);
  139.     pw_vector(pw,x1,y2,x1,y1,PIX_SRC,cur_color);
  140.   }
  141. }
  142.  
  143.  
  144. /*
  145.  * highlight the selected region on the drawing area by throwing up a
  146.  * XORed rectangle
  147.  */
  148. select_region(pw,x1,y1,x2,y2)
  149. struct pixwin *pw;
  150. int x1,y1,x2,y2;
  151. {
  152.   pw_vector(pw,x1,y1,x2,y1,PIX_XOR,1);
  153.   pw_vector(pw,x2,y1,x2,y2,PIX_XOR,1);
  154.   pw_vector(pw,x2,y2,x1,y2,PIX_XOR,1);
  155.   pw_vector(pw,x1,y2,x1,y1,PIX_XOR,1);
  156. }
  157.  
  158.  
  159. /*
  160.  * reset the current REGION
  161.  */
  162. reset_region()
  163. {
  164.   top_x=0;
  165.   top_y=0;
  166.   bottom_x=0;
  167.   bottom_y=0;
  168. }
  169.  
  170.  
  171. /*
  172.  * draw up a point, how stupid ???
  173.  */
  174. draw_point(pw,x,y)
  175. struct pixwin *pw;
  176. int x,y;
  177. {
  178.   pw_put(pw,x,y,cur_color);
  179. }
  180.  
  181.  
  182. /*
  183.  * Draw up the paint brush by copying the current pattern
  184.  * through a stencil of the current brush
  185.  */
  186. draw_brush(pw,x,y)
  187. struct pixwin *pw;
  188. int x,y;
  189. {
  190.   if (brush_temp_pr == NULL)
  191.     brush_temp_pr = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,1);
  192.  
  193.  
  194.   if (((int)panel_get_value(pattern_choice) != 39) || (image_depth == 1))
  195.   {
  196.     if (brush_temp_pr->pr_depth != 1)
  197.     {
  198.          MY_pr_destroy(brush_temp_pr);
  199.         brush_temp_pr = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,1);
  200.     }
  201.     pr_replrop(brush_temp_pr,0,0,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],x,y);
  202.         pw_stencil(pw,x-PATTERN_SIZE/2,y-PATTERN_SIZE/2,PATTERN_SIZE,PATTERN_SIZE,PIX_COLOR(cur_color) | PIX_SRC,
  203.     brushes[(int)panel_get_value(brush_choice)],0,0,brush_temp_pr,0,0);
  204.   }
  205.   else
  206.   {
  207.     if (brush_temp_pr->pr_depth != image_depth)
  208.     {
  209.          MY_pr_destroy(brush_temp_pr);
  210.         brush_temp_pr = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,image_depth);
  211.     }
  212.     pr_replrop(brush_temp_pr,0,0,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],x,y);
  213.         pw_stencil(pw,x-PATTERN_SIZE/2,y-PATTERN_SIZE/2,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,
  214.     brushes[(int)panel_get_value(brush_choice)],0,0,brush_temp_pr,0,0);
  215.  
  216.   }
  217.  
  218. }
  219.  
  220.  
  221. /*
  222.  * flip-flop two varibles (ints)
  223.  */
  224. swap(x,y)
  225. int *x,*y;
  226. {
  227. int temp;
  228.   temp = *x;
  229.   *x = *y;
  230.   *y = temp;
  231. }
  232.  
  233.  
  234. region_fix()
  235. {
  236.   if (top_x > bottom_x)
  237.      swap(&top_x,&bottom_x);
  238.   if (top_y > bottom_y)
  239.      swap(&top_y,&bottom_y);
  240.  
  241.  
  242. /*
  243.  * put the eraser on the drawing area
  244.  */
  245. erase_brush(pw,x,y)
  246. struct pixwin *pw;
  247. int x,y;
  248. {
  249.   select_region(pw,top_x,top_y,top_x+PATTERN_SIZE,top_y+PATTERN_SIZE);
  250.   pw_rop(pw,x-PATTERN_SIZE/2,y-PATTERN_SIZE/2,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,0,0,0);
  251.   top_x = x-PATTERN_SIZE/2; top_y= y-PATTERN_SIZE/2;
  252.   select_region(pw,top_x,top_y,top_x+PATTERN_SIZE,top_y+PATTERN_SIZE);
  253. }
  254.  
  255.  
  256. /*
  257.  * draw up some cross hairs to be used to select a point
  258.  */
  259. #define CROSS_HAIR 20
  260. select_point(x,y)
  261. int x,y;
  262. {
  263.   pw_vector(pw,x-CROSS_HAIR,y,x+CROSS_HAIR,y,PIX_XOR,1);
  264.   pw_vector(pw,x,y-CROSS_HAIR,x,y+CROSS_HAIR,PIX_XOR,1);
  265. }
  266.  
  267.  
  268. /*
  269.  * reset the currently selected point
  270.  */
  271. reset_point()
  272. {
  273.   select_pt_x = 0-1;
  274.   select_pt_y = 0-1;
  275. }
  276.  
  277.  
  278. /*
  279.  * take a currently selected region and invert that baby ! FAST !!!
  280.  */
  281. inverse_region()
  282. {
  283.   if (top_x || top_y || bottom_x || bottom_y)
  284.     {
  285.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  286.      region_fix();
  287.      pw_replrop(pw,top_x,top_y,bottom_x-top_x,bottom_y-top_y, PIX_XOR, pattern[0],0,0);
  288.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  289.     }
  290.   else
  291.     {
  292.      ERROR("Select a region first, then select INVERSE.");
  293.      panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  294.      mouse_parms();
  295.     }
  296. }
  297.  
  298.  
  299.  
  300. /*
  301.  * take a currently selected region and rotate around the center
  302.  * point.  SLOW !!
  303.  */
  304. rotate_region()
  305. {
  306. register i,j,t1,t2;
  307.  
  308.   if (top_x || top_y || bottom_x || bottom_y)
  309.     {
  310.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  311.      region_fix();
  312.      MY_pr_destroy(cut_buffer_pr);
  313.      cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  314.      pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  315.         PIX_SRC,pw->pw_prretained,top_x,top_y);
  316.      t1 = top_x + cut_buffer_pr->pr_size.x/2+ cut_buffer_pr->pr_size.y/2;
  317.      t2 = top_y - cut_buffer_pr->pr_size.x/2+ cut_buffer_pr->pr_size.y/2;
  318.      for (j = 0; j < cut_buffer_pr->pr_size.y; j++)
  319.        for (i = 0; i < cut_buffer_pr->pr_size.x; i++)
  320.         pw_rop(pw, t1-j, t2+i, 1,1, PIX_SRC, cut_buffer_pr,i,j);
  321.  
  322.      top_x = top_x + cut_buffer_pr->pr_size.x/2 - cut_buffer_pr->pr_size.y/2;
  323.      top_y = top_y - cut_buffer_pr->pr_size.x/2 + cut_buffer_pr->pr_size.y/2;
  324.      bottom_x = top_x + cut_buffer_pr->pr_size.y;
  325.      bottom_y = top_y + cut_buffer_pr->pr_size.x;
  326.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  327.     }
  328.   else
  329.     {
  330.      ERROR("Select a region first, then select ROTATE.");
  331.      panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  332.      mouse_parms();
  333.     }
  334. }
  335.  
  336.  
  337.  
  338. /*
  339.  * take a currently selected region and make a mirror image of it
  340.  */
  341. flip_hor_region()
  342. {
  343. register i;
  344.   if (top_x || top_y || bottom_x || bottom_y)
  345.     {
  346.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  347.      region_fix();
  348.      MY_pr_destroy(cut_buffer_pr);
  349.      cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  350.      pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  351.         PIX_SRC,pw->pw_prretained,top_x,top_y);
  352.      for (i = 0; i < cut_buffer_pr->pr_size.x; i++) {
  353.         pw_rop(pw, top_x+(cut_buffer_pr->pr_size.x - i)-1,top_y,
  354.             1,cut_buffer_pr->pr_size.y, PIX_SRC, cut_buffer_pr,i,0);
  355.     }
  356.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  357.     }
  358.   else
  359.     {
  360.      ERROR("Select a region first, then select MIRROR.");
  361.      panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  362.      mouse_parms();
  363.     }
  364. }
  365.  
  366.  
  367. /*
  368.  * take a currently selected region and turn it upside down
  369.  */
  370. flip_ver_region()
  371. {
  372. register i;
  373.   if (top_x || top_y || bottom_x || bottom_y)
  374.     {
  375.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  376.      region_fix();
  377.      MY_pr_destroy(cut_buffer_pr);
  378.      cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  379.      pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  380.         PIX_SRC,pw->pw_prretained,top_x,top_y);
  381.      for (i = 0; i < cut_buffer_pr->pr_size.y; i++) {
  382.         pw_rop(pw, top_x, top_y+(cut_buffer_pr->pr_size.y - i)-1,
  383.             cut_buffer_pr->pr_size.x, 1, PIX_SRC, cut_buffer_pr, 0, i);
  384.     }
  385.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  386.     }
  387.   else
  388.     {
  389.      ERROR("Select a region first, then select FLIP VERTICAL.");
  390.      panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  391.      mouse_parms();
  392.     }
  393. }
  394.  
  395.  
  396.  
  397. /*
  398.  * grab what is in the Cut/Paste buffer and put it up on the drawing area
  399.  */
  400. paste_region()
  401. {
  402. int ROP=PIX_SRC;
  403.  
  404.   if (select_pt_x == -1)
  405.      {
  406.     ERROR("Select a point first, then select PASTE.");
  407.     set_select_mode();
  408.     return(0);
  409.      }
  410.   if (cut_buffer_pr)
  411.   {
  412.      select_point(select_pt_x,select_pt_y);
  413.      save_screen();
  414.      pw_write(pw,select_pt_x,select_pt_y,cut_buffer_pr->pr_size.x,cut_buffer_pr->pr_size.y, ROP, cut_buffer_pr,0,0);
  415.      reset_point();
  416.   }
  417.   else
  418.     ERROR("The Cut/Paste buffer is empty.");
  419. }
  420.  
  421.  
  422. /*
  423.  * grab the currently selected region on the drawing area and stuff
  424.  * it into the cut/paste buffer AND destroy the source area by
  425.  * filling in with the current paint pattern
  426.  */
  427. cut_region()
  428. {
  429. int t1,t2,t3,t4;
  430.   if (top_x || top_y || bottom_x || bottom_y)
  431.     {
  432.       t1 = top_x;
  433.       t2 = top_y;
  434.       t3 = bottom_x;
  435.       t4 = bottom_y;
  436.       copy_region();
  437.       top_x = t1;
  438.       top_y = t2;
  439.       bottom_x = t3;
  440.       bottom_y = t4;
  441.       select_region(pw,top_x,top_y,bottom_x,bottom_y);
  442.       fill_region();
  443.       set_select_mode();
  444.       print_msg("Region copied to Cut/Paste buffer, select a point and then press PASTE.");
  445.     }
  446.    else
  447.     {
  448.      ERROR("Select a region first, then select CUT.");
  449.      panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  450.      mouse_parms();
  451.     }
  452. }
  453.  
  454.  
  455. /*
  456.  * grab the currently selected region on the drawing area and stuff
  457.  * it into the cut/paste buffer
  458.  */
  459. copy_region()
  460. {
  461.   if (top_x || top_y || bottom_x || bottom_y)
  462.     {
  463.      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  464.      region_fix();
  465.      MY_pr_destroy(cut_buffer_pr);
  466.      cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  467.      pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  468.         PIX_SRC,pw->pw_prretained,top_x,top_y);
  469.      reset_region();
  470.     }
  471.    else
  472.     {
  473.     ERROR("Select a region first, then select COPY.");
  474.         panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  475.         mouse_parms();
  476.     }
  477. }
  478.  
  479.  
  480. /*
  481.  * take the cut/paste buffer and XOR it that stuff on to the drawing area
  482.  * so that I can move that sucker around FAST
  483.  */
  484. move_region(old_x,old_y,new_x,new_y)
  485. int old_x,old_y,new_x,new_y;
  486. {
  487.   if (cut_buffer_pr)
  488.     {
  489.      pw_write(pw,old_x-cut_buffer_pr->pr_size.x/2,
  490.          old_y-cut_buffer_pr->pr_size.y/2,
  491.          cut_buffer_pr->pr_size.x,
  492.          cut_buffer_pr->pr_size.y,
  493.          PIX_XOR, cut_buffer_pr,0,0);
  494.  
  495.      pw_write(pw,new_x-cut_buffer_pr->pr_size.x/2,
  496.          new_y-cut_buffer_pr->pr_size.y/2,
  497.          cut_buffer_pr->pr_size.x,
  498.          cut_buffer_pr->pr_size.y,
  499.          PIX_XOR, cut_buffer_pr,0,0);
  500.     }
  501.    else
  502.     {
  503.        ERROR("CUT or COPY a region first, then select MOVE.");
  504.     }
  505. }
  506.  
  507.  
  508. /*
  509.  * fill in a rectanglar region with the current paint pattern
  510.  */
  511. fill_region(item, event)
  512. Panel_item      item;
  513. Event           *event;
  514. {
  515.    if (top_x || top_y || bottom_x || bottom_y)
  516.     {
  517.       select_region(pw,top_x,top_y,bottom_x,bottom_y);
  518.       region_fix();
  519.       pw_replrop(pw,top_x,top_y,bottom_x-top_x,bottom_y-top_y,PIX_COLOR(cur_color) | PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],0,0);
  520.       reset_region();
  521.     }
  522. }
  523.  
  524.  
  525. /*
  526.  * let the user lasso any free form region on the drawing area
  527.  * and stuff that into the cut/paste buffer
  528.  */
  529. laso_cut_paste()
  530. {
  531. int found;
  532. int i,no_points;
  533. int npts[1];
  534.  
  535.   top_x = image_wid;
  536.   top_y = image_hgt;
  537.   bottom_x = 0;
  538.   bottom_y = 0;
  539.  
  540.   i=0;
  541.   while ((i<MAX_PTS) && (ptlist[i++].x != -1));
  542.   no_points = --i;
  543.   npts[0] = no_points; 
  544.   pw_polygon_2(pw,0,0,1,npts,ptlist,PIX_XOR,pattern[0],0,0);
  545.   pw_polygon_2(pw,0,0,1,npts,ptlist,PIX_XOR,pattern[0],0,0);
  546.  
  547.   for (i=0;i < no_points;i++)
  548.     {
  549.         top_x = MIN(top_x,ptlist[i].x);
  550.         top_y = MIN(top_y,ptlist[i].y);
  551.         bottom_x = MAX(bottom_x,ptlist[i].x);
  552.         bottom_y = MAX(bottom_y,ptlist[i].y);
  553.         if (i>0)
  554.         pw_vector(pw,ptlist[i].x,ptlist[i].y,
  555.                  ptlist[i-1].x,ptlist[i-1].y,PIX_XOR,1);
  556.     }
  557.   for (i=0;i < no_points;i++)
  558.     {
  559.         ptlist[i].x -=top_x;
  560.         ptlist[i].y -=top_y;
  561.     }
  562.   MY_pr_destroy(cut_buffer_pr);
  563.   cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  564.   pr_polygon_2(cut_buffer_pr,0,0,1,npts,ptlist,PIX_SRC,pw->pw_prretained,top_x,top_y);
  565.   reset_region();
  566.   print_msg("The selected area is now in the Cut/Paste buffer.");
  567. }
  568.  
  569.  
  570. /*
  571.  * the user can lasso any area on the screen by just encircling the
  572.  * object on the bitmap
  573.  * we do this by remembering all of the points the mouse moved to
  574.  * and make a polygon stencil from these points
  575.  */
  576. laso_addpt(py_pts,x,y)
  577. struct pr_pos py_pts[];
  578. int x,y;
  579. {
  580. int found;
  581. int i;
  582. int npts[1];
  583.  
  584.   found =0;
  585.   i=0;
  586.   while (i<MAX_PTS && !found)
  587.     {
  588.       if (py_pts[i++].x == -1)
  589.     found=TRUE;
  590.     }
  591.   i--;
  592.   npts[0] =i;
  593.         
  594.   py_pts[i].x = x;
  595.   py_pts[i].y = y;
  596.   if (i>0)
  597.     pw_vector(pw,py_pts[i].x,py_pts[i].y,py_pts[i-1].x,py_pts[i-1].y,PIX_XOR,1);
  598.   i++;
  599.   py_pts[i].x = 0-1;
  600.   py_pts[i].y = 0-1;
  601. }
  602.  
  603.  
  604. /*
  605.  * add a point to the list of vetexs in the current polygon
  606.  */
  607. poly_addpt(py_pts,x,y)
  608. struct pr_pos py_pts[];
  609. int x,y;
  610. {
  611. int found;
  612. int i;
  613.  
  614.   found =0;
  615.   i=0;
  616.   while (i<MAX_POLY && !found)
  617.     {
  618.       if (py_pts[i++].x == -1)
  619.     found=TRUE;
  620.     }
  621.   i--;
  622.        {
  623.          py_pts[i].x = x;
  624.          py_pts[i].y = y;
  625.      i++;
  626.      py_pts[i].x = 0-1;
  627.      py_pts[i].y = 0-1;
  628.        }
  629. }
  630.  
  631.  
  632. /*
  633.  * take the list of currnet vertexs and draw up the
  634.  * the polygon and fill it with the current paint pattern
  635.  */
  636. draw_poly(py_pts)
  637. struct pr_pos py_pts[];
  638. {
  639. int npts[1];
  640. int found;
  641. int i;
  642.  
  643.   if (py_pts[0].x == 0-1)
  644.     return(0);
  645.  
  646.   found =0;
  647.   i=0;
  648.   while (i<MAX_POLY && !found)
  649.     {
  650.       if (py_pts[i++].x == -1)
  651.     found=TRUE;
  652.     }
  653.   i--;
  654.  
  655.   npts[0] =i;
  656.  
  657.   /*
  658.    * do we want this baby filled ????
  659.    */ 
  660.   if ((int)panel_get_value(command_choice)==POLY_F)
  661.        pw_polygon_2(pw,0,0,1,npts,py_pts,PIX_COLOR(cur_color) | PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],0,0);
  662.  
  663.   /*
  664.    * do we want to wrap the polygon up in a vector border
  665.    */
  666.   if ((int)panel_get_value(border_cycle))
  667.   {
  668.       i=1;
  669.       while (i<MAX_POLY && (py_pts[i].x != -1))
  670.         {
  671.         pw_vector(pw,py_pts[i].x,py_pts[i].y,
  672.                  py_pts[i-1].x,py_pts[i-1].y,PIX_SRC,cur_color);
  673.         i++;
  674.         }
  675.       i--;
  676.       pw_vector(pw,py_pts[i].x,py_pts[i].y,
  677.                  py_pts[0].x,py_pts[0].y,PIX_SRC,cur_color);
  678.   }
  679.   clean_poly();
  680. }
  681.  
  682.  
  683. /*
  684.  * reset the vertex list for the current polygon
  685.  */
  686. clean_poly()
  687. {
  688.   poly_points[0].x = 0-1;
  689.   poly_points[0].y = 0-1;
  690. }
  691.