Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit f1be22d

Browse files
committed
[[ Canvas ]] Change "list of Foo" to "list" in foreign handler signatures
[[ Canvas ]] Implement hash & isequal for MCCanvasPathRef type
1 parent dcd8bdd commit f1be22d

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

engine/src/canvas.mlc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ end syntax
469469
// Constructors
470470

471471
public foreign handler MCCanvasGradientStopMake(in pOffset as CanvasFloat, in pColor as Color, out rStop as GradientStop) as undefined binds to "<builtin>"
472-
public foreign handler MCCanvasGradientMakeWithRamp(in pType as integer, in pRamp as list of GradientStop, out rGradient as Gradient) as undefined binds to "<builtin>"
472+
public foreign handler MCCanvasGradientMakeWithRamp(in pType as integer, in pRamp as list, out rGradient as Gradient) as undefined binds to "<builtin>"
473473

474474
syntax MakeGradientStop is prefix operator with precedence 4
475475
"gradient" "stop" "at" <mOffset: Expression> "with" <mColor: Expression>
@@ -505,10 +505,10 @@ public foreign handler MCCanvasGradientStopSetOffset(in pOffset as CanvasFloat,
505505
public foreign handler MCCanvasGradientStopGetColor(in pStop as GradientStop, out rColor as Color) as undefined binds to "<builtin>"
506506
public foreign handler MCCanvasGradientStopSetColor(in pColor as Color, inout xStop as GradientStop) as undefined binds to "<builtin>"
507507

508-
public foreign handler MCCanvasGradientGetRamp(in pGradient as Gradient, out rRamp as list of GradientStop) as undefined binds to "<builtin>"
509-
public foreign handler MCCanvasGradientSetRamp(in pRamp as list of GradientStop, inout xGradient as Gradient) as undefined binds to "<builtin>"
510-
// public foreign handler MCCanvasGradientGetStops(in pGradient as Gradient, in pStart as integer, in pEnd as integer, out rStops as list of GradientStop) as undefined binds to "<builtin>"
511-
// public foreign handler MCCanvasGradientSetStops(in pStart as integer, in pEnd as integer, in rStops as list of GradientStop, inout xGradient as Gradient) as undefined binds to "<builtin>"
508+
public foreign handler MCCanvasGradientGetRamp(in pGradient as Gradient, out rRamp as list) as undefined binds to "<builtin>"
509+
public foreign handler MCCanvasGradientSetRamp(in pRamp as list, inout xGradient as Gradient) as undefined binds to "<builtin>"
510+
// public foreign handler MCCanvasGradientGetStops(in pGradient as Gradient, in pStart as integer, in pEnd as integer, out rStops as list) as undefined binds to "<builtin>"
511+
// public foreign handler MCCanvasGradientSetStops(in pStart as integer, in pEnd as integer, in rStops as list, inout xGradient as Gradient) as undefined binds to "<builtin>"
512512
public foreign handler MCCanvasGradientGetTypeAsString(in pGradient as Gradient, out rType as string) as undefined binds to "<builtin>"
513513
public foreign handler MCCanvasGradientSetTypeAsString(in pType as string, inout xGradient as Gradient) as undefined binds to "<builtin>"
514514
public foreign handler MCCanvasGradientGetRepeat(in pGradient as Gradient, out rRepeat as integer) as undefined binds to "<builtin>"

engine/src/module-canvas.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,14 +2783,32 @@ static bool __MCCanvasPathEqual(MCValueRef p_left, MCValueRef p_right)
27832783
if (p_left == p_right)
27842784
return true;
27852785

2786-
// TODO - implememt MCGPath comparison
2787-
return MCCanvasPathGetMCGPath((MCCanvasPathRef)p_left) == MCCanvasPathGetMCGPath((MCCanvasPathRef)p_right);
2786+
return MCGPathIsEqualTo(MCCanvasPathGetMCGPath(p_left), MCCanvasPathGetMCGPath(p_right));
2787+
}
2788+
2789+
bool __MCCanvasPathHashCallback(void *p_context, MCGPathCommand p_command, MCGPoint *p_points, uint32_t p_point_count)
2790+
{
2791+
hash_t *t_hash;
2792+
t_hash = static_cast<hash_t*>(p_context);
2793+
2794+
t_hash ^= MCHashInteger(p_command);
2795+
for (uint32_t i = 0; i < p_point_count; i++)
2796+
{
2797+
t_hash ^= MCHashDouble(p_points[i].x);
2798+
t_hash ^= MCHashDouble(p_points[i].y);
2799+
}
2800+
2801+
return true;
27882802
}
27892803

27902804
static hash_t __MCCanvasPathHash(MCValueRef p_value)
27912805
{
2792-
// TODO - implement MCGPath hash
2793-
return MCHashBytes(MCValueGetExtraBytesPtr(p_value), sizeof(__MCCanvasPathImpl));
2806+
hash_t t_hash;
2807+
t_hash = 0;
2808+
2809+
/* UNCHECKED */ MCGPathIterate(MCCanvasPathGetMCGPath((MCCanvasPathRef)p_value), __MCCanvasPathHashCallback, &t_hash);
2810+
2811+
return t_hash;
27942812
}
27952813

27962814
static bool __MCCanvasPathDescribe(MCValueRef p_value, MCStringRef &r_desc)

libgraphics/include/graphics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ void MCGPathRelease(MCGPathRef path);
735735

736736
bool MCGPathIsValid(MCGPathRef path);
737737
bool MCGPathIsEmpty(MCGPathRef path);
738+
bool MCGPathIsEqualTo(MCGPathRef a, MCGPathRef b);
738739

739740
void MCGPathCopy(MCGPathRef path, MCGPathRef& r_new_path);
740741
void MCGPathCopyAndRelease(MCGPathRef path, MCGPathRef& r_new_path);

libgraphics/src/path.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ bool MCGPathIsEmpty(MCGPathRef self)
109109
return self -> path -> isEmpty();
110110
}
111111

112+
bool MCGPathIsEqualTo(MCGPathRef a, MCGPathRef b)
113+
{
114+
return *a->path == *b->path;
115+
}
116+
112117
////////////////////////////////////////////////////////////////////////////////
113118

114119
void MCGPathCopy(MCGPathRef self, MCGPathRef& r_new_path)

0 commit comments

Comments
 (0)