home *** CD-ROM | disk | FTP | other *** search
- /*
- RECTANGLE TOOL
-
- Modifiers:
- ALT will constrain the rectangle to a square
- Double Clicking will bring up a requester which allows you to set
- the dimensions and radius of curvature of the rectangle
-
- */
- /* enhanced by Don Cox, Oct '95 */
- /* $VER: RectangleTool Oct 95 */
-
- call open("STDERR","ram:traceRect","W")
- trace r
-
-
- msg = PDSetup.rexx(2,0)
- units = getclip(pds_units)
- if msg ~= 1 then exit_msg(msg)
-
- magic = 0.55228479
-
- /* Get centre of page for defaults */
- psize = pdm_GetPageSize()
- pcentreX = word(psize,1)/2
- pcentreY = word(psize,2)/2
-
- cr = '0a'x
- width = getclip(pduserrectwidth)
- height = getclip(pduserrectheight)
- radius = getclip(pduserrectradius)
- xcorner = getclip(pduserrectxcorner) /* for corners */
- xcentre = getclip(pduserrectxcentre) /* for centres */
- ycorner = getclip(pduserrectycorner) /* for corners */
- ycentre = getclip(pduserrectycentre) /* for centres */
- cc = upper(getclip(pduserrectcc)) /* set centre or corner */
- rotation = getclip(pduserrectrotation)
-
- if units > 2 then
- do
- width = pdm_ConvertUnits(1,units, width)
- height = pdm_ConvertUnits(1,units, height)
- radius = pdm_ConvertUnits(1,units, radius)
- xcorner = pdm_ConvertUnits(1,units, xcorner)
- xcentre = pdm_ConvertUnits(1,units, xcentre)
- ycorner = pdm_ConvertUnits(1,units, ycorner)
- ycentre = pdm_ConvertUnits(1,units, ycentre)
- end
-
- if pos('O',cc)=0 then cc='E'
- xpos = xcorner
- ypos = ycorner
- if cc= 'E' then do
- xpos = xcentre
- ypos = ycentre
- end
-
- size = pdm_GetForm("Enter size of Rect", 8, "Width:"width || cr"Height:"height ||cr"radius:"radius ||cr||"Centre/Corner (E/O):"CC ||cr|| "X position:"xpos ||cr|| "Y position:"ypos ||cr|| "Angle (degrees):"rotation)
- if size = '' then exit_msg()
-
- parse var size width '0a'x height '0a'x radius '0a'x cc '0a'x xpos '0a'x ypos '0a'x rotation
- if radius = '' then radius = 0
- click = 0
- if (xpos = ''| ypos= '') then click = 1 /* use click if no position given */
- if ~datatype(rotation,n) then rotation = 0
-
- if ~(datatype(width, n) & datatype(height,n) & datatype(radius,n)) then
- exit_msg("Invalid Entry")
- if ~(datatype(xpos,n) & datatype(ypos,n)) then click = 1
-
- if width <= 0 | height <= 0 then
- exit_msg("Invalid Entry")
-
- if units > 2 then
- do
- width = pdm_ConvertUnits(units,1, width)
- height = pdm_ConvertUnits(units,1, height)
- radius = pdm_ConvertUnits(units,1, radius)
- if datatype(xpos,n) then xpos = pdm_ConvertUnits(1,units, xpos)
- if datatype(ypos,n) then ypos = pdm_ConvertUnits(1,units, ypos)
- end
-
- if click = 1 then do
- xpos = pcentreX
- ypos = pcentreY
- end
-
- if click = 0 then do
- if pos('O',upper(cc)) = 0 then do /* position by centre */
- xcorner = xpos-(width/2)
- ycorner = ypos-(height/2)
- xcentre = xpos
- ycentre = ypos
- end
- else do
- xcorner = xpos
- ycorner = ypos
- xcentre = xpos+(width/2)
- ycentre = ypos+(width/2)
- end
- end
-
- call setclip(pduserrectwidth, width)
- call setclip(pduserrectheight, height)
- call setclip(pduserrectradius, radius)
- call setclip(pduserrectxcorner, xcorner)
- call setclip(pduserrectxcentre, xcentre)
- call setclip(pduserrectycorner, ycorner)
- call setclip(pduserrectycentre, ycentre)
- call setclip(pduserrectcc, cc)
- call setclip(pduserrectrotation, rotation)
-
- if click = 1 then do
- rect = pdm_ClickRectangle("Click", width, height)
- if rect = '' then exit_msg()
- xpos = word(rect,1)
- ypos = word(rect,2)
- left = xpos - (width / 2)
- top = ypos - (height / 2)
- right = left + width
- bottom = top + height
- end
-
- else do
- left = xcorner
- top = ycorner
- right = xcorner+width
- bottom = ycorner+height
- end
-
-
-
- if radius = 0 then
- object = pdm_DrawRectangle(left, top, right, bottom)
- else
- do
-
- call pdm_InitPlot()
-
- lxpos = left + radius
- rxpos = right - radius
- typos = top + radius
- bypos = bottom - radius
-
- radlen = radius * magic
- nradlen = -radlen
-
- call pdm_PlotBezier(lxpos" "top" "nradlen" 0 0 0")
- call pdm_PlotBezier(rxpos" "top" 0 0 "radlen" 0")
- call pdm_PlotBezier(right" "typos" 0 "nradlen" 0 0")
- call pdm_PlotBezier(right" "bypos" 0 0 0 "radlen)
- call pdm_PlotBezier(rxpos" "bottom" "radlen" 0 0 0")
- call pdm_PlotBezier(lxpos" "bottom" 0 0 "nradlen" 0")
- call pdm_PlotBezier(left" "bypos" 0 "radlen" 0 0")
- call pdm_PlotBezier(left" "typos" 0 0 0 "nradlen)
- call pdm_PlotBezier(lxpos" "top" "nradlen" 0 0 0")
-
- object = pdm_ClosePlot()
- end
-
- call pdm_UnselectObj()
- call pdm_SelectObj(object)
- if rotation ~=0 then call pdm_RotateObj(object, rotation, xpos, ypos)
-
- exit_msg()
-
- exit_msg: procedure expose units
- do
- parse arg message
-
- if message ~= '' then call pdm_Inform(1,message,)
- call pdm_SetUnits(units)
- call pdm_AutoUpdate(1)
- exit
- end
-