This event is generated when a dynamic hook of an object is moved.
Syntax: |
---|
function OnDynamicMoveHook(obj, index, mode) |
Parameters
Parameter | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj | An object of a class derived from DlxObject object to which the hook belongs. | ||||||||||||
index | Index of the hook being moved. | ||||||||||||
mode | The value of this parameter can be a combination of the following values:
|
Remarks
This function is called when the user drags a dynamic hook. The purpose of this function is to execute the action corresponding to the hook.
Use the object's SetHookMessage method to display status bar information.
Use the object's GetHookPoint method to get the coordinates of the mouse pointer.
Use the object's SetHookParam and GetHookParam methods to persist parameter values between calls.
Use the object's SetParam and GetParamNumber methods to persist the data by storing it in the object's attributes.
Note: |
---|
This function is called repeatedly during the hook drag operation. Avoid operations that are excessively complex or different from the simple modification of a graphic object belonging to the dynamic object provided in the obj parameter. |
This event implements the dynamic functionality of the objects.
Example
In the following example, the object of type shape provided in obj is modified. The shape takes on the appearance of a star. The amplitude of the mouse movement in combination with pressing the keys: SHIFT, CTRL and ALT allows you to change the number and shape of the rays. The parameters of the star are stored in the dyndata attribute of the object.
For the complete code see "dynamic star.clxjob" in the sample files.
Copy code | |
---|---|
function OnDynamicMoveHook(obj, index, mode)
{
var view = obj.GetPage().GetActiveView()
if (!view.IsValid())
return;
if (obj.GetType() != DlxApp.OBJTYPE_SHAPE)
return;
if (mode & DlxApp.DYNAMICHOOK_BEGIN)
{
// load parameters
obj.SetHookParam(0, obj.GetParamNumber("dyndata/shape", 1, 8));
obj.SetHookParam(1, obj.GetParamNumber("dyndata/shape", 2, 5));
obj.SetHookParam(2, obj.GetParamNumber("dyndata/shape", 3, 30));
obj.SetHookParam(3, obj.GetParamNumber("dyndata/shape", 4, 0));
obj.SetHookParam(4, obj.GetParamNumber("dyndata/shape", 5, 180/36));
obj.SetHookParam(5, obj.GetBoundingBox().CenterPoint().x);
obj.SetHookParam(6, obj.GetBoundingBox().CenterPoint().y);
}
if (mode & DlxApp.DYNAMICHOOK_END)
{
// save parameters
obj.SetParam("dyndata/shape", 1, obj.GetHookParam(0));
obj.SetParam("dyndata/shape", 2, obj.GetHookParam(1));
obj.SetParam("dyndata/shape", 3, obj.GetHookParam(2));
obj.SetParam("dyndata/shape", 4, obj.GetHookParam(3));
obj.SetParam("dyndata/shape", 5, obj.GetHookParam(4));
}
if (mode & DlxApp.DYNAMICHOOK_NEXT)
{
// initialize parameters
var rays = obj.GetHookParam(0);
var height = obj.GetHookParam(1);
var radius = obj.GetHookParam(2);
var rotation = obj.GetHookParam(3);
var width = obj.GetHookParam(4);
// movement amplitude in pixels
var dx = obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWCURRENTPOINT).x-obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWPREVIOUSPOINT).x;
var dy = obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWPREVIOUSPOINT).y-obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWCURRENTPOINT).y;
if (Math.abs(dx) > Math.abs(dy))
var delta = dx;
else delta = dy;
// update values
var msgCode = 0
if (mode & DlxApp.DYNAMICHOOK_SHIFT)
{
if (mode & DlxApp.DYNAMICHOOK_CTRL)
{
width += delta*0.5; // 0.5 degrees per pixel
msgCode = 4;
}
else
{
height += delta*0.5; // 0.5mm per pixel
msgCode = 1;
}
}
else if (mode & DlxApp.DYNAMICHOOK_CTRL)
{
radius += delta*0.5; // 0.5mm per pixel
msgCode = 2;
}
else if (mode & DlxApp.DYNAMICHOOK_ALT)
{
rotation = (Math.atan2(obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWPICKEDPOINT).y-obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWCURRENTPOINT).y,
obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWCURRENTPOINT).x-obj.GetHookPoint(DlxApp.DYNAMICHOOK_VIEWPICKEDPOINT).x))/Math.PI*180;
msgCode = 3;
}
else
{
rays += Math.round(delta/5); // one point every 5 pixels
msgCode = 0;
}
// limit values
rays = Math.limit(rays, 3, 36);
radius = Math.limit(radius, 1, 100);
height = Math.limit(height, -radius, 10 * radius);
width = Math.limit(width, 1, 360 / rays);
// save parameters for next step
obj.SetHookParam(0, rays);
obj.SetHookParam(1, height);
obj.SetHookParam(2, radius);
obj.SetHookParam(3, rotation);
obj.SetHookParam(4, width);
// message
var info = "";
switch (msgCode)
{
case 0:
info = DlxApp.Format("Number of star rays: %i", rays);
break;
case 1:
info = DlxApp.Format("Star ray height: %s", view.LengthToString(height, true));
break;
case 2:
info = DlxApp.Format("Radius: %s", view.LengthToString(radius, true));
break;
case 3:
info = DlxApp.Format("Rotation: %s", view.AngleToString(rotation, true));
break;
case 4:
info = DlxApp.Format("Star ray width: %s", view.AngleToString(width, true));
break;
}
obj.SetHookMessage(info + message);
var hs = new DlxPoint(obj.GetHookParam(5), obj.GetHookParam(6));
DrawShape(obj, hs, rays, height, radius, rotation, width);
}
}
|