home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Painting / OpalPaint32B-020+Version.LHA / OpalVision / Rexx / ResizeCanvas.oprx < prev    next >
Encoding:
Text File  |  1994-04-21  |  9.8 KB  |  364 lines

  1. /* Resize canvas operator for OpalPaint.
  2.    AREXX script by Greg Niles, Centaur Development.
  3.    Requires OpalPaint 2.3 or greater.
  4.  
  5.    Version 1.0 - Initial release
  6. */
  7.  
  8. address 'OpalPaint_Rexx'
  9.  
  10. options Results
  11.  
  12. SaveSetUp
  13.  
  14. call TestVersion
  15. if VersionNum < 2.3 then do
  16.     Okay "You need OpalPaint 2.3 or above to run this AREXX script!"
  17.     EXIT
  18.     END
  19.  
  20. call Setup
  21. call OptionsRequester
  22. call ChangeCanvas
  23.  
  24. RestoreSetUp
  25. Exit
  26.  
  27.  
  28. TestVersion:
  29.     Version
  30.     VersionNum = substr(Result,17,3)
  31. Return
  32.  
  33.  
  34. SetUp:
  35.     /* get current page size & initialize variables */
  36.     PageSize
  37.     parse var result Width Height
  38.     Width = compress(Width)
  39.     Height = compress(Height)
  40.     NewWidth = Width
  41.     NewHeight = Height
  42.     MaxSize = 32767
  43.     Placement = MidCenter
  44.     PageGadStatus = 'Resize Source Page'
  45.  
  46.     CurrPage
  47.     OrigPage = Result
  48.  
  49.     /* get current screen resolution */
  50.     PageRes
  51.     Modes = Result
  52.     HorizRes=''
  53.     VertRes=''
  54.     Scan=''
  55.  
  56.     Do i=1 to 3
  57.         Parse var Modes ModeFlag Dummy1 Dummy2
  58.         if ModeFlag='Hires' then HorizRes = HIRES
  59.         if ModeFlag='Interlace' then VertRes = INTERLACE
  60.         if ModeFlag='Overscan' then Scan=OVERSCAN
  61.         Modes = DelWord(Modes,1,1)
  62.         END
  63.  
  64. Return
  65.  
  66.  
  67. OptionsRequester:
  68.     ReqBuild '510 270 "Resize Image Canvas"'
  69.  
  70.     /* Placement buttons */
  71.     AddGadget 'Toggle TopLeftGad 35 55 30 30'
  72.     AddGadget 'Toggle TopCenterGad Right TopLeftGad 0 0 30 30'
  73.     AddGadget 'Toggle TopRightGad Right TopCenterGad 0 0 30 30'
  74.     AddGadget 'Toggle MidLeftGad Below TopLeftGad 0 0 30 30'
  75.     AddGadget 'Toggle MidCenterGad Right MidLeftGad 0 0 30 30'
  76.     AddGadget 'Toggle MidRightGad Right MidCenterGad 0 0 30 30'
  77.     AddGadget 'Toggle BottomLeftGad Below MidLeftGad 0 0 30 30'
  78.     AddGadget 'Toggle BottomCenterGad Right BottomLeftGad 0 0 30 30'
  79.     AddGadget 'Toggle BottomRightGad Right BottomCenterGad 0 0 30 30'
  80.     MutualEx 'TopLeftGad TopCenterGad TopRightGad MidLeftGad MidCenterGad MidRightGad BottomLeftGad BottomCenterGad BottomRightGad'
  81.     InitGadget ''Placement'Gad Selected'
  82.     AddHeading 'Above TopLeftGad 10 -10 "Placement"'
  83.     AddBox 'Above TopLeftGad -15 -25 125 140'
  84.  
  85.     /* Screen size buttons */
  86.     AddGadget 'Toggle HiresGad Right TopRightGad 50 0 Medium "Hires"'
  87.     AddGadget 'Toggle InterlaceGad Below HiresGad 0 10 Medium "Interlace"'
  88.     AddGadget 'Toggle OverscanGad Below InterlaceGad 0 10 Medium "Overscan"'
  89.     AddHeading 'Above HiresGad 5 -10 "Screen Sizes"'
  90.     if HorizRes=HIRES then
  91.         InitGadget 'HiresGad Selected'
  92.     if VertRes=INTERLACE then
  93.         InitGadget 'InterlaceGad Selected'
  94.     if Scan=OVERSCAN then
  95.         InitGadget 'OverscanGad Selected'
  96.     AddBox 'Above HiresGad -15 -25 135 140'
  97.  
  98.     /* Numeric width & height gadgets */
  99.     AddGadget 'Integer WidthString Right HiresGad 145 0 40 21 1 'MaxSize''
  100.     AddGadget 'Integer HeightString Below WidthString 0 10 40 21 1 'MaxSize''
  101.     AddGadget 'Button ScreenSize Below HeightString -98 20 Large "Use Screen Size"'
  102.     InitGadget 'WidthString 'NewWidth''
  103.     InitGadget 'HeightString 'NewHeight''
  104.     AddText 'Left WidthString -5 6 "New Width:"'
  105.     AddText 'Left HeightString -5 6 "New Height:"'
  106.     AddHeading 'Above WidthString -70 -10 "Canvas Size"'
  107.     AddBox 'Above WidthString -110 -25 175 140'
  108.  
  109.     /* Help gadget */
  110.     AddGadget 'Button HelpGad 470 5 20 20 "?"'
  111.  
  112.     /* get names of all open pages */
  113.     OpenPages
  114.     Pages = Result
  115.     PageNames = '"Resize Source Page" "Create New Page" '
  116.  
  117.     if Pages > 1 then do
  118.         do i=1 to Pages
  119.             if i~=OrigPage then do
  120.                 PageName i
  121.                 Result = Left(Result,15)
  122.                 if Result='' then
  123.                     PageNames = PageNames  || i || ':Untitled '
  124.                 else
  125.                     PageNames = PageNames  || i || ':' || Result || ' '
  126.                 End
  127.                 end
  128.             end
  129.  
  130.     /* Page size readouts */
  131.     AddBox '20 -90 225 50'
  132.     AddBox '265 -90 224 50'
  133.     AddHeading 'Below BottomLeftGad 15 43 "Original canvas size:"'
  134.     AddHeading 'Below BottomLeftGad 60 58 "'Width' x 'Height'"'
  135.  
  136.     /* cycle gadget for destination page */
  137.     AddGadget 'Cycle PageGad Below ScreenSize -40 47 Large ' PageNames
  138.     AddHeading 'Above PageGad 10 -5 "Destination Options:"'
  139.     InitGadget 'PageGad "'PageGadStatus'"'
  140.  
  141.     Request
  142.  
  143.     /* get destination page */
  144.     GadgetStatus PageGad
  145.     PageGadStatus = Result
  146.     Dest=Result
  147.     First=Left(Dest,1)
  148.     DestPage = OrigPage
  149.     if First=='R' then
  150.         DeleteSource=1
  151.     else if First=='C' then
  152.         DeleteSource=0
  153.     else do
  154.         Parse var Dest DestPage ':'
  155.         end
  156.  
  157.     GadgetStatus Cancel
  158.     if Result=1 Then do
  159.         Exit
  160.         END
  161.  
  162.     GadgetStatus WidthString
  163.     NewWidth = Result
  164.  
  165.     GadgetStatus HeightString
  166.     NewHeight = Result
  167.  
  168.     GadgetStatus TopLeftGad
  169.         if Result=1 then Placement=TopLeft
  170.     GadgetStatus TopCenterGad
  171.         if Result=1 then Placement=TopCenter
  172.     GadgetStatus TopRightGad
  173.         if Result=1 then Placement=TopRight
  174.     GadgetStatus MidLeftGad
  175.         if Result=1 then Placement=MidLeft
  176.     GadgetStatus MidCenterGad
  177.         if Result=1 then Placement=MidCenter
  178.     GadgetStatus MidRightGad
  179.         if Result=1 then Placement=MidRight
  180.     GadgetStatus BottomLeftGad
  181.         if Result=1 then Placement=BottomLeft
  182.     GadgetStatus BottomCenterGad
  183.         if Result=1 then Placement=BottomCenter
  184.     GadgetStatus BottomRightGad
  185.         if Result=1 then Placement=BottomRight
  186.  
  187.     GadgetStatus HiresGad
  188.     HiresON = Result
  189.     GadgetStatus InterlaceGad
  190.     InterlaceON = Result
  191.     GadgetStatus OverscanGad
  192.     OverscanON = Result
  193.  
  194.     HorizRes=''
  195.     VertRes=''
  196.     Scan=''
  197.  
  198.     if HiresON=1 then HorizRes=HIRES
  199.     if InterlaceON=1 then VertRes=INTERLACE
  200.     if OverscanON=1 then Scan=OVERSCAN
  201.  
  202.     GadgetStatus ScreenSize
  203.     if Result=1 then do
  204.         if (HiresON=1 & OverscanON=1) then NewWidth=736
  205.         if (HiresON=1 & OverscanON~=1) then NewWidth=640
  206.         if (HiresON~=1 & OverscanON=1) then NewWidth=368
  207.         if (HiresON~=1 & OverscanON~=1) then NewWidth=320
  208.         if VMode=PAL then do
  209.             if (InterlaceON=1 & OverscanON=1) then NewHeight=576
  210.             if (InterlaceON=1 & OverscanON~=1) then NewHeight=512
  211.             if (InterlaceON~=1 & OverscanON=1) then NewHeight=286
  212.             if (InterlaceON~=1 & OverscanON~=1) then NewHeight=256
  213.             end
  214.         else do
  215.             if (InterlaceON=1 & OverscanON=1) then NewHeight=476
  216.             if (InterlaceON=1 & OverscanON~=1) then NewHeight=400
  217.             if (InterlaceON~=1 & OverscanON=1) then NewHeight=236
  218.             if (InterlaceON~=1 & OverscanON~=1) then NewHeight=200
  219.             end
  220.         if PageGadStatus~= 'Create New Page' then
  221.             PageGadStatus = 'Resize Source Page'
  222.         call OptionsRequester
  223.         return
  224.         end
  225.  
  226.     GadgetStatus HelpGad
  227.     if Result=1 then do
  228.         call Help
  229.         call OptionsRequester
  230.         Return
  231.         END
  232.  
  233.     GadgetStatus Okay
  234.     HorizRes=''
  235.     VertRes=''
  236.     Scan=''
  237.     if Result=1 then do
  238.         if NewWidth>640 then do
  239.             HorizRes=HIRES
  240.             Scan=OVERSCAN
  241.             end
  242.         else if NewWidth>370 then
  243.             HorizRes=HIRES
  244.         else if NewWidth>320 then
  245.             Scan=OVERSCAN
  246.         if VMode=PAL then do
  247.             if NewHeight>512 then do
  248.                 VertRes=INTERLACE
  249.                 Scan=OVERSCAN
  250.                 end
  251.             else if NewHeight>286 then
  252.                 VertRes=INTERLACE
  253.             else if NewHeight>256 then
  254.                 Scan=OVERSCAN
  255.             end
  256.         else do
  257.             if NewHeight>400 then do
  258.                 VertRes=INTERLACE
  259.                 Scan=OVERSCAN
  260.                 end
  261.             else if NewHeight>236 then
  262.                 VertRes=INTERLACE
  263.             else if NewHeight>200 then
  264.                 Scan=OVERSCAN
  265.             end
  266. Return
  267.  
  268.  
  269. ChangeCanvas:
  270.     /* figure out destination page */
  271.     if DestPage = OrigPage then do
  272.         /* add new page of specified dimensions */
  273.         AddPage NewWidth NewHeight HorizRes VertRes Scan
  274.         OpenPages
  275.         NewPage = Result
  276.         DestPage = NewPage
  277.         end
  278.     else do
  279.         PickPage DestPage
  280.         PageSize
  281.         parse var result NewWidth NewHeight
  282.         end
  283.  
  284.     /* figure out placement for image on new page */
  285.     if Placement=TopLeft then do
  286.         OffSetX = 0
  287.         OffSetY = 0
  288.         end
  289.     if Placement=TopCenter then do
  290.         OffsetX = (NewWidth/2)-(Width/2)
  291.         OffsetY = 0
  292.         end
  293.     if Placement=TopRight then do
  294.         OffsetX = NewWidth-Width
  295.         OffsetY = 0
  296.         end
  297.     if Placement=MidLeft then do
  298.         OffsetX = 0
  299.         OffsetY = (NewHeight/2)-(Height/2)
  300.         end
  301.     if Placement=MidCenter then do
  302.         OffsetX = (NewWidth/2)-(Width/2)
  303.         OffsetY = (NewHeight/2)-(Height/2)
  304.         end
  305.     if Placement=MidRight then do
  306.         OffsetX = NewWidth-Width
  307.         OffsetY = (NewHeight/2)-(Height/2)
  308.         end
  309.     if Placement=BottomLeft then do
  310.         OffsetX = 0
  311.         OffsetY = NewHeight-Height
  312.         end
  313.     if Placement=BottomCenter then do
  314.         OffsetX = (NewWidth/2)-(Width/2)
  315.         OffsetY = NewHeight-Height
  316.         end
  317.     if Placement=BottomRight then do
  318.         OffsetX = NewWidth-Width
  319.         OffsetY = NewHeight-Height
  320.         end
  321.  
  322.     /* copy old page to new page with offset */
  323.     CopyPage OrigPage DestPage OffsetX OffsetY
  324.  
  325.     /* delete old page */
  326.     if DeleteSource=1 then do
  327.         MovePage DestPage OrigPage
  328.         DeletePage OrigPage+1
  329.         end
  330.     else PickPage DestPage
  331. Return
  332.  
  333.  
  334. Help:
  335.     ReqBuild '615 310 "Help for Resize Image Canvas"'
  336.     AddBox '15 30 585 235'
  337.     AddGadget 'Button ExitHelp CenterX 275 Medium "Exit Help"'
  338.  
  339.     AddHeading 'CenterX 40 "General Information"'
  340.     AddText '25 55 "This  AREXX  script resizes the current page to a new size, similar in"'
  341.     AddText '25 65 "operation  to  the PAGE FORMAT requester within OpalPaint itself.  The"'
  342.     AddText '25 75 "difference  is that the original image is NOT altered or scaled in any"'
  343.     AddText '25 85 "way,  rather  it  is  placed  on the new size ''canvas'' at a particular"'
  344.     AddText '25 95 "location.  This is useful for ''adding'' area to an image you''re working"'
  345.     AddText '25 105 "on, or for centering a smaller image within a larger one."'
  346.  
  347.     AddHeading 'CenterX 120 "How to use"'
  348.     AddText '25 135 "Basically,  this  requester  works exactly the same as the page format"'
  349.     AddText '25 145 "requester (see your OpalPaint manual for further details), except that"'
  350.     AddText '25 155 "there  are  9  ''placement'' buttons on the left side, plus a gadget for"'
  351.     AddText '25 165 "determining  where  the  image  will  be  placed:  either resizing the"'
  352.     AddText '25 175 "current  page, creating a new page with the specified size, or copying"'
  353.     AddText '25 185 "to  a  spare  page  currently  in  memory,  at the location set by the"'
  354.     AddText '25 195 "placement  gadgets.   Click  the  cycle  gadget to select one of these"'
  355.     AddText '25 205 "options  or the page to be copied to.  The original image is copied on"'
  356.     AddText '25 215 "top  of  the destination image at the chosen location only, i.e.  if a"'
  357.     AddText '25 225 "smaller  image  is  copied to a larger one, the original image will be"'
  358.     AddText '25 235 "composited on top of the larger destination image."'
  359.  
  360.     Request NoOk NoCancel
  361. Return
  362.  
  363. EXIT
  364.