diff options
Diffstat (limited to 'src/nanovg.cpp')
-rw-r--r-- | src/nanovg.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/nanovg.cpp b/src/nanovg.cpp index f1d1702..95bba7d 100644 --- a/src/nanovg.cpp +++ b/src/nanovg.cpp @@ -179,7 +179,7 @@ static real32 * NVG_ButtCap(nvg_point *Point, real32 *StrokeData, static uint32 NVG_FlattenPath(memory *Memory, shape_layer *Shape, shape_options ShapeOpt, nvg_point *PointData, project_state *State, layer_transforms T, int Width, int Height, - int CompWidth, int CompHeight, bool32 Interact, v2 *Min, v2 *Max) + int CompWidth, int CompHeight, bool32 Interact, v2 *Min, v2 *Max, bool32 *IsConvex) { nvg_point *PointPlayhead = PointData; bezier_point *BezierPointData = (bezier_point *)Memory_PushScratch(Memory, sizeof(bezier_point) * 128); @@ -226,13 +226,29 @@ NVG_FlattenPath(memory *Memory, shape_layer *Shape, shape_options ShapeOpt, nvg_ Min->y = Point->y; Point = NextPoint++; } + // Tell whether we need concave filling or not. ExpandStroke also does this. + if (ShapeOpt.Visibility == 2) { + Point = &PointData[NumberOfVerts - 1]; + NextPoint = PointData; + int LeftCount = 0; + for (int i = 0; i < NumberOfVerts; i++) { + real32 cross = NextPoint->dx * Point->dy - Point->dx * NextPoint->dy; + if (cross > 0.0f) { + LeftCount++; + } + Point = NextPoint++; + } + if (LeftCount == NumberOfVerts) + *IsConvex = true; + } + return NumberOfVerts; } real32 MiterLimit = 2.4f; static uint32 -NVG_ExpandStroke(void *Memory, int NumberOfVerts, real32 StartWidth, nvg_line_cap LineCap, nvg_line_cap LineJoin, bool32 IsClosed, nvg_point *PointData, real32 *StrokeData) +NVG_ExpandStroke(void *Memory, int NumberOfVerts, real32 StartWidth, nvg_line_cap LineCap, nvg_line_cap LineJoin, bool32 IsClosed, nvg_point *PointData, real32 *StrokeData, bool32 *IsConvex) { real32 Width = StartWidth * 0.5; int ncap = 12; @@ -254,6 +270,7 @@ NVG_ExpandStroke(void *Memory, int NumberOfVerts, real32 StartWidth, nvg_line_ca StrokeData = NVG_ButtCap(Point, StrokeData, Point->dx, Point->dy, Width, Width-1, 0.5, 0.5, 0); } } + int LeftCount = 0; for (int i = Start; i < LoopAmount; i++) { @@ -282,6 +299,7 @@ NVG_ExpandStroke(void *Memory, int NumberOfVerts, real32 StartWidth, nvg_line_ca // Keep track of left turns. cross = NextPoint->dx * Point->dy - Point->dx * NextPoint->dy; if (cross > 0.0f) { + LeftCount++; NextPoint->Flags |= NVG_PT_LEFT; } @@ -309,6 +327,8 @@ NVG_ExpandStroke(void *Memory, int NumberOfVerts, real32 StartWidth, nvg_line_ca Point = NextPoint++; } + if (LeftCount == LoopAmount) + *IsConvex = true; if (!IsClosed) { if (LineCap == NVG_ROUND) { @@ -321,6 +341,7 @@ NVG_ExpandStroke(void *Memory, int NumberOfVerts, real32 StartWidth, nvg_line_ca StrokeData = NVG_Point(StrokeData, StartingStrokeData[4], StartingStrokeData[5], 0, 0); } + int GL_PointCount = (StrokeData - StartingStrokeData) / 4; return GL_PointCount; |