home *** CD-ROM | disk | FTP | other *** search
/ Total C++ 2 / TOTALCTWO.iso / vfp5.0 / vfp / samples / solution / forms / graphics / anim.prg next >
Encoding:
Text File  |  1996-08-21  |  3.6 KB  |  156 lines

  1. PUBLIC ox
  2.  
  3. =sys(1075)
  4. close data
  5. IF !FILE("frames.dbf")
  6.     CREATE TABLE frames (frameno i,objno i,x1 i,y1 i,x2 i,y2 i)
  7. ELSE
  8.     USE frames
  9. ENDIF
  10. ox = Create("myForm")
  11.  
  12.  
  13. ox.show
  14.  
  15.  
  16.  
  17. DEFINE CLASS myForm AS FORM
  18.     pendown = .f.
  19.     oldx = -1
  20.     oldy = 0
  21.     frameno = 1
  22.     objno = 1
  23.     add object cmdQuit as Commandbutton WITH ;
  24.         caption= "Quit",cancel=.t.,width = 60
  25.     add object cmdErase as Commandbutton WITH ;
  26.         caption= "Erase",left = 80,width = 60
  27.     add object cmdPlay as Commandbutton WITH ;
  28.         caption= "\<Play",left = 160,width = 60
  29.     add object cmdNextFrame as Commandbutton WITH ;
  30.         caption= "NextFrame",left = 240,width = 80
  31.     proc mousemove(btn,shft,m.x,m.y)
  32.         if this.pendown
  33.             this.drawmode = 10
  34.             if this.oldx # -1
  35.                 thisform.line(this.oldx,this.oldy,this.currentx,this.currenty)
  36.             endif
  37.             thisform.line(this.oldx,this.oldy,m.x,m.y)
  38.             this.drawmode = 1
  39.         endif
  40.     proc mousedown(btn,shft,m.x,m.y)
  41.         LOCAL lx,ly
  42.         if m.btn = 2
  43.             this.drawmode = 10
  44.             thisform.line(this.oldx,this.oldy,this.currentx,this.currenty)
  45.             this.drawmode = 1
  46.             this.pendown = .f.
  47.             this.currentx = m.x
  48.             this.currenty = m.y
  49.             this.objno = this.objno + 1
  50.             retu
  51.         endif
  52.         if this.pendown
  53.             lx = this.currentx
  54.             ly = this.currenty
  55.             INSERT INTO frames (frameno,objno,x1,y1,x2,y2) values ;
  56.                 (this.frameno,this.objno,this.oldx,this.oldy,m.x,m.y)
  57.                 
  58.             this.oldx = m.x
  59.             this.oldy = m.y
  60.         ELSE
  61.             this.currentx = m.x
  62.             this.currenty = m.y
  63.             this.oldx = m.x
  64.             this.oldy = m.y
  65.             this.pendown = .t.
  66.         ENDIF
  67.     proc cmdquit.click
  68.         thisform.release
  69.     proc cmdErase.click
  70.         thisform.pendown = .f.
  71.         thisform.oldx = -1
  72.         thisform.frameno = 1
  73.         thisform.objno = 1
  74.         zap
  75.         thisform.cls
  76.     proc cmdPlay.click
  77.         nBetween = 15
  78.         thisform.pendown = .f.
  79.         thisform.oldx = -1
  80.         thisform.cls
  81.         LOCATE
  82.         THISFORM.objno = 1
  83.         THISFORM.frameno = frameno
  84.         USE frames AGAIN IN 0 ALIAS frames2
  85.         SELECT frames2
  86.         LOCATE FOR frameno # frames.frameno
  87.         SELECT frames
  88.         DO WHILE !EOF("frames2")
  89.             mr = recno()
  90.             mr2 = recno("frames2")
  91.             FOR nb = 1 TO nBetween && changed 0 to 1 in the loop -- RKH
  92.                 thisform.cls
  93.                 GO mr
  94.                 IF mr2 < RECCOUNT("frames2")
  95.                     GO mr2 IN frames2
  96.                 ENDIF
  97.                 nFrames1 = frames.frameno
  98.                 nFrames2 = frames2.frameno
  99.                 SCAN WHILE frames.frameno = nFrames1
  100.                     nx1 = frames.x1 + nb * (frames2.x1 - frames.x1) / nBetween
  101.                     ny1 = frames.y1 + nb * (frames2.y1 - frames.y1) / nBetween
  102.                     nx2 = frames.x2 + nb * (frames2.x2 - frames.x2) / nBetween
  103.                     ny2 = frames.y2 + nb * (frames2.y2 - frames.y2) / nBetween
  104.                     thisform.line(nx1,ny1,nx2,ny2)
  105.                     IF !EOF("frames2")
  106.                         SKIP IN frames2
  107.                         IF frames2.frameno # nFrames2
  108.                             SKIP -1 IN frames2
  109.                         ENDIF
  110.                     ENDI
  111.                 ENDSCAN
  112.                 SELECT frames2
  113.                 IF !EOF()
  114.                     SKIP
  115.                     LOCATE REST FOR frames2.Frameno # nFrames2
  116.                 ENDIF
  117.                 SELECT frames
  118.                 wait wind "" time .05
  119.             ENDFOR
  120.         ENDDO
  121.         USE IN frames2
  122.         SCAN REST
  123.             thisform.line(x1,y1,x2,y2)
  124.         ENDSCAN
  125.         thisform.frameno = nFrames1 + 1
  126.     proc cmdNextFrame.click
  127.         thisform.frameno = thisform.frameno + 1
  128.         thisform.cls
  129.         thisform.objno = 1
  130. ENDDEFINE
  131.  
  132. DEFINE CLASS myshape AS shape
  133.     backcolor = rgb(255,0,0)
  134.     visible = .t.
  135.     top = 50
  136.     width = 6
  137.     height = 9
  138.     left = 100
  139.     proc mouseup(btn,shft,m.x,m.y)
  140.         thisform.mouseup(btn,shft,m.x,m.y)
  141.     proc mousedown(btn,shft,m.x,m.y)
  142.         thisform.mousedown(btn,shft,m.x,m.y)
  143.     proc mousemove(btn,shft,m.x,m.y)
  144.         thisform.mousemove(btn,shft,m.x,m.y)
  145. ENDDEFINE
  146.  
  147.  
  148. DEFINE CLASS cPoint AS custom
  149.     x = 0
  150.     y = 0
  151. ENDDEFINE
  152.  
  153. DEFINE CLASS cLine AS custom
  154.     oP1 = .NULL.
  155.     oP2 = .NULL.
  156. ENDDEFINE