Skip to content

Commit

Permalink
resize handlers moved
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Dec 9, 2021
1 parent 6c3e252 commit b1fcfe5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
25 changes: 0 additions & 25 deletions src/scene-view/game-container/game-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { GameParent } from 'scene-view/game-parent/game-parent';
import { ReferenceImage } from 'scene-view/reference-image/reference-image';
import { SelectionArea } from 'scene-view/selection-area/selection-area';
import './game-container.scss';
import { GameResizeHandle } from './game-resize-handle';

export class GameContainer extends HTMLElement {
public static readonly tagName = 'phred-game-container';
Expand All @@ -28,8 +27,6 @@ export class GameContainer extends HTMLElement {
const selectionArea = document.createElement(SelectionArea.tagName) as SelectionArea;
this.selectionArea = parent.appendChild(selectionArea);
selectionArea.init(game);

this.createResizeHandles(parent);
}

public setupActions(actions: ActionHandler) {
Expand All @@ -44,24 +41,6 @@ export class GameContainer extends HTMLElement {
this.onmouseup = this.onInputUp;
}

private createResizeHandles(parent: HTMLElement) {
const onStopDrag = this.onGameResized.bind(this);
const handleRight = document.createElement(GameResizeHandle.tagName) as GameResizeHandle;
handleRight.init(parent, 'right');
handleRight.onStopDrag = onStopDrag;
parent.appendChild(handleRight);

const handleBottom = document.createElement(GameResizeHandle.tagName) as GameResizeHandle;
handleBottom.init(parent, 'bottom');
handleBottom.onStopDrag = onStopDrag;
parent.appendChild(handleBottom);

const handleBoth = document.createElement(GameResizeHandle.tagName) as GameResizeHandle;
handleBoth.init(parent, 'both');
handleBoth.onStopDrag = onStopDrag;
parent.appendChild(handleBoth);
}

public enable(config: PluginConfig) {
const el = this.game.canvas.parentElement;
this.gameOriginalParentElement = el.parentElement;
Expand Down Expand Up @@ -133,10 +112,6 @@ export class GameContainer extends HTMLElement {
}
}

private onGameResized(width: number, height: number) {
Editor.prefs.responsiveSize = { width, height };
}

// #endregion
}

Expand Down
Empty file.
26 changes: 25 additions & 1 deletion src/scene-view/game-parent/game-parent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ActionHandler } from 'core/action-handler';
import { Actions } from 'core/actions';
import { Editor } from 'core/editor';
import { Size } from 'plugin.model';
import './game-parent.scss';
import { GameResizeHandle } from './game-resize-handle';

const MIN_WIDTH = 100;
const MAX_WIDTH = 10000;
Expand All @@ -13,6 +14,25 @@ export class GameParent extends HTMLElement {

public init() {
this.id = GameParent.tagName;
this.createResizeHandles();
}

private createResizeHandles() {
const onStopDrag = this.onGameResized.bind(this);
const handleRight = document.createElement(GameResizeHandle.tagName) as GameResizeHandle;
handleRight.init(this, 'right');
handleRight.onStopDrag = onStopDrag;
this.appendChild(handleRight);

const handleBottom = document.createElement(GameResizeHandle.tagName) as GameResizeHandle;
handleBottom.init(this, 'bottom');
handleBottom.onStopDrag = onStopDrag;
this.appendChild(handleBottom);

const handleBoth = document.createElement(GameResizeHandle.tagName) as GameResizeHandle;
handleBoth.init(this, 'both');
handleBoth.onStopDrag = onStopDrag;
this.appendChild(handleBoth);
}

public setupActions(actions: ActionHandler) {
Expand Down Expand Up @@ -62,6 +82,10 @@ export class GameParent extends HTMLElement {
this.classList.remove('resizable');
}
}

private onGameResized(width: number, height: number) {
Editor.prefs.responsiveSize = { width, height };
}
}

customElements.define(GameParent.tagName, GameParent);

0 comments on commit b1fcfe5

Please sign in to comment.