Goblin-King
September 12th, 2008, 08:29
The 2.2.0 version of Fantasy Grounds allows the definition of custom pointer types in the ruleset. You can create any shape that can be defined using a series of spline curves defined using four control points.
488
To accomplish this, you need to include a <pointertypes> element in your imagecontrol definition:
<pointertypes>
<arrow>
<icon>pointer</icon>
<label>Draw Arrow</label>
</arrow>
<custom name="my_cone">
<icon>pointer_cone</icon>
<label>Draw Cone</label>
</custom>
</pointertypes>
Doing this resets the selection of pointer types. If you want to preserve the original selection of pointer types, use the subelements arrow, circle, rectangle or cone (the example adds the basic arrow). The custom element adds a new type.
When pointers of a custom type are created or modified, a new script event will be fired to build the list of control points.
function transformSpline(spline, angle, centerx, centery)
for segmentindex, segment in ipairs(spline) do
for controlpointindex, controlpoint in ipairs(segment) do
local x = controlpoint[1];
local y = controlpoint[2];
local nx = (x-centerx) * math.cos(angle) -
(y-centery) * math.sin(angle) + centerx;
local ny = (x-centerx) * math.sin(angle) +
(y-centery) * math.cos(angle) + centery;
segment[controlpointindex] = { nx, ny };
end
end
end
function onBuildCustomPointer(startx, starty, endx, endy, type)
local segments = {};
local distpos;
local drawarrow;
local u = 32;
if hasGrid() then
u = getGridSize();
end
local angle = math.atan2(endx - startx, - endy + starty);
if type == "my_cone" then
-- Build a cone facing in the negative y direction
local segment = { { startx, starty },
{ startx, starty },
{ startx - 1.5*u, starty - 6.5*u },
{ startx - 1.5*u, starty - 7.5*u } };
table.insert(segments, segment);
local segment = { { startx - 1.5*u, starty - 7.5*u },
{ startx - 1.5*u, starty - 8.25*u },
{ startx - 0.75*u, starty - 9*u },
{ startx, starty - 9*u } };
table.insert(segments, segment);
local segment = { { startx, starty },
{ startx, starty },
{ startx + 1.5*u, starty - 6.5*u },
{ startx + 1.5*u, starty - 7.5*u } };
table.insert(segments, segment);
local segment = { { startx + 1.5*u, starty - 7.5*u },
{ startx + 1.5*u, starty - 8.25*u },
{ startx + 0.75*u, starty - 9*u },
{ startx, starty - 9*u } };
table.insert(segments, segment);
-- Set the distance indicator position (in pixels)
distpos = { 30, 30 };
end
-- Transform it to match angle
transformSpline(segments, angle, startx, starty);
return segments, distpos, drawarrow;
end
The script snippet provides a useful utility function that allows you to make the definition for the shape in the negative y direction (i.e. up) and transform it to match the orientation of the pointer.
The onBuildCustomPointer event can return three values. The first is the list of spline segments, the second is a table of two values that specify where the length of the pointer should be drawn relative to its origin (given by onMeasurePointer), and the third a boolean value indicating whether to end the pointer with an arrowhead pointing in the direction of the last segment.
Please keep in mind that very complex shapes can cause performance issues on slower computers.
Custom pointers don't support grid shading at this time, we're looking into this possibility.
488
To accomplish this, you need to include a <pointertypes> element in your imagecontrol definition:
<pointertypes>
<arrow>
<icon>pointer</icon>
<label>Draw Arrow</label>
</arrow>
<custom name="my_cone">
<icon>pointer_cone</icon>
<label>Draw Cone</label>
</custom>
</pointertypes>
Doing this resets the selection of pointer types. If you want to preserve the original selection of pointer types, use the subelements arrow, circle, rectangle or cone (the example adds the basic arrow). The custom element adds a new type.
When pointers of a custom type are created or modified, a new script event will be fired to build the list of control points.
function transformSpline(spline, angle, centerx, centery)
for segmentindex, segment in ipairs(spline) do
for controlpointindex, controlpoint in ipairs(segment) do
local x = controlpoint[1];
local y = controlpoint[2];
local nx = (x-centerx) * math.cos(angle) -
(y-centery) * math.sin(angle) + centerx;
local ny = (x-centerx) * math.sin(angle) +
(y-centery) * math.cos(angle) + centery;
segment[controlpointindex] = { nx, ny };
end
end
end
function onBuildCustomPointer(startx, starty, endx, endy, type)
local segments = {};
local distpos;
local drawarrow;
local u = 32;
if hasGrid() then
u = getGridSize();
end
local angle = math.atan2(endx - startx, - endy + starty);
if type == "my_cone" then
-- Build a cone facing in the negative y direction
local segment = { { startx, starty },
{ startx, starty },
{ startx - 1.5*u, starty - 6.5*u },
{ startx - 1.5*u, starty - 7.5*u } };
table.insert(segments, segment);
local segment = { { startx - 1.5*u, starty - 7.5*u },
{ startx - 1.5*u, starty - 8.25*u },
{ startx - 0.75*u, starty - 9*u },
{ startx, starty - 9*u } };
table.insert(segments, segment);
local segment = { { startx, starty },
{ startx, starty },
{ startx + 1.5*u, starty - 6.5*u },
{ startx + 1.5*u, starty - 7.5*u } };
table.insert(segments, segment);
local segment = { { startx + 1.5*u, starty - 7.5*u },
{ startx + 1.5*u, starty - 8.25*u },
{ startx + 0.75*u, starty - 9*u },
{ startx, starty - 9*u } };
table.insert(segments, segment);
-- Set the distance indicator position (in pixels)
distpos = { 30, 30 };
end
-- Transform it to match angle
transformSpline(segments, angle, startx, starty);
return segments, distpos, drawarrow;
end
The script snippet provides a useful utility function that allows you to make the definition for the shape in the negative y direction (i.e. up) and transform it to match the orientation of the pointer.
The onBuildCustomPointer event can return three values. The first is the list of spline segments, the second is a table of two values that specify where the length of the pointer should be drawn relative to its origin (given by onMeasurePointer), and the third a boolean value indicating whether to end the pointer with an arrowhead pointing in the direction of the last segment.
Please keep in mind that very complex shapes can cause performance issues on slower computers.
Custom pointers don't support grid shading at this time, we're looking into this possibility.