home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0925.lha / DonsGenies / DonsGenies.lha / Don'sGenies / BordersSimpleShapes.pprx < prev    next >
Text File  |  1993-05-25  |  27KB  |  836 lines

  1. /* This Genie puts a decorative border around a box, using data stored in the genie. The resulting border is merged into a single box. The current line and fill colours are used. 
  2. Genie written and ⌐ by Don Cox   July 92. Bug fixes Jan 93. Not public domain.  All rights reserved. */
  3.  
  4.  
  5. trace n
  6. address command
  7. signal on error
  8. signal on syntax
  9. signal on halt
  10. signal on break_c
  11. signal on break_d
  12. signal on break_e
  13.  
  14. if ~show("l", "gdarexxsupport.library") then
  15.     if ~addlib("gdarexxsupport.library", 0, -30,0) then
  16.     do
  17.         call ppm_Inform(1,"Please install the gdarexxsupport.library in your libs: directory before running this Genie.")
  18.     end
  19.  
  20. call ppm_AutoUpdate(0)
  21. call SafeEndEdit.rexx()
  22. cr="0a"x
  23.  
  24.  
  25. CurrentUnits = ppm_GetUnits()
  26.  
  27. select
  28.     when CurrentUnits = 1 then do
  29.         units="inches"
  30.         mul = 1
  31.         mul2 = 72
  32.         end
  33.     when CurrentUnits = 2 then do
  34.         units="mm"
  35.         mul = 10
  36.         mul2 = 28.4
  37.         end
  38.     otherwise do 
  39.         call ppm_SetUnits(2)
  40.         units="mm"
  41.         mul = 10
  42.         mul2 = 28.4
  43.         end
  44.     end
  45.  
  46. mainbox = ppm_ClickOnBox("  Click on box to be given a border")
  47. if mainbox = 0 then exit_msg("No box selected")
  48. mainpos = ppm_GetBoxPosition(mainbox)
  49. mainXpos = word(mainpos, 1)
  50. mainYpos = word(mainpos, 2)
  51. mainsize = ppm_GetBoxSize(mainbox)
  52. mainwidth = word(mainsize,1)
  53. mainheight = word(mainsize,2)
  54. mainangle = ppm_GetBoxAngle(mainbox)
  55.  
  56.  
  57. /* Initialize data strings  */
  58. cornerline1 = "" 
  59. cornerline2 = ""
  60. cornerline3 = ""
  61. cornerweight1 = "" 
  62. cornerweight2 = ""
  63. cornerweight3 = ""
  64. sideline1 = ""
  65. sideline2 = ""
  66. sideline3 = ""
  67. cornerXoffset = 0
  68. cornerYoffset = 0
  69. sideXoffset = 0
  70. sideYoffset = 0
  71. cornerfill1 = 0
  72. cornerfill2 = 0
  73. cornerfill3 = 0
  74. sidefill1 = 0
  75. sidefill2 = 0
  76. sidefill3 = 0
  77. lines = 1
  78.  
  79. list = "Greek Key"cr"Two Rules"cr"Two Rules Rounded"cr"Two Rules Reverse Rounded"cr"Three Rules"cr"Battlements"cr"Cutout"cr"Filled Squares"cr"Double Squares"cr"Off-Centre Squares"cr"Filled Triangles"cr"Filled Triangles 2"cr"Three Ls"cr"Bars"
  80. chosen = ppm_SelectFromList("Select Border Pattern",30,14,0,list)
  81. if chosen = "" then exit_msg("Aborted by User")
  82.  
  83. /* Data for various patterns. The numbers are lists of coordinates in the format required by the DrawPoly command.  */
  84.  
  85. select 
  86.  
  87.     when chosen = "Bars" then do
  88.         cornerline1 = "0 0"cr"3 0"cr"3 3"cr"0 3"cr"0 0"
  89.         cornerline2 = "5 0"cr"7 0"cr"7 7"cr"0 7"cr"0 5"cr"5 5"cr"5 0"
  90.         cornerline3 = "9 0"cr"11 0"cr"11 11"cr"0 11"cr"0 9"cr"9 9"cr"9 0"
  91.         sideline1 = "1 0"cr"3 0"cr"3 12"cr"1 12"cr"1 0"
  92.         sideline2 = "5 0"cr"7 0"cr"7 12"cr"5 12"cr"5 0"
  93.         sideheight = 12
  94.         sidewidth = 8
  95.         sideXoffset = 1
  96.         sideYoffset = 0
  97.         cornerheight = 12
  98.         cornerwidth = 12
  99.         cornerXoffset = 0
  100.         cornerYoffset = 0
  101.         cornerfill1 = 1
  102.         cornerfill2 = 1
  103.         cornerfill3 = 1
  104.         sidefill1 = 1
  105.         sidefill2 = 1
  106.         sidefill3 = 0
  107.         lines = 0   /* number of line weights to be set by user  */
  108.         end
  109.  
  110.     when chosen = "Three Ls" then do
  111.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  112.         cornerline2 = "6 0"cr"9 0"cr"9 9"cr"0 9"cr"0 6"cr"6 6"cr"6 0"
  113.         sideline1 = "1 0"cr"3 0"cr"3 8"cr"11 8"cr"11 10"cr"1 10"cr"1 0"
  114.         sideline2 = "5 0"cr"7 0"cr"7 4"cr"11 4"cr"11 6"cr"5 6"cr"5 0"
  115.         sideline3 = "9 0"cr"11 0"cr"11 2"cr"9 2"cr"9 0"
  116.         sideheight = 10
  117.         sidewidth = 12
  118.         sideXoffset = 1
  119.         sideYoffset = 0
  120.         cornerheight = 10
  121.         cornerwidth = 10
  122.         cornerXoffset = 0
  123.         cornerYoffset = 0
  124.         cornerfill1 = 1
  125.         cornerfill2 = 1
  126.         sidefill1 = 1
  127.         sidefill2 = 1
  128.         sidefill3 = 1
  129.         lines = 0
  130.         end
  131.  
  132.     when chosen = "Filled Triangles 2" then do
  133.         cornerline1 = "4.3 0"cr"4.3 4.3"cr"0 4.3"cr"4.3 0"
  134.         sideline1 = "0 0"cr"4 0"cr"0 4"cr"0 0"
  135.         sideline2 = "5 1"cr"5 5"cr"1 5"cr"5 1"
  136.         sideheight = 5
  137.         sidewidth = 6.4
  138.         sideXoffset = 0.7
  139.         sideYoffset = 0
  140.         cornerheight = 5
  141.         cornerwidth = 5
  142.         cornerXoffset = 0
  143.         cornerYoffset = 0
  144.         cornerfill1 = 1
  145.         sidefill1 = 1
  146.         sidefill2 = 1
  147.         sidefill3 = 0
  148.         lines = 0
  149.         end
  150.  
  151.     when chosen = "Filled Triangles" then do
  152.         cornerline1 = "2.6 0"cr"2.6 2.6"cr"0 2.6"cr"2.6 0"
  153.         sideline1 = "0 0"cr"4 4"cr"0 4"cr"0 0"
  154.         sideline2 = "2 0"cr"10 0"cr"6 4"cr"2 0"
  155.         sideline3 = "12 0"cr"12 4"cr"8 4"cr"12 0"
  156.         sideheight = 4
  157.         sidewidth = 12
  158.         sideXoffset = 0
  159.         sideYoffset = 0
  160.         cornerheight = 4
  161.         cornerwidth = 4
  162.         cornerXoffset = 0
  163.         cornerYoffset = 0
  164.         cornerfill1 = 1
  165.         sidefill1 = 1
  166.         sidefill2 = 1
  167.         sidefill3 = 1
  168.         lines = 0
  169.         end
  170.  
  171.     when chosen = "Off-Centre Squares" then do
  172.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  173.         cornerline2 = "0 0"cr"2 0"cr"2 2"cr"0 2"cr"0 0"
  174.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  175.         sideline2 = "1 0"cr"3 0"cr"3 2"cr"1 2"cr"1 0"
  176.         sideheight = 5
  177.         sidewidth = 6
  178.         sideXoffset = 1
  179.         sideYoffset = 0
  180.         cornerheight = 5
  181.         cornerwidth = 5
  182.         cornerXoffset = 0
  183.         cornerYoffset = 0
  184.         cornerfill1 = 0
  185.         sidefill1 = 0
  186.         lines = 1
  187.         end
  188.  
  189.     when chosen = "Double Squares" then do
  190.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  191.         cornerline2 = "1 1"cr"3 1"cr"3 3"cr"1 3"cr"1 1"
  192.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  193.         sideline2 = "2 1"cr"4 1"cr"4 3"cr"2 3"cr"2 1"
  194.         sideheight = 5
  195.         sidewidth = 6
  196.         sideXoffset = 1
  197.         sideYoffset = 0
  198.         cornerheight = 5
  199.         cornerwidth = 5
  200.         cornerXoffset = 0
  201.         cornerYoffset = 0
  202.         cornerfill1 = 0
  203.         sidefill1 = 0
  204.         lines = 1
  205.         end
  206.  
  207.     when chosen = "Filled Squares" then do
  208.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  209.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  210.         sideheight = 5
  211.         sidewidth = 6
  212.         sideXoffset = 1
  213.         sideYoffset = 0
  214.         cornerheight = 5
  215.         cornerwidth = 5
  216.         cornerXoffset = 0
  217.         cornerYoffset = 0
  218.         cornerfill1 = 1
  219.         sidefill1 = 1
  220.         lines = 0
  221.         end
  222.  
  223.     when chosen = "Cutout" then do
  224.         cornerline1 = "0 1"cr"0 0"cr"1 0"
  225.         sideline1 = "0 0"cr"1 0"
  226.         sideline2 = "3 0"cr"4 0"
  227.         sideheight = 1
  228.         sidewidth = 4
  229.         sideXoffset = 0
  230.         sideYoffset = 0
  231.         cornerheight = 1
  232.         cornerwidth = 1
  233.         cornerXoffset = 0
  234.         cornerYoffset = 0
  235.         lines = 1
  236.         end
  237.  
  238.     when chosen = "Battlements" then do
  239.         cornerline1 = "0 0"cr"3.3 0"cr"3.3 2.3"cr"2.3 2.3"cr"2.3 3.3"cr"0 3.3"cr"0 0"
  240.         sideline1 = "0 6"cr"1 6"cr"1 0"cr"3 0"cr"3 6"cr"4 6"
  241.         sideheight = 6
  242.         sidewidth = 4
  243.         sideXoffset = 0
  244.         sideYoffset = 0
  245.         cornerheight = 4
  246.         cornerwidth = 4
  247.         cornerXoffset = 0
  248.         cornerYoffset = 0
  249.         lines = 1
  250.         end
  251.  
  252.     when chosen = "Greek Key" then do
  253.         sideline1 = "0 0"cr"6 0"cr"6 5"cr"3 5"cr"3 3"cr"2 3"cr"2 6"cr"7 6"cr"7 0"cr"8 0"
  254.         sideline2 = "0 1"cr"5 1"cr"5 4"cr"4 4"cr"4 2"cr"1 2"cr"1 7"cr"8 7"cr"8 0.8"
  255.         sideheight = 8
  256.         sidewidth = 8
  257.         sideXoffset = 0
  258.         sideYoffset = 0
  259.         cornerheight = 8
  260.         cornerwidth = 8
  261.         cornerXoffset = 0
  262.         cornerYoffset = 0
  263.         Cornerline1 = "0 8"cr"0 0"cr"6 0"cr"6 5"cr"2 5"cr"2 2"cr"4 2"cr"4 3"cr"3 3"cr"3 4"cr"5 4"cr"5 1"cr"1 1"cr"1 6"cr"7 6"cr"7 0"cr"8 0"
  264.         Cornerline2 = "1 8"cr"1 7"cr"8 7"cr"8 0.8"
  265.         lines = 0
  266.         end
  267.  
  268.     when chosen = "Two Rules" then do
  269.         sideline1 = ""
  270.         sideline2 = ""
  271.         Cornerline1 = ""
  272.         cornerline2 = ""
  273.         lines = 2
  274.         end
  275.  
  276.     when chosen = "Two Rules Rounded" | chosen = "Two Rules Reverse Rounded" then do
  277.         sideline1 = ""
  278.         sideline2 = ""
  279.         Cornerline1 = ""
  280.         cornerline2 = ""
  281.         lines = 100    /* impossible number as a flag */
  282.         end
  283.  
  284.     when chosen = "Three Rules" then do
  285.         sideline1 = ""
  286.         sideline2 = ""
  287.         Cornerline1 = ""
  288.         cornerline2 = ""
  289.         lines = 3
  290.         end
  291.  
  292.     otherwise do
  293.         cornerline1 = "" 
  294.         cornerline2 = ""
  295.         cornerline3 = ""
  296.         sideline1 = ""
  297.         sideline2 = ""
  298.         sideline3 = ""
  299.         end
  300.     end
  301.  
  302.  
  303. /* Collect line weights from user  */
  304.  
  305. if lines>3  & lines~=100 then lines = 3
  306.  
  307. select
  308.     when lines = 0 then do
  309.         form = ppm_GetForm("Set sizes",8,"Border width ("units")")
  310.         if form = "" then exit_msg("Aborted by user")
  311.         cornerweight1 = ""
  312.         parse var form breadth 
  313.         end
  314.  
  315.     when lines = 1 then do
  316.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line weight (points)")
  317.         if form = "" then exit_msg("Aborted by user")
  318.         parse var form breadth "0a"x cornerweight1
  319.         end
  320.  
  321.     when lines = 2 then do
  322.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)")
  323.         if form = "" then exit_msg("Aborted by user")
  324.         parse var form breadth "0a"x cornerweight1 "0a"x cornerweight2
  325.         end
  326.  
  327.     when lines = 3 then do
  328.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)"cr"Line 3 (points)")
  329.         if form = "" then exit_msg("Aborted by user")
  330.         parse var form  breadth "0a"x cornerweight1 "0a"x cornerweight2 "0a"x cornerweight3
  331.         end
  332.  
  333.     when lines = 100 then do
  334.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)"cr"Corner Radius ("units")")
  335.         if form = "" then exit_msg("Aborted by user")
  336.         parse var form  breadth "0a"x cornerweight1 "0a"x cornerweight2 "0a"x cornerRadius
  337.         if cornerRadius = "" then cornerRadius = breadth*2
  338.         end
  339.  
  340.     otherwise nop
  341.     end
  342.  
  343.  
  344. if breadth="" then exit_msg("Aborted by User")
  345. breadth = breadth/mul /* mm to cm */
  346. if breadth>(word(mainsize,1))/2 | breadth>(word(mainsize,2))/2 then exit_msg("Too big")
  347.  
  348. defaultweight = (breadth*mul2)/20
  349. if cornerweight1 = "" then cornerweight1 = defaultweight
  350. if cornerweight2 = "" then cornerweight2 = defaultweight
  351. if cornerweight3 = "" then cornerweight3 = defaultweight
  352.  
  353. if lines = 1 | lines = 0 then do
  354.     cornerweight2 = cornerweight1
  355.     cornerweight3 = cornerweight1
  356.     end
  357. if lines = 2 then cornerweight3 = cornerweight2
  358. sideweight1 = cornerweight1
  359. sideweight2 = cornerweight2
  360. sideweight3 = cornerweight3
  361. maxweight = max(cornerweight1, cornerweight2, cornerweight3)
  362. maxwt = maxweight/72  /* max. line weight in inches  */
  363. if CurrentUnits = 2 then maxwt = maxwt*2.54  /* or centimetres  */
  364.  
  365.  
  366. /* First deal with plain rectangular borders  */
  367.  
  368. if chosen = "Two Rules" then do
  369.         call ppm_SetFillPattern(0)
  370.         call ppm_NewGroup()
  371.         call ppm_SetLineWeight(sideweight1)
  372.         rect1 = ppm_DrawRect(mainXpos, mainYpos, mainXpos+word(mainsize,1), mainYpos+word(mainsize,2))
  373.         call ppm_AddToGroup(rect1)
  374.         call ppm_SetLineWeight(sideweight2)
  375.         rect2 = ppm_DrawRect(mainXpos+breadth, mainYpos+breadth, mainXpos+word(mainsize,1)-breadth, mainYpos+word(mainsize,2)-breadth)
  376.         call ppm_AddToGroup(rect2)
  377.         borderbox = ppm_MergeGroup()
  378.         call ppm_SetBoxAngle(borderbox,mainangle)
  379.         call ppm_SetBoxPosition(borderbox,mainXpos,mainYpos)
  380. /* Set an arbitrary margin in main box  */
  381.         margin = breadth*2
  382.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  383.         exit_msg("Done")
  384.         end
  385.  
  386. if chosen = "Two Rules Rounded" | chosen = "Two Rules Reverse Rounded" then do
  387.         rev = 0
  388.         if chosen = "Two Rules Reverse Rounded" then rev = 1
  389.         call ppm_ShowStatus("  Calculating outer line ...")
  390.         call ppm_SetFillPattern(0)
  391.         call ppm_NewGroup()
  392. trace n
  393. cornerRadius = cornerRadius/mul /* convert units */
  394. cRadius = cornerRadius /* for positioning centres of arcs */
  395.  
  396. AA=6.2831853/360    /* 2pi divided by 360 */
  397. AAA=AA*3
  398. angle= 180*AA /* convert to radians  */
  399. if rev = 1 then do /* for reverse curve corners  */
  400.     angle = 90*AA
  401.     AAA=-AAA  /* anti-clockwise arcs  */
  402.     cRadius = 0
  403.     end
  404.  
  405. drawstring = mainXpos (mainYpos+cornerRadius)||"0a"x
  406.  
  407. /* Draw the outer line, using 3 degree steps to give a smooth curve */
  408.         call ppm_SetLineWeight(sideweight1)
  409.         Xcentre = mainXpos+cRadius  /* centre of corner arc  */
  410.         Ycentre = mainYpos+cRadius
  411.         do i = 1 to 30
  412.             X2=Xcentre+(cornerRadius*cos(angle))
  413.             Y2=Ycentre+(cornerRadius*sin(angle))
  414.             angle=angle+AAA
  415.             drawstring=drawstring||X2 Y2"0a"x
  416.             end
  417.         if rev = 1 then drawstring = drawstring||(mainXpos +cornerRadius) mainYpos"0a"x
  418.         drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) mainYpos"0a"x
  419.         Xcentre = mainXpos+mainwidth-cRadius
  420.         Ycentre = mainYpos+cRadius
  421.         if rev = 1 then angle = angle+(60*AAA)
  422.         do i = 1 to 30
  423.             X2=Xcentre+(cornerRadius*cos(angle))
  424.             Y2=Ycentre+(cornerRadius*sin(angle))
  425.             angle=angle+AAA
  426.             drawstring=drawstring||X2 Y2"0a"x
  427.             end
  428.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth) (mainYpos+cornerRadius)"0a"x
  429.         drawstring = drawstring||(mainXpos+mainwidth) (mainYpos+mainheight-cornerRadius)"0a"x
  430.  
  431.         Xcentre = mainXpos+mainwidth-cRadius
  432.         Ycentre = mainYpos+mainheight-cRadius
  433.         if rev = 1 then angle = angle+(60*AAA)
  434.         do i = 1 to 30
  435.             X2=Xcentre+(cornerRadius*cos(angle))
  436.             Y2=Ycentre+(cornerRadius*sin(angle))
  437.             angle=angle+AAA
  438.             drawstring=drawstring||X2 Y2"0a"x
  439.             end
  440.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+mainheight)"0a"x
  441.         drawstring = drawstring||(mainXpos+cornerRadius) (mainYpos+mainheight)"0a"x
  442.         Xcentre = mainXpos+cRadius
  443.         Ycentre = mainYpos+mainheight-cRadius
  444.         if rev = 1 then angle = angle+(60*AAA)
  445.         do i = 1 to 30
  446.             X2=Xcentre+(cornerRadius*cos(angle))
  447.             Y2=Ycentre+(cornerRadius*sin(angle))
  448.             angle=angle+AAA
  449.             drawstring=drawstring||X2 Y2"0a"x
  450.             end
  451.         if rev = 1 then drawstring = drawstring||mainXpos (mainYpos+mainheight-cornerRadius)"0a"x
  452.         drawstring = drawstring||mainXpos (mainYpos+cornerRadius)"0a"x
  453.         call ppm_SaveText("ram:arcdata",drawstring)
  454.         box = ppm_DrawPoly("ram:arcdata",boxname)
  455.         call ppm_AddToGroup(box)
  456.  
  457. trace n
  458. /* Draw the inner arc, in 3 degree steps to give a smooth curve */
  459.         call ppm_ShowStatus("  Calculating inner line ...")
  460.         call ppm_SetLineWeight(sideweight2)
  461.         cornerRadius2 = cornerRadius-breadth
  462.         if rev = 1 then do
  463.             cornerRadius2 = cornerRadius+breadth
  464.             cornerRadius = cornerRadius+breadth
  465.             a2 = sin(90*AA)/cornerRadius*breadth
  466.             a2 = atan(a2/sqrt(-a2*a2+1))
  467.             a3 = 3.1415927-(90*AA)-a2
  468.             startangle = a2
  469.             arcangle = (90*AA)-(2*startangle)
  470.             AAA = -(arcangle/30)
  471.             angle = (90*AA)-startangle
  472.             end
  473. trace n
  474. /* first corner */
  475.         drawstring = (mainXpos+breadth) (mainYpos+cornerRadius)||"0a"x
  476.         Xcentre = mainXpos+cRadius
  477.         Ycentre = mainYpos+cRadius
  478.         do i = 0 to 30
  479.             X2=Xcentre+(cornerRadius2*cos(angle))
  480.             Y2=Ycentre+(cornerRadius2*sin(angle))
  481.             angle=angle+AAA
  482.             drawstring=drawstring||X2 Y2"0a"x
  483.             end
  484.         if rev = 1 then drawstring = drawstring||(mainXpos +cornerRadius) (mainYpos+breadth)"0a"x
  485.         drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+breadth)"0a"x
  486.  
  487. /* second corner */
  488.         Xcentre = mainXpos+mainwidth-cRadius
  489.         Ycentre = mainYpos+cRadius
  490.         if rev = 1 then angle = (180*AA)-startangle
  491.         do i = 0 to 30
  492.             X2=Xcentre+(cornerRadius2*cos(angle))
  493.             Y2=Ycentre+(cornerRadius2*sin(angle))
  494.             angle=angle+AAA
  495.             drawstring=drawstring||X2 Y2"0a"x
  496.             end
  497.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -breadth) (mainYpos+cornerRadius)"0a"x
  498.         drawstring = drawstring||(mainXpos+mainwidth-breadth) (mainYpos+mainheight-cornerRadius)"0a"x
  499.  
  500. /* third corner  */
  501.         Xcentre = mainXpos+mainwidth-cRadius
  502.         Ycentre = mainYpos+mainheight-cRadius
  503.         if rev = 1 then angle = (270*AA)-startangle
  504.         do i = 0 to 30
  505.             X2=Xcentre+(cornerRadius2*cos(angle))
  506.             Y2=Ycentre+(cornerRadius2*sin(angle))
  507.             angle=angle+AAA
  508.             drawstring=drawstring||X2 Y2"0a"x
  509.             end
  510.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+mainheight-breadth)"0a"x
  511.         drawstring = drawstring||(mainXpos+cornerRadius) (mainYpos+mainheight-breadth)"0a"x
  512.  
  513. /* fourth corner  */
  514.         Xcentre = mainXpos+cRadius
  515.         Ycentre = mainYpos+mainheight-cRadius
  516.         if rev = 1 then angle = 0-startangle
  517.         do i = 0 to 30
  518.             X2=Xcentre+(cornerRadius2*cos(angle))
  519.             Y2=Ycentre+(cornerRadius2*sin(angle))
  520.             angle=angle+AAA
  521.             drawstring=drawstring||X2 Y2"0a"x
  522.             end
  523.         if rev = 1 then drawstring = drawstring||(mainXpos +breadth) (mainYpos+mainheight-cornerRadius)"0a"x
  524.         drawstring = drawstring||(mainXpos+breadth) (mainYpos+cornerRadius)"0a"x
  525.         call ppm_SaveText("ram:arcdata2",drawstring)
  526.         box = ppm_DrawPoly("ram:arcdata2",boxname)
  527.         call ppm_AddToGroup(box)
  528.         borderbox = ppm_MergeGroup()
  529.         call ppm_SetBoxAngle(borderbox,mainangle)
  530.         call ppm_SetBoxPosition(borderbox,mainXpos-((sideweight1/2)/mul2), mainYpos-((sideweight1/2)/mul2))  
  531.  
  532.  
  533. /* Set an arbitrary margin in main box  */
  534.         margin = cornerRadius*1.2
  535.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  536.         exit_msg()
  537.         end
  538.  
  539.  
  540. if chosen = "Three Rules" then do
  541.         call ppm_NewGroup()
  542.         call ppm_SetLineWeight(sideweight1)
  543.         call ppm_SetFillPattern(0)
  544.         rect1 = ppm_DrawRect(mainXpos, mainYpos, mainXpos+word(mainsize,1), mainYpos+word(mainsize,2))
  545.         call ppm_AddToGroup(rect1)
  546.         call ppm_SetLineWeight(sideweight2)
  547.         rect2 = ppm_DrawRect(mainXpos+(breadth/3), mainYpos+(breadth/3), mainXpos+word(mainsize,1)-(breadth/3), mainYpos+word(mainsize,2)-(breadth/3))
  548.         call ppm_AddToGroup(rect2)
  549.         call ppm_SetLineWeight(sideweight3)
  550.         rect3 = ppm_DrawRect(mainXpos+breadth, mainYpos+breadth, mainXpos+word(mainsize,1)-breadth, mainYpos+word(mainsize,2)-breadth)
  551.         call ppm_AddToGroup(rect3)
  552.         borderbox = ppm_MergeGroup()
  553.         call ppm_SetBoxAngle(borderbox,mainangle)
  554.         call ppm_SetBoxPosition(borderbox,mainXpos,mainYpos)
  555. /* Set an arbitrary margin in main box  */
  556.         margin = breadth*2
  557.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  558.         exit_msg("Done")
  559.         end
  560.  
  561.  
  562. /* Now deal with borders using shapes scaled to fit  */
  563.  
  564. mainheight = (word(mainsize, 2))-(breadth*2)
  565. mainwidth = (word(mainsize, 1))-(breadth*2)
  566.  
  567. call ppm_NewGroup()
  568. count = 0
  569.  
  570. if cornerline1 ~= "" then do
  571.     drawstring = cornerline1
  572.     call ppm_SaveText("ram:linedata",drawstring)
  573.     call ppm_SetLineWeight(cornerweight1)
  574.     call ppm_SetFillPattern(cornerfill1)
  575.     cornerbox = ppm_DrawPoly("ram:linedata")
  576.     call ppm_AddToGroup(cornerbox)
  577.     count = count+1
  578.     end
  579.  
  580. if cornerline2 ~= "" then do
  581.     drawstring = cornerline2
  582.     call ppm_SaveText("ram:linedata",drawstring)
  583.     call ppm_SetLineWeight(cornerweight2)
  584.     call ppm_SetFillPattern(cornerfill2)
  585.     cornerbox = ppm_DrawPoly("ram:linedata")
  586.     call ppm_AddToGroup(cornerbox)
  587.     count = count+1
  588.     end
  589.  
  590. if cornerline3 ~= "" then do
  591.     drawstring = cornerline3
  592.     call ppm_SaveText("ram:linedata",drawstring)
  593.     call ppm_SetLineWeight(cornerweight3)
  594.     call ppm_SetFillPattern(cornerfill3)
  595.     cornerbox = ppm_DrawPoly("ram:linedata")
  596.     call ppm_AddToGroup(cornerbox)
  597.     count = count+1
  598.     end
  599.  
  600. if count>1 then cornerbox = ppm_MergeGroup() /* Merge fails with 1 box */
  601.  
  602. if cornerbox ~=0 then do
  603.     if cornerheight~=0 & cornerwidth~=0 then call ppm_SetBoxSize(cornerbox, cornerwidth, cornerheight)
  604.     call ppm_SetBoxOffset(cornerbox,cornerXoffset,cornerYoffset)
  605.     csize = ppm_GetBoxSize(cornerbox)
  606.     cXsize = word(csize, 1)
  607.     cYsize = word(csize, 2)
  608.     cscale = ppm_GetBoxScale(cornerbox)
  609.     cscaleX = word(cscale, 1)
  610.     cscaleY = word(cscale, 2)
  611.     cangle = ppm_GetBoxAngle(cornerbox)
  612.     end
  613.  
  614.  
  615. call ppm_NewGroup()
  616. count = 0
  617.  
  618. if sideline1 ~= "" then do
  619.     drawstring = sideline1
  620.     call ppm_SaveText("ram:linedata",drawstring)
  621.     call ppm_SetLineWeight(sideweight1)
  622.     call ppm_SetFillPattern(sidefill1)
  623.     sidebox = ppm_DrawPoly("ram:linedata")
  624.     call ppm_AddToGroup(sidebox)
  625.     count = count+1
  626.     end
  627.  
  628. if sideline2 ~= "" then do
  629.     drawstring = sideline2
  630.     call ppm_SaveText("ram:linedata",drawstring)
  631.     call ppm_SetLineWeight(sideweight2)
  632.     call ppm_SetFillPattern(sidefill2)
  633.     sidebox = ppm_DrawPoly("ram:linedata")
  634.     call ppm_AddToGroup(sidebox)
  635.     count = count+1
  636.     end
  637.  
  638. if sideline3 ~= "" then do
  639.     drawstring = sideline3
  640.     call ppm_SaveText("ram:linedata",drawstring)
  641.     call ppm_SetLineWeight(sideweight3)
  642.     call ppm_SetFillPattern(sidefill3)
  643.     sidebox = ppm_DrawPoly("ram:linedata")
  644.     call ppm_AddToGroup(sidebox)
  645.     count = count+1
  646.     end
  647.  
  648. if count>1 then sidebox = ppm_MergeGroup()
  649.  
  650. trace n
  651. /* Place Corner Units. Setting angle before position is best for these as the basic unit is always at 0 degrees. It gives good results with boxes smaller than 2.5 mm. (Contrast BordersRepeats which has position before angle. */
  652. call ppm_NewGroup()
  653. call ppm_ShowStatus("Placing Corner Units")
  654. if cornerbox ~=0 then do
  655.     bbreadth = breadth*2
  656.     cbox = ppm_CloneBox(cornerbox, 0, 0)
  657.     call ppm_AddToGroup(cbox)
  658.     call ppm_SetBoxAngle(cbox,0)
  659.     call ppm_SetBoxSize(cbox, breadth, breadth)
  660.     call ppm_SetBoxScale(cbox, cscaleX*breadth/cXsize, cscaleY*breadth/cYsize)
  661.  
  662.     cbox2 = ppm_CloneBox(cbox, 0, 0)
  663.     call ppm_AddToGroup(cbox2)
  664.     call ppm_SetBoxAngle(cbox2, 90)
  665.     call ppm_SetBoxPosition(cbox2, mainXpos, mainYpos+mainheight +bbreadth)
  666.  
  667.     cbox3 = ppm_CloneBox(cbox, 0, 0)
  668.     call ppm_AddToGroup(cbox3)
  669.     call ppm_SetBoxAngle(cbox3, 180)
  670.     call ppm_SetBoxPosition(cbox3, mainXpos+mainwidth+bbreadth, mainYpos+mainheight+bbreadth)
  671.  
  672.     cbox4 = ppm_CloneBox(cbox, 0, 0)
  673.     call ppm_AddToGroup(cbox4)
  674.     call ppm_SetBoxAngle(cbox4, 270)
  675.     call ppm_SetBoxPosition(cbox4, mainXpos+mainwidth+bbreadth, mainYpos)
  676.  
  677.     call ppm_SetBoxAngle(cbox, cangle)
  678.     call ppm_SetBoxPosition(cbox, mainXpos, mainYpos)
  679.     end
  680.  
  681. trace n
  682.  
  683. if sidebox = 0 then exit_msg("Done")
  684.  
  685.  
  686. /* Collect original size and graphic scale of box */
  687.     if sideheight~=0 & sidewidth~=0 then call ppm_SetBoxSize(sidebox, sidewidth, sideheight)
  688.     call ppm_SetBoxOffset(sidebox,sideXoffset,sideYoffset)
  689.     scaleX = word(ppm_GetBoxScale(sidebox), 1)
  690.     scaleY = word(ppm_GetBoxScale(sidebox), 2)
  691.     width = word(ppm_GetBoxSize(sidebox), 1)
  692.     height = word(ppm_GetBoxSize(sidebox), 2)
  693.     scale1 = breadth/height
  694.     width2 = width*scale1
  695. totalwidth = width2
  696.  
  697.  
  698. heightcount = mainheight%totalwidth /* Use integer division to get number of repeats */
  699. widthcount = mainwidth%totalwidth
  700. if widthcount = 0 | heightcount = 0 then do
  701.     gone = ppm_DeleteBox(sidebox)
  702.     gone = ppm_DeleteBox(cornerbox)
  703.     gone = ppm_DeleteBox(cbox)
  704.     gone = ppm_DeleteBox(cbox2)
  705.     gone = ppm_DeleteBox(cbox3)
  706.     gone = ppm_DeleteBox(cbox4)
  707.     exit_msg("Pattern too big")
  708.     end
  709.  
  710. Xtotalwidth = mainwidth/widthcount  /* Exact width of whole pattern */
  711. Ytotalwidth = mainheight/heightcount
  712. Xscale = Xtotalwidth/totalwidth
  713. Yscale = Ytotalwidth/totalwidth
  714.  
  715.  
  716. widthX = width2*Xscale
  717. widthY = width2*Yscale 
  718.  
  719.  
  720. /* Place top units  */
  721.  
  722. call ppm_ShowStatus("Placing Top Units")
  723. leftpos = mainXpos+breadth
  724. do j=1 to widthcount
  725.     newbox = ppm_CloneBox(sidebox, 0, 0)
  726.     call ppm_AddToGroup(newbox)
  727.     call ppm_SetBoxSize(newbox, widthX, breadth)
  728.     call ppm_SetBoxPosition(newbox, leftpos, mainYpos)
  729.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Xscale), (scaleY * abs(scale1)) )
  730.     call ppm_SetBoxAngle(newbox, 0)
  731.     leftpos = leftpos+widthX
  732.     end
  733.  
  734. /* Place right side units */
  735. call ppm_ShowStatus("Placing Right Side Units")
  736. toppos = mainYpos+breadth
  737. leftpos = mainXpos+word(mainsize, 1)
  738.  
  739. do j=1 to heightcount
  740.     newbox = ppm_CloneBox(sidebox, 0, 0)
  741.     call ppm_AddToGroup(newbox)
  742.     call ppm_SetBoxAngle(newbox, 270)
  743.     call ppm_SetBoxSize(newbox, widthY, breadth)
  744.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  745.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Yscale), (scaleY * abs(scale1)) )
  746.     toppos = toppos+widthY
  747.     end
  748.  
  749.  
  750. /* Place bottom units  */
  751.  
  752. call ppm_ShowStatus("Placing Bottom Units")
  753. leftpos = mainXpos+breadth+mainwidth
  754. toppos = mainYpos+word(mainsize, 2)
  755.  
  756. do j=1 to widthcount
  757.     newbox = ppm_CloneBox(sidebox, 0, 0)
  758.     call ppm_AddToGroup(newbox)
  759.     call ppm_SetBoxAngle(newbox, 180)
  760.     call ppm_SetBoxSize(newbox, widthX, breadth)
  761.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  762.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Xscale), (scaleY * abs(scale1)) )
  763.     leftpos = leftpos-widthX
  764.     end
  765.  
  766. /* Place left side units */
  767. call ppm_ShowStatus("Placing Left Side Units")
  768. toppos = mainYpos+breadth+mainheight
  769. leftpos = mainXpos
  770.  
  771. do j=1 to heightcount
  772.     newbox = ppm_CloneBox(sidebox, 0, 0)
  773.     call ppm_AddToGroup(newbox)
  774.     call ppm_SetBoxAngle(newbox, 90)
  775.     call ppm_SetBoxSize(newbox, widthY, breadth)
  776.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  777.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Yscale), (scaleY * abs(scale1)) )
  778.     toppos = toppos-widthY
  779.     end 
  780.  
  781. /* Merge all the units into one box  */
  782. borderbox = ppm_MergeGroup()
  783. call ppm_SetBoxAngle(borderbox,mainangle)
  784.  
  785. /* resize box slightly so that thick lines are not cropped */
  786. bsize = ppm_GetBoxSize(borderbox)
  787. bwidth = word(bsize,1)
  788. bheight = word(bsize,2)
  789. call ppm_SetBoxSize(borderbox,bwidth+(maxwt*2),bheight+(maxwt*2))
  790. call ppm_SetBoxPosition(borderbox,mainXpos-maxwt,mainYpos-maxwt)
  791. call ppm_SetBoxOffset(borderbox,maxwt,maxwt)
  792.  
  793. /* Delete the pattern boxes  */
  794.  
  795.     gone = ppm_DeleteBox(cornerbox)
  796.     gone = ppm_DeleteBox(sidebox)   
  797.  
  798. /* Set an arbitrary margin in main box  */
  799. margin = breadth*1.5
  800. boxtype = upper(word(ppm_GetBoxInfo(mainbox),1))
  801. if boxtype = "TEXT" then margin = breadth*2
  802. call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  803. call ppm_BoxToFront(borderbox)
  804.  
  805. call ppm_NewGroup()
  806. call ppm_AddToGroup(mainbox)
  807. call ppm_AddToGroup(borderbox)
  808.  
  809. call exit_msg()
  810.  
  811. end
  812.  
  813. error:
  814. syntax:
  815.     do
  816.     exit_msg("Genie failed due to error: "errortext(rc))
  817.     end
  818.  
  819. break_d:
  820. break_e:
  821. break_c:
  822. halt:
  823. call exit_msg("Aborted by User")
  824.  
  825. exit_msg:
  826.     do
  827.     parse arg message
  828.     if message ~= "" then
  829.     call ppm_Inform(1, message,"Resume")
  830.     call ppm_ClearStatus()
  831.     call ppm_SetUnits(CurrentUnits)
  832.     call ppm_AutoUpdate(1)
  833.     exit
  834.     end
  835.  
  836.