Skip to content

Commit 3c562c5

Browse files
dakerjourdain
authored andcommitted
fix(CanvasView): allow setting canvas element
1 parent 89758ed commit 3c562c5

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Sources/Rendering/Misc/CanvasView/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ export function extend(publicAPI, model, initialValues = {}) {
148148
Object.assign(model, DEFAULT_VALUES, initialValues);
149149

150150
// Create internal instances
151-
model.canvas = document.createElement('canvas');
152-
model.canvas.style.width = '100%';
151+
if (!model.canvas) {
152+
model.canvas = document.createElement('canvas');
153+
model.canvas.style.width = '100%';
154+
}
153155

154156
// Create internal bgImage
155157
model.bgImage = new Image();

Sources/Rendering/Misc/RemoteView/index.d.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ interface IRemoteViewInitialValues {
1313
rpcGestureEvent?: any;
1414
rpcWheelEvent?: any;
1515
viewStream?: vtkViewStream;
16+
canvasElement?: HTMLCanvasElement;
1617
}
1718

1819
export interface vtkRemoteView extends vtkObject {
1920
/**
20-
* Get container element
21+
* Get container HTML element
2122
*/
2223
getContainer(): HTMLElement;
2324

2425
/**
25-
*
26+
* Get vtkViewStream object
2627
*/
2728
getViewStream(): vtkViewStream;
2829

2930
/**
30-
*
31+
* Get the canvas HTML element
32+
*/
33+
getCanvasElement(): HTMLCanvasElement;
34+
35+
/**
36+
* Get the vtkCanvasView object
3137
*/
3238
getCanvasView(): vtkCanvasView;
3339

Sources/Rendering/Misc/RemoteView/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ function vtkRemoteView(publicAPI, model) {
1717
model.classHierarchy.push('vtkRemoteView');
1818

1919
// Constructor
20-
model.canvasView = vtkCanvasView.newInstance();
20+
model.canvasView = vtkCanvasView.newInstance({
21+
canvas: model.canvasElement,
22+
});
2123
model.interactorStyle = vtkInteractorStyleRemoteMouse.newInstance();
2224

2325
model.interactor = vtkRenderWindowInteractor.newInstance();
@@ -62,6 +64,8 @@ function vtkRemoteView(publicAPI, model) {
6264
}
6365
}, publicAPI.delete);
6466

67+
publicAPI.getCanvasElement = () => model.canvasView.getCanvas();
68+
6569
// --------------------------------------------------------------------------
6670
// remote handing
6771
// --------------------------------------------------------------------------
@@ -201,6 +205,7 @@ const DEFAULT_VALUES = {
201205
rpcMouseEvent: 'viewport.mouse.interaction',
202206
rpcGestureEvent: null,
203207
rpcWheelEvent: null,
208+
canvasElement: null,
204209
};
205210

206211
// ----------------------------------------------------------------------------
@@ -219,6 +224,7 @@ export function extend(publicAPI, model, initialValues = {}) {
219224
'interactiveRatio',
220225
'stillQuality',
221226
'stillRatio',
227+
'canvasElement',
222228
]);
223229
macro.setGet(publicAPI, model, [
224230
'session',

0 commit comments

Comments
 (0)