mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
Move setOutputAreaSize
This commit is contained in:
27
js/Canvas.js
27
js/Canvas.js
@@ -330,33 +330,10 @@ export class Canvas {
|
||||
}
|
||||
/**
|
||||
* Ustawia nowy rozmiar output area zgodnie z nowym systemem (resetuje rozszerzenia, pozycję, rozmiar)
|
||||
* (Fasada: deleguje do CanvasLayers)
|
||||
*/
|
||||
setOutputAreaSize(width, height) {
|
||||
// Reset rozszerzeń
|
||||
this.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
this.outputAreaExtensionEnabled = false;
|
||||
this.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
// Oblicz środek obecnego output area
|
||||
const prevBounds = this.outputAreaBounds;
|
||||
const centerX = prevBounds.x + prevBounds.width / 2;
|
||||
const centerY = prevBounds.y + prevBounds.height / 2;
|
||||
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
|
||||
const newX = centerX - width / 2;
|
||||
const newY = centerY - height / 2;
|
||||
// Ustaw nowy rozmiar bazowy i pozycję
|
||||
this.originalCanvasSize = { width, height };
|
||||
this.originalOutputAreaPosition = { x: newX, y: newY };
|
||||
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
|
||||
this.outputAreaBounds = {
|
||||
x: newX,
|
||||
y: newY,
|
||||
width,
|
||||
height
|
||||
};
|
||||
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
|
||||
this.updateOutputAreaSize(width, height, true);
|
||||
this.render();
|
||||
this.saveState();
|
||||
this.canvasLayers.setOutputAreaSize(width, height);
|
||||
}
|
||||
/**
|
||||
* Eksportuje spłaszczony canvas jako blob
|
||||
|
||||
@@ -492,6 +492,36 @@ export class CanvasLayers {
|
||||
this.canvas.canvasState.saveStateToDB();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Ustawia nowy rozmiar output area względem środka, resetuje rozszerzenia.
|
||||
*/
|
||||
setOutputAreaSize(width, height) {
|
||||
// Reset rozszerzeń
|
||||
this.canvas.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
this.canvas.outputAreaExtensionEnabled = false;
|
||||
this.canvas.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
// Oblicz środek obecnego output area
|
||||
const prevBounds = this.canvas.outputAreaBounds;
|
||||
const centerX = prevBounds.x + prevBounds.width / 2;
|
||||
const centerY = prevBounds.y + prevBounds.height / 2;
|
||||
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
|
||||
const newX = centerX - width / 2;
|
||||
const newY = centerY - height / 2;
|
||||
// Ustaw nowy rozmiar bazowy i pozycję
|
||||
this.canvas.originalCanvasSize = { width, height };
|
||||
this.canvas.originalOutputAreaPosition = { x: newX, y: newY };
|
||||
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
|
||||
this.canvas.outputAreaBounds = {
|
||||
x: newX,
|
||||
y: newY,
|
||||
width,
|
||||
height
|
||||
};
|
||||
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
|
||||
this.updateOutputAreaSize(width, height, true);
|
||||
this.canvas.render();
|
||||
this.canvas.saveState();
|
||||
}
|
||||
getHandles(layer) {
|
||||
const centerX = layer.x + layer.width / 2;
|
||||
const centerY = layer.y + layer.height / 2;
|
||||
|
||||
@@ -430,39 +430,10 @@ export class Canvas {
|
||||
|
||||
/**
|
||||
* Ustawia nowy rozmiar output area zgodnie z nowym systemem (resetuje rozszerzenia, pozycję, rozmiar)
|
||||
* (Fasada: deleguje do CanvasLayers)
|
||||
*/
|
||||
setOutputAreaSize(width: number, height: number) {
|
||||
// Reset rozszerzeń
|
||||
this.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
this.outputAreaExtensionEnabled = false;
|
||||
this.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
|
||||
// Oblicz środek obecnego output area
|
||||
const prevBounds = this.outputAreaBounds;
|
||||
const centerX = prevBounds.x + prevBounds.width / 2;
|
||||
const centerY = prevBounds.y + prevBounds.height / 2;
|
||||
|
||||
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
|
||||
const newX = centerX - width / 2;
|
||||
const newY = centerY - height / 2;
|
||||
|
||||
// Ustaw nowy rozmiar bazowy i pozycję
|
||||
this.originalCanvasSize = { width, height };
|
||||
this.originalOutputAreaPosition = { x: newX, y: newY };
|
||||
|
||||
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
|
||||
this.outputAreaBounds = {
|
||||
x: newX,
|
||||
y: newY,
|
||||
width,
|
||||
height
|
||||
};
|
||||
|
||||
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
|
||||
this.updateOutputAreaSize(width, height, true);
|
||||
|
||||
this.render();
|
||||
this.saveState();
|
||||
this.canvasLayers.setOutputAreaSize(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -565,6 +565,43 @@ export class CanvasLayers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ustawia nowy rozmiar output area względem środka, resetuje rozszerzenia.
|
||||
*/
|
||||
setOutputAreaSize(width: number, height: number): void {
|
||||
// Reset rozszerzeń
|
||||
this.canvas.outputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
this.canvas.outputAreaExtensionEnabled = false;
|
||||
this.canvas.lastOutputAreaExtensions = { top: 0, bottom: 0, left: 0, right: 0 };
|
||||
|
||||
// Oblicz środek obecnego output area
|
||||
const prevBounds = this.canvas.outputAreaBounds;
|
||||
const centerX = prevBounds.x + prevBounds.width / 2;
|
||||
const centerY = prevBounds.y + prevBounds.height / 2;
|
||||
|
||||
// Nowa pozycja lewego górnego rogu, by środek pozostał w miejscu
|
||||
const newX = centerX - width / 2;
|
||||
const newY = centerY - height / 2;
|
||||
|
||||
// Ustaw nowy rozmiar bazowy i pozycję
|
||||
this.canvas.originalCanvasSize = { width, height };
|
||||
this.canvas.originalOutputAreaPosition = { x: newX, y: newY };
|
||||
|
||||
// Ustaw outputAreaBounds na nowy rozmiar i pozycję
|
||||
this.canvas.outputAreaBounds = {
|
||||
x: newX,
|
||||
y: newY,
|
||||
width,
|
||||
height
|
||||
};
|
||||
|
||||
// Zaktualizuj rozmiar przez istniejącą metodę (ustawia maskę, itp.)
|
||||
this.updateOutputAreaSize(width, height, true);
|
||||
|
||||
this.canvas.render();
|
||||
this.canvas.saveState();
|
||||
}
|
||||
|
||||
getHandles(layer: Layer): Record<string, Point> {
|
||||
const centerX = layer.x + layer.width / 2;
|
||||
const centerY = layer.y + layer.height / 2;
|
||||
|
||||
Reference in New Issue
Block a user