Skip to content

Commit

Permalink
fix(CanvasView): allow setting canvas element
Browse files Browse the repository at this point in the history
  • Loading branch information
daker committed Dec 27, 2024
1 parent 89758ed commit 1fc265e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Sources/Rendering/Misc/CanvasView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

// Create internal instances
model.canvas = document.createElement('canvas');
model.canvas.style.width = '100%';
if (!model.canvas) {
model.canvas = document.createElement('canvas');
model.canvas.style.width = '100%';
}

// Create internal bgImage
model.bgImage = new Image();
Expand Down
10 changes: 8 additions & 2 deletions Sources/Rendering/Misc/RemoteView/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IRemoteViewInitialValues {
rpcGestureEvent?: any;
rpcWheelEvent?: any;
viewStream?: vtkViewStream;
canvasElement?: HTMLCanvasElement;
}

export interface vtkRemoteView extends vtkObject {
Expand All @@ -22,12 +23,17 @@ export interface vtkRemoteView extends vtkObject {
getContainer(): HTMLElement;

/**
*
* Get vtk viewstream
*/
getViewStream(): vtkViewStream;

/**
*
* Get canvas HTML element
*/
getCanvasElement(): HTMLCanvasElement;

/**
* Get canvas view object
*/
getCanvasView(): vtkCanvasView;

Expand Down
6 changes: 5 additions & 1 deletion Sources/Rendering/Misc/RemoteView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ function vtkRemoteView(publicAPI, model) {
model.classHierarchy.push('vtkRemoteView');

// Constructor
model.canvasView = vtkCanvasView.newInstance();
model.canvasView = vtkCanvasView.newInstance({
canvas: model.canvasElement,
});
model.interactorStyle = vtkInteractorStyleRemoteMouse.newInstance();

model.interactor = vtkRenderWindowInteractor.newInstance();
Expand Down Expand Up @@ -201,6 +203,7 @@ const DEFAULT_VALUES = {
rpcMouseEvent: 'viewport.mouse.interaction',
rpcGestureEvent: null,
rpcWheelEvent: null,
canvasElement: null,
};

// ----------------------------------------------------------------------------
Expand All @@ -219,6 +222,7 @@ export function extend(publicAPI, model, initialValues = {}) {
'interactiveRatio',
'stillQuality',
'stillRatio',
'canvasElement',
]);
macro.setGet(publicAPI, model, [
'session',
Expand Down

0 comments on commit 1fc265e

Please sign in to comment.