summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/drawing/plugins/tools/Zoom.js
blob: 14105999930c4c239e6a0f321e42b2b146a2a30b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.drawing.plugins.tools.Zoom"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.drawing.plugins.tools.Zoom"] = true;
dojo.provide("dojox.drawing.plugins.tools.Zoom");
dojo.require("dojox.drawing.plugins._Plugin");

(function(){
	//
	// 	zoomInc: Float
	//		The amount of zoom that will occur upon each click.
	var zoomInc = Math.pow(2.0,0.25),
	//
	//	maxZoom: Number
	//		The maximum the canvas can be zoomed in. 10 = 1000%
	maxZoom = 10,
	//
	//	minZoom: Float
	//		The most the canvas can be zoomed out. .1 = 10%
	minZoom = 0.1,
	//
	//	zoomFactor: [readonly] Float
	//		The current zoom amount
	zoomFactor = 1,
	
	dt = dojox.drawing.plugins.tools;
	
	dt.ZoomIn = dojox.drawing.util.oo.declare(
		// summary:
		//		A plugin that allows for zooming the canvas in and out. An
		//		action-tool is added to the toolbar with plus, minus and 100%
		//		buttons.
		//
		function(options){
			// mix in private vars
			
		},
		{}
	);
	
	
	dt.ZoomIn = dojox.drawing.util.oo.declare(
		// summary:
		dojox.drawing.plugins._Plugin,
		function(options){
			
		},
		{
			type:"dojox.drawing.plugins.tools.ZoomIn",
			onZoomIn: function(){
				// summary:
				//		Handles zoom in.
				//
				zoomFactor *= zoomInc;
				zoomFactor = Math.min(zoomFactor, maxZoom);
				this.canvas.setZoom(zoomFactor);
				this.mouse.setZoom(zoomFactor);
			},
			onClick: function(){
				this.onZoomIn();
			}
		}
	);
	
	dt.Zoom100 = dojox.drawing.util.oo.declare(
		// summary:
		dojox.drawing.plugins._Plugin,
		function(options){
			
		},
		{
			type:"dojox.drawing.plugins.tools.Zoom100",
			onZoom100: function(){
				// summary:
				//		Zooms to 100%
				//
				zoomFactor = 1;
				this.canvas.setZoom(zoomFactor);
				this.mouse.setZoom(zoomFactor);
			},
			onClick: function(){
				this.onZoom100();
			}
		}
	);
	
	dt.ZoomOut = dojox.drawing.util.oo.declare(
		// summary:
		dojox.drawing.plugins._Plugin,
		function(options){
			
		},
		{
			type:"dojox.drawing.plugins.tools.ZoomOut",
			onZoomOut: function(){
				// summary:
				//		Handles zoom out.
				//
				zoomFactor /= zoomInc;
				zoomFactor = Math.max(zoomFactor, minZoom);
				this.canvas.setZoom(zoomFactor);
				this.mouse.setZoom(zoomFactor);
			},
			onClick: function(){
				this.onZoomOut();
			}
		}
	);

	
	dt.ZoomIn.setup = {
		name:"dojox.drawing.plugins.tools.ZoomIn",
		tooltip:"Zoom In"
	};
	dojox.drawing.register(dt.ZoomIn.setup, "plugin");
	
	dt.Zoom100.setup = {
		name:"dojox.drawing.plugins.tools.Zoom100",
		tooltip:"Zoom to 100%"
	};
	dojox.drawing.register(dt.Zoom100.setup, "plugin");
	
	dt.ZoomOut.setup = {
		name:"dojox.drawing.plugins.tools.ZoomOut",
		tooltip:"Zoom In"
	};
	dojox.drawing.register(dt.ZoomOut.setup, "plugin");

})();

}