home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Graphics
/
Graphics.zip
/
pgpro40.zip
/
3DShadow.cwx
< prev
next >
Wrap
Text File
|
1999-08-04
|
15KB
|
461 lines
/*
3DShadow.cwx
PGPro Scripts v3.0 - by Don Eitner, 1999
Creates a "3D shadow" of an object in user-defined direction with
user-defined color fade.
This code is neither supported nor under warranty. Feel free to
examine and modify this script for your own purposes. See the
included readme.txt for additional information.
*/
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
Handle.0 = CwGetSelectedObject()
/* no object selected */
if \CwIsHandleValid(Handle.0) then
do
call CwMsg "No object selected."
exit
end
/* Set initial variables */
Output = CwGetAppHandle("Output Settings")
Measure = CwGetProperty(Output, "Unit")
/* Force project into pixels mode -- we'll change it back later */
if (Measure = "Inches") | (Measure = "Centimeters") | (Measure = "Points") then
call CwSetProperty Output, Unit, "Pixels"
/* Set additional variables */
oWidth = CwGetProperty(Output, "Output Size:Width")
oHeight = CwGetProperty(Output, "Output Size:Height")
Xcenter.0 = CwGetProperty(Handle.0, "Position:X Center")
Ycenter.0 = CwGetProperty(Handle.0, "Position:Y Center")
Width = CwGetProperty(Handle.0, "Position:Width")
Height = CwGetProperty(Handle.0, "Position:Height")
Rotate = CwGetProperty(Handle.0, "Position:Angle")
Sheer = CwGetProperty(Handle.0, "Position:Skew")
if oHeight <= 200 then
Move = 1
else
Move = (oHeight / 200)
/* Prompt user for number of shadow instances and wait for them to press the button */
call Prompt1
call Wait
if Instances = 0 then
call Finish
/* Assemble the starting and ending shadow colors */
x1 = lastpos(",",StartColor)
SC3 = substr(StartColor, (x1+1))
x2 = lastpos(",",StartColor,(x1-1))
SC2 = substr(StartColor, (x2+1), (x1-x2-1))
x3 = lastpos(",",StartColor,(x2-1))
SC1 = substr(StartColor, (x3+1), (x2-x3-1))
y1 = lastpos(",",EndColor)
EC3 = substr(EndColor, (y1+1))
y2 = lastpos(",",EndColor,(y1-1))
EC2 = substr(EndColor, (y2+1), (y1-y2-1))
y3 = lastpos(",",EndColor,(y2-1))
EC1 = substr(EndColor, (y3+1), (y2-y3-1))
/* Assemble the RGB color shifts across the range of shadow instances */
RedShift = ((SC1-EC1) % (Instances - 1))
GreenShift = ((SC2-EC2) % (Instances - 1))
BlueShift = ((SC3-EC3) % (Instances - 1))
/* Prompt user for direction of shadow and wait for them to press a button */
call Prompt2
call Wait
/* Do the shadowing of the selected object */
/* Stop drawing until we've setup the display */
Window=CwGetCurrentView()
call CwStopRender window
do Num=1 to Instances
/* Set some variables for this operation */
Prevnum = Num - 1
Handle.Num = CwDuplicateObject(Handle.Prevnum)
ColorVal1 = SC1 - RedShift * (Num-1)
ColorVal2 = SC2 - GreenShift * (Num-1)
ColorVal3 = SC3 - BlueShift * (Num-1)
/* Move the current shadow instance by the value specified in MOVE */
Xcenter = CwGetProperty(Handle.Prevnum, "Position:X Center")
Ycenter = CwGetProperty(Handle.Prevnum, "Position:Y Center")
Xcenter = Xcenter + (XMod * Move)
Ycenter = Ycenter + (YMod * Move)
call CwSetProperty Handle.Num, "Position:Y Center", Ycenter
call CwSetProperty Handle.Num, "Position:X Center", Xcenter
call CwMoveObjectBehindObject Handle.Num , Handle.Prevnum
call CwSetPosition Handle.Num, Xcenter, Ycenter, Width, Height, Rotate, Sheer
/* Check to see if the object is a group object */
call Recurse Handle.Num, 'call CwSetTool handle, "Solid Color"'
/* Do the shading of the current shadow instance */
call Recurse Handle.Num, 'call CwSetProperty CwGetTool(handle), "Color", "('ColorVal1','ColorVal2','ColorVal3')"'
end
/* Group the original object and its shadows into a single object */
GH = CwAddObjectToGroup(Handle.0, 0)
do Num = 1 to Instances
call CwAddObjectToGroup Handle.Num, GH
end
/* Make sure the user wants to do this */
if RxMessageBox("Do you wish to shift the selected object and all shadows to be centered on the original object's location?", ,
"Shift Object?","yesno","warning") \= 6 then
call Finish
else
do
GroupWidth = CwGetProperty(gh, "Position:Width")
GroupHeight = CwGetProperty(gh, "Position:Height")
GroupRotate = CwGetProperty(gh, "Position:Angle")
GroupSheer = CwGetProperty(gh, "Position:Skew")
call CwSetPosition GH, Xcenter.0, Ycenter.0, GroupWidth, GroupHeight, GroupRotate, GroupSheer
end
Finish:
/* Now render the screen for the user */
call CwStartRender window
/* Set project back to original unit of measurement */
call CwSetProperty Output, Unit, Measure
exit
/* If object is a group, recurse into it. Otherwise, perform operation. */
Recurse: procedure
parse arg Handle, Operation
if translate(CwGetHandleType(Handle)) == "GROUP" then
do
Handle = CwFindFirstObject(Handle)
do while CwIsHandleValid(Handle)
if translate(CwGetHandleType(Handle)) == "GROUP" then
call Recurse Handle, Operation
else
interpret Operation
Handle = CwFindNextObject(handle)
end
end
else
interpret Operation
return
/* Prompt user for number of shadow instances */
Prompt1:
/* Stop drawing until we've setup the display */
call CwClearSelectionRectangle
Window=CwGetCurrentView()
call CwStopRender window
/* Drop a white box over everything so we can see our prompts */
Boxeffect = CwCreateEffect('Rectangle', 'Solid Color')
call CwSetPosition Boxeffect, oWidth/2, oHeight/2, oWidth, oHeight, 0,0
Whitebox = CwGetTool(Boxeffect)
call CwSetProperty Whitebox, "Color", "(255,255,255)"
/* show the prompts */
Text1effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text1effect, oWidth/3, oHeight-oHeight/12, (2*oWidth/3), oHeight/6, 0, 0
Textobj = CwGetRegion(Text1effect)
call CwSetProperty Textobj, "Caption", "# of Shadows (>1):"
call CwSetName Text1effect, CwGetProperty(Textobj, "Caption")
Textobj = CwGetTool(Text1effect)
call CwSetProperty Textobj, "Color", "(0,0,0)"
Text2effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text2effect, oWidth-oWidth/8, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
Textobj = CwGetRegion(Text2effect)
call CwSetProperty Textobj, "Caption", "10"
Textobj = CwGetTool(Text2effect)
call CwSetProperty Textobj, "Color", "(0,0,255)"
Text3effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text3effect, oWidth/3, oHeight-oHeight/4, (2*oWidth/3), oHeight/6, 0, 0
Textobj = CwGetRegion(Text3effect)
call CwSetProperty Textobj, "Caption", "Starting Color (RGB):"
call CwSetName Text3effect, CwGetProperty(Textobj, "Caption")
Textobj = CwGetTool(Text3effect)
call CwSetProperty Textobj, "Color", "(0,0,0)"
Text4effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text4effect, oWidth-oWidth/8, oHeight-oHeight/4, oWidth/4, oHeight/6, 0, 0
Textobj = CwGetRegion(Text4effect)
call CwSetProperty Textobj, "Caption", "255,255,255"
Textobj = CwGetTool(Text4effect)
call CwSetProperty Textobj, "Color", "(0,0,255)"
Text5effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text5effect, oWidth/3, oHeight-(5*oHeight)/12, (2*oWidth/3), oHeight/6, 0, 0
Textobj = CwGetRegion(Text5effect)
call CwSetProperty Textobj, "Caption", "Ending Color (RGB):"
call CwSetName Text5effect, CwGetProperty(Textobj, "Caption")
Textobj = CwGetTool(Text5effect)
call CwSetProperty Textobj, "Color", "(0,0,0)"
Text6effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text6effect, oWidth-oWidth/8, oHeight-(5*oHeight)/12, oWidth/4, oHeight/6, 0, 0
Textobj = CwGetRegion(Text6effect)
call CwSetProperty Textobj, "Caption", "0,0,0"
Textobj = CwGetTool(Text6effect)
call CwSetProperty Textobj, "Color", "(0,0,255)"
Text7effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text7effect, oWidth/3, oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text7effect, "OK"
Textobj = CwGetRegion(Text7effect)
call CwSetProperty Textobj, "Caption", "OK"
Textobj = CwGetTool(Text7effect)
call CwSetProperty Textobj, "Color", "(0,255,0)"
Text8effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text8effect, oWidth-oWidth/3, oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text8effect, "CANCEL"
Textobj = CwGetRegion(Text8effect)
call CwSetProperty Textobj, "Caption", "Cancel"
Textobj = CwGetTool(Text8effect)
call CwSetProperty Textobj, "Color", "(255,0,0)"
/* Show user instructions */
Instructeffect = CwCreateEffect('Block Text', 'Solid Color')
call CwSetPosition Instructeffect, oWidth/2, oHeight/3, oWidth/2, oHeight/3, 0, 0
O = CwGetRegion(Instructeffect)
call CwSetProperty O, "Caption", "Set blue values above amd select OK, or Cancel to end script."
call CwSetProperty O, "Justification", "Center"
O = CwGetTool(Instructeffect)
call CwSetProperty O, "Color", "(0,0,0)"
/* Now render the screen for the user */
call CwStartRender window
return
/* Prompt user for shadow direction */
Prompt2:
/* Stop drawing until we've setup the display */
call CwClearSelectionRectangle
Window=CwGetCurrentView()
call CwStopRender window
/* Drop a white box over everything so we can see our prompts */
Boxeffect = CwCreateEffect('Rectangle', 'Solid Color')
call CwSetPosition Boxeffect, oWidth/2, oHeight/2, oWidth, oHeight, 0,0
Whitebox = CwGetTool(Boxeffect)
call CwSetProperty Whitebox, "Color", "(255,255,255)"
/* show the prompts */
Text1effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text1effect, oWidth/8, oHeight/2, oWidth/4, oHeight/6, 0, 0
call CwSetName Text1effect, "LEFT"
Textobj = CwGetRegion(Text1effect)
call CwSetProperty Textobj, "Caption", "Left"
Textobj = CwGetTool(Text1effect)
call CwSetProperty Textobj, "Color", "(255,0,0)"
Text2effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text2effect, oWidth/8, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text2effect, "UPLEFT"
Textobj = CwGetRegion(Text2effect)
call CwSetProperty Textobj, "Caption", "Up & Left"
Textobj = CwGetTool(Text2effect)
call CwSetProperty Textobj, "Color", "(255,0,0)"
Text3effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text3effect, oWidth/2, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text3effect, "UP"
Textobj = CwGetRegion(Text3effect)
call CwSetProperty Textobj, "Caption", "Up"
Textobj = CwGetTool(Text3effect)
call CwSetProperty Textobj, "Color", "(255,0,0)"
Text4effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text4effect, oWidth-oWidth/8, oHeight-oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text4effect, "UPRIGHT"
Textobj = CwGetRegion(Text4effect)
call CwSetProperty Textobj, "Caption", "Up & Right"
Textobj = CwGetTool(Text4effect)
call CwSetProperty Textobj, "Color", "(255,0,0)"
Text5effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text5effect, oWidth-oWidth/8, oHeight/2, oWidth/4, oHeight/6, 0, 0
call CwSetName Text5effect, "RIGHT"
Textobj = CwGetRegion(Text5effect)
call CwSetProperty Textobj, "Caption", "Right"
Textobj = CwGetTool(Text5effect)
call CwSetProperty Textobj, "Color", "(255,0,0)"
Text6effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text6effect, oWidth-oWidth/8, oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text6effect, "DOWNRIGHT"
O = CwGetRegion(Text6effect)
call CwSetProperty O, "Caption", "Down & Right"
O = CwGetTool(Text6effect)
call CwSetProperty O, "Color", "(255,0,0)"
Text7effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text7effect, oWidth/2, oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text7effect, "DOWN"
O = CwGetRegion(Text7effect)
call CwSetProperty O, "Caption", "Down"
O = CwGetTool(Text7effect)
call CwSetProperty O, "Color", "(255,0,0)"
Text8effect = CwCreateEffect('Headline Text', 'Solid Color')
call CwSetPosition Text8effect, oWidth/8, oHeight/12, oWidth/4, oHeight/6, 0, 0
call CwSetName Text8effect, "DOWNLEFT"
O = CwGetRegion(Text8effect)
call CwSetProperty O, "Caption", "Down & Left"
O = CwGetTool(Text8effect)
call CwSetProperty O, "Color", "(255,0,0)"
/* Show user instructions */
Instructeffect = CwCreateEffect('Block Text', 'Solid Color')
call CwSetPosition Instructeffect, oWidth/2, oHeight/2, oWidth/2, oHeight/4, 0, 0
O = CwGetRegion(Instructeffect)
call CwSetProperty O, "Caption", "Click a direction to select shadow angle."
call CwSetProperty O, "Justification", "Center"
O = CwGetTool(Instructeffect)
call CwSetProperty O, "Color", "(0,0,0)"
/* Now render the screen for the user */
call CwStartRender window
return
Wait:
/* Begin loop to wait for button selection */
if RxFuncQuery('SysLoadFuncs') then
do
call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
call SysLoadFuncs
end
do forever
/* sleep */
rc = SysSleep 5
/* see what (if anything) is selected */
Obj = CwGetSelectedObject()
/* nothing selected? Continue */
if \CwIsHandleValid(Obj) then iterate
/* Something selected. What is it? */
Name = CwGetName(Obj)
/* if it is a button then go on */
if Name = "OK" then
do
o = CwGetRegion(text2effect)
Instances = CwGetProperty(o,"Caption")
/* Protect against divide by zero error later on */
if Instances < 2 then
do
Instances = 2
call CwMsg "You must select at least 2 shadow instances. I will correct."
end
o = CwGetRegion(text4effect)
StartColor = CwGetProperty(o, "Caption")
o = CwGetRegion(text6effect)
EndColor = CwGetProperty(o, "Caption")
leave
end
if Name = "CANCEL" then
do
Instances = 0
leave
end
if Name = "LEFT" then
do
XMod = -1
YMod = 0
leave
end
if Name = "UPLEFT" then
do
XMod = -1
YMod = 1
leave
end
if Name = "UP" then
do
XMod = 0
YMod = 1
leave
end
if Name = "UPRIGHT" then
do
XMod = 1
YMod = 1
leave
end
if Name = "RIGHT" then
do
XMod = 1
YMod = 0
leave
end
if Name = "DOWNRIGHT" then
do
XMod = 1
YMod = -1
leave
end
if Name = "DOWN" then
do
XMod = 0
YMod = -1
leave
end
if Name = "DOWNLEFT" then
do
XMod = -1
YMod = -1
leave
end
end
/* delete all the prompting stuff before continuing */
rc = CwDeleteObject(Text1effect)
rc = CwDeleteObject(Text2effect)
rc = CwDeleteObject(Text3effect)
rc = CwDeleteObject(Text4effect)
rc = CwDeleteObject(Text5effect)
rc = CwDeleteObject(Text6effect)
rc = CwDeleteObject(Text7effect)
rc = CwDeleteObject(Text8effect)
rc = CwDeleteObject(Instructeffect)
rc = CwDeleteObject(Boxeffect)
return