webvirtmgr/static/js/novnc/display.js
/* Set CSS cursor property using data URI encoded cursor file */
Set CSS cursor property using data URI encoded cursor file
Set CSS cursor property using data URI encoded cursor file
function changeCursor(target, pixels, mask, hotx, hoty, w0, h0, cmap) {
    "use strict";
    var cur = [], rgb, IHDRsz, RGBsz, ANDsz, XORsz, url, idx, alpha, x, y;
    var w = w0;
    var h = h0;
    if (h < w)
        h = w;                 
    else
        w = h;                 
    cur.push16le = function (num) {
        this.push((num     ) & 0xFF,
                  (num >> 8) & 0xFF  );
    };
    cur.push32le = function (num) {
        this.push((num      ) & 0xFF,
                  (num >>  8) & 0xFF,
                  (num >> 16) & 0xFF,
                  (num >> 24) & 0xFF  );
    };
    IHDRsz = 40;
    RGBsz = w * h * 4;
    XORsz = Math.ceil( (w * h) / 8.0 );
    ANDsz = Math.ceil( (w * h) / 8.0 );
    cur.push16le(0);      
    cur.push16le(2);      
    cur.push16le(1);      
    cur.push(w);          
    cur.push(h);          
    cur.push(0);          
    cur.push(0);          
    cur.push16le(hotx);   
    cur.push16le(hoty);   
    cur.push32le(IHDRsz + RGBsz + XORsz + ANDsz);
    cur.push32le(22);     
    cur.push32le(IHDRsz); 
    cur.push32le(w);      
    cur.push32le(h*2);    
    cur.push16le(1);      
    cur.push16le(32);     
    cur.push32le(0);      
    cur.push32le(XORsz + ANDsz); 
    cur.push32le(0);      
    cur.push32le(0);      
    cur.push32le(0);      
    cur.push32le(0);      
    for (y = h-1; y >= 0; y -= 1) {
        for (x = 0; x < w; x += 1) {
            if (x >= w0 || y >= h0) {
                cur.push(0);          
                cur.push(0);          
                cur.push(0);          
                cur.push(0);          
            } else {
                idx = y * Math.ceil(w0 / 8) + Math.floor(x/8);
                alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0;
                if (cmap) {
                    idx = (w0 * y) + x;
                    rgb = cmap[pixels[idx]];
                    cur.push(rgb[2]);          
                    cur.push(rgb[1]);          
                    cur.push(rgb[0]);          
                    cur.push(alpha);           
                } else {
                    idx = ((w0 * y) + x) * 4;
                    cur.push(pixels[idx + 2]); 
                    cur.push(pixels[idx + 1]); 
                    cur.push(pixels[idx    ]); 
                    cur.push(alpha);           
                }
            }
        }
    }
    for (y = 0; y < h; y += 1) {
        for (x = 0; x < Math.ceil(w / 8); x += 1) {
            cur.push(0x00);
        }
    }
    for (y = 0; y < h; y += 1) {
        for (x = 0; x < Math.ceil(w / 8); x += 1) {
            cur.push(0x00);
        }
    }
    url = "data:image/x-icon;base64," + Base64.encode(cur);
    target.style.cursor = "url(" + url + ") " + hotx + " " + hoty + ", default";
}
function changeCursor ( target , pixels , mask , hotx , hoty , w0 , h0 , cmap ) { "use strict" ; var cur = [ ] , rgb , IHDRsz , RGBsz , ANDsz , XORsz , url , idx , alpha , x , y ; var w = w0 ; var h = h0 ; if ( h < w ) h = w ; else w = h ; cur . push16le = function ( num ) { this . push ( ( num ) & 0xFF , ( num >> 8 ) & 0xFF ) ; } ; cur . push32le = function ( num ) { this . push ( ( num ) & 0xFF , ( num >> 8 ) & 0xFF , ( num >> 16 ) & 0xFF , ( num >> 24 ) & 0xFF ) ; } ; IHDRsz = 40 ; RGBsz = w * h * 4 ; XORsz = Math . ceil ( ( w * h ) / 8.0 ) ; ANDsz = Math . ceil ( ( w * h ) / 8.0 ) ; cur . push16le ( 0 ) ; cur . push16le ( 2 ) ; cur . push16le ( 1 ) ; cur . push ( w ) ; cur . push ( h ) ; cur . push ( 0 ) ; cur . push ( 0 ) ; cur . push16le ( hotx ) ; cur . push16le ( hoty ) ; cur . push32le ( IHDRsz + RGBsz + XORsz + ANDsz ) ; cur . push32le ( 22 ) ; cur . push32le ( IHDRsz ) ; cur . push32le ( w ) ; cur . push32le ( h * 2 ) ; cur . push16le ( 1 ) ; cur . push16le ( 32 ) ; cur . push32le ( 0 ) ; cur . push32le ( XORsz + ANDsz ) ; cur . push32le ( 0 ) ; cur . push32le ( 0 ) ; cur . push32le ( 0 ) ; cur . push32le ( 0 ) ; for ( y = h - 1 ; y >= 0 ; y -= 1 ) { for ( x = 0 ; x < w ; x += 1 ) { if ( x >= w0 || y >= h0 ) { cur . push ( 0 ) ; cur . push ( 0 ) ; cur . push ( 0 ) ; cur . push ( 0 ) ; } else { idx = y * Math . ceil ( w0 / 8 ) + Math . floor ( x / 8 ) ; alpha = ( mask [ idx ] << ( x % 8 ) ) & 0x80 ? 255 : 0 ; if ( cmap ) { idx = ( w0 * y ) + x ; rgb = cmap [ pixels [ idx ] ] ; cur . push ( rgb [ 2 ] ) ; cur . push ( rgb [ 1 ] ) ; cur . push ( rgb [ 0 ] ) ; cur . push ( alpha ) ; } else { idx = ( ( w0 * y ) + x ) * 4 ; cur . push ( pixels [ idx + 2 ] ) ; cur . push ( pixels [ idx + 1 ] ) ; cur . push ( pixels [ idx ] ) ; cur . push ( alpha ) ; } } } } for ( y = 0 ; y < h ; y += 1 ) { for ( x = 0 ; x < Math . ceil ( w / 8 ) ; x += 1 ) { cur . push ( 0x00 ) ; } } for ( y = 0 ; y < h ; y += 1 ) { for ( x = 0 ; x < Math . ceil ( w / 8 ) ; x += 1 ) { cur . push ( 0x00 ) ; } } url = "data:image/x-icon;base64," + Base64 . encode ( cur ) ; target . style . cursor = "url(" + url + ") " + hotx + " " + hoty + ", default" ; }
Set CSS cursor property using data URI encoded cursor file
Set CSS cursor property using data URI encoded cursor file
//Util.Debug(">> changeCursor, x: " + hotx + ", y: " + hoty + ", w0: " + w0 + ", h0: " + h0); // increase h to make it square // increace w to make it square // Push multi-byte little-endian values // Main header // 0: Reserved // 2: .CUR type // 4: Number of images, 1 for non-animated ico // Cursor #1 header (ICONDIRENTRY) // 6: width // 7: height // 8: colors, 0 -> true-color // 9: reserved // 10: hotspot x coordinate // 12: hotspot y coordinate // 14: cursor data byte size // 18: offset of cursor data in the file // Cursor #1 InfoHeader (ICONIMAGE/BITMAPINFO) // 22: Infoheader size // 26: Cursor width // 30: XOR+AND height // 34: number of planes // 36: bits per pixel // 38: Type of compression // 43: Size of Image // Gimp leaves this as 0 // 46: reserved // 50: reserved // 54: reserved // 58: reserved // 62: color data (RGBQUAD icColors[]) // blue // green // red // alpha // blue // green // red // alpha // blue // green // red // alpha // XOR/bitmask data (BYTE icXOR[]) // (ignored, just needs to be right size) // AND/bitmask data (BYTE icAND[]) // (ignored, just needs to be right size) //Util.Debug("<< changeCursor, cur.length: " + cur.length);