2
0

structured gui and models

This commit is contained in:
2018-05-10 20:56:00 +02:00
parent 4617e90374
commit 51e7822b04
3 changed files with 49 additions and 3 deletions

View File

@@ -1,10 +1,44 @@
import { Directive } from '@angular/core';
import { Directive, ElementRef, Renderer, AfterViewInit, HostListener } from '@angular/core';
import { Config } from './../models/config.model';
@Directive({
selector: '[appCanvas]'
})
export class CanvasDirective {
export class CanvasDirective implements AfterViewInit {
private canvas: any;
private context: any;
public config: Config;
constructor() { }
@HostListener('window:resize', ['$event'])
private onResize(event) {
this.updateConfig();
}
constructor(
private el: ElementRef,
private renderer: Renderer
) {
this.canvas = el.nativeElement;
this.context = this.canvas.getContext('2d');
}
ngAfterViewInit() {
this.updateConfig();
}
private updateConfig(): void {
this.config = {
width: this.canvas.clientWidth,
height: this.canvas.clientHeight,
start: {
x: this.canvas.clientWidth,
y: 0
},
end: {
x: 0,
y: this.canvas.clientHeight
},
};
console.log(this.config);
}
}

View File

@@ -0,0 +1,8 @@
import { Point } from './point.model';
export interface Config {
width: Number;
height: Number;
start: Point;
end: Point;
}

View File

@@ -0,0 +1,4 @@
export interface Point {
x: Number;
y: Number;
}