Skip to content

Commit

Permalink
added render.options.showMousePosition
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Dec 2, 2015
1 parent e0a6de0 commit e191d44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
demo.mouseConstraint = MouseConstraint.create(demo.engine);
World.add(demo.engine.world, demo.mouseConstraint);

// pass mouse to renderer to enable showMousePosition
demo.engine.render.mouse = demo.mouseConstraint.mouse;

// get the scene function name from hash
if (window.location.hash.length !== 0)
demo.sceneName = window.location.hash.replace('#', '').replace('-inspect', '');
Expand Down
21 changes: 20 additions & 1 deletion src/render/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var Grid = require('../collision/Grid');
controller: Render,
element: null,
canvas: null,
mouse: null,
options: {
width: 800,
height: 600,
Expand All @@ -58,7 +59,8 @@ var Grid = require('../collision/Grid');
showShadows: false,
showVertexNumbers: false,
showConvexHulls: false,
showInternalEdges: false
showInternalEdges: false,
showMousePosition: false
}
};

Expand Down Expand Up @@ -226,6 +228,9 @@ var Grid = require('../collision/Grid');
if (options.showVertexNumbers)
Render.vertexNumbers(engine, bodies, context);

if (options.showMousePosition)
Render.mousePosition(engine, render.mouse, context);

Render.constraints(constraints, context);

if (options.showBroadphase && engine.broadphase.controller === Grid)
Expand Down Expand Up @@ -592,6 +597,20 @@ var Grid = require('../collision/Grid');
}
};

/**
* Renders mouse position.
* @private
* @method mousePosition
* @param {engine} engine
* @param {mouse} mouse
* @param {RenderingContext} context
*/
Render.mousePosition = function(engine, mouse, context) {
var c = context;
c.fillStyle = 'rgba(255,255,255,0.8)';
c.fillText(mouse.position.x + ' ' + mouse.position.y, mouse.position.x + 5, mouse.position.y - 5);
};

/**
* Draws body bounds
* @private
Expand Down

0 comments on commit e191d44

Please sign in to comment.