diff options
author | Javiya Vivekkumar Dineshbhai <vivek.javiya@collabora.com> | 2024-07-05 21:46:40 +0530 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2024-07-07 13:04:22 +0200 |
commit | 8dcbe8d736688d1ff6ca859dcc73e4b5055b5fb1 (patch) | |
tree | 43225aa57592c73e1441d7baf47554e1013eeb21 | |
parent | Transition: Add Push transition (diff) | |
download | online-8dcbe8d736688d1ff6ca859dcc73e4b5055b5fb1.tar.gz online-8dcbe8d736688d1ff6ca859dcc73e4b5055b5fb1.zip |
Transition: Add Split transition
Signed-off-by: Javiya Vivekkumar Dineshbhai <vivek.javiya@collabora.com>
Change-Id: Iaf884265a2ae7d90e4bed032222c73e0a6ef8b0e
-rw-r--r-- | browser/Makefile.am | 2 | ||||
-rw-r--r-- | browser/src/slideshow/PerformTransition.ts | 7 | ||||
-rw-r--r-- | browser/src/slideshow/transition/SplitTransition.ts | 83 |
3 files changed, 92 insertions, 0 deletions
diff --git a/browser/Makefile.am b/browser/Makefile.am index aa7004e740..811801ef40 100644 --- a/browser/Makefile.am +++ b/browser/Makefile.am @@ -429,6 +429,7 @@ COOL_JS_LST =\ src/slideshow/transition/WheelTransition.ts \ src/slideshow/transition/UncoverTransition.ts \ src/slideshow/transition/CoverTransition.ts \ + src/slideshow/transition/SplitTransition.ts \ src/slideshow/transition/WipeTransition.ts \ src/dom/PosAnimation.js \ src/map/anim/Map.PanAnimation.js \ @@ -881,6 +882,7 @@ pot: src/slideshow/transition/WheelTransition.ts \ src/slideshow/transition/UncoverTransition.ts \ src/slideshow/transition/CoverTransition.ts \ + src/slideshow/transition/SplitTransition.ts \ src/core/Socket.js \ src/core/Debug.js \ src/docstate.js \ diff --git a/browser/src/slideshow/PerformTransition.ts b/browser/src/slideshow/PerformTransition.ts index b0d88ad36c..8dc21183f4 100644 --- a/browser/src/slideshow/PerformTransition.ts +++ b/browser/src/slideshow/PerformTransition.ts @@ -152,6 +152,13 @@ SlideShow.PerformTransition = function ( ).start(1); break; + case 'SPLIT': + new SplitTransition( + canvas, + image1, + image2, + ).start(1); + break; default: console.error('Unknown transition type'); diff --git a/browser/src/slideshow/transition/SplitTransition.ts b/browser/src/slideshow/transition/SplitTransition.ts new file mode 100644 index 0000000000..0593522514 --- /dev/null +++ b/browser/src/slideshow/transition/SplitTransition.ts @@ -0,0 +1,83 @@ +/* + * Copyright the Collabora Online contributors. + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +declare var SlideShow: any; + +class SplitTransition extends Transition2d { + private direction: number = 0; + constructor( + canvas: HTMLCanvasElement, + image1: HTMLImageElement, + image2: HTMLImageElement, + ) { + super(canvas, image1, image2); + this.prepareTransition(); + this.animationTime = 2000; + } + + public renderUniformValue(): void { + this.gl.uniform1i( + this.gl.getUniformLocation(this.program, 'direction'), + this.direction, + ); + } + + public start(direction: number): void { + this.direction = direction; + this.startTransition(); + } + + public getVertexShader(): string { + return `#version 300 es + in vec4 a_position; + in vec2 a_texCoord; + out vec2 v_texCoord; + + void main() { + gl_Position = a_position; + v_texCoord = a_texCoord; + } + `; + } + + public getFragmentShader(): string { + return `#version 300 es + precision mediump float; + + uniform sampler2D leavingSlideTexture; + uniform sampler2D enteringSlideTexture; + uniform float time; + uniform int direction; + + in vec2 v_texCoord; + out vec4 outColor; + + void main() { + vec2 uv = v_texCoord; + float progress = time; + + vec2 center = vec2(0.5, 0.5); + + vec2 dist = abs(uv - center); + + float size = (direction == 2 || direction == 4) ? progress * 1.5 : (1.0 - progress * 1.5); + + float mask = (direction == 1 || direction == 2 ) ? step(dist.y, size / 2.0) : step(dist.x, size / 2.0); + + mask = min(mask, 1.0); + + vec4 color1 = texture(leavingSlideTexture, uv); + vec4 color2 = texture(enteringSlideTexture, uv); + + outColor = (direction == 2 || direction == 4) ? mix(color1, color2, mask) : mix(color2, color1, mask); + } + `; + } +} |