// create a short variable name to represent the mouse position var mouse = smartShape.currentMousePos; // create a short variable name to represent the control points array var cps = smartShape.elem.controlPoints; // create a new generic object to contain event handler functions operation = new Object(); // event handlers: // define an InsertSmartShapeAt event handler that will create the // shape for the InsertSmartShapeAt event operation.InsertSmartShapeAt = function(){ // create new path as first element in elements array smartShape.elem.elements[0] = new Path(); // create new contour as first contour in contours array smartShape.elem.elements[0].contours[0] = new Contour(); // set the contour to be a closed contour smartShape.elem.elements[0].contours[0].isClosed = true; // assign a short variable to represent the nodes array var nods = smartShape.elem.elements[0].contours[0].nodes; // create 3 nodes in the contour by altering the nodes array (nods) length nods.length = 3; // set the position of the 3 nodes in the first contour in a triangle shape // each point is based around the location of the mouse SetNodePosition(nods[0], AddPoints(mouse, {x:-25, y:-25})); SetNodePosition(nods[1], AddPoints(mouse, {x:25, y:0})); SetNodePosition(nods[2], AddPoints(mouse, {x:-25, y:25})); // create a new control point in the first position of the control points array cps[0] = new ControlPoint(); // set the first control point to the position of the second node in nods // with the name "Tip" and the toolTip "Move Tip" SetControlPoint(cps[0], nods[1], "Tip", "Move Tip"); } // define an BeginDragControlPoint event handler that will initiate // register move calls to handle control point and node positioning // when the control point is moved. operation.BeginDragControlPoint = function(){ // define a variable to hold a default RegisterMoveParms object var parms = smartShape.GetDefaultMoveParms(); // assign a short variable to represent the nodes array var nods = smartShape.elem.elements[0].contours[0].nodes; // set the second path node and the control point to move with a // RegisterMove type of movement with default properties specified in parms cps[0].RegisterMove(parms); nods[1].RegisterMove(parms); } // end event handlers // custom functions: /** * SetBezierNodePosition sets the position of the passed node to the * position of the point pt parameter. All node control points are * set to this point as well * Requires: SetBezierNodePosition */ SetNodePosition = function(node, pt){ SetBezierNodePosition(node, pt,pt,pt); // set point position for all nodes to pt } /** * SetBezierNodePosition sets the position of the passed node to the * position of the points ptp (node predecessor), pt (main point), and * pts (node successor) */ SetBezierNodePosition = function(node, ptp, pt, pts){ node.predX = ptp.x; node.predY = ptp.y; // Predecessor point node.x = pt.x; node.y = pt.y; // Main points node.succX = pts.x; node.succY = pts.y; // Successor points } /** * SetControlPoint positions the passed control point cp to the location * specified by pt and assigns to it name and toolTip */ SetControlPoint = function(cp, pt, name, toolTip){ cp.x = pt.x; // set x position from x of pt cp.y = pt.y; // set y position from y of pt cp.name = name; // set control point name to name passed cp.toolTip = toolTip; // set control point toolTip to toolTip passed } /** * AddPoints adds two points pt1 and pt2 and returns the resulting point */ AddPoints = function(pt1, pt2){ return {x:pt1.x + pt2.x, y:pt1.y + pt2.y}; // add x and y properties in returned object } // end custom functions // invoke event handler: // if the event specified by smartShape.operation exists // in the operation object, call that event as a function if (operation[smartShape.operation]) operation[smartShape.operation]();