home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0925.lha / DonsGenies / DonsGenies.lha / Don'sGenies / StepAndRepeatDeLuxe.pprx < prev    next >
Text File  |  1993-08-07  |  13KB  |  367 lines

  1. /*
  2. StepAndRepeatDeLuxe  
  3. This Genie will make multiple copies of a box with user specified offset and rotation between copies. You can also scale the copies and set the centre of rotation. 
  4. Written by Don Cox   July 92., debug Aug 93. Not Public Domain. All rights reserved. 
  5. */
  6.  
  7.  
  8. if ~show("l", "gdarexxsupport.library") then
  9.     if ~addlib("gdarexxsupport.library", 0, -30,0) then
  10.     do
  11.         call ppm_Inform(1,"Please install the gdarexxsupport.library in your libs: directory before running this Genie.")
  12.     end
  13.  
  14.  
  15. cr = '0a'x
  16. address command
  17. call SafeEndEdit.rexx()
  18. units = ppm_GetUnits()
  19. if units = 3 then call ppm_SetUnits(2)
  20.  
  21. signal on halt
  22. signal on break_c
  23. signal on break_e
  24. signal on break_d
  25.  
  26. cu = "in"
  27. if units = 2 then cu = "cm"
  28.  
  29. call ppm_AutoUpdate(0)
  30.  
  31. call ppm_NewGroup()
  32. box = ppm_ClickOnBox("Click on box to duplicate..")
  33. if box = 0 then exit_msg("No box selected")
  34. call ppm_AddToGroup(box)  /* whole set grouped including original box */
  35. dup = 0
  36.  
  37. trace n
  38.  
  39. source = ppm_Inform(3,"Settings from...","Same again","Defaults","Disk file")
  40.  
  41. oldangle = ppm_GetBoxAngle(box)
  42. call ppm_SetBoxAngle(box,0)   /* rotate to zero to get centre */
  43. boxpos  = ppm_GetBoxPosition(box)
  44. curX   = word(boxpos, 1 )
  45. curY   = word(boxpos, 2 )
  46.  
  47. boxsize = ppm_GetBoxSize(box)
  48. width   = word(boxsize, 1 )
  49. height  = word(boxsize, 2 )
  50.  
  51. centreX = curX+(width/2)
  52. centreY = curY+(height/2)
  53. call ppm_SetBoxAngle(box,oldangle)
  54. boxpos  = ppm_GetBoxPosition(box)
  55.  
  56. ImageScaleX = word(ppm_GetBoxScale(box),1)
  57. ImageScaleY = word(ppm_GetBoxScale(box),2)
  58.  
  59. call ppm_ShowStatus("Position: "curX", "curY" size: w"width", h"height)
  60.  
  61. formstring = ""
  62.  
  63. if source = 0 then do
  64.     if open("temp","ram:SRD.data","R") then do
  65.         formstring = readch("temp",512)
  66.         call close("temp")
  67.         end
  68.     if formstring = "" then source = 1  /* defaults if failed  */
  69.     end   /* source = 0  */
  70.  
  71. if source = 2 then do
  72.     loadfile = ppm_GetFileName("Load settings from disk","PPage:","")
  73.     if loadfile = "" then break
  74.     if open("loader",loadfile,"R") then do
  75.         formstring = readch("loader",512)
  76.         call close("loader")
  77.         end
  78.     if formstring = "" then source = 1  /* go for defaults  */
  79.     end
  80.  
  81. if formstring = "" then formstring ="rows:2"||cr"columns:1"||cr"horiz. spacing ("cu"):"width||cr"vertical spacing ("cu"):"height||cr"horiz. offset ("cu"):"0||cr"offset angle:"0||cr"rotation angle:"0||cr"rotation centre, X:"centreX||cr"rotation centre, Y:"centreY||cr"scale, X:1.00"||cr"scale, Y:1.00"||cr"spiral scale:1.00"||cr"spiral spacing("cu"):0"||cr"save settings (Y/N):N"||cr"Link boxes (Y/N):N"
  82.  
  83.  
  84. form = ppm_GetForm("Step & Repeat DeLuxe", 12, formstring)
  85. if form = '' then exit_msg("Aborted by User")
  86.  
  87. parse var form rows '0a'x columns '0a'x  horizontal '0a'x vertical '0a'x HorizOffset '0a'x OffsetAngle '0a'x RotAngle '0a'x Xcentre '0a'x Ycentre '0a'x Xscale '0a'x Yscale '0a'x SpiralScale '0a'x SpiralIncrement '0a'x Saving '0a'x Linking
  88.  
  89.  
  90. if rows = '' then rows = 1
  91. if columns = '' then columns = 1
  92. if horizontal = '' then horizontal = 0
  93. if vertical = '' then vertical = 0
  94. if HorizOffset = "" then HorizOffset = 0
  95. if OffsetAngle = "" then OffsetAngle = 0
  96. if RotAngle = '' then RotAngle = 0
  97. if Xcentre = "" then Xcentre = centreX
  98. if Ycentre = "" then Ycentre = centreY
  99. if Xscale = "" then Xscale = 1
  100. if Yscale = "" then Yscale = 1
  101. if SpiralScale = "" then SpiralScale = 1
  102. if SpiralIncrement = "" then SpiralIncrement = 0
  103.  
  104. if ~(datatype(rows, n)) then exit_msg("Invalid Entry for Rows: "rows)
  105. if ~(datatype(columns, n)) then exit_msg("Invalid Entry for Columns: "columns)
  106. if ~(datatype(horizontal, n)) then exit_msg("Invalid Entry for Horiz. Spacing: "horizontal)
  107. if ~(datatype(HorizOffset, n)) then exit_msg("Invalid Entry for Horiz. Offset: "HorizOffset)
  108. if ~(datatype(vertical, n)) then exit_msg("Invalid Entry for Vertical Spacing: "vertical)
  109. if ~(datatype(OffsetAngle, n)) then exit_msg("Invalid Entry for Offset Angle: "OffsetAngle)
  110. if ~(datatype(RotAngle, n)) then exit_msg("Invalid Entry for Rotation Angle: "RotAngle)
  111. if ~(datatype(Xcentre, n)) then exit_msg("Invalid Entry for Rotation Centre X: "Xcentre)
  112. if ~(datatype(Ycentre, n)) then exit_msg("Invalid Entry for Rotation Centre Y: "Ycentre)
  113. if ~(datatype(Xscale, n)) then exit_msg("Invalid Entry for X scale: "Xscale)
  114. if ~(datatype(Yscale, n)) then exit_msg("Invalid Entry for Y scale: "Yscale)
  115. if ~(datatype(SpiralScale, n)) then exit_msg("Invalid Entry for Spiral Scale: "SpiralScale)
  116. if ~(datatype(SpiralIncrement, n)) then exit_msg("Invalid Entry for Spiral Increment: "SpiralIncrement)
  117.  
  118. formstring ="rows:"rows||"0a"x"columns:"columns||"0a"x"horiz. spacing ("cu"):"horizontal||"0a"x"vertical spacing ("cu"):"vertical||"0a"x"horiz. offset ("cu"):"HorizOffset||"0a"x"offset angle:"OffsetAngle||"0a"x"rotation angle:"RotAngle||"0a"x"rotation centre, X:"Xcentre||"0a"x"rotation centre, Y:"Ycentre||"0a"x"scale, X:"Xscale||"0a"x"scale, Y:"Yscale||"0a"x"spiral scale:"SpiralScale||"0a"x"spiral spacing("cu"):"SpiralIncrement||"0a"x"save settings (Y/N):"upper(Saving)||"0a"x"Link boxes (Y/N):"upper(Linking)"0a"x
  119.  
  120. if open("temp","ram:SRD.data","W") then do
  121.     call seek("temp",0,"B") 
  122.     call writech("temp",formstring)
  123.     call close("temp")
  124.     end
  125.  
  126. if upper(Saving) = "Y" then do
  127.     savefile = ppm_GetFileName("Save settings to disk","PPage:","")
  128.     if savefile = "" then break
  129.     if open("saver",savefile,"W") then do
  130.         call writech("saver",formstring)
  131.         call close("saver")
  132.         end
  133.     end
  134.  
  135. if RotAngle ~=0 then SpiralIncrement = SpiralIncrement/(360/RotAngle) /* get value for each unit  */
  136.  
  137. if upper(linking)="Y" then do /* don't try to link if not text */
  138.     info = ppm_GetBoxInfo(box)
  139.     boxtype = word(info,1)
  140.     if upper(boxtype) ~= "TEXT" then linking = "N"
  141.     end
  142.  
  143. AroundCentre = 0
  144. if centreX ~= Xcentre | centreY ~= Ycentre then AroundCentre = 1
  145. rotationangle = oldangle
  146. HorizShift = 0   /* sideways shift for offset angle */
  147. if OffsetAngle ~= 0 then do  /* use horiz. spacing and offset angle */
  148.     Oangle=OffsetAngle*3.1415926/180  /* convert to radians  */
  149.     vertical = horizontal*sin(Oangle)
  150.     HorizShift = horizontal*cos(Oangle)
  151.     end
  152. ScaledWidth = width
  153. ScaledHeight = height
  154. ScaledImageX = ImageScaleX
  155. ScaledImageY = ImageScaleY
  156. scaling = 0
  157. if Xscale~=1 | Yscale~=1 then scaling = 1    /* set scaling flag  */
  158.  
  159. boxes.1.1 = box
  160.  
  161.  
  162. /* For single rows or lines of units */
  163. if rows = 1 | columns = 1 then do
  164.     call ppm_ShowStatus("   Working on single column ")
  165.     do i = 2 to max(rows,columns)
  166.         k=i-1
  167.         box = boxes.1.k
  168.         
  169.         /* to avoid a bug in CloneBox we have to clone first and then set the position  */
  170.         boxX=word(ppm_GetBoxPosition(box),1)
  171.         boxY=word(ppm_GetBoxPosition(box),2)
  172.         boxX=boxX+HorizShift+HorizOffset+horizontal
  173.         boxY=boxY+vertical
  174.         newbox = ppm_CloneBox(box, 0,0)
  175.         call ppm_AddToGroup(newbox)
  176.         call ppm_SetBoxPosition(newbox,boxX,boxY)
  177.         
  178.         boxes.1.i = newbox
  179.         if rotangle ~= 0 then do
  180.             newangle = (rotationangle + rotangle)//360
  181.             call ppm_SetBoxAngle(newbox, newangle)
  182.             rotationangle = newangle
  183.             end
  184.  
  185.         if  AroundCentre = 1 then do
  186.             adjustment = newbox "0a"x Xcentre "0a"x Ycentre "0a"x rotangle "0a"x SpiralScale "0a"x SpiralIncrement
  187.             call rotator(adjustment)
  188.             end
  189.  
  190.         if upper(linking)="Y" then linked = ppm_LinkBox(box,newbox)
  191.  
  192.         if scaling = 1 then do
  193.             ScaledWidth = ScaledWidth*abs(Xscale)
  194.             ScaledHeight = ScaledHeight*abs(Yscale)
  195.             ScaledImageX = ScaledImageX*Xscale
  196.             ScaledImageY = ScaledImageY*Yscale
  197.             call ppm_SetBoxSize(newbox,ScaledWidth,ScaledHeight)
  198.             call ppm_SetBoxScale(newbox,ScaledImageX,ScaledImageY)
  199.             vertical = vertical * abs(Yscale)
  200.             horizontal = horizontal * abs(Xscale)
  201.             end
  202.  
  203.         end   /* of column */
  204. end /* rows or columns = 1  */
  205.  
  206.  
  207. else do   /* for multiple columns  */
  208.  
  209. /* make first column */
  210. call ppm_ShowStatus("   Working on column 1")
  211.     do i = 2 to rows
  212.         k=i-1
  213.         box = boxes.1.k
  214.                 
  215.         /* to avoid a bug in CloneBox we have to clone first and then set the position  */
  216.         boxX=word(ppm_GetBoxPosition(box),1)
  217.         boxY=word(ppm_GetBoxPosition(box),2)
  218.         boxX=boxX+HorizShift+HorizOffset
  219.         boxY=boxY+vertical
  220.         newbox = ppm_CloneBox(box, 0,0)
  221.         call ppm_AddToGroup(newbox)
  222.         call ppm_SetBoxPosition(newbox,boxX,boxY)
  223.         
  224.         boxes.1.i = newbox
  225.         if rotangle ~= 0 then do
  226.             newangle = (rotationangle + rotangle)//360
  227.             call ppm_SetBoxAngle(newbox, newangle)
  228.             rotationangle = newangle
  229.             end
  230.  
  231.         if  AroundCentre = 1 then do
  232.             adjustment = newbox "0a"x Xcentre "0a"x Ycentre "0a"x rotangle "0a"x SpiralScale "0a"x SpiralIncrement
  233.             call rotator(adjustment)
  234.             end
  235.  
  236.         if upper(linking)="Y" then linked = ppm_LinkBox(box,newbox)
  237.  
  238.         if scaling = 1 then do
  239.             ScaledImageY = ScaledImageY*Yscale
  240.             ScaledHeight = ScaledHeight*abs(Yscale)
  241.             call ppm_SetBoxSize(newbox,width,ScaledHeight)
  242.             call ppm_SetBoxScale(newbox,ImageScaleX,ScaledImageY)
  243.             vertical = vertical * abs(Yscale)
  244.             end
  245.  
  246.     end   /* of first column */
  247.  
  248.  
  249.     vertical = height
  250.     box = boxes.1.1
  251.     rotationangle = oldangle
  252.  
  253.     do j = 2 to columns
  254.        call ppm_ShowStatus("  Working on column "j) 
  255.        k = j-1
  256.  
  257.         rotationangle = ppm_GetBoxAngle(boxes.k.1)
  258.         do i = 1 to rows
  259.             box = boxes.k.i
  260.                     
  261.             /* to avoid a bug in CloneBox we have to clone first and then set the position  */
  262.             boxX=word(ppm_GetBoxPosition(box),1)
  263.             boxY=word(ppm_GetBoxPosition(box),2)
  264.             boxX=boxX+Horizontal
  265.             newbox = ppm_CloneBox(box, 0,0)
  266.             call ppm_AddToGroup(newbox)
  267.             call ppm_SetBoxPosition(newbox,boxX,boxY)
  268.             
  269.             boxes.j.i = newbox
  270.             if rotangle ~= 0 then do
  271.                 newangle = (rotationangle + rotangle)//360
  272.                 call ppm_SetBoxAngle(newbox, newangle)
  273.                 rotationangle = newangle
  274.                 end
  275.  
  276.         if  AroundCentre = 1 then do
  277.             adjustment = newbox "0a"x Xcentre "0a"x Ycentre "0a"x rotangle "0a"x SpiralScale "0a"x SpiralIncrement
  278.             call rotator(adjustment)
  279.             end
  280.  
  281.         if upper(linking)="Y" then linked = ppm_LinkBox(box,newbox)
  282.  
  283.         if scaling = 1 then do
  284.             ScaledWidth = word(ppm_GetBoxSize(box),1) * abs(Xscale)
  285.             ScaledHeight = word(ppm_GetBoxSize(box),2)
  286.             ScaledImageX = word(ppm_GetBoxScale(box),1) *Xscale
  287.             ScaledImageY = word(ppm_GetBoxScale(box),2)
  288.             call ppm_SetBoxSize(newbox,ScaledWidth,ScaledHeight)
  289.             call ppm_SetBoxScale(newbox,ScaledImageX,ScaledImageY)
  290.             vertical = vertical * abs(Yscale)
  291.             ScaledImageY = ScaledImageY * Yscale
  292.             end
  293.  
  294.         end   /* rows */
  295.         
  296.         if scaling = 1 then do 
  297.             horizontal = horizontal* abs(Xscale)
  298.             vertical = height
  299.             ScaledImageX = ScaledImageX*Xscale
  300.             ScaledImageY = ImageScaleY
  301.             end
  302.     end   /* columns */
  303.  
  304. end  /* multiple columns  */
  305.  
  306. exit_msg()
  307. end
  308.  
  309.  
  310. /* Rotate box around a centre */
  311.  
  312. rotator: procedure
  313.  
  314. parse arg box '0a'x Xcentre '0a'x Ycentre '0a'x angle '0a'x SpiralScale '0a'x SpiralIncrement
  315. startangle = ppm_GetBoxAngle(box)
  316. call ppm_SetBoxAngle(box,0)
  317. boxpos = ppm_GetBoxPosition(box)
  318. boxleft = word(boxpos,1)
  319. boxtop = word(boxpos,2)
  320. boxsize = ppm_GetBoxSize(box)
  321. boxwidth = word(boxsize,1)
  322. boxheight = word(boxsize,2)
  323. boxcentreX = boxleft+(boxwidth/2)
  324. boxcentreY = boxtop+(boxheight/2)
  325.  
  326. rangle=angle*3.1415926/180  /* convert to radians  */
  327. cosa = cos(rangle)
  328. sina = sin(rangle)
  329. Xoffset = boxcentreX-Xcentre
  330. Yoffset = boxcentreY-Ycentre
  331. newX = (Xoffset*cosa)+(Yoffset*sina)
  332. newY = (Yoffset*cosa)-(Xoffset*sina)
  333.  
  334. if SpiralIncrement ~= 0 then do   /* using Pythagoras to split increment of radius into x & y  */
  335.     incX = (SpiralIncrement * newX) / (sqrt((newX*newX) + (newY*newY)))
  336.     incY = (SpiralIncrement * newY) / (sqrt((newX*newX) + (newY*newY)))
  337.     newX = NewX + incX
  338.     newY = newY + incY
  339.     end
  340.  
  341. x = Xcentre+newX
  342. y = Ycentre+newY
  343. x = x * SpiralScale
  344. y = y * SpiralScale
  345. call ppm_SetBoxPosition(box,x-(boxwidth/2),y-(boxheight/2))
  346. call ppm_SetBoxAngle(box,startangle)
  347.  
  348. return
  349.  
  350.  
  351. break_d:
  352. break_e:
  353. break_c:
  354. halt:
  355.     call exit_msg("User aborted Genie!")
  356.  
  357. exit_msg: procedure  expose units
  358. do
  359.     parse arg message
  360.  
  361.     if message ~= '' then call ppm_Inform(1, message,"Resume")
  362.     call ppm_ClearStatus()
  363.     call ppm_SetUnits(units)
  364.     call ppm_AutoUpdate(1)
  365.     exit
  366. end
  367.