home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / pgpro40.zip / 3DShadow.cwx < prev    next >
Text File  |  1999-08-04  |  15KB  |  461 lines

  1. /*
  2.     3DShadow.cwx
  3.     PGPro Scripts v3.0 - by Don Eitner, 1999
  4.  
  5.     Creates a "3D shadow" of an object in user-defined direction with
  6.     user-defined color fade.
  7.  
  8.     This code is neither supported nor under warranty.  Feel free to
  9.     examine and modify this script for your own purposes.  See the
  10.     included readme.txt for additional information.
  11. */
  12.  
  13. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  14. call SysLoadFuncs
  15.  
  16. Handle.0 = CwGetSelectedObject()
  17.  
  18. /* no object selected */
  19. if \CwIsHandleValid(Handle.0) then
  20.     do
  21.         call CwMsg "No object selected."
  22.         exit
  23.     end
  24.  
  25. /* Set initial variables */
  26. Output  = CwGetAppHandle("Output Settings")
  27. Measure = CwGetProperty(Output, "Unit")
  28.  
  29. /* Force project into pixels mode -- we'll change it back later */
  30. if (Measure = "Inches") | (Measure = "Centimeters") | (Measure = "Points") then
  31.     call CwSetProperty Output, Unit, "Pixels"
  32.  
  33. /* Set additional variables */
  34. oWidth    = CwGetProperty(Output, "Output Size:Width")
  35. oHeight   = CwGetProperty(Output, "Output Size:Height")
  36. Xcenter.0 = CwGetProperty(Handle.0, "Position:X Center")
  37. Ycenter.0 = CwGetProperty(Handle.0, "Position:Y Center")
  38. Width     = CwGetProperty(Handle.0, "Position:Width")
  39. Height    = CwGetProperty(Handle.0, "Position:Height")
  40. Rotate    = CwGetProperty(Handle.0, "Position:Angle")
  41. Sheer     = CwGetProperty(Handle.0, "Position:Skew")
  42.  
  43. if oHeight <= 200 then
  44.     Move = 1
  45. else
  46.     Move = (oHeight / 200)
  47.  
  48. /* Prompt user for number of shadow instances and wait for them to press the button */
  49. call Prompt1
  50. call Wait
  51.  
  52. if Instances = 0 then
  53.     call Finish
  54.  
  55. /* Assemble the starting and ending shadow colors */
  56. x1 = lastpos(",",StartColor)
  57. SC3 = substr(StartColor, (x1+1))
  58. x2 = lastpos(",",StartColor,(x1-1))
  59. SC2 = substr(StartColor, (x2+1), (x1-x2-1))
  60. x3 = lastpos(",",StartColor,(x2-1))
  61. SC1 = substr(StartColor, (x3+1), (x2-x3-1))
  62. y1 = lastpos(",",EndColor)
  63. EC3 = substr(EndColor, (y1+1))
  64. y2 = lastpos(",",EndColor,(y1-1))
  65. EC2 = substr(EndColor, (y2+1), (y1-y2-1))
  66. y3 = lastpos(",",EndColor,(y2-1))
  67. EC1 = substr(EndColor, (y3+1), (y2-y3-1))
  68.  
  69. /* Assemble the RGB color shifts across the range of shadow instances */
  70. RedShift = ((SC1-EC1) % (Instances - 1))
  71. GreenShift = ((SC2-EC2) % (Instances - 1))
  72. BlueShift = ((SC3-EC3) % (Instances - 1))
  73.  
  74. /* Prompt user for direction of shadow and wait for them to press a button */
  75. call Prompt2
  76. call Wait
  77.  
  78. /* Do the shadowing of the selected object */
  79. /* Stop drawing until we've setup the display */
  80. Window=CwGetCurrentView()
  81. call CwStopRender window
  82.  
  83. do Num=1 to Instances
  84.     /* Set some variables for this operation */
  85.     Prevnum = Num - 1
  86.     Handle.Num = CwDuplicateObject(Handle.Prevnum)
  87.     ColorVal1 = SC1 - RedShift * (Num-1)
  88.     ColorVal2 = SC2 - GreenShift * (Num-1)
  89.     ColorVal3 = SC3 - BlueShift * (Num-1)
  90.  
  91.     /* Move the current shadow instance by the value specified in MOVE */
  92.     Xcenter = CwGetProperty(Handle.Prevnum, "Position:X Center")
  93.     Ycenter = CwGetProperty(Handle.Prevnum, "Position:Y Center")
  94.     Xcenter = Xcenter + (XMod * Move)
  95.     Ycenter = Ycenter + (YMod * Move)
  96.  
  97.     call CwSetProperty Handle.Num, "Position:Y Center", Ycenter
  98.     call CwSetProperty Handle.Num, "Position:X Center", Xcenter
  99.     call CwMoveObjectBehindObject Handle.Num , Handle.Prevnum
  100.     call CwSetPosition Handle.Num, Xcenter, Ycenter, Width, Height, Rotate, Sheer
  101.  
  102.     /* Check to see if the object is a group object */
  103.     call Recurse Handle.Num, 'call CwSetTool handle, "Solid Color"'
  104.  
  105.     /* Do the shading of the current shadow instance */
  106.     call Recurse Handle.Num, 'call CwSetProperty CwGetTool(handle), "Color", "('ColorVal1','ColorVal2','ColorVal3')"'
  107. end
  108.  
  109. /* Group the original object and its shadows into a single object */
  110. GH = CwAddObjectToGroup(Handle.0, 0)
  111. do Num = 1 to Instances
  112.     call CwAddObjectToGroup Handle.Num, GH
  113. end
  114.  
  115. /* Make sure the user wants to do this */
  116. if RxMessageBox("Do you wish to shift the selected object and all shadows to be centered on the original object's location?", ,
  117.     "Shift Object?","yesno","warning") \= 6 then
  118.     call Finish
  119. else
  120.     do
  121.         GroupWidth  = CwGetProperty(gh, "Position:Width")
  122.         GroupHeight = CwGetProperty(gh, "Position:Height")
  123.         GroupRotate = CwGetProperty(gh, "Position:Angle")
  124.         GroupSheer  = CwGetProperty(gh, "Position:Skew")
  125.         call CwSetPosition GH, Xcenter.0, Ycenter.0, GroupWidth, GroupHeight, GroupRotate, GroupSheer
  126.     end
  127.  
  128. Finish:
  129.  
  130. /* Now render the screen for the user */
  131. call CwStartRender window
  132.  
  133. /* Set project back to original unit of measurement */
  134. call CwSetProperty Output, Unit, Measure
  135.  
  136. exit
  137.  
  138.  
  139. /* If object is a group, recurse into it. Otherwise, perform operation. */
  140. Recurse: procedure
  141. parse arg Handle, Operation
  142.  
  143.     if translate(CwGetHandleType(Handle)) == "GROUP" then
  144.     do
  145.         Handle = CwFindFirstObject(Handle)
  146.         do while CwIsHandleValid(Handle)
  147.             if translate(CwGetHandleType(Handle)) == "GROUP" then
  148.                 call Recurse Handle, Operation
  149.             else
  150.                 interpret Operation
  151.                 Handle = CwFindNextObject(handle)
  152.             end
  153.         end
  154.     else
  155.         interpret Operation
  156.  
  157. return
  158.  
  159.  
  160. /* Prompt user for number of shadow instances */
  161. Prompt1:
  162.  
  163.     /* Stop drawing until we've setup the display */
  164.     call CwClearSelectionRectangle
  165.     Window=CwGetCurrentView()
  166.     call CwStopRender window
  167.  
  168.     /* Drop a white box over everything so we can see our prompts */
  169.     Boxeffect = CwCreateEffect('Rectangle', 'Solid Color')
  170.     call CwSetPosition Boxeffect, oWidth/2, oHeight/2, oWidth, oHeight, 0,0
  171.     Whitebox = CwGetTool(Boxeffect)
  172.     call CwSetProperty Whitebox, "Color", "(255,255,255)"
  173.  
  174.     /* show the prompts */
  175.     Text1effect = CwCreateEffect('Headline Text', 'Solid Color')
  176.     call CwSetPosition Text1effect, oWidth/3, oHeight-oHeight/12, (2*oWidth/3), oHeight/6, 0, 0
  177.     Textobj = CwGetRegion(Text1effect)
  178.     call CwSetProperty Textobj, "Caption", "# of Shadows (>1):"
  179.     call CwSetName Text1effect, CwGetProperty(Textobj, "Caption")
  180.     Textobj = CwGetTool(Text1effect)
  181.     call CwSetProperty Textobj, "Color", "(0,0,0)"
  182.  
  183.     Text2effect = CwCreateEffect('Headline Text', 'Solid Color')
  184.     call CwSetPosition Text2effect, oWidth-oWidth/8, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
  185.     Textobj = CwGetRegion(Text2effect)
  186.     call CwSetProperty Textobj, "Caption", "10"
  187.     Textobj = CwGetTool(Text2effect)
  188.     call CwSetProperty Textobj, "Color", "(0,0,255)"
  189.  
  190.     Text3effect = CwCreateEffect('Headline Text', 'Solid Color')
  191.     call CwSetPosition Text3effect, oWidth/3, oHeight-oHeight/4, (2*oWidth/3), oHeight/6, 0, 0
  192.     Textobj = CwGetRegion(Text3effect)
  193.     call CwSetProperty Textobj, "Caption", "Starting Color (RGB):"
  194.     call CwSetName Text3effect, CwGetProperty(Textobj, "Caption")
  195.     Textobj = CwGetTool(Text3effect)
  196.     call CwSetProperty Textobj, "Color", "(0,0,0)"
  197.  
  198.     Text4effect = CwCreateEffect('Headline Text', 'Solid Color')
  199.     call CwSetPosition Text4effect, oWidth-oWidth/8, oHeight-oHeight/4, oWidth/4, oHeight/6, 0, 0
  200.     Textobj = CwGetRegion(Text4effect)
  201.     call CwSetProperty Textobj, "Caption", "255,255,255"
  202.     Textobj = CwGetTool(Text4effect)
  203.     call CwSetProperty Textobj, "Color", "(0,0,255)"
  204.  
  205.     Text5effect = CwCreateEffect('Headline Text', 'Solid Color')
  206.     call CwSetPosition Text5effect, oWidth/3, oHeight-(5*oHeight)/12, (2*oWidth/3), oHeight/6, 0, 0
  207.     Textobj = CwGetRegion(Text5effect)
  208.     call CwSetProperty Textobj, "Caption", "Ending Color (RGB):"
  209.     call CwSetName Text5effect, CwGetProperty(Textobj, "Caption")
  210.     Textobj = CwGetTool(Text5effect)
  211.     call CwSetProperty Textobj, "Color", "(0,0,0)"
  212.  
  213.     Text6effect = CwCreateEffect('Headline Text', 'Solid Color')
  214.     call CwSetPosition Text6effect, oWidth-oWidth/8, oHeight-(5*oHeight)/12, oWidth/4, oHeight/6, 0, 0
  215.     Textobj = CwGetRegion(Text6effect)
  216.     call CwSetProperty Textobj, "Caption", "0,0,0"
  217.     Textobj = CwGetTool(Text6effect)
  218.     call CwSetProperty Textobj, "Color", "(0,0,255)"
  219.  
  220.     Text7effect = CwCreateEffect('Headline Text', 'Solid Color')
  221.     call CwSetPosition Text7effect, oWidth/3, oHeight/12, oWidth/4, oHeight/6, 0, 0
  222.     call CwSetName Text7effect, "OK"
  223.     Textobj = CwGetRegion(Text7effect)
  224.     call CwSetProperty Textobj, "Caption", "OK"
  225.     Textobj = CwGetTool(Text7effect)
  226.     call CwSetProperty Textobj, "Color", "(0,255,0)"
  227.  
  228.     Text8effect = CwCreateEffect('Headline Text', 'Solid Color')
  229.     call CwSetPosition Text8effect, oWidth-oWidth/3, oHeight/12, oWidth/4, oHeight/6, 0, 0
  230.     call CwSetName Text8effect, "CANCEL"
  231.     Textobj = CwGetRegion(Text8effect)
  232.     call CwSetProperty Textobj, "Caption", "Cancel"
  233.     Textobj = CwGetTool(Text8effect)
  234.     call CwSetProperty Textobj, "Color", "(255,0,0)"
  235.  
  236.     /* Show user instructions */
  237.     Instructeffect = CwCreateEffect('Block Text', 'Solid Color')
  238.     call CwSetPosition Instructeffect, oWidth/2, oHeight/3, oWidth/2, oHeight/3, 0, 0
  239.     O = CwGetRegion(Instructeffect)
  240.     call CwSetProperty O, "Caption", "Set blue values above amd select OK, or Cancel to end script."
  241.     call CwSetProperty O, "Justification", "Center"
  242.     O = CwGetTool(Instructeffect)
  243.     call CwSetProperty O, "Color", "(0,0,0)"
  244.  
  245.     /* Now render the screen for the user */
  246.     call CwStartRender window
  247.  
  248. return
  249.  
  250.  
  251. /* Prompt user for shadow direction */
  252. Prompt2:
  253.  
  254.     /* Stop drawing until we've setup the display */
  255.     call CwClearSelectionRectangle
  256.     Window=CwGetCurrentView()
  257.     call CwStopRender window
  258.  
  259.     /* Drop a white box over everything so we can see our prompts */
  260.     Boxeffect = CwCreateEffect('Rectangle', 'Solid Color')
  261.     call CwSetPosition Boxeffect, oWidth/2, oHeight/2, oWidth, oHeight, 0,0
  262.     Whitebox = CwGetTool(Boxeffect)
  263.     call CwSetProperty Whitebox, "Color", "(255,255,255)"
  264.  
  265.     /* show the prompts */
  266.     Text1effect = CwCreateEffect('Headline Text', 'Solid Color')
  267.     call CwSetPosition Text1effect, oWidth/8, oHeight/2, oWidth/4, oHeight/6, 0, 0
  268.     call CwSetName Text1effect, "LEFT"
  269.     Textobj = CwGetRegion(Text1effect)
  270.     call CwSetProperty Textobj, "Caption", "Left"
  271.     Textobj = CwGetTool(Text1effect)
  272.     call CwSetProperty Textobj, "Color", "(255,0,0)"
  273.  
  274.     Text2effect = CwCreateEffect('Headline Text', 'Solid Color')
  275.     call CwSetPosition Text2effect, oWidth/8, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
  276.     call CwSetName Text2effect, "UPLEFT"
  277.     Textobj = CwGetRegion(Text2effect)
  278.     call CwSetProperty Textobj, "Caption", "Up & Left"
  279.     Textobj = CwGetTool(Text2effect)
  280.     call CwSetProperty Textobj, "Color", "(255,0,0)"
  281.  
  282.     Text3effect = CwCreateEffect('Headline Text', 'Solid Color')
  283.     call CwSetPosition Text3effect, oWidth/2, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
  284.     call CwSetName Text3effect, "UP"
  285.     Textobj = CwGetRegion(Text3effect)
  286.     call CwSetProperty Textobj, "Caption", "Up"
  287.     Textobj = CwGetTool(Text3effect)
  288.     call CwSetProperty Textobj, "Color", "(255,0,0)"
  289.  
  290.     Text4effect = CwCreateEffect('Headline Text', 'Solid Color')
  291.     call CwSetPosition Text4effect, oWidth-oWidth/8, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
  292.     call CwSetName Text4effect, "UPRIGHT"
  293.     Textobj = CwGetRegion(Text4effect)
  294.     call CwSetProperty Textobj, "Caption", "Up & Right"
  295.     Textobj = CwGetTool(Text4effect)
  296.     call CwSetProperty Textobj, "Color", "(255,0,0)"
  297.  
  298.     Text5effect = CwCreateEffect('Headline Text', 'Solid Color')
  299.     call CwSetPosition Text5effect, oWidth-oWidth/8, oHeight/2, oWidth/4, oHeight/6, 0, 0
  300.     call CwSetName Text5effect, "RIGHT"
  301.     Textobj = CwGetRegion(Text5effect)
  302.     call CwSetProperty Textobj, "Caption", "Right"
  303.     Textobj = CwGetTool(Text5effect)
  304.     call CwSetProperty Textobj, "Color", "(255,0,0)"
  305.  
  306.     Text6effect = CwCreateEffect('Headline Text', 'Solid Color')
  307.     call CwSetPosition Text6effect, oWidth-oWidth/8, oHeight/12, oWidth/4, oHeight/6, 0, 0
  308.     call CwSetName Text6effect, "DOWNRIGHT"
  309.     O = CwGetRegion(Text6effect)
  310.     call CwSetProperty O, "Caption", "Down & Right"
  311.     O = CwGetTool(Text6effect)
  312.     call CwSetProperty O, "Color", "(255,0,0)"
  313.  
  314.     Text7effect = CwCreateEffect('Headline Text', 'Solid Color')
  315.     call CwSetPosition Text7effect, oWidth/2, oHeight/12, oWidth/4, oHeight/6, 0, 0
  316.     call CwSetName Text7effect, "DOWN"
  317.     O = CwGetRegion(Text7effect)
  318.     call CwSetProperty O, "Caption", "Down"
  319.     O = CwGetTool(Text7effect)
  320.     call CwSetProperty O, "Color", "(255,0,0)"
  321.  
  322.     Text8effect = CwCreateEffect('Headline Text', 'Solid Color')
  323.     call CwSetPosition Text8effect, oWidth/8, oHeight/12, oWidth/4, oHeight/6, 0, 0
  324.     call CwSetName Text8effect, "DOWNLEFT"
  325.     O = CwGetRegion(Text8effect)
  326.     call CwSetProperty O, "Caption", "Down & Left"
  327.     O = CwGetTool(Text8effect)
  328.     call CwSetProperty O, "Color", "(255,0,0)"
  329.  
  330.     /* Show user instructions */
  331.     Instructeffect = CwCreateEffect('Block Text', 'Solid Color')
  332.     call CwSetPosition Instructeffect, oWidth/2, oHeight/2, oWidth/2, oHeight/4, 0, 0
  333.     O = CwGetRegion(Instructeffect)
  334.     call CwSetProperty O, "Caption", "Click a direction to select shadow angle."
  335.     call CwSetProperty O, "Justification", "Center"
  336.     O = CwGetTool(Instructeffect)
  337.     call CwSetProperty O, "Color", "(0,0,0)"
  338.  
  339.     /* Now render the screen for the user */
  340.     call CwStartRender window
  341.  
  342. return
  343.  
  344.  
  345. Wait:
  346.  
  347.     /* Begin loop to wait for button selection */
  348.     if RxFuncQuery('SysLoadFuncs') then
  349.         do
  350.             call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  351.             call SysLoadFuncs
  352.         end
  353.  
  354.     do forever
  355.         /* sleep */
  356.         rc = SysSleep 5
  357.  
  358.         /* see what (if anything) is selected */
  359.         Obj = CwGetSelectedObject()
  360.  
  361.         /* nothing selected?  Continue */
  362.         if \CwIsHandleValid(Obj) then iterate
  363.  
  364.         /* Something selected.  What is it? */
  365.         Name = CwGetName(Obj)
  366.  
  367.         /* if it is a button then go on */
  368.         if Name = "OK" then
  369.             do
  370.                 o = CwGetRegion(text2effect)
  371.                 Instances = CwGetProperty(o,"Caption")
  372.                 /* Protect against divide by zero error later on */
  373.                 if Instances < 2 then
  374.                     do
  375.                         Instances = 2
  376.                         call CwMsg "You must select at least 2 shadow instances.  I will correct."
  377.                     end
  378.                 o = CwGetRegion(text4effect)
  379.                 StartColor = CwGetProperty(o, "Caption")
  380.                 o = CwGetRegion(text6effect)
  381.                 EndColor = CwGetProperty(o, "Caption")
  382.                 leave
  383.             end
  384.  
  385.         if Name = "CANCEL" then
  386.             do
  387.                 Instances = 0
  388.                 leave
  389.             end
  390.  
  391.         if Name = "LEFT" then
  392.             do
  393.                 XMod = -1
  394.                 YMod = 0
  395.                 leave
  396.             end
  397.  
  398.         if Name = "UPLEFT" then
  399.             do
  400.                 XMod = -1
  401.                 YMod = 1
  402.                 leave
  403.             end
  404.  
  405.         if Name = "UP" then
  406.             do
  407.                 XMod = 0
  408.                 YMod = 1
  409.                 leave
  410.             end
  411.  
  412.         if Name = "UPRIGHT" then
  413.             do
  414.                 XMod = 1
  415.                 YMod = 1
  416.                 leave
  417.             end
  418.  
  419.         if Name = "RIGHT" then
  420.             do
  421.                 XMod = 1
  422.                 YMod = 0
  423.                 leave
  424.             end
  425.  
  426.         if Name = "DOWNRIGHT" then
  427.             do
  428.                 XMod = 1
  429.                 YMod = -1
  430.                 leave
  431.             end
  432.  
  433.         if Name = "DOWN" then
  434.             do
  435.                 XMod = 0
  436.                 YMod = -1
  437.                 leave
  438.             end
  439.  
  440.         if Name = "DOWNLEFT" then
  441.             do
  442.                 XMod = -1
  443.                 YMod = -1
  444.                 leave
  445.             end
  446.     end
  447.  
  448.     /* delete all the prompting stuff before continuing */
  449.     rc = CwDeleteObject(Text1effect)
  450.     rc = CwDeleteObject(Text2effect)
  451.     rc = CwDeleteObject(Text3effect)
  452.     rc = CwDeleteObject(Text4effect)
  453.     rc = CwDeleteObject(Text5effect)
  454.     rc = CwDeleteObject(Text6effect)
  455.     rc = CwDeleteObject(Text7effect)
  456.     rc = CwDeleteObject(Text8effect)
  457.     rc = CwDeleteObject(Instructeffect)
  458.     rc = CwDeleteObject(Boxeffect)
  459.  
  460. return
  461.