Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation improvements #232

Merged
merged 8 commits into from
Apr 19, 2024
6 changes: 4 additions & 2 deletions docs/xml/modules/classes/vector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@
<method>
<name>NewMatrix</name>
<comment>Returns a VectorMatrix structure that allows transformations to be applied to the vector.</comment>
<prototype>ERR vecNewMatrix(OBJECTPTR Object, struct VectorMatrix ** Transform)</prototype>
<prototype>ERR vecNewMatrix(OBJECTPTR Object, struct VectorMatrix ** Transform, LONG End)</prototype>
<input>
<param type="struct VectorMatrix **" name="Transform">A reference to the new transform structure is returned here.</param>
<param type="LONG" name="End">If true, the matrix priority is lowered by inserting it at the end of the transform list.</param>
</input>
<description>
<p>Call NewMatrix() to allocate a transformation matrix that allows transforms to be applied to a vector. Manipulating the transformation matrix is supported by functions in the Vector module, such as <function module="Vector">Scale</function> and <function module="Vector">Rotate</function>.</p>
Expand Down Expand Up @@ -252,7 +253,7 @@
<param type="LONG" name="Transform">Set to TRUE if all transforms applicable to the vector should be applied to the path.</param>
</input>
<description>
<p>Any vector that generates a path can be traced by calling this method. Tracing allows the caller to follow the path from point-to-point if the path were to be rendered with a stroke. The prototype of the callback function is <code>ERR Function(OBJECTPTR Vector, LONG Index, LONG Command, DOUBLE X, DOUBLE Y, APTR Meta)</code>.</p>
<p>Any vector that generates a path can be traced by calling this method. Tracing allows the caller to follow the path from point-to-point if the path were to be rendered with a stroke. The prototype of the callback function is <code>ERR Function(OBJECTPTR Vector, LONG Index, LONG Command, DOUBLE X, DOUBLE Y, APTR Meta)</code>.</p>
<p>The Vector parameter refers to the vector targeted by the method. The Index is an incrementing counter that reflects the currently plotted point. The X and Y parameters reflect the coordinate of a point on the path.</p>
<p>If the Callback returns <code>ERR::Terminate</code>, then no further coordinates will be processed.</p>
</description>
Expand Down Expand Up @@ -800,6 +801,7 @@ Z: Close Path
<field name="ScaleY" type="DOUBLE">Matrix value D</field>
<field name="TranslateX" type="DOUBLE">Matrix value E</field>
<field name="TranslateY" type="DOUBLE">Matrix value F</field>
<field name="Tag" type="LONG">An optional tag value defined by the client for matrix identification.</field>
</struct>

</structs>
Expand Down
1 change: 1 addition & 0 deletions docs/xml/modules/classes/vectorgradient.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
<field name="ScaleY" type="DOUBLE">Matrix value D</field>
<field name="TranslateX" type="DOUBLE">Matrix value E</field>
<field name="TranslateY" type="DOUBLE">Matrix value F</field>
<field name="Tag" type="LONG">An optional tag value defined by the client for matrix identification.</field>
</struct>

</structs>
Expand Down
1 change: 1 addition & 0 deletions docs/xml/modules/classes/vectorpattern.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
<field name="ScaleY" type="DOUBLE">Matrix value D</field>
<field name="TranslateX" type="DOUBLE">Matrix value E</field>
<field name="TranslateY" type="DOUBLE">Matrix value F</field>
<field name="Tag" type="LONG">An optional tag value defined by the client for matrix identification.</field>
</struct>

</structs>
Expand Down
1 change: 1 addition & 0 deletions docs/xml/modules/classes/vectorviewport.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
<field name="ScaleY" type="DOUBLE">Matrix value D</field>
<field name="TranslateX" type="DOUBLE">Matrix value E</field>
<field name="TranslateY" type="DOUBLE">Matrix value F</field>
<field name="Tag" type="LONG">An optional tag value defined by the client for matrix identification.</field>
</struct>

<struct name="VectorPainter" comment="Deserialised painter information; compliant with SVG painter definitions.">
Expand Down
1 change: 1 addition & 0 deletions docs/xml/modules/vector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ Z: Close Path
<field name="ScaleY" type="DOUBLE">Matrix value D</field>
<field name="TranslateX" type="DOUBLE">Matrix value E</field>
<field name="TranslateY" type="DOUBLE">Matrix value F</field>
<field name="Tag" type="LONG">An optional tag value defined by the client for matrix identification.</field>
</struct>

<struct name="VectorPainter" comment="Deserialised painter information; compliant with SVG painter definitions.">
Expand Down
36 changes: 23 additions & 13 deletions include/parasol/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ namespace pf {

template <class T = double> struct POINT {
T x, y;

constexpr POINT<T> & operator += (const POINT &Other) {
x += Other.x;
y += Other.y;
return *this;
}
};

template <class T = double> bool operator==(const POINT<T> &a, const POINT<T> &b) {
return (a.x == b.x) and (a.y == b.y);
}

template <class T = double> T operator-(POINT<T> A, const POINT<T> &B) {
template <class T = double> T operator-(const POINT<T> A, const POINT<T> &B) {
if (A == B) return 0;
double a = std::abs(B.x - A.x);
double b = std::abs(B.y - A.y);
Expand All @@ -52,6 +58,10 @@ template <class T = double> T operator-(POINT<T> A, const POINT<T> &B) {
//return T(std::sqrt((a * a) + (b * b))); // Full accuracy
}

template <class T = double> POINT<T> operator * (const POINT<T> &lhs, const double &Multiplier) {
return POINT<T> { lhs.x * Multiplier, lhs.y * Multiplier };
}

//********************************************************************************************************************

DEFINE_ENUM_FLAG_OPERATORS(ERR)
Expand Down Expand Up @@ -429,7 +439,7 @@ inline FieldValue FileDescription(const std::string &Value) { return FieldValue(
constexpr FieldValue FileHeader(CSTRING Value) { return FieldValue(FID_FileHeader, Value); }
inline FieldValue FileHeader(const std::string &Value) { return FieldValue(FID_FileHeader, Value.c_str()); }

constexpr FieldValue FontSize(DOUBLE Value) { return FieldValue(FID_FontSize, Value); }
constexpr FieldValue FontSize(double Value) { return FieldValue(FID_FontSize, Value); }
constexpr FieldValue FontSize(LONG Value) { return FieldValue(FID_FontSize, Value); }
constexpr FieldValue FontSize(CSTRING Value) { return FieldValue(FID_FontSize, Value); }
inline FieldValue FontSize(const std::string &Value) { return FieldValue(FID_FontSize, Value.c_str()); }
Expand All @@ -452,7 +462,7 @@ constexpr FieldValue ReadOnly(bool Value) { return FieldValue(FID_ReadOnly, (Val
constexpr FieldValue ButtonOrder(CSTRING Value) { return FieldValue(FID_ButtonOrder, Value); }
inline FieldValue ButtonOrder(const std::string &Value) { return FieldValue(FID_ButtonOrder, Value.c_str()); }

constexpr FieldValue Point(DOUBLE Value) { return FieldValue(FID_Point, Value); }
constexpr FieldValue Point(double Value) { return FieldValue(FID_Point, Value); }
constexpr FieldValue Point(LONG Value) { return FieldValue(FID_Point, Value); }
constexpr FieldValue Point(CSTRING Value) { return FieldValue(FID_Point, Value); }
inline FieldValue Point(const std::string &Value) { return FieldValue(FID_Point, Value.c_str()); }
Expand All @@ -463,7 +473,7 @@ inline FieldValue Points(const std::string &Value) { return FieldValue(FID_Point
constexpr FieldValue Pretext(CSTRING Value) { return FieldValue(FID_Pretext, Value); }
inline FieldValue Pretext(const std::string &Value) { return FieldValue(FID_Pretext, Value.c_str()); }

constexpr FieldValue Acceleration(DOUBLE Value) { return FieldValue(FID_Acceleration, Value); }
constexpr FieldValue Acceleration(double Value) { return FieldValue(FID_Acceleration, Value); }
constexpr FieldValue Actions(CPTR Value) { return FieldValue(FID_Actions, Value); }
constexpr FieldValue AmtColours(LONG Value) { return FieldValue(FID_AmtColours, Value); }
constexpr FieldValue BaseClassID(LONG Value) { return FieldValue(FID_BaseClassID, Value); }
Expand All @@ -472,11 +482,11 @@ constexpr FieldValue BitsPerPixel(LONG Value) { return FieldValue(FID_BitsPerPix
constexpr FieldValue BytesPerPixel(LONG Value) { return FieldValue(FID_BytesPerPixel, Value); }
constexpr FieldValue Category(CCF Value) { return FieldValue(FID_Category, LONG(Value)); }
constexpr FieldValue ClassID(LONG Value) { return FieldValue(FID_ClassID, Value); }
constexpr FieldValue ClassVersion(DOUBLE Value) { return FieldValue(FID_ClassVersion, Value); }
constexpr FieldValue ClassVersion(double Value) { return FieldValue(FID_ClassVersion, Value); }
constexpr FieldValue Closed(bool Value) { return FieldValue(FID_Closed, (Value ? 1 : 0)); }
constexpr FieldValue Cursor(PTC Value) { return FieldValue(FID_Cursor, LONG(Value)); }
constexpr FieldValue DataFlags(MEM Value) { return FieldValue(FID_DataFlags, LONG(Value)); }
constexpr FieldValue DoubleClick(DOUBLE Value) { return FieldValue(FID_DoubleClick, Value); }
constexpr FieldValue DoubleClick(double Value) { return FieldValue(FID_DoubleClick, Value); }
constexpr FieldValue Feedback(CPTR Value) { return FieldValue(FID_Feedback, Value); }
constexpr FieldValue Fields(const FieldArray *Value) { return FieldValue(FID_Fields, Value, FD_ARRAY); }
constexpr FieldValue Flags(LONG Value) { return FieldValue(FID_Flags, Value); }
Expand All @@ -489,28 +499,28 @@ constexpr FieldValue Listener(LONG Value) { return FieldValue(FID_Listener, Valu
constexpr FieldValue MatrixColumns(LONG Value) { return FieldValue(FID_MatrixColumns, Value); }
constexpr FieldValue MatrixRows(LONG Value) { return FieldValue(FID_MatrixRows, Value); }
constexpr FieldValue MaxHeight(LONG Value) { return FieldValue(FID_MaxHeight, Value); }
constexpr FieldValue MaxSpeed(DOUBLE Value) { return FieldValue(FID_MaxSpeed, Value); }
constexpr FieldValue MaxSpeed(double Value) { return FieldValue(FID_MaxSpeed, Value); }
constexpr FieldValue MaxWidth(LONG Value) { return FieldValue(FID_MaxWidth, Value); }
constexpr FieldValue Methods(const MethodEntry *Value) { return FieldValue(FID_Methods, Value, FD_ARRAY); }
constexpr FieldValue Opacity(DOUBLE Value) { return FieldValue(FID_Opacity, Value); }
constexpr FieldValue Opacity(double Value) { return FieldValue(FID_Opacity, Value); }
constexpr FieldValue Owner(OBJECTID Value) { return FieldValue(FID_Owner, Value); }
constexpr FieldValue Parent(OBJECTID Value) { return FieldValue(FID_Parent, Value); }
constexpr FieldValue Permissions(PERMIT Value) { return FieldValue(FID_Permissions, LONG(Value)); }
constexpr FieldValue Picture(OBJECTPTR Value) { return FieldValue(FID_Picture, Value); }
constexpr FieldValue PopOver(OBJECTID Value) { return FieldValue(FID_PopOver, Value); }
constexpr FieldValue RefreshRate(DOUBLE Value) { return FieldValue(FID_RefreshRate, Value); }
constexpr FieldValue RefreshRate(double Value) { return FieldValue(FID_RefreshRate, Value); }
constexpr FieldValue Routine(CPTR Value) { return FieldValue(FID_Routine, Value); }
constexpr FieldValue Size(LONG Value) { return FieldValue(FID_Size, Value); }
constexpr FieldValue Speed(DOUBLE Value) { return FieldValue(FID_Speed, Value); }
constexpr FieldValue StrokeWidth(DOUBLE Value) { return FieldValue(FID_StrokeWidth, Value); }
constexpr FieldValue Speed(double Value) { return FieldValue(FID_Speed, Value); }
constexpr FieldValue StrokeWidth(double Value) { return FieldValue(FID_StrokeWidth, Value); }
constexpr FieldValue Surface(OBJECTID Value) { return FieldValue(FID_Surface, Value); }
constexpr FieldValue Target(OBJECTID Value) { return FieldValue(FID_Target, Value); }
constexpr FieldValue Target(OBJECTPTR Value) { return FieldValue(FID_Target, Value); }
constexpr FieldValue UserData(CPTR Value) { return FieldValue(FID_UserData, Value); }
constexpr FieldValue Version(DOUBLE Value) { return FieldValue(FID_Version, Value); }
constexpr FieldValue Version(double Value) { return FieldValue(FID_Version, Value); }
constexpr FieldValue Viewport(OBJECTID Value) { return FieldValue(FID_Viewport, Value); }
constexpr FieldValue Viewport(OBJECTPTR Value) { return FieldValue(FID_Viewport, Value); }
constexpr FieldValue WheelSpeed(DOUBLE Value) { return FieldValue(FID_WheelSpeed, Value); }
constexpr FieldValue WheelSpeed(double Value) { return FieldValue(FID_WheelSpeed, Value); }
constexpr FieldValue WindowHandle(APTR Value) { return FieldValue(FID_WindowHandle, Value); }
constexpr FieldValue WindowHandle(LONG Value) { return FieldValue(FID_WindowHandle, Value); }

Expand Down
13 changes: 10 additions & 3 deletions include/parasol/modules/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,15 @@ struct VectorMatrix {
DOUBLE ScaleY; // Matrix value D
DOUBLE TranslateX; // Matrix value E
DOUBLE TranslateY; // Matrix value F
LONG Tag; // An optional tag value defined by the client for matrix identification.
};

#define MTAG_ANIMATE_MOTION 0x8b929127
#define MTAG_ANIMATE_TRANSFORM 0x5374188d
#define MTAG_SCENE_GRAPH 0xacc188f2
#define MTAG_USE_TRANSFORM 0x35a3f7fb
#define MTAG_SVG_TRANSFORM 0x3479679e

struct FontMetrics {
LONG Height; // Capitalised font height
LONG LineSpacing; // Vertical advance from one line to the next
Expand Down Expand Up @@ -1570,7 +1577,7 @@ struct vecPointInPath { DOUBLE X; DOUBLE Y; };
struct vecSubscribeInput { JTYPE Mask; FUNCTION * Callback; };
struct vecSubscribeKeyboard { FUNCTION * Callback; };
struct vecSubscribeFeedback { FM Mask; FUNCTION * Callback; };
struct vecNewMatrix { struct VectorMatrix * Transform; };
struct vecNewMatrix { struct VectorMatrix * Transform; LONG End; };
struct vecFreeMatrix { struct VectorMatrix * Matrix; };

inline ERR vecPush(APTR Ob, LONG Position) noexcept {
Expand Down Expand Up @@ -1615,8 +1622,8 @@ inline ERR vecSubscribeFeedback(APTR Ob, FM Mask, FUNCTION * Callback) noexcept

#define vecDebug(obj) Action(MT_VecDebug,(obj),0)

inline ERR vecNewMatrix(APTR Ob, struct VectorMatrix ** Transform) noexcept {
struct vecNewMatrix args = { (struct VectorMatrix *)0 };
inline ERR vecNewMatrix(APTR Ob, struct VectorMatrix ** Transform, LONG End) noexcept {
struct vecNewMatrix args = { (struct VectorMatrix *)0, End };
ERR error = Action(MT_VecNewMatrix, (OBJECTPTR)Ob, &args);
if (Transform) *Transform = args.Transform;
return(error);
Expand Down
12 changes: 6 additions & 6 deletions scripts/vfx.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ vfx.zoomIn = function(Viewport, Seconds, Delay, CallbackOnCompletion)
local state = { name = 'zoomIn', seconds = nz(Seconds, 1.0), delay = nz(Delay, 0), callback = CallbackOnCompletion }

local err
err, state.matrix = Viewport.mtNewMatrix()
err, state.matrix = Viewport.mtNewMatrix(false)
mVector.Translate(state.matrix, Viewport.width*0.5, Viewport.height*0.5)
mVector.Scale(state.matrix, value, value)
mVector.Translate(state.matrix, -Viewport.width*0.5, -Viewport.height*0.5)
Expand Down Expand Up @@ -196,7 +196,7 @@ vfx.zoomOut = function(Viewport, Seconds, Delay, CallbackOnCompletion)
local state = { name = 'zoomOut', seconds = nz(Seconds, 1.0), delay = nz(Delay, 0), callback = CallbackOnCompletion }

local err
err, state.matrix = Viewport.mtNewMatrix()
err, state.matrix = Viewport.mtNewMatrix(false)
mVector.Translate(state.matrix, Viewport.width*0.5, Viewport.height*0.5)
mVector.Scale(state.matrix, value, value)
mVector.Translate(state.matrix, -Viewport.width*0.5, -Viewport.height*0.5)
Expand Down Expand Up @@ -251,7 +251,7 @@ vfx.shake = function(Viewport, Seconds, Delay, Intensity, CallbackOnCompletion)
if (SHAKES < 1) then SHAKES = 1 end

local err
err, state.matrix = Viewport.mtNewMatrix()
err, state.matrix = Viewport.mtNewMatrix(false)
err, state.timerID = mSys.SubscribeTimer(1*vfx.fps, function(Subscriber, Elapsed, CurrentTime)
if not Viewport.exists() then check(ERR_Terminate) end

Expand Down Expand Up @@ -298,7 +298,7 @@ vfx.rotate = function(Viewport, Seconds, Delay, CallbackOnCompletion)
local state = { name = 'rotate', seconds = nz(Seconds, 1.0), delay = nz(Delay, 0), callback = CallbackOnCompletion }

local err
err, state.matrix = Viewport.mtNewMatrix()
err, state.matrix = Viewport.mtNewMatrix(false)
err, state.timerID = mSys.SubscribeTimer(1*vfx.fps, function(Subscriber, Elapsed, CurrentTime)
if not Viewport.exists() then check(ERR_Terminate) end

Expand Down Expand Up @@ -333,7 +333,7 @@ end
vfx.wipes.simple.init = function(State, Options)
if (Options.rotate) then
local err
err, State.matrix = State.clip_path.mtNewMatrix()
err, State.matrix = State.clip_path.mtNewMatrix(false)
mVector.Rotate(State.matrix, Options.rotate, State.v_width * 0.5, State.v_height * 0.5)
end
end
Expand Down Expand Up @@ -516,7 +516,7 @@ end
vfx.wipes.shutter.init = function(State, Options)
if (Options.rotate) then
local err
err, State.matrix = State.clip_path.mtNewMatrix()
err, State.matrix = State.clip_path.mtNewMatrix(false)
mVector.Rotate(State.matrix, Options.rotate, State.v_width * 0.5, State.v_height * 0.5)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/core/data_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const CSTRING glMessages[LONG(ERR::END)+1] = {
"It is not possible to perform the requested operation.",
"Failed to resolve a linked library symbol.",
"A function call failed.",
"Attempted to change a value that cannot be redefined.",
"Re-definition is not permitted.",
"Attempted to set a numeric field with an incompatible value.",
"Attempted to set a string field with an incompatible value.",
"Attempted to set an object field with an incompatible value.",
Expand Down
2 changes: 1 addition & 1 deletion src/document/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ static ERR inputevent_button(objVectorViewport *Viewport, const InputEvent *Even

if (!button->viewport->Matrices) {
VectorMatrix *matrix;
vecNewMatrix(*button->viewport, &matrix);
vecNewMatrix(*button->viewport, &matrix, false);
}

const auto width = button->viewport->get<DOUBLE>(FID_Width);
Expand Down
Loading
Loading