home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Painting / OpalPaint2,3-020+Version.LHA / Rexx / DropShadow.oprx < prev    next >
Encoding:
Text File  |  1994-04-21  |  9.3 KB  |  341 lines

  1. /* Automatic brush drop shadow creator for OpalPaint.
  2.    AREXX script by Greg Niles, Centaur Development.
  3.  
  4.    Version 1.0 - Initial release!
  5.    Version 1.1 - now deletes the spare page when it's done...
  6.    Version 2.0 - automatically configures to OpalPaint 2.3's new AREXX
  7.          requesters!
  8.            - Added feather out capability -- much better for handling
  9.          thinner brushes, such as text brushes in narrow fonts
  10.          (Times or similar), although slower to calculate than the
  11.          normal method.
  12.            - Deleting the temporary spare page is now an option, just
  13.          in case you want to recover the old brush.
  14.            - Cleaned a few things up, also added a little error checking...
  15.            - Instruction window, plus online help button (!?)
  16.            - Noticably faster than before, due to new AREXX commands for
  17.          alpha channel control...
  18. */
  19.  
  20. address 'OpalPaint_Rexx'
  21.  
  22. options Results
  23.  
  24. SaveSetUp
  25.  
  26. call TestVersion
  27. if VersionNum > 2.2 then
  28.     call OptionsRequester
  29. else
  30.     call StandardIO
  31. endif
  32. call ComputeShadow
  33.  
  34. Okay "We're done!  Paste your new brush anywhere you want!"
  35.  
  36. RestoreSetUp
  37. ColorSource Multicolor
  38. EXIT
  39.  
  40.  
  41. TestVersion:
  42.     Version
  43.     VersionNum = substr(Result,17,3)
  44. Return
  45.  
  46.  
  47. OptionsRequester:
  48.     ActiveBrush
  49.     BrushBay = Result
  50.  
  51.     if BrushBay=-1 then BrushBay=1
  52.  
  53.     ReqBuild '450 238 "Drop Shadow Maker v2.0"'
  54.  
  55.     /* Brush exclusive gadgets */
  56.     AddGadget 'Toggle Brush1 30 67 Small "B1"'
  57.     AddGadget 'Toggle Brush2 Right Brush1 10 0 Small "B2"'
  58.     AddGadget 'Toggle Brush3 Right Brush2 10 0 Small "B3"'
  59.     AddText 'Above Brush2 -22 -3 "Brush Number"'
  60.     MutualEx Brush1 Brush2 Brush3
  61.     InitGadget 'Brush'BrushBay' Selected'
  62.  
  63.     /* Feathering amount gadgets */
  64.     AddGadget 'HProp Feather1 Below Brush1 5 26 45 20 0 20 1'
  65.     AddGadget 'Toggle FeatherIn Right Feather1 35 0 40 20 "IN"'
  66.     AddGadget 'Toggle FeatherOut Right FeatherIn 5 0 40 20 "OUT"'
  67.     AddText 'Above Feather1 13 -3 "Feathering Amount"'
  68.     MutualEx FeatherIn FeatherOut
  69.     InitGadget Feather1 0
  70.     InitGadget 'FeatherIn Selected'
  71.  
  72.     /* Transparency prop gadgets */
  73.     AddGadget 'HProp Trans1 Below Feather1 0 25 130 16 0 100 1 Percent'
  74.     AddText 'Above Trans1 15 -3 "Transparency"'
  75.     InitGadget 'Trans1 50'
  76.  
  77.     /* Spare page delete toggle gadget */
  78.     AddGadget 'Toggle TempPage1 Below Trans1 CenterX 20 Large "Delete temp page"'
  79.     InitGadget 'TempPage1 Selected'
  80.  
  81.     /* Help gadget */
  82.     AddGadget 'Button HelpGad 402 30 20 20 "?"'
  83.  
  84.     /* Bevel boxes & headers */
  85.     AddBox 'Above Brush1 -10 -40 194 167'
  86.     AddHeading 'Above Brush2 -34 -24 "Shadow Options"'
  87.  
  88.     AddBox 'Right Brush3 30 -41 194 167'
  89.     AddHeading 'Above Brush3 130 -24 "INSTRUCTIONS"'
  90.  
  91.     AddText 'Right Brush3 35 -5 "-----------------------"'
  92.     AddText 'Right Brush3 35 5 "Selects the brush to"'
  93.     AddText 'Right Brush3 35 15 "apply the shadow to."'
  94.  
  95.     AddText 'Right Brush3 35 40 "-----------------------"'
  96.     AddText 'Right Brush3 35 50 "The ''fuzziness'' of the"'
  97.     AddText 'Right Brush3 35 60 "shadow, inwards or out."'
  98.     AddText 'Right Brush3 35 70 "0 = sharp, max = 20"'
  99.  
  100.     AddText 'Right Brush3 35 88 "-----------------------"'
  101.     AddText 'Right Brush3 35 98 "Selects the level of"'
  102.     AddText 'Right Brush3 35 108 "shadow transparency."'
  103.  
  104.     Request
  105.  
  106.     GadgetStatus Cancel
  107.     if Result=1 Then do
  108.         Exit
  109.         END
  110.  
  111.     /* go to online help screen */
  112.     GadgetStatus HelpGad
  113.     if Result=1 then do
  114.         call Help
  115.         call OptionsRequester
  116.         Return
  117.         END
  118.  
  119.     /* get which brush was selected */
  120.     GadgetStatus Brush1
  121.     if Result=1 then BrushBay=1
  122.  
  123.     GadgetStatus Brush2
  124.     if Result=1 then BrushBay=2
  125.  
  126.     GadgetStatus Brush3
  127.     if Result=1 then BrushBay=3
  128.  
  129.     /* See if the selected brush is empty */
  130.     ActiveBrush BrushBay
  131.     BrushSize
  132.     parse var result CheckWidth CheckHeight
  133.     if CheckWidth = -1 then do
  134.         Okay "Brush "BrushBay" is empty! Please select another brush."
  135.         call OptionsRequester
  136.         Return
  137.         end
  138.  
  139.     /* get the feather amount */
  140.     GadgetStatus Feather1
  141.     FeatherAmt = Result
  142.  
  143.     /* get the feather type */
  144.     GadgetStatus FeatherIn
  145.     if Result=1 then FeatherType = IN
  146.  
  147.     GadgetStatus FeatherOut
  148.     if Result=1 then FeatherType = OUT
  149.  
  150.     /* get the transparency amount */
  151.     GadgetStatus Trans1
  152.     TransAmt = Result
  153.  
  154.     /* find whether to delete the temp page or not */
  155.     GadgetStatus TempPage1
  156.     KillTempPage = Result
  157. Return
  158.  
  159.  
  160. ComputeShadow:
  161.     Panic
  162.  
  163.     /* Get size of selected brush */
  164.     ActiveBrush BrushBay
  165.     BrushSize
  166.     parse var result BWidth BHeight
  167.  
  168.     /* Make a new screen */
  169.     CurrPage
  170.     OrigPage = Result
  171.     ClonePage OrigPage
  172.     OpenPages
  173.     NewPage = Result
  174.     PickPage NewPage
  175.  
  176.     /* Place brush in center of new screen & in alpha channel */
  177.     PageSize
  178.     parse var result PageWidth PageHeight
  179.     XPosition = Trunc((PageWidth/2)-(BWidth/2))
  180.     YPosition = Trunc((PageHeight/2)-(BHeight/2))
  181.     ActiveBrush BrushBay
  182.     Handle 0 0
  183.     ColorSource Multicolor
  184.     PutBrush XPosition YPosition
  185.     if VersionNum > 2.2 then do
  186.         AddAlpha
  187.         InvertAlpha
  188.         AlphaPattern GreyScale
  189.         WorkMode ALPHA
  190.         end
  191.     if VersionNum <= 2.2 then do
  192.         WorkMode ALPHA
  193.         SetDrawMode 4
  194.         Zap
  195.         end
  196.     SetDrawMode 1
  197.     ActiveBrush BrushBay
  198.     Handle 0 0
  199.     ColorSource PaintPot 
  200.     ActivePot 1
  201.     PutBrush XPosition YPosition
  202.     WorkMode Image
  203.  
  204.     /* Ask for position of drop shadow */
  205.     AskBool "Now, choose the location of your drop shadow.\nSelect CANCEL now if you don't want to lose B"BrushBay"!"
  206.     If Result = 0 then do
  207.         PickPage OrigPage
  208.         DeletePage NewPage
  209.         NotBusy
  210.         RestoreSetUp
  211.         EXIT
  212.         end
  213.     Handle 0 0
  214.     GetPoint
  215.     parse var result XDropPos YDropPos
  216.  
  217.     /* Feather the brush */
  218.     if FeatherAmt > 0 then do
  219.         if FeatherType=OUT then do
  220.             do OutlineNum = 1 to FeatherAmt
  221.                 Key OutlineBrush
  222.                 end
  223.             BWidth = BWidth+(FeatherAmt*2)
  224.             BHeight = BHeight+(FeatherAmt*2)
  225.             XDropPos = XDropPos-FeatherAmt
  226.             YDropPos = YDropPos-FeatherAmt
  227.             end
  228.         Feather FeatherAmt
  229.         end
  230.  
  231.     /* Let's do it! */
  232.     Busy
  233.     WorkMode Alpha        /* Paste drop shadow into alpha channel */
  234.     Panic
  235.     SetDrawMode 1
  236.     ActiveBrush BrushBay
  237.     Handle 0 0
  238.     ColorSource PaintPot
  239.     TransType Standard TransAmt
  240.     Trans Enable
  241.     ActivePot 1
  242.     PutBrush XDropPos YDropPos
  243.     Trans Disable
  244.  
  245.     /* Calculate size of area to contain brush & drop shadow */
  246.     X1 = MIN(XPosition,XDropPos)
  247.     Y1 = MIN(YPosition,YDropPos)
  248.     X2 = MAX(XPosition+BWidth,XDropPos+BWidth)
  249.     Y2 = MAX(YPosition+BHeight,YDropPos+BHeight)
  250.  
  251.     /* Cut brush with alpha drop shadow */
  252.     WorkMode Image
  253.     ActiveBrush BrushBay
  254.     CutMode Normal 1
  255.     RectCut X1 Y1 X2 Y2
  256.  
  257.     /* Go back to original page & delete temp page */
  258.     PickPage OrigPage
  259.     if KillTempPage=1 then do
  260.         DeletePage NewPage
  261.         end
  262.     NotBusy
  263. Return
  264.  
  265.  
  266. Help:
  267.     ReqBuild '640 310 "Help for Drop Shadow Maker v2.0"'
  268.     AddBox '15 30 610 235'
  269.     AddGadget 'Button ExitHelp CenterX 275 Medium "Exit Help"'
  270.  
  271.     AddHeading 'CenterX 40 "Shadow Options"'
  272.     AddText '25 55 "- The  FEATHERING option ''softens'' the edges of the drop shadow.  To apply"'
  273.     AddText '25 65 "  feathering  to  the drop shadow, simply drag the slider to the amount of"'
  274.     AddText '25 75 "  feathering  desired,  in  pixels.   Depending  on the size of the brush,"'
  275.     AddText '25 85 "  amounts of more than 10 pixels usually produce undesirable results."'
  276.  
  277.     AddText '25 95 "- The  TRANSPARENCY slider determines the opacity of the drop shadow.  The"'
  278.     AddText '25 105 "  higher the setting, the more transparent the drop shadow."'
  279.  
  280.     AddText '25 115 "- The  DELETE  TEMP  PAGE  option  determines  whether  the temporary page"'
  281.     AddText '25 125 "  created  by  Drop  Shadow  Maker is deleted after the shadow is created."'
  282.     AddText '25 135 "  Turn  this  option  off only if you have a burning need for the original"'
  283.     AddText '25 145 "  for the original brush and it hasn''t been saved."'
  284.  
  285.     AddHeading 'CenterX 160 "When to use Feathering IN or OUT"'
  286.     AddText '25 175 "There are two types of feathering:  IN will fade the transparency from the"'
  287.     AddText '25 185 "edge  of the brush inwards, while OUT will fade from the edge of the brush"'
  288.     AddText '25 195 "outward.  FEATHER IN is the default, suitable for brushes with a solid and"'
  289.     AddText '25 205 "continuous  edge  (spheres,  rectangles, free shapes, etc.), while FEATHER"'
  290.     AddText '25 215 "OUT  gives  much  better  results  for text brushes, which contain complex"'
  291.     AddText '25 225 "curves and narrow passages that may disappear if the feathering setting is"'
  292.     AddText '25 235 "too high.  FEATHER OUT also takes more time to compute, so only use it for"'
  293.     AddText '25 245 "text brushes where the effect is needed."'
  294.  
  295.     Request NoOk NoCancel
  296. Return
  297.  
  298.  
  299. StandardIO:
  300.     AskBool "Drop Shadow Maker v2.0 - by Greg Niles\nClick OK to continue, Cancel to Abort."
  301.     If Result = 0 then EXIT
  302.  
  303.     do forever
  304.         /* Ask which brush to use */
  305.         AskProp 1 3 1 "Select brush number (1-3).\n(Select CANCEL if you don't want to lose your brush!)"
  306.         If RC = 5 then EXIT
  307.         BrushBay = Result
  308.  
  309.         /* See if the selected brush is empty */
  310.         ActiveBrush BrushBay
  311.         BrushSize
  312.         parse var result CheckWidth CheckHeight
  313.         if CheckWidth ~= -1 then break
  314.         Okay "Brush "BrushBay" is empty! Please select another brush."
  315.         end
  316.  
  317.     /* Get feather amount from user */
  318.     AskInt 0 20 0 "Enter feather amount (0=no feathering).\nThis determines the 'fuzziness' of your drop shadow, in pixels."
  319.     If RC = 5 then EXIT
  320.     FeatherAmt = Result
  321.  
  322.     /* Get feather type from user */
  323.     if FeatherAmt > 0 then do
  324.         AskBool "Select feathering type:\n\n[OK]     Feather in (standard)\n[CANCEL] Feather out"
  325.         if Result=0 then FeatherType = OUT
  326.         if Result=1 then FeatherType = IN
  327.         end
  328.  
  329.     /* Get transparency level from user */
  330.     AskProp 0 100 50 "Select transparency level of drop shadow."
  331.     If RC = 5 then EXIT
  332.     TransAmt = Result
  333.  
  334.     /* Ask about deleting the spare page */
  335.     AskBool "Delete the temporary spare page?"
  336.     KillTempPage = Result
  337. Return
  338.  
  339.  
  340. EXIT
  341.