home *** CD-ROM | disk | FTP | other *** search
- /* Resize canvas operator for OpalPaint.
- AREXX script by Greg Niles, Centaur Development.
- Requires OpalPaint 2.3 or greater.
-
- Version 1.0 - Initial release
- */
-
- address 'OpalPaint_Rexx'
-
- options Results
-
- SaveSetUp
-
- call TestVersion
- if VersionNum < 2.3 then do
- Okay "You need OpalPaint 2.3 or above to run this AREXX script!"
- EXIT
- END
-
- call Setup
- call OptionsRequester
- call ChangeCanvas
-
- RestoreSetUp
- Exit
-
-
- TestVersion:
- Version
- VersionNum = substr(Result,17,3)
- Return
-
-
- SetUp:
- /* get current page size & initialize variables */
- PageSize
- parse var result Width Height
- Width = compress(Width)
- Height = compress(Height)
- NewWidth = Width
- NewHeight = Height
- MaxSize = 32767
- Placement = MidCenter
- PageGadStatus = 'Resize Source Page'
-
- CurrPage
- OrigPage = Result
-
- /* get current screen resolution */
- PageRes
- Modes = Result
- HorizRes=''
- VertRes=''
- Scan=''
-
- Do i=1 to 3
- Parse var Modes ModeFlag Dummy1 Dummy2
- if ModeFlag='Hires' then HorizRes = HIRES
- if ModeFlag='Interlace' then VertRes = INTERLACE
- if ModeFlag='Overscan' then Scan=OVERSCAN
- Modes = DelWord(Modes,1,1)
- END
-
- Return
-
-
- OptionsRequester:
- ReqBuild '510 270 "Resize Image Canvas"'
-
- /* Placement buttons */
- AddGadget 'Toggle TopLeftGad 35 55 30 30'
- AddGadget 'Toggle TopCenterGad Right TopLeftGad 0 0 30 30'
- AddGadget 'Toggle TopRightGad Right TopCenterGad 0 0 30 30'
- AddGadget 'Toggle MidLeftGad Below TopLeftGad 0 0 30 30'
- AddGadget 'Toggle MidCenterGad Right MidLeftGad 0 0 30 30'
- AddGadget 'Toggle MidRightGad Right MidCenterGad 0 0 30 30'
- AddGadget 'Toggle BottomLeftGad Below MidLeftGad 0 0 30 30'
- AddGadget 'Toggle BottomCenterGad Right BottomLeftGad 0 0 30 30'
- AddGadget 'Toggle BottomRightGad Right BottomCenterGad 0 0 30 30'
- MutualEx 'TopLeftGad TopCenterGad TopRightGad MidLeftGad MidCenterGad MidRightGad BottomLeftGad BottomCenterGad BottomRightGad'
- InitGadget ''Placement'Gad Selected'
- AddHeading 'Above TopLeftGad 10 -10 "Placement"'
- AddBox 'Above TopLeftGad -15 -25 125 140'
-
- /* Screen size buttons */
- AddGadget 'Toggle HiresGad Right TopRightGad 50 0 Medium "Hires"'
- AddGadget 'Toggle InterlaceGad Below HiresGad 0 10 Medium "Interlace"'
- AddGadget 'Toggle OverscanGad Below InterlaceGad 0 10 Medium "Overscan"'
- AddHeading 'Above HiresGad 5 -10 "Screen Sizes"'
- if HorizRes=HIRES then
- InitGadget 'HiresGad Selected'
- if VertRes=INTERLACE then
- InitGadget 'InterlaceGad Selected'
- if Scan=OVERSCAN then
- InitGadget 'OverscanGad Selected'
- AddBox 'Above HiresGad -15 -25 135 140'
-
- /* Numeric width & height gadgets */
- AddGadget 'Integer WidthString Right HiresGad 145 0 40 21 1 'MaxSize''
- AddGadget 'Integer HeightString Below WidthString 0 10 40 21 1 'MaxSize''
- AddGadget 'Button ScreenSize Below HeightString -98 20 Large "Use Screen Size"'
- InitGadget 'WidthString 'NewWidth''
- InitGadget 'HeightString 'NewHeight''
- AddText 'Left WidthString -5 6 "New Width:"'
- AddText 'Left HeightString -5 6 "New Height:"'
- AddHeading 'Above WidthString -70 -10 "Canvas Size"'
- AddBox 'Above WidthString -110 -25 175 140'
-
- /* Help gadget */
- AddGadget 'Button HelpGad 470 5 20 20 "?"'
-
- /* get names of all open pages */
- OpenPages
- Pages = Result
- PageNames = '"Resize Source Page" "Create New Page" '
-
- if Pages > 1 then do
- do i=1 to Pages
- if i~=OrigPage then do
- PageName i
- Result = Left(Result,15)
- if Result='' then
- PageNames = PageNames || i || ':Untitled '
- else
- PageNames = PageNames || i || ':' || Result || ' '
- End
- end
- end
-
- /* Page size readouts */
- AddBox '20 -90 225 50'
- AddBox '265 -90 224 50'
- AddHeading 'Below BottomLeftGad 15 43 "Original canvas size:"'
- AddHeading 'Below BottomLeftGad 60 58 "'Width' x 'Height'"'
-
- /* cycle gadget for destination page */
- AddGadget 'Cycle PageGad Below ScreenSize -40 47 Large ' PageNames
- AddHeading 'Above PageGad 10 -5 "Destination Options:"'
- InitGadget 'PageGad "'PageGadStatus'"'
-
- Request
-
- /* get destination page */
- GadgetStatus PageGad
- PageGadStatus = Result
- Dest=Result
- First=Left(Dest,1)
- DestPage = OrigPage
- if First=='R' then
- DeleteSource=1
- else if First=='C' then
- DeleteSource=0
- else do
- Parse var Dest DestPage ':'
- end
-
- GadgetStatus Cancel
- if Result=1 Then do
- Exit
- END
-
- GadgetStatus WidthString
- NewWidth = Result
-
- GadgetStatus HeightString
- NewHeight = Result
-
- GadgetStatus TopLeftGad
- if Result=1 then Placement=TopLeft
- GadgetStatus TopCenterGad
- if Result=1 then Placement=TopCenter
- GadgetStatus TopRightGad
- if Result=1 then Placement=TopRight
- GadgetStatus MidLeftGad
- if Result=1 then Placement=MidLeft
- GadgetStatus MidCenterGad
- if Result=1 then Placement=MidCenter
- GadgetStatus MidRightGad
- if Result=1 then Placement=MidRight
- GadgetStatus BottomLeftGad
- if Result=1 then Placement=BottomLeft
- GadgetStatus BottomCenterGad
- if Result=1 then Placement=BottomCenter
- GadgetStatus BottomRightGad
- if Result=1 then Placement=BottomRight
-
- GadgetStatus HiresGad
- HiresON = Result
- GadgetStatus InterlaceGad
- InterlaceON = Result
- GadgetStatus OverscanGad
- OverscanON = Result
-
- HorizRes=''
- VertRes=''
- Scan=''
-
- if HiresON=1 then HorizRes=HIRES
- if InterlaceON=1 then VertRes=INTERLACE
- if OverscanON=1 then Scan=OVERSCAN
-
- GadgetStatus ScreenSize
- if Result=1 then do
- if (HiresON=1 & OverscanON=1) then NewWidth=736
- if (HiresON=1 & OverscanON~=1) then NewWidth=640
- if (HiresON~=1 & OverscanON=1) then NewWidth=368
- if (HiresON~=1 & OverscanON~=1) then NewWidth=320
- if VMode=PAL then do
- if (InterlaceON=1 & OverscanON=1) then NewHeight=576
- if (InterlaceON=1 & OverscanON~=1) then NewHeight=512
- if (InterlaceON~=1 & OverscanON=1) then NewHeight=286
- if (InterlaceON~=1 & OverscanON~=1) then NewHeight=256
- end
- else do
- if (InterlaceON=1 & OverscanON=1) then NewHeight=476
- if (InterlaceON=1 & OverscanON~=1) then NewHeight=400
- if (InterlaceON~=1 & OverscanON=1) then NewHeight=236
- if (InterlaceON~=1 & OverscanON~=1) then NewHeight=200
- end
- if PageGadStatus~= 'Create New Page' then
- PageGadStatus = 'Resize Source Page'
- call OptionsRequester
- return
- end
-
- GadgetStatus HelpGad
- if Result=1 then do
- call Help
- call OptionsRequester
- Return
- END
-
- GadgetStatus Okay
- HorizRes=''
- VertRes=''
- Scan=''
- if Result=1 then do
- if NewWidth>640 then do
- HorizRes=HIRES
- Scan=OVERSCAN
- end
- else if NewWidth>370 then
- HorizRes=HIRES
- else if NewWidth>320 then
- Scan=OVERSCAN
- if VMode=PAL then do
- if NewHeight>512 then do
- VertRes=INTERLACE
- Scan=OVERSCAN
- end
- else if NewHeight>286 then
- VertRes=INTERLACE
- else if NewHeight>256 then
- Scan=OVERSCAN
- end
- else do
- if NewHeight>400 then do
- VertRes=INTERLACE
- Scan=OVERSCAN
- end
- else if NewHeight>236 then
- VertRes=INTERLACE
- else if NewHeight>200 then
- Scan=OVERSCAN
- end
- Return
-
-
- ChangeCanvas:
- /* figure out destination page */
- if DestPage = OrigPage then do
- /* add new page of specified dimensions */
- AddPage NewWidth NewHeight HorizRes VertRes Scan
- OpenPages
- NewPage = Result
- DestPage = NewPage
- end
- else do
- PickPage DestPage
- PageSize
- parse var result NewWidth NewHeight
- end
-
- /* figure out placement for image on new page */
- if Placement=TopLeft then do
- OffSetX = 0
- OffSetY = 0
- end
- if Placement=TopCenter then do
- OffsetX = (NewWidth/2)-(Width/2)
- OffsetY = 0
- end
- if Placement=TopRight then do
- OffsetX = NewWidth-Width
- OffsetY = 0
- end
- if Placement=MidLeft then do
- OffsetX = 0
- OffsetY = (NewHeight/2)-(Height/2)
- end
- if Placement=MidCenter then do
- OffsetX = (NewWidth/2)-(Width/2)
- OffsetY = (NewHeight/2)-(Height/2)
- end
- if Placement=MidRight then do
- OffsetX = NewWidth-Width
- OffsetY = (NewHeight/2)-(Height/2)
- end
- if Placement=BottomLeft then do
- OffsetX = 0
- OffsetY = NewHeight-Height
- end
- if Placement=BottomCenter then do
- OffsetX = (NewWidth/2)-(Width/2)
- OffsetY = NewHeight-Height
- end
- if Placement=BottomRight then do
- OffsetX = NewWidth-Width
- OffsetY = NewHeight-Height
- end
-
- /* copy old page to new page with offset */
- CopyPage OrigPage DestPage OffsetX OffsetY
-
- /* delete old page */
- if DeleteSource=1 then do
- MovePage DestPage OrigPage
- DeletePage OrigPage+1
- end
- else PickPage DestPage
- Return
-
-
- Help:
- ReqBuild '615 310 "Help for Resize Image Canvas"'
- AddBox '15 30 585 235'
- AddGadget 'Button ExitHelp CenterX 275 Medium "Exit Help"'
-
- AddHeading 'CenterX 40 "General Information"'
- AddText '25 55 "This AREXX script resizes the current page to a new size, similar in"'
- AddText '25 65 "operation to the PAGE FORMAT requester within OpalPaint itself. The"'
- AddText '25 75 "difference is that the original image is NOT altered or scaled in any"'
- AddText '25 85 "way, rather it is placed on the new size ''canvas'' at a particular"'
- AddText '25 95 "location. This is useful for ''adding'' area to an image you''re working"'
- AddText '25 105 "on, or for centering a smaller image within a larger one."'
-
- AddHeading 'CenterX 120 "How to use"'
- AddText '25 135 "Basically, this requester works exactly the same as the page format"'
- AddText '25 145 "requester (see your OpalPaint manual for further details), except that"'
- AddText '25 155 "there are 9 ''placement'' buttons on the left side, plus a gadget for"'
- AddText '25 165 "determining where the image will be placed: either resizing the"'
- AddText '25 175 "current page, creating a new page with the specified size, or copying"'
- AddText '25 185 "to a spare page currently in memory, at the location set by the"'
- AddText '25 195 "placement gadgets. Click the cycle gadget to select one of these"'
- AddText '25 205 "options or the page to be copied to. The original image is copied on"'
- AddText '25 215 "top of the destination image at the chosen location only, i.e. if a"'
- AddText '25 225 "smaller image is copied to a larger one, the original image will be"'
- AddText '25 235 "composited on top of the larger destination image."'
-
- Request NoOk NoCancel
- Return
-
- EXIT
-