From 046612f8dad72bee5ca166206195510971634625 Mon Sep 17 00:00:00 2001 From: Aiosa Date: Wed, 26 Jul 2023 23:55:46 +0200 Subject: [PATCH] Better drawer resolution, also supporting inline class spec. Fix minor review stuff. --- Gruntfile.js | 2 +- src/drawerbase.js | 4 +--- src/matrix.js | 5 ++--- src/viewer.js | 56 +++++++++++++++++++++++------------------------ 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index c96e2e79..979a602a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -67,7 +67,7 @@ module.exports = function(grunt) { "src/tilecache.js", "src/world.js", - // Aoisa's webgl drawer - needs optimization, polishing, trimming + // Aiosa's webgl drawer - needs optimization, polishing, trimming // "src/webgl/webGLWrapper.js", // "src/webgl/visualisationLayer.js", // "src/webgl/dataLoader.js", diff --git a/src/drawerbase.js b/src/drawerbase.js index e4df9068..62cb1e04 100644 --- a/src/drawerbase.js +++ b/src/drawerbase.js @@ -108,9 +108,7 @@ $.DrawerBase = class DrawerBase{ this._checkForAPIOverrides(); } - get isOpenSeadragonDrawer(){ - return true; - } + get canvas(){ if(!this._renderingTarget){ this._renderingTarget = this.createDrawingElement(); diff --git a/src/matrix.js b/src/matrix.js index b0b91ab0..1f580658 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -1,8 +1,8 @@ - /* * OpenSeadragon - Mat3 * - * Copyright (C) 2010-2023 OpenSeadragon contributors + * Modified from https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html + * Copyright (C) 2010-2023 webglfundamentals.org and OpenSeadragon contributors * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -36,7 +36,6 @@ /** * Matrix left-to-right system representation - * Modified from https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html */ $.Mat3 = class Mat3 { constructor(values){ diff --git a/src/viewer.js b/src/viewer.js index 3b98cd74..4e823743 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -445,44 +445,44 @@ $.Viewer = function( options ) { delete this.drawerOptions.useCanvas; } - let drawerPriority = Array.isArray(this.drawer) ? this.drawer : [this.drawer]; - let drawersToTry = drawerPriority.filter(d => ['webgl', 'canvas', 'html'].includes(d) || (d.prototype && d.prototype.isOpenSeadragonDrawer) ); - if(drawerPriority.length !== drawersToTry.length){ - $.console.error('An invalid drawer was requested.'); - } - if(drawersToTry.length === 0){ - drawersToTry = [$.DEFAULT_SETTINGS.drawer].flat(); // ensure it is a list + let drawerCandidates = Array.isArray(this.drawer) ? this.drawer : [this.drawer]; + if (drawerCandidates.length === 0){ + drawerCandidates = [$.DEFAULT_SETTINGS.drawer].flat(); // ensure it is a list $.console.warn('No valid drawers were selected. Using the default value.'); } // extend the drawerOptions object with additional properties to pass to the Drawer implementation // TODO: how to deal with the possibility that none of the requested drawers are supported? this.drawer = null; - for(let i = 0; i < drawersToTry.length; i++){ + for (let i = 0; i < drawerCandidates.length; i++) { - //todo necessary? why not to use class names as drawer IDs - let optsKey = drawersToTry[i]; - let Drawer = $.determineDrawer(optsKey); - if (!Drawer) { - optsKey = 'custom'; - //todo will raise error anyway... + let drawerCandidate = drawerCandidates[i]; + let Drawer = null; + + //if inherits from a drawer base, use it + if (drawerCandidate && drawerCandidate.prototype instanceof $.DrawerBase) { + Drawer = drawerCandidate; + drawerCandidate = 'custom'; + } else if (typeof drawerCandidate === "string") { + Drawer = $.determineDrawer(drawerCandidate); } else { - // if the drawer is supported, create it and break the loop - if (Drawer.isSupported()){ - this.drawer = new Drawer({ - viewer: this, - viewport: this.viewport, - element: this.canvas, - debugGridColor: this.debugGridColor, - options: this.drawerOptions[optsKey], - }); - this.drawerOptions.constructor = Drawer; - break; - } + $.console.warn('Unsupported drawer! Drawer must be an existing string type, or a class that extends OpenSeadragon.DrawerBase.'); + continue; } - + // if the drawer is supported, create it and break the loop + if (Drawer.isSupported()) { + this.drawer = new Drawer({ + viewer: this, + viewport: this.viewport, + element: this.canvas, + debugGridColor: this.debugGridColor, + options: this.drawerOptions[drawerCandidate], + }); + this.drawerOptions.constructor = Drawer; + break; + } } - if(this.drawer === null){ + if (!this.drawer){ $.console.error('No drawer could be created!'); throw('Error with creating the selected drawer(s)'); }