Commit 8886bab3 authored by Romain DELEAU's avatar Romain DELEAU

Merge branch 'zoomable' into 'develop'

add mouse-wheel-zoom

See merge request romain.deleau/rlg-tool!2
parents ef732a04 83c1ea36
<div class="container"> <div class="container">
<div class="container-main" appDragScroll> <div class="container-main" appDragScroll>
<div class="container-main-scenario" style="display: flex;"> <div class="container-main-scenario" style="display: flex;" appMouseWheelZoom>
<div style="display: flex; flex-direction: column;" [style.z-index]="4"> <div style="display: flex; flex-direction: column;" [style.z-index]="4">
<app-game-educationnal-objective></app-game-educationnal-objective> <app-game-educationnal-objective></app-game-educationnal-objective>
<app-game-context [style.z-index]="2"></app-game-context> <app-game-context [style.z-index]="2"></app-game-context>
...@@ -47,8 +47,6 @@ ...@@ -47,8 +47,6 @@
</div> </div>
<div class="container-sider-element" style="width: 400px; height: 400px; background-color: green;"> <div class="container-sider-element" style="width: 400px; height: 400px; background-color: green;">
</div>
</div> </div>
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
scrollbar-width: none; scrollbar-width: none;
&-scenario { &-scenario {
position: relative;
transform-origin: top left;
padding: 60px 5px 10px 5px; padding: 60px 5px 10px 5px;
margin-right: 7px; margin-right: 7px;
} }
......
...@@ -14,7 +14,8 @@ import { AnnexeTaskComponent } from './pieces/annexe-task/annexe-task.component' ...@@ -14,7 +14,8 @@ import { AnnexeTaskComponent } from './pieces/annexe-task/annexe-task.component'
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatIconModule } from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon';
import { DragScrollDirective } from './directives/drag-scroll.directive'; import { DragScrollDirective } from './directives/drag-scroll.directive';
import { MouseWheelZoomDirective } from './directives/mouse-wheel-zoom.directive';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -26,7 +27,8 @@ import { DragScrollDirective } from './directives/drag-scroll.directive'; ...@@ -26,7 +27,8 @@ import { DragScrollDirective } from './directives/drag-scroll.directive';
GameContextComponent, GameContextComponent,
TaskComponent, TaskComponent,
AnnexeTaskComponent, AnnexeTaskComponent,
DragScrollDirective DragScrollDirective,
MouseWheelZoomDirective
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
......
...@@ -9,12 +9,12 @@ export class DragScrollDirective { ...@@ -9,12 +9,12 @@ export class DragScrollDirective {
private startY: number = 0; private startY: number = 0;
private element: HTMLElement; private element: HTMLElement;
constructor(elementRef: ElementRef) { constructor(private elementRef: ElementRef) {
this.element = elementRef.nativeElement; this.element = elementRef.nativeElement;
} }
@HostListener('mousedown', ['$event']) @HostListener('mousedown', ['$event'])
onMouseDown(event: any) { onMouseDown(event: MouseEvent) {
this.isMouseDown = true; this.isMouseDown = true;
this.startX = event.clientX; this.startX = event.clientX;
this.startY = event.clientY; this.startY = event.clientY;
...@@ -22,13 +22,13 @@ export class DragScrollDirective { ...@@ -22,13 +22,13 @@ export class DragScrollDirective {
} }
@HostListener('mouseup', ['$event']) @HostListener('mouseup', ['$event'])
onMouseUp(event: any) { onMouseUp(event: MouseEvent) {
this.isMouseDown = false; this.isMouseDown = false;
this.element.style.cursor = 'grab'; this.element.style.cursor = 'grab';
} }
@HostListener('mousemove', ['$event']) @HostListener('mousemove', ['$event'])
onMouseMove(event: any) { onMouseMove(event: MouseEvent) {
if(this.isMouseDown) { if(this.isMouseDown) {
event.preventDefault(); event.preventDefault();
const x = event.clientX - this.startX; const x = event.clientX - this.startX;
......
import { MouseWheelZoomDirective } from './mouse-wheel-zoom.directive';
describe('MouseWheelZoomDirective', () => {
it('should create an instance', () => {
const directive = new MouseWheelZoomDirective();
expect(directive).toBeTruthy();
});
});
import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: '[appMouseWheelZoom]'
})
export class MouseWheelZoomDirective {
private zoom: number = 1;
private element: HTMLElement;
constructor(private elementRef: ElementRef) {
this.element = elementRef.nativeElement;
}
@HostListener('wheel', ['$event'])
onMouseWheel(event: WheelEvent) {
event.preventDefault();
const zoomLevel = event.deltaY < 0 ? 0.1 : -0.1;
this.zoom += zoomLevel;
this.element.style.transform = `scale(${this.zoom})`;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment