Recent

Author Topic: Interactive open polygon without array of pointtype using ptcmouse  (Read 168 times)

TBMan

  • Full Member
  • ***
  • Posts: 126
This routine uses ptcgraph, ptccrt and ptcmouse.  I couldn't get the drawpoly routine in ptcgraph to work so I made my own, even without the mouse selection of points. Thinking back I'm wondering if I had to pass a pointer to the var polypoints, instead of the array itself. Anyway, this works.

Code: Pascal  [Select][+][-]
  1. { Select the first point with the left mouse button, then select the subsequent points using the right mouse button and then
  2. close the polygon with a keypress}
  3.  
  4. procedure Poly(Paintcolor:byte);
  5.   var
  6.     GotFirst,
  7.     First: boolean;
  8.     fx, fy, mxx, myy, mx, my, mb: longint;
  9.   begin
  10.     First := True;
  11.     GotFirst := false;
  12.     setcolor(paintcolor);
  13.     repeat
  14.       getmousestate(mx, my, mb);
  15.  
  16.       if lpressed and not gotfirst then     {allow only one left mouse click}
  17.       begin
  18.         mxx := mx;
  19.         myy := my;
  20.         if First then
  21.         begin
  22.           fx := mx;       {save starting points}
  23.           fy := my;
  24.           First := False;
  25.           putpixel(fx, fy, paintcolor);
  26.         end;
  27.         GotFirst := true;
  28.         while lpressed do  {wait for mouse release}
  29.         begin
  30.         end;
  31.       end;
  32.  
  33.       if rpressed then    {set subsequent points with right mouse clicks}
  34.       begin
  35.         line(mx, my, mxx, myy);
  36.         mxx := mx;
  37.         myy := my;
  38.         while rpressed do   {wait for mouse release}
  39.         begin
  40.         end;
  41.       end;
  42.  
  43.     until keypressed;
  44.     line(mxx, myy, fx, fy);  {close the polygon}
  45.    
  46.   end;                        
« Last Edit: February 19, 2025, 03:22:19 pm by TBMan »

 

TinyPortal © 2005-2018