DIM s AS STRING = $"<html>"
s += "<body style='margin:0; padding:0; overflow:auto;'>"
s += $"<canvas id='cv' width='" & STR(cvWidth) & "' height='" & STR(cvHeight) & "'></canvas>"
s += $"</body>"
s += $"</html>"
DIM JS_INIT AS STRING = $"var cv, ctx;"
JS_INIT += "window.onload = function() {"
JS_INIT += " cv = document.getElementById('cv');"
JS_INIT += " ctx = cv.getContext('2d');"
JS_INIT += "};"
IF this.IsReady THEN
this.AddScriptToExecuteOnDocumentCreated(JS_INIT, NULL)
this.NavigateToString(s)
END IF
DIM pCanvas AS CWebView2Canvas = CWebView2Canvas(hWin, dwsUserDataFolder)
...
...
pCanvas->DrawText("Hello World", 100, 100, "red", 40)
pCanvas->DrawLine(50, 50, 300, 200, "blue", 4)
pCanvas->DrawCircle(200, 200, 50, "purple", 3)
' ========================================================================================
' Draws a circle.
' x, y : coordinates
' radius; Radius
' clr: The color of the pen
' nWidth : The width of the pen
' ========================================================================================
PRIVATE SUB CWebView2Canvas.DrawCircle( _
BYVAL x AS SINGLE, BYVAL y AS SINGLE, _
BYVAL radius AS SINGLE, _
BYREF clr AS STRING, _
BYVAL nWidth AS LONG = 1)
' // Make sure that the JS function exists
IF m_hasDrawCircle = FALSE THEN
DIM js AS STRING
js = _
"function drawCircle(x, y, radius, color, width) {" _
& " ctx.strokeStyle = color;" _
& " ctx.lineWidth = width;" _
& " ctx.beginPath();" _
& " ctx.arc(x, y, radius, 0, Math.PI * 2);" _
& " ctx.stroke();" _
& "}"
this.ExecuteScript(js, NULL)
m_hasDrawCircle = TRUE
END IF
' // Call the JS function
DIM js AS STRING
js = "drawCircle(" _
& STR(x) & "," & STR(y) & "," _
& STR(radius) & ",'" _
& clr & "'," & STR(nWidth) & ");"
this.ExecuteScript(js, NULL)
END SUB
' ========================================================================================

pCanvas->DrawText("Hello World", 100, 100, "red", 40)
pCanvas->DrawLine(50, 50, 300, 200, "blue", 4)
pCanvas->DrawCircle(200, 200, 50, "purple", 3)