Commit 4df655fe authored by techird's avatar techird

zoom

parent 0a07428c
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
"KITYMINDER_CONFIG", "KITYMINDER_CONFIG",
"keymap", "keymap",
"Utils", "Utils",
"utils" "utils",
"$",
"KM"
] ]
} }
\ No newline at end of file
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(), 'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏 //定义工具栏
toolbars: [ toolbars: [
'hand | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers' 'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers'
] ]
//设置主题 //设置主题
......
KM.registerUI( 'hand', function zoom( paper, rate ) {
var viewbox = paper.getViewBox();
var zoomValue = paper._zoom || 1;
var w = viewbox.width,
h = viewbox.height,
x = viewbox.x,
y = viewbox.y;
var ww = w * rate,
hh = h * rate,
xx = x + ( w - ww ) / 2,
yy = y + ( h - hh ) / 2;
var animator = new kity.Animator( {
beginValue: viewbox,
finishValue: {
width: ww,
height: hh,
x: xx,
y: yy
},
setter: function ( target, value ) {
target.setViewBox( value.x, value.y, value.width, value.height );
}
} );
animator.start( paper, 100, 'ease' );
paper._zoom = zoomValue *= rate;
return zoomValue;
}
KM.registerUI( 'hand zoom-in zoom-out',
function ( name ) { function ( name ) {
var me = this; var me = this;
var $btn = $.kmuibutton( { var $btn = $.kmuibutton( {
icon: name, icon: name,
click: function ( e ) { click: {
var drag = me._onDragMode = !me._onDragMode; 'hand': function ( e ) {
me._paper.setStyle( 'cursor', drag ? 'pointer' : 'default' ); var drag = me._onDragMode = !me._onDragMode;
me._paper.setStyle( 'cursor', drag ? '-webkit-grab' : 'default' ); me._paper.setStyle( 'cursor', drag ? 'pointer' : 'default' );
$btn.kmui().active( drag ); me._paper.setStyle( 'cursor', drag ? '-webkit-grab' : 'default' );
if ( drag ) { $btn.kmui().active( drag );
me._paper.drag(); if ( drag ) {
} else { me._paper.drag();
me._paper.undrag(); } else {
me._paper.undrag();
}
},
'zoom-in': function ( e ) {
var value = zoom( me.getPaper(), 0.707 );
me.fire( 'zoom', {
zoom: value
} );
},
'zoom-out': function ( e ) {
var value = zoom( me.getPaper(), 1 / 0.707 );
me.fire( 'zoom', {
zoom: value
} );
} }
}, }[ name ],
title: this.getLang( 'tooltips.' )[ name ] || '' title: this.getLang( 'tooltips.' )[ name ] || ''
} ); } );
me.on( 'beforemousemove', function ( e ) { switch ( name ) {
if ( this._onDragMode ) { case 'hand':
e.stopPropagation(); me.on( 'beforemousemove', function ( e ) {
} if ( this._onDragMode ) {
} ); e.stopPropagation();
kity.extendClass( kity.Paper, kity.Draggable ); }
} );
kity.extendClass( kity.Paper, kity.Draggable );
break;
case 'zoom-in':
me.on( 'zoom', function ( e ) {
$btn.kmui().disabled( e.zoom <= 0.5 );
} );
break;
case 'zoom-out':
me.on( 'zoom', function ( e ) {
$btn.kmui().disabled( e.zoom >= 2 );
} );
me.on( 'mousewheel', function ( e ) {
var delta = e.originEvent.wheelDelta;
if ( Math.abs( delta ) > 100 ) {
clearTimeout( me._wheelZoomTimeout );
} else {
return;
}
me._wheelZoomTimeout = setTimeout( function () {
var value;
var lastValue = me.getPaper()._zoom || 1;
if ( delta < 0 && lastValue > 0.5 ) {
value = zoom( me.getPaper(), 0.707 );
me.fire( 'zoom', {
zoom: value
} );
} else if ( delta > 0 && lastValue < 2 ) {
value = zoom( me.getPaper(), 1 / 0.707 );
me.fire( 'zoom', {
zoom: value
} );
}
}, 100 );
e.originEvent.preventDefault();
} );
}
return $btn; return $btn;
} }
); );
\ No newline at end of file
...@@ -206,8 +206,8 @@ var DragBox = kity.createClass( "DragBox", { ...@@ -206,8 +206,8 @@ var DragBox = kity.createClass( "DragBox", {
} }
if ( target ) { if ( target ) {
this._addDropStyle( target ); this._addDropStyle( target );
this._lastSucceedTarget = target;
} }
this._lastSucceedTarget = target;
}, },
_removeDropStyle: function ( node ) { _removeDropStyle: function ( node ) {
...@@ -215,7 +215,7 @@ var DragBox = kity.createClass( "DragBox", { ...@@ -215,7 +215,7 @@ var DragBox = kity.createClass( "DragBox", {
}, },
_addDropStyle: function ( node ) { _addDropStyle: function ( node ) {
node._layout.bgRect.stroke( 'rgb(254, 219, 0)', 2 ); node._layout.bgRect.stroke( 'rgb(254, 219, 0)', 3 );
}, },
dragStart: function ( position ) { dragStart: function ( position ) {
......
...@@ -80,7 +80,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -80,7 +80,7 @@ KityMinder.registerModule( "Select", function () {
} }
if ( marqueeMode ) { if ( marqueeMode ) {
marqueeShape.fadeOut( 200, 'ease', 0, function () { marqueeShape.fadeOut( 200, 'ease', 0, function () {
marqueeShape.remove(); if(marqueeShape.remove) marqueeShape.remove();
} ); } );
marqueeMode = false; marqueeMode = false;
} }
......
KityMinder.registerModule( 'Zoom', function () { KityMinder.registerModule( 'Zoom', function () {
/*
return { return {
events: { events: {
'mousewheel': function ( e ) { 'mousewheel': function ( e ) {
if ( e.originEvent.wheelDelta > 0 ) {
if ( this._zoom < 0.2 ) return;
this._zoom *= 0.95;
this.getRenderContainer().scale( 0.95 );
} else {
if ( this._zoom > 5 ) return;
this._zoom /= 0.95;
this.getRenderContainer().scale( 1 / 0.95 );
}
e.originEvent.preventDefault(); e.originEvent.preventDefault();
}, },
'ready': function () { 'ready': function () {
this._zoom = 1; this._zoom = 1;
} }
} }
};*/ };
return {};
} ); } );
\ No newline at end of file
...@@ -22,4 +22,10 @@ ...@@ -22,4 +22,10 @@
} }
.kmui-btn-toolbar .kmui-btn .kmui-icon-clock { .kmui-btn-toolbar .kmui-btn .kmui-icon-clock {
background: url(../images/clock.png) no-repeat 2px 2px; background: url(../images/clock.png) no-repeat 2px 2px;
}
.kmui-btn-toolbar .kmui-btn .kmui-icon-zoom-in {
background: url(../images/zoom_in.png) no-repeat 2px 2px;
}
.kmui-btn-toolbar .kmui-btn .kmui-icon-zoom-out {
background: url(../images/zoom_out.png) no-repeat 2px 2px;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment