diff --git a/packages/runtime/src/graphics/PortugolGraphicsContext.ts b/packages/runtime/src/graphics/PortugolGraphicsContext.ts index 522ec260..b483df00 100644 --- a/packages/runtime/src/graphics/PortugolGraphicsContext.ts +++ b/packages/runtime/src/graphics/PortugolGraphicsContext.ts @@ -567,6 +567,25 @@ class PortugolGraphicsContext { } }); } + + drawLine(x1, y1, x2, y2) { + this.drawCall(() => { + if (this.canvasContext) { + this.applyWorkParams(false, { + x: Math.min(x1, x2), + y: Math.min(y1, y2), + width: Math.abs(x2 - x1), + height: Math.abs(y2 - y1), + }); + + this.canvasContext.beginPath(); + this.canvasContext.moveTo(x1, y1); + this.canvasContext.lineTo(x2, y2); + this.canvasContext.closePath(); + this.canvasContext.stroke(); + } + }); + } } //endregion `; diff --git a/packages/runtime/src/libs/Graficos.ts b/packages/runtime/src/libs/Graficos.ts index 14bc1f88..bcea797c 100644 --- a/packages/runtime/src/libs/Graficos.ts +++ b/packages/runtime/src/libs/Graficos.ts @@ -325,6 +325,17 @@ export default /* javascript */ `{ self.graphics.drawText(x.getValue(), y.getValue(), texto.getValue()); }, + desenhar_linha(x1, y1, x2, y2) { + self.runtime.expectType("desenhar_linha", "x1", x1, "inteiro", "real"); + self.runtime.expectType("desenhar_linha", "y1", y1, "inteiro", "real"); + self.runtime.expectType("desenhar_linha", "x2", x2, "inteiro", "real"); + self.runtime.expectType("desenhar_linha", "y2", y2, "inteiro", "real"); + + self.runtime.assertGraphicsContext(); + + self.graphics.drawLine(x1.getValue(), y1.getValue(), x2.getValue(), y2.getValue()); + }, + altura_imagem(endereco) { self.runtime.expectType("altura_imagem", "endereco", endereco, "inteiro"); self.runtime.unimplementedMethod("altura_imagem", "Graficos");