📄 window.js.svn-base
字号:
}); this.overlayEl.setStyles({ 'height': height, 'top': shadowBlur - shadowOffset.y, 'left': shadowBlur - shadowOffset.x }); // Opera requires the canvas height and width be set this way when resizing: this.canvasEl.height = height; this.canvasEl.width = width; // Part of the fix for IE6 select z-index bug and FF on Mac scrollbar z-index bug if (Browser.Engine.trident4){ this.zIndexFixEl.setStyles({ 'width': width, 'height': height }) } this.titleBarEl.setStyles({ 'width': width - shadowBlur2x, 'height': options.headerHeight }); // Draw Window var ctx = this.canvasEl.getContext('2d'); ctx.clearRect(0, 0, width, height); switch(options.shape) { case 'box': this.drawBox(ctx, width, height, shadowBlur, shadowOffset, shadows); break; case 'gauge': this.drawGauge(ctx, width, height, shadowBlur, shadowOffset, shadows); break; } if (options.type != 'notification' && options.useCanvasControls == true){ this.drawControls(width, height, shadows); } if (options.resizable){ MochaUI.triangle( ctx, width - (shadowBlur + shadowOffset.x + 17), height - (shadowBlur + shadowOffset.y + 18), 11, 11, options.resizableColor, 1.0 ); } // Invisible dummy object. The last element drawn is not rendered consistently while resizing in IE6 and IE7 if (Browser.Engine.trident){ MochaUI.triangle(ctx, 0, 0, 10, 10, options.resizableColor, 0); } }, drawWindowCollapsed: function(windowEl, shadows) { var options = this.options; var shadowBlur = options.shadowBlur; var shadowBlur2x = shadowBlur * 2; var shadowOffset = options.shadowOffset; var headerShadow = options.headerHeight + shadowBlur2x + 2; var height = headerShadow; var width = this.contentWrapperEl.getStyle('width').toInt() + shadowBlur2x; this.windowEl.setStyle('height', height); this.overlayEl.setStyles({ 'height': height, 'top': shadowBlur - shadowOffset.y, 'left': shadowBlur - shadowOffset.x }); // Opera height and width must be set like this, when resizing: this.canvasEl.height = height; this.canvasEl.width = width; // Part of the fix for IE6 select z-index bug and FF on Mac scrollbar z-index bug if (Browser.Engine.trident4){ this.zIndexFixEl.setStyles({ 'width': width, 'height': height }); } // Set width this.windowEl.setStyle('width', width); this.overlayEl.setStyle('width', width); this.titleBarEl.setStyles({ 'width': width - shadowBlur2x, 'height': options.headerHeight }); // Draw Window var ctx = this.canvasEl.getContext('2d'); ctx.clearRect(0, 0, width, height); this.drawBoxCollapsed(ctx, width, height, shadowBlur, shadowOffset, shadows); if (options.useCanvasControls == true){ this.drawControls(width, height, shadows); } // Invisible dummy object. The last element drawn is not rendered consistently while resizing in IE6 and IE7 if ( Browser.Engine.trident ){ MochaUI.triangle(ctx, 0, 0, 10, 10, options.resizableColor, 0); } }, drawControls : function(width, height, shadows){ var options = this.options; var shadowBlur = options.shadowBlur; var shadowOffset = options.shadowOffset; var controlsOffset = options.controlsOffset; // Make sure controls are placed correctly. this.controlsEl.setStyles({ 'right': shadowBlur + shadowOffset.x + controlsOffset.right, 'top': shadowBlur - shadowOffset.y + controlsOffset.top }); this.canvasControlsEl.setStyles({ 'right': shadowBlur + shadowOffset.x + controlsOffset.right, 'top': shadowBlur - shadowOffset.y + controlsOffset.top }); // Calculate X position for controlbuttons //var mochaControlsWidth = 52; this.closebuttonX = options.closable ? this.mochaControlsWidth - 7 : this.mochaControlsWidth + 12; this.maximizebuttonX = this.closebuttonX - (options.maximizable ? 19 : 0); this.minimizebuttonX = this.maximizebuttonX - (options.minimizable ? 19 : 0); var ctx2 = this.canvasControlsEl.getContext('2d'); ctx2.clearRect(0, 0, 100, 100); if (this.options.closable){ this.closebutton( ctx2, this.closebuttonX, 7, options.closeBgColor, 1.0, options.closeColor, 1.0 ); } if (this.options.maximizable){ this.maximizebutton( ctx2, this.maximizebuttonX, 7, options.maximizeBgColor, 1.0, options.maximizeColor, 1.0 ); } if (this.options.minimizable){ this.minimizebutton( ctx2, this.minimizebuttonX, 7, options.minimizeBgColor, 1.0, options.minimizeColor, 1.0 ); } }, drawBox: function(ctx, width, height, shadowBlur, shadowOffset, shadows){ var shadowBlur2x = shadowBlur * 2; var cornerRadius = this.options.cornerRadius; // This is the drop shadow. It is created onion style. if ( shadows != false ) { for (var x = 0; x <= shadowBlur; x++){ MochaUI.roundedRect( ctx, shadowOffset.x + x, shadowOffset.y + x, width - (x * 2) - shadowOffset.x, height - (x * 2) - shadowOffset.y, cornerRadius + (shadowBlur - x), [0, 0, 0], x == shadowBlur ? .28 : .06 + (x * .01) ); } } // Window body. this.bodyRoundedRect( ctx, // context shadowBlur - shadowOffset.x, // x shadowBlur - shadowOffset.y, // y width - shadowBlur2x, // width height - shadowBlur2x, // height cornerRadius, // corner radius (this.options.type == 'notification' ? this.options.notificationBg : this.options.bodyBgColor) // Footer color ); if (this.options.type != 'notification'){ // Window header. this.topRoundedRect( ctx, // context shadowBlur - shadowOffset.x, // x shadowBlur - shadowOffset.y, // y width - shadowBlur2x, // width this.options.headerHeight, // height cornerRadius, // corner radius this.options.headerStartColor, // Header gradient's top color this.options.headerStopColor // Header gradient's bottom color ); } }, drawBoxCollapsed: function(ctx, width, height, shadowBlur, shadowOffset, shadows){ var options = this.options; var shadowBlur2x = shadowBlur * 2; var cornerRadius = options.cornerRadius; // This is the drop shadow. It is created onion style. if ( shadows != false ) { for (var x = 0; x <= shadowBlur; x++){ MochaUI.roundedRect( ctx, shadowOffset.x + x, shadowOffset.y + x, width - (x * 2) - shadowOffset.x, height - (x * 2) - shadowOffset.y, cornerRadius + (shadowBlur - x), [0, 0, 0], x == shadowBlur ? .3 : .06 + (x * .01) ); } } // Window header this.topRoundedRect2( ctx, // context shadowBlur - shadowOffset.x, // x shadowBlur - shadowOffset.y, // y width - shadowBlur2x, // width options.headerHeight + 2, // height cornerRadius, // corner radius options.headerStartColor, // Header gradient's top color options.headerStopColor // Header gradient's bottom color ); }, drawGauge: function(ctx, width, height, shadowBlur, shadowOffset, shadows){ var options = this.options; var radius = (width * .5) - (shadowBlur) + 16; if (shadows != false) { for (var x = 0; x <= shadowBlur; x++){ MochaUI.circle( ctx, width * .5 + shadowOffset.x, (height + options.headerHeight) * .5 + shadowOffset.x, (width *.5) - (x * 2) - shadowOffset.x, [0, 0, 0], x == shadowBlur ? .6 : .06 + (x * .04) ); } } MochaUI.circle( ctx, width * .5 - shadowOffset.x, (height + options.headerHeight) * .5 - shadowOffset.y, (width *.5) - shadowBlur, options.bodyBgColor, 1 ); // Draw gauge header this.canvasHeaderEl.setStyles({ 'top': shadowBlur - shadowOffset.y, 'left': shadowBlur - shadowOffset.x }); var ctx = this.canvasHeaderEl.getContext('2d'); ctx.clearRect(0, 0, width, 100); ctx.beginPath(); ctx.lineWidth = 24; ctx.lineCap = 'round'; ctx.moveTo(13, 13); ctx.lineTo(width - (shadowBlur*2) - 13, 13); ctx.strokeStyle = 'rgba(0, 0, 0, .25)'; ctx.stroke(); }, bodyRoundedRect: function(ctx, x, y, width, height, radius, rgb){ ctx.fillStyle = 'rgba(' + rgb.join(',') + ', 100)'; ctx.beginPath(); ctx.moveTo(x, y + radius); ctx.lineTo(x, y + height - radius); ctx.quadraticCurveTo(x, y + height, x + radius, y + height); ctx.lineTo(x + width - radius, y + height); ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius); ctx.lineTo(x + width, y + radius); ctx.quadraticCurveTo(x + width, y, x + width - radius, y); ctx.lineTo(x + radius, y); ctx.quadraticCurveTo(x, y, x, y + radius); ctx.fill(); }, topRoundedRect: function(ctx, x, y, width, height, radius, headerStartColor, headerStopColor){ var lingrad = ctx.createLinearGradient(0, 0, 0, height); lingrad.addColorStop(0, 'rgba(' + headerStartColor.join(',') + ', 1)'); lingrad.addColorStop(1, 'rgba(' + headerStopColor.join(',') + ', 1)'); ctx.fillStyle = lingrad; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x, y + height); ctx.lineTo(x + width, y + height); ctx.lineTo(x + width, y + radius); ctx.quadraticCurveTo(x + width, y, x + width - radius, y); ctx.lineTo(x + radius, y); ctx.quadraticCurveTo(x, y, x, y + radius); ctx.fill(); }, topRoundedRect2: function(ctx, x, y, width, height, radius, headerStartColor, headerStopColor){ var lingrad = ctx.createLinearGradient(0, this.options.shadowBlur - 1, 0, height + this.options.shadowBlur + 3); lingrad.addColorStop(0, 'rgba(' + headerStartColor.join(',') + ', 1)'); lingrad.addColorStop(1, 'rgba(' + headerStopColor.join(',') + ', 1)'); ctx.fillStyle = lingrad; ctx.beginPath(); ctx.moveTo(x, y + radius); ctx.lineTo(x, y + height - radius); ctx.quadraticCurveTo(x, y + height, x + radius, y + height); ctx.lineTo(x + width - radius, y + height); ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius); ctx.lineTo(x + width, y + radius); ctx.quadraticCurveTo(x + width, y, x + width - radius, y); ctx.lineTo(x + radius, y); ctx.quadraticCurveTo(x, y, x, y + radius); ctx.fill(); }, maximizebutton: function(ctx, x, y, rgbBg, aBg, rgb, a){ // Circle ctx.beginPath(); ctx.moveTo(x, y); ctx.arc(x, y, 7, 0, Math.PI*2, true); ctx.fillStyle = 'rgba(' + rgbBg.join(',') + ',' + aBg + ')'; ctx.fill(); // X sign ctx.strokeStyle = 'rgba(' + rgb.join(',') + ',' + a + ')'; ctx.beginPath(); ctx.moveTo(x, y - 4); ctx.lineTo(x, y + 4); ctx.stroke(); ctx.beginPath(); ctx.moveTo(x - 4, y); ctx.lineTo(x + 4, y); ctx.stroke(); }, closebutton: function(ctx, x, y, rgbBg, aBg, rgb, a){ // Circle ctx.beginPath(); ctx.moveTo(x, y); ctx.arc(x, y, 7, 0, Math.PI*2, true); ctx.fillStyle = 'rgba(' + rgbBg.join(',') + ',' + aBg + ')'; ctx.fill(); // Plus sign ctx.strokeStyle = 'rgba(' + rgb.join(',') + ',' + a + ')'; ctx.beginPath(); ctx.moveTo(x - 3, y - 3); ctx.lineTo(x + 3, y + 3); ctx.stroke(); ctx.beginPath(); ctx.moveTo(x + 3, y - 3); ctx.lineTo(x - 3, y + 3); ctx.stroke(); }, minimizebutton: function(ctx, x, y, rgbBg, aBg, rgb, a){ // Circle ctx.beginPath(); ctx.moveTo(x,y); ctx.arc(x,y,7,0,Math.PI*2,true); ctx.fillStyle = 'rgba(' + rgbBg.join(',') + ',' + aBg + ')'; ctx.fill(); // Minus sign ctx.strokeStyle = 'rgba(' + rgb.join(',') + ',' + a + ')'; ctx.beginPath(); ctx.moveTo(x - 4, y); ctx.lineTo(x + 4, y); ctx.stroke(); }, setMochaControlsWidth: function(){ this.mochaControlsWidth = 0; var options = this.options; if (options.minimizable){ this.mochaControlsWidth += (this.minimizeButtonEl.getStyle('margin-left').toInt() + this.minimizeButtonEl.getStyle('width').toInt()); } if (options.maximizable){ this.mochaControlsWidth += (this.maximizeButtonEl.getStyle('margin-left').toInt() + this.maximizeButtonEl.getStyle('width').toInt()); } if (options.closable){ this.mochaControlsWidth += (this.closeButtonEl.getStyle('margin-left').toInt() + this.closeButtonEl.getStyle('width').toInt()); } this.controlsEl.setStyle('width', this.mochaControlsWidth); if (options.useCanvasControls == true){ this.canvasControlsEl.setProperty('width', this.mochaControlsWidth); } }});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -