From 8119a695722c0aa78a2215bbde35c0a3e45e2cdb Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 16 Oct 2015 10:46:26 -0400 Subject: [PATCH] Implemented dashing on Windows. --- ui.h | 1 + windows/draw.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui.h b/ui.h index 82f1e735..3eb95129 100644 --- a/ui.h +++ b/ui.h @@ -377,6 +377,7 @@ struct uiDrawBrushGradientStop { struct uiDrawStrokeParams { uiDrawLineCap Cap; uiDrawLineJoin Join; + // TODO what if this is 0? on windows there will be a crash with dashing double Thickness; double MiterLimit; double *Dashes; diff --git a/windows/draw.c b/windows/draw.c index 5c7bf41e..0cf82302 100644 --- a/windows/draw.c +++ b/windows/draw.c @@ -552,6 +552,8 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP ID2D1Brush *brush; ID2D1StrokeStyle *style; D2D1_STROKE_STYLE_PROPERTIES dsp; + FLOAT *dashes; + size_t i; ID2D1Layer *cliplayer; HRESULT hr; @@ -588,14 +590,25 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP break; } dsp.dashStyle = D2D1_DASH_STYLE_SOLID; - dsp.dashOffset = 0; + dashes = NULL; + // note that dash widths and the dash phase are scaled up by the thickness by Direct2D + // TODO be sure to formally document this + if (sp->NumDashes != 0) { + dsp.dashStyle = D2D1_DASH_STYLE_CUSTOM; + dashes = (FLOAT *) uiAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]"); + for (i = 0; i < sp->NumDashes; i++) + dashes[i] = sp->Dashes[i] / sp->Thickness; + } + dsp.dashOffset = sp->DashPhase / sp->Thickness; hr = ID2D1Factory_CreateStrokeStyle(d2dfactory, &dsp, - NULL, - 0, + dashes, + sp->NumDashes, &style); if (hr != S_OK) logHRESULT("error creating stroke style in uiDrawStroke()", hr); + if (dashes != NULL) + uiFree(dashes); cliplayer = applyClip(c); ID2D1RenderTarget_DrawGeometry(c->rt,