Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/wasm-viewport.ts @ 504:7cdb4634846c
Merge
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 26 Feb 2019 21:15:20 +0100 |
parents | 50229f6eb4cd 5055031f4a06 |
children | 801d2697a1b1 |
comparison
equal
deleted
inserted
replaced
460:4d8ac609fc33 | 504:7cdb4634846c |
---|---|
1 import wasmApplicationRunner = require('./wasm-application-runner'); | |
2 //import stoneFrameworkLoader = require('./stone-framework-loader'); | |
3 | |
1 var isPendingRedraw = false; | 4 var isPendingRedraw = false; |
2 | 5 |
3 function ScheduleWebViewportRedraw(cppViewportHandle: any) : void | 6 function ScheduleWebViewportRedraw(cppViewportHandle: any) : void |
4 { | 7 { |
5 if (!isPendingRedraw) { | 8 if (!isPendingRedraw) { |
6 isPendingRedraw = true; | 9 isPendingRedraw = true; |
7 console.log('Scheduling a refresh of the viewport, as its content changed'); | 10 console.log('Scheduling a refresh of the viewport, as its content changed'); |
8 window.requestAnimationFrame(function() { | 11 window.requestAnimationFrame(function() { |
9 isPendingRedraw = false; | 12 isPendingRedraw = false; |
10 Stone.WasmViewport.GetFromCppViewport(cppViewportHandle).Redraw(); | 13 WasmViewport.GetFromCppViewport(cppViewportHandle).Redraw(); |
11 }); | 14 }); |
12 } | 15 } |
13 } | 16 } |
14 | 17 |
18 (<any>window).ScheduleWebViewportRedraw = ScheduleWebViewportRedraw; | |
19 | |
15 declare function UTF8ToString(any): string; | 20 declare function UTF8ToString(any): string; |
16 | 21 |
17 function CreateWasmViewport(htmlCanvasId: string) : any { | 22 function CreateWasmViewport(htmlCanvasId: string) : any { |
18 var cppViewportHandle = CreateCppViewport(); | 23 var cppViewportHandle = wasmApplicationRunner.CreateCppViewport(); |
19 var canvasId = UTF8ToString(htmlCanvasId); | 24 var canvasId = UTF8ToString(htmlCanvasId); |
20 var webViewport = new Stone.WasmViewport(StoneFrameworkModule, canvasId, cppViewportHandle); // viewports are stored in a static map in WasmViewport -> won't be deleted | 25 var webViewport = new WasmViewport((<any> window).StoneFrameworkModule, canvasId, cppViewportHandle); // viewports are stored in a static map in WasmViewport -> won't be deleted |
21 webViewport.Initialize(); | 26 webViewport.Initialize(); |
22 | 27 |
23 return cppViewportHandle; | 28 return cppViewportHandle; |
24 } | 29 } |
25 | 30 |
26 module Stone { | 31 (<any>window).CreateWasmViewport = CreateWasmViewport; |
27 | 32 |
28 // export declare type InitializationCallback = () => void; | 33 // export declare type InitializationCallback = () => void; |
29 | 34 |
30 // export declare var StoneFrameworkModule : any; | 35 // export declare var StoneFrameworkModule : any; |
31 | 36 |
32 //const ASSETS_FOLDER : string = "assets/lib"; | 37 //const ASSETS_FOLDER : string = "assets/lib"; |
33 //const WASM_FILENAME : string = "orthanc-framework"; | 38 //const WASM_FILENAME : string = "orthanc-framework"; |
34 | 39 |
35 export class WasmViewport { | 40 export class WasmViewport { |
36 | 41 |
37 private static viewportsMapByCppHandle_ : Map<number, WasmViewport> = new Map<number, WasmViewport>(); // key = the C++ handle | 42 private static viewportsMapByCppHandle_ : Map<number, WasmViewport> = new Map<number, WasmViewport>(); // key = the C++ handle |
38 private static viewportsMapByCanvasId_ : Map<string, WasmViewport> = new Map<string, WasmViewport>(); // key = the canvasId | 43 private static viewportsMapByCanvasId_ : Map<string, WasmViewport> = new Map<string, WasmViewport>(); // key = the canvasId |
39 | 44 |
40 private module_ : any; | 45 private module_ : any; |
329 d | 334 d |
330 ]; | 335 ]; |
331 } | 336 } |
332 | 337 |
333 } | 338 } |
334 } | 339 |
335 | 340 |