Skip to content

Commit

Permalink
Remoção do package @portugol-webstudio/graphics e migração dos seus a…
Browse files Browse the repository at this point in the history
…rquivos para o @portugol-webstudio/runtime
  • Loading branch information
dngadelha committed Jan 5, 2025
1 parent 55249d5 commit 2301278
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 101 deletions.
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"build:parser": "lerna run build --scope=@portugol-webstudio/parser",
"build:runner": "lerna run build --scope=@portugol-webstudio/runner",
"build:runtime": "lerna run build --scope=@portugol-webstudio/runtime",
"build:graphics": "lerna run build --scope=@portugol-webstudio/graphics",
"test:parser": "lerna run test --scope=@portugol-webstudio/parser",
"release": "lerna run release",
"postinstall": "patch-package"
Expand Down
1 change: 0 additions & 1 deletion packages/graphics/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions packages/graphics/.npmignore

This file was deleted.

3 changes: 0 additions & 3 deletions packages/graphics/README.md

This file was deleted.

44 changes: 0 additions & 44 deletions packages/graphics/package.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/graphics/src/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/graphics/tsconfig.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/ide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"@portugol-webstudio/resources": "*",
"@portugol-webstudio/runner": "*",
"@portugol-webstudio/runtime": "*",
"@portugol-webstudio/graphics": "*",
"@sentry/angular": "^8.47.0",
"angular-split": "^18.0.0",
"angular-svg-icon": "^19.1.0",
Expand Down
14 changes: 12 additions & 2 deletions packages/ide/src/app/tab-editor/tab-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from "@angular/core";
import { MatSnackBar } from "@angular/material/snack-bar";
import type { PortugolCodeError } from "@portugol-webstudio/antlr";
import { GraphicsContext } from "@portugol-webstudio/graphics";
import { PortugolExecutor, PortugolWebWorkersRunner } from "@portugol-webstudio/runner";
import { PortugolGraphicsContext } from "@portugol-webstudio/runtime";
import { captureException, setExtra } from "@sentry/angular";
import { saveAs } from "file-saver";
import { encode } from "iconv-lite";
Expand Down Expand Up @@ -64,7 +64,7 @@ export class TabEditorComponent implements OnInit, OnDestroy {

transpiling = false;
executor = new PortugolExecutor(PortugolWebWorkersRunner);
graphicsContext = new GraphicsContext(this.executor);
graphicsContext = new PortugolGraphicsContext();

codeEditor?: monaco.editor.IStandaloneCodeEditor;

Expand Down Expand Up @@ -194,6 +194,16 @@ export class TabEditorComponent implements OnInit, OnDestroy {
wordWrap: wordWrap ? "on" : "off",
};
});

this.graphicsContext.addEventListener("close", event => {
if (event instanceof CustomEvent && event.detail.userClose && this.executor.running) {
this.executor.stop();
}
});

this.graphicsContext.addEventListener("rendered", () => {
this.executor.postMessage({ type: "graphics-rendered" });
});
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { PortugolExecutor } from "@portugol-webstudio/runner";
import { PortugolGraphicsDrawCall } from "./PortugolGraphicsDrawCall";

type DrawCallFunction = () => void;

export class GraphicsContext {
export class PortugolGraphicsContext extends EventTarget {
window: Window | null = null;
canvas: HTMLCanvasElement | null = null;
canvasContext: CanvasRenderingContext2D | null = null;

private _executor: PortugolExecutor;
private _title = "";

private _width = 800;
Expand All @@ -16,11 +13,7 @@ export class GraphicsContext {
private _workingColor = 0;
private _workingOpacity = 255;

private _drawCalls: DrawCallFunction[] = [];

constructor(executor: PortugolExecutor) {
this._executor = executor;
}
private _drawCalls: PortugolGraphicsDrawCall[] = [];

/**
* Inicializa o contexto gráfico.
Expand All @@ -37,8 +30,7 @@ export class GraphicsContext {
this.window.document.body.style.overflow = "hidden";

this.window.addEventListener("beforeunload", () => {
this.destroy();
this._executor?.stop();
this.destroy(true);
});

this.canvas = this.window.document.createElement("canvas");
Expand All @@ -47,6 +39,15 @@ export class GraphicsContext {
this.window.document.body.append(this.canvas);

this.canvasContext = this.canvas.getContext("2d");

this.onInit();
}

/**
* Função chamada quando o contexto gráfico é inicializado.
*/
private onInit() {
this.dispatchEvent(new Event("init"));
}

/**
Expand All @@ -59,12 +60,21 @@ export class GraphicsContext {
/**
* Fecha a janela.
*/
closeWindow() {
closeWindow(userClose = false) {
try {
if (this.window) {
this.window.close();
}
} catch {}

this.onWindowClose(userClose);
}

/**
* Função chamada quando a janela é fechada.
*/
private onWindowClose(userClose = false) {
this.dispatchEvent(new CustomEvent("close", { detail: { userClose } }));
}

/**
Expand All @@ -86,8 +96,8 @@ export class GraphicsContext {
/**
* Destroi o contexto gráfico.
*/
destroy() {
this.closeWindow();
destroy(userClose = false) {
this.closeWindow(userClose);
this.canvas = null;
this.canvasContext = null;
this.window = null;
Expand Down Expand Up @@ -270,7 +280,7 @@ export class GraphicsContext {
* Função interna para adicionar um desenho na lista de chamadas.
* @param drawFunc Função de desenho.
*/
private drawCall(drawFunc: DrawCallFunction) {
private drawCall(drawFunc: PortugolGraphicsDrawCall) {
this._drawCalls.push(drawFunc);
}

Expand Down Expand Up @@ -298,11 +308,17 @@ export class GraphicsContext {
this._drawCalls = [];
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this._executor.postMessage({ type: "graphics-rendered" });
this.onRendered();
});
}

/**
* Função chamada quando a tela é renderizada.
*/
private onRendered() {
this.dispatchEvent(new Event("rendered"));
}

/**
* Limpa a tela.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime/src/graphics/PortugolGraphicsDrawCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Representa uma chamada de desenho de gráficos.
*/
export type PortugolGraphicsDrawCall = () => void;
2 changes: 2 additions & 0 deletions packages/runtime/src/graphics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./PortugolGraphicsContext.js";
export * from "./PortugolGraphicsDrawCall.js";
1 change: 1 addition & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./graphics/index.js";
export * from "./PortugolJs.js";
export { runtime as PortugolJsRuntime } from "./runtime/index.js";

0 comments on commit 2301278

Please sign in to comment.