#+ Simple draw functions for Canvases. #+ GLOBALS DEFINE __fgldraw_theCanvas om.DomNode DEFINE __fgldraw_theCanvas_fillColor String DEFINE __fgldraw_theCanvas_linesAreBlack INTEGER DEFINE __fgldraw_theCanvas_anchor String DEFINE __fgldraw_theCanvas_fontSize String DEFINE __fgldraw_theCanvas_trans INTEGER DEFINE __fgldraw_theCanvas_lineWidth INTEGER END GLOBALS FUNCTION drawInit () LET __fgldraw_theCanvas=NULL LET __fgldraw_theCanvas_fillColor="white" LET __fgldraw_theCanvas_linesAreBlack = 0 LET __fgldraw_theCanvas_lineWidth = 1 END FUNCTION #+ Selects a canvas. #+ @param canvasName Canvas identifier. #+ #+ The function initializes the fillColor to "white", #+ the anchor to "s". #+ #+ The selected canvas is the parent for all susequently created objects. FUNCTION drawSelect(canvasName) DEFINE canvasName String DEFINE formField om.DomNode DEFINE w ui.Window let w = ui.Window.getCurrent() let formField=w.findNode("Canvas",canvasName) if formField is NULL then initialize __fgldraw_theCanvas to NULL end if # let __fgldraw_theCanvas=formField.getFirstChild() let __fgldraw_theCanvas=formField let __fgldraw_theCanvas_fillColor="white" let __fgldraw_theCanvas_trans=0 let __fgldraw_theCanvas_anchor="s" initialize __fgldraw_theCanvas_fontSize to null END FUNCTION #+ Enable or Disable color mode for lines. #+ @param ColorLines FALSE:Lines are in color, TRUE:Lines are black. #+ #+ This is a global configuration. FUNCTION drawDisableColorLines(ColorLines) DEFINE ColorLines SMALLINT IF ColorLines != 1 THEN LET __fgldraw_theCanvas_linesAreBlack = FALSE ELSE LET __fgldraw_theCanvas_linesAreBlack = TRUE END IF END FUNCTION #+ Set fill color. #+ @param color The name of the color for filling shapes. FUNCTION drawFillColor(color) DEFINE color String let __fgldraw_theCanvas_fillColor=color.trim() END FUNCTION #+ Define the with of the lines. #+ @param width Pen size for drawing. FUNCTION drawLineWidth(width) DEFINE width SMALLINT LET __fgldraw_theCanvas_lineWidth = width END FUNCTION #+ Set anchor to draw a text. #+ @param a One of: 'n','e','s','w' FUNCTION drawAnchor(a) DEFINE a String LET __fgldraw_theCanvas_anchor=a.trim() IF __fgldraw_theCanvas_trans THEN CASE a WHEN "n" LET __fgldraw_theCanvas_anchor="e" WHEN "e" LET __fgldraw_theCanvas_anchor="n" WHEN "s" LET __fgldraw_theCanvas_anchor="w" WHEN "w" LET __fgldraw_theCanvas_anchor="s" END CASE END IF END FUNCTION #+ Set the fontSize attribute for all subsequent drawText operations. #+ @param size fontSize The new font size. FUNCTION drawSetFontSize(size) DEFINE size String LET __fgldraw_theCanvas_fontSize=size.trim() END FUNCTION #+ Draws a line. #+ @param startX The x start position. #+ @param startY The y start position. #+ @param dy The relative y end position. #+ @param dx The relative x end position. #+ @return Item identifier in the canvas. FUNCTION drawLine(startY,startX,dy,dx) DEFINE m om.DomNode DEFINE startY,startX,dy,dx INTEGER IF __fgldraw_theCanvas is NULL THEN return NULL END IF LET m=__fgldraw_theCanvas.createChild("CanvasLine") if NOT __fgldraw_theCanvas_linesAreBlack then CALL m.setAttribute("fillColor",__fgldraw_theCanvas_fillColor); end if CALL m.setAttribute("startY",startY); CALL m.setAttribute("startX",startX); CALL m.setAttribute("endY",startY+dy); CALL m.setAttribute("endX",startX+dx); CALL m.setAttribute("width",__fgldraw_theCanvas_lineWidth); return m.getId() END FUNCTION #+ Draws a text. #+ @param startX The x start position. #+ @param startY The y start position. #+ @param text Text to draw. #+ @return Item identifier in the canvas. FUNCTION drawText(startY,startX,text) DEFINE startY,startX INTEGER DEFINE text String DEFINE m om.DomNode IF __fgldraw_theCanvas is NULL THEN RETURN NULL END IF LET m=__fgldraw_theCanvas.createChild("CanvasText") CALL m.setAttribute("fillColor",__fgldraw_theCanvas_fillColor); CALL m.setAttribute("startY",startY); CALL m.setAttribute("startX",startX); CALL m.setAttribute("text",text.trim()); CALL m.setAttribute("anchor",__fgldraw_theCanvas_anchor); if __fgldraw_theCanvas_fontSize is not null then CALL m.setAttribute("fontSize",__fgldraw_theCanvas_fontSize); end if return m.getId() END FUNCTION #+ Draws a rectangle. #+ @param startX The x start position. #+ @param startY The y start position. #+ @param width The rectangle width. #+ @param height The rectangle height. FUNCTION drawRectangle(startY,startX,height,width) DEFINE startY,startX,height,width INTEGER DEFINE m om.DomNode IF __fgldraw_theCanvas is NULL THEN return NULL END IF LET m=__fgldraw_theCanvas.createChild("CanvasRectangle") CALL m.setAttribute("fillColor",__fgldraw_theCanvas_fillColor); CALL m.setAttribute("startY",startY); CALL m.setAttribute("startX",startX); CALL m.setAttribute("endY",startY+height); CALL m.setAttribute("endX",startX+width); return m.getId() END FUNCTION #+ Draws an Circle from a bounding square. #+ @returnType INTEGER #+ @param startX The x start position of the boundig square. #+ @param startY The y start position of the boundig square. #+ @param diameter The diameter (the width of the bounding square). #+ @return Item identifier in the canvas. FUNCTION drawCircle(startY,startX,diameter) DEFINE m om.DomNode DEFINE startY,startX,diameter INTEGER IF __fgldraw_theCanvas is NULL THEN RETURN NULL END IF LET m=__fgldraw_theCanvas.createChild("CanvasCircle") CALL m.setAttribute("fillColor",__fgldraw_theCanvas_fillColor); CALL m.setAttribute("startY",startY); CALL m.setAttribute("startX",startX); CALL m.setAttribute("diameter",diameter); return m.getId() END FUNCTION #+ Draws an Oval from a bounding rectangle. #+ @returnType INTEGER #+ @param startX The x start position of the bounding rectangle. #+ @param startY The y start position of the bounding rectangle. #+ @param width The width of the bounding rectangle. #+ @param height The the height of the bounding rectangle. #+ @return Item identifier in the canvas. FUNCTION drawOval(startY,startX,height,width) DEFINE m om.DomNode DEFINE startY,startX,height,width INTEGER IF __fgldraw_theCanvas is NULL THEN RETURN NULL END IF LET m=__fgldraw_theCanvas.createChild("CanvasOval") CALL m.setAttribute("fillColor",__fgldraw_theCanvas_fillColor); CALL m.setAttribute("startY",startY); CALL m.setAttribute("startX",startX); CALL m.setAttribute("endY",startY+height); CALL m.setAttribute("endX",startX+width); return m.getId() END FUNCTION #+ Draws a filled polygone. #+ @param xyList A blank separated list of points. #+ @return Item identifier in the canvas. FUNCTION drawPolygon(xyList) DEFINE m om.DomNode DEFINE xyList String IF __fgldraw_theCanvas is NULL THEN RETURN NULL END IF LET m=__fgldraw_theCanvas.createChild("CanvasPolygon") CALL m.setAttribute("fillColor",__fgldraw_theCanvas_fillColor); CALL m.setAttribute("xyList",xyList); RETURN m.getId() END FUNCTION #+ Draws an arc in a bounding square. #+ @param startX The x start position of the bounding quadrat. #+ @param startY The y start position of the bounding quadrat. #+ @param diameter The diameter (the with of the bounding quadrat). #+ @param startDegrees Specifies the beginning of the angular range occupied #+ by the arc. #+ @param extentDegrees Specifies the size of the angular range occupied by #+ the arc. #+ @return Item identifier in the canvas. FUNCTION drawArc(startY,startX,diameter,startDegrees,extentDegrees) DEFINE m om.DomNode DEFINE startY,startX,diameter,startDegrees,extentDegrees INTEGER IF __fgldraw_theCanvas is NULL THEN RETURN NULL END IF LET m=__fgldraw_theCanvas.createChild("CanvasArc") CALL m.setAttribute("fillColor",__fgldraw_theCanvas_fillColor); CALL m.setAttribute("startY",startY); CALL m.setAttribute("startX",startX); CALL m.setAttribute("diameter",diameter); CALL m.setAttribute("startDegrees",startDegrees); CALL m.setAttribute("extentDegrees",extentDegrees); return m.getId() END FUNCTION #+ Clears the drawing area. FUNCTION drawClear() DEFINE c om.DomNode IF __fgldraw_theCanvas is not NULL THEN LET c=__fgldraw_theCanvas.getFirstChild() WHILE c is NOT NULL CALL __fgldraw_theCanvas.removeChild(c) LET c=__fgldraw_theCanvas.getFirstChild() END WHILE END IF END FUNCTION #+ Defines key to send when left button click on. #+ @param id Item identifier. #+ @param key Key to send. FUNCTION drawButtonLeft(id,key) DEFINE id INTEGER DEFINE key String DEFINE m om.DomNode DEFINE doc om.DomDocument LET doc=ui.Interface.getDocument() LET m=doc.getElementById(id) IF m is NOT NULL THEN CALL m.setAttribute("acceleratorKey1",key.trim()) END IF END FUNCTION #+ Defines key to send when right button click on. #+ @param id Item identifier. #+ @param key Key to send. FUNCTION drawButtonRight(id,key) DEFINE id INTEGER DEFINE key String DEFINE m om.DomNode DEFINE doc om.DomDocument LET doc=ui.Interface.getDocument() LET m=doc.getElementById(id) IF m is NOT NULL THEN CALL m.setAttribute("acceleratorKey3",key.trim()) END IF END FUNCTION #+ Removes key bindings between item and mouse. #+ @param id Item identifier. #+ @param key Key to send. FUNCTION drawClearButton(id,key) DEFINE id INTEGER DEFINE key String DEFINE m om.DomNode DEFINE doc om.DomDocument LET doc=ui.Interface.getDocument() LET m=doc.getElementById(id) IF m is NOT NULL THEN CALL m.setAttribute("acceleratorKey1","") CALL m.setAttribute("acceleratorKey3","") END IF END FUNCTION #+ Sets a comment for a canvas item. #+ @param id Item identifier. #+ @param comment Comment to set. FUNCTION drawSetComment(id,comment) DEFINE id INTEGER DEFINE comment String DEFINE m om.DomNode DEFINE doc om.DomDocument LET doc=ui.Interface.getDocument() LET m=doc.getElementById(id) IF m is NOT NULL THEN CALL m.setAttribute("comment",comment.trim()) END IF END FUNCTION