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 authored and jourdain committed Jan 1, 2025
1 parent 89758ed commit 3c562c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 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
12 changes: 9 additions & 3 deletions Sources/Rendering/Misc/RemoteView/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ interface IRemoteViewInitialValues {
rpcGestureEvent?: any;
rpcWheelEvent?: any;
viewStream?: vtkViewStream;
canvasElement?: HTMLCanvasElement;
}

export interface vtkRemoteView extends vtkObject {
/**
* Get container element
* Get container HTML element
*/
getContainer(): HTMLElement;

/**
*
* Get vtkViewStream object
*/
getViewStream(): vtkViewStream;

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

/**
* Get the vtkCanvasView object
*/
getCanvasView(): vtkCanvasView;

Expand Down
8 changes: 7 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 @@ -62,6 +64,8 @@ function vtkRemoteView(publicAPI, model) {
}
}, publicAPI.delete);

publicAPI.getCanvasElement = () => model.canvasView.getCanvas();

// --------------------------------------------------------------------------
// remote handing
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -201,6 +205,7 @@ const DEFAULT_VALUES = {
rpcMouseEvent: 'viewport.mouse.interaction',
rpcGestureEvent: null,
rpcWheelEvent: null,
canvasElement: null,
};

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

0 comments on commit 3c562c5

Please sign in to comment.