Skip to content

Commit aa84a39

Browse files
committed
Improving scaling method
1 parent 4e79773 commit aa84a39

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

js/blocks.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,29 @@ Blocks = function()
139139

140140
// Binding the mouse wheel
141141
self.div.bind('mousewheel', function(event, delta, deltaX, deltaY) {
142-
self.scale *= Math.pow(1.1, deltaY);
142+
var dX = self.mouseX - self.center.x;
143+
var dY = self.mouseY - self.center.y;
144+
var deltaScale = Math.pow(1.1, deltaY);
145+
self.center.x -= dX*(deltaScale-1);
146+
self.center.y -= dY*(deltaScale-1);
147+
self.scale *= deltaScale;
143148
self.redraw();
144149
});
145150
});
146151
};
147152

153+
/**
154+
* Gets the mouse position
155+
*/
156+
this.getPosition = function()
157+
{
158+
var position = {};
159+
position.x = (blocks.mouseX-blocks.center.x)/blocks.scale;
160+
position.y = (blocks.mouseY-blocks.center.y)/blocks.scale;
161+
162+
return position;
163+
};
164+
148165
/**
149166
* Adds a block
150167
*/

js/blocksmenu.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function BlocksMenu(blocks)
2828
*/
2929
this.show = function()
3030
{
31-
self.menu.css('margin-left', (10+blocks.mouseX)+'px');
32-
self.menu.css('margin-top', (10+blocks.mouseY)+'px');
31+
self.menu.css('margin-left', (5+blocks.mouseX)+'px');
32+
self.menu.css('margin-top', (5+blocks.mouseY)+'px');
3333
self.menu.show();
3434
self.visible = true;
3535
};
@@ -41,8 +41,7 @@ function BlocksMenu(blocks)
4141
if (self.visible) {
4242
self.hide();
4343
} else {
44-
self.position.x = (blocks.mouseX-blocks.center.x)/blocks.scale;
45-
self.position.y = (blocks.mouseY-blocks.center.y)/blocks.scale;
44+
self.position = blocks.getPosition();
4645

4746
// Sorting types by family
4847
var families = {};

0 commit comments

Comments
 (0)