web-common-resource/terminal/smartxKs/display.js

10 lines
12 KiB
JavaScript
Raw Permalink Normal View History

2024-08-20 12:11:35 +00:00
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2015 Samuel Mannehed for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
var Display;!function(){"use strict";var t=!1;try{new ImageData(new Uint8ClampedArray(1),1,1),t=!0}catch(t){}Display=function(t){if(this._drawCtx=null,this._c_forceCanvas=!1,this._renderQ=[],this._fb_width=0,this._fb_height=0,this._maxWidth=0,this._maxHeight=0,this._viewportLoc={x:0,y:0,w:0,h:0},this._cleanRect={x1:0,y1:0,x2:-1,y2:-1},this._prevDrawStyle="",this._tile=null,this._tile16x16=null,this._tile_x=0,this._tile_y=0,Util.set_defaults(this,t,{true_color:!0,colourMap:[],scale:1,viewport:!1,render_mode:""}),Util.Debug(">> Display.constructor"),!this._target)throw new Error("Target must be set");if("string"==typeof this._target)throw new Error("target must be a DOM element");if(!this._target.getContext)throw new Error("no getContext method");if(this._drawCtx||(this._drawCtx=this._target.getContext("2d")),Util.Debug("User Agent: "+navigator.userAgent),Util.Engine.gecko&&Util.Debug("Browser: gecko "+Util.Engine.gecko),Util.Engine.webkit&&Util.Debug("Browser: webkit "+Util.Engine.webkit),Util.Engine.trident&&Util.Debug("Browser: trident "+Util.Engine.trident),Util.Engine.presto&&Util.Debug("Browser: presto "+Util.Engine.presto),this.clear(),!("createImageData"in this._drawCtx))throw new Error("Canvas does not support createImageData");this._render_mode="canvas rendering",null===this._prefer_js&&(Util.Info("Prefering javascript operations"),this._prefer_js=!0),(this._cursor_uri||null===this._cursor_uri||void 0===this._cursor_uri)&&(this._cursor_uri=Util.browserSupportsCursorURIs()),Util.Debug("<< Display.constructor")},Display.prototype={viewportChangePos:function(t,i){var e=this._viewportLoc;t=Math.floor(t),i=Math.floor(i),this._viewport||(t=-e.w,i=-e.h);var h=e.x+e.w-1,r=e.y+e.h-1;if(t<0&&e.x+t<0&&(t=-e.x),h+t>=this._fb_width&&(t-=h+t-this._fb_width+1),e.y+i<0&&(i=-e.y),r+i>=this._fb_height&&(i-=r+i-this._fb_height+1),0!==t||0!==i){Util.Debug("viewportChange deltaX: "+t+", deltaY: "+i),e.x+=t,h+=t,e.y+=i,r+=i;var s=this._cleanRect;e.x>s.x1&&(s.x1=e.x),h<s.x2&&(s.x2=h),e.y>s.y1&&(s.y1=e.y),r<s.y2&&(s.y2=r);var a,o;t<0?(a=0,o=-t):(a=e.w-t,o=t);var _,n;i<0?(_=0,n=-i):(_=e.h-i,n=i);var l=this._drawCtx.fillStyle,g=this._target;this._drawCtx.fillStyle="rgb(255,255,255)",this._drawCtx.mozImageSmoothingEnabled?this._drawCtx.mozImageSmoothingEnabled=!1:this._drawCtx.webkitImageSmoothingEnabled?this._drawCtx.webkitImageSmoothingEnabled=!1:this._drawCtx.msImageSmoothingEnabled?this._drawCtx.msImageSmoothingEnabled=!1:this._drawCtx.imageSmoothingEnabled&&(this._drawCtx.imageSmoothingEnabled=!1),this._drawCtx.drawImage(g,0,0,e.w,e.h,-t,-i,e.w,e.h),0!==t&&this._drawCtx.fillRect(a,0,o,e.h),0!==i&&this._drawCtx.fillRect(0,_,e.w,n),this._drawCtx.fillStyle=l}},viewportChangeSize:function(t,i){void 0!==t&&void 0!==i||(Util.Debug("Setting viewport to full display region"),t=this._fb_width,i=this._fb_height);var e=this._viewportLoc;if(e.w!==t||e.h!==i){this._viewport&&(0!==this._maxWidth&&t>this._maxWidth&&(t=this._maxWidth),0!==this._maxHeight&&i>this._maxHeight&&(i=this._maxHeight));var h=this._cleanRect;t<e.w&&h.x2>e.x+t-1&&(h.x2=e.x+t-1),i<e.h&&h.y2>e.y+i-1&&(h.y2=e.y+i-1),e.w=t,e.h=i;var r=this._target;if(r.width!==t||r.height!==i){var s=null;if(e.w>0&&e.h>0&&r.width>0&&r.height>0){var a=r.width<e.w?r.width:e.w,o=r.height<e.h?r.height:e.h;s=this._drawCtx.getImageData(0,0,a,o)}r.width!==t&&(r.width=t,r.style.width=t+"px"),r.height!==i&&(r.height=i,r.style.height=i+"px"),s&&this._drawCtx.putImageData(s,0,0)}}},getCleanDirtyReset:function(){var t=this._viewportLoc,i=this._cleanRect,e={x:i.x1,y:i.y1,w:i.x2-i.x1+1,h:i.y2-i.y1+1},h=[];if(i.x1>=i.x2||i.y1>=i.y2)h.push({x:t.x,y:t.y,w:t.w,h:t.h});else{var r=t.x+t.w-1,s=t.y+t.h-1;t.x<i.x1&&h.push({x:t.x,y:t.y,w:i.x1-t.x+1,h:t.h}),r>i.x2&&h.push({x:i.x2+1,y:t.y,w:r-i.x2,h:t.h}),t.y<i.y1&&h.push({x:i.x1,y:t.y,w:i.x2-i.x1+1,h:i.y1-t.y}),s>i.y2&&h.push({x:i.x1,y:i.y2+1,w:i.x2-i.x1+1,h:s-i.y2})}return this._cleanRect={x1:t.x,y1:t.y,x2:t.x+t.w-1,y2:t.y+t.h-1},{cleanBox:e,dirtyBoxes:h}},absX:function(t){return t+this._viewportLoc.x},absY:function(t){return t+this._viewportLoc.y},resize:function(t,i){t