Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix SpriteFont origin parameter.

Implement mousedown/mouseup handling.
commit af1ca6e3c00399f7648a1baf0f6c05f24d1821b0 1 parent 7c46b41
@kg kg authored
Showing with 74 additions and 38 deletions.
  1. +68 −36 Libraries/JSIL.Browser.js
  2. +6 −2 Libraries/JSIL.XNACore.js
View
104 Libraries/JSIL.Browser.js
@@ -162,42 +162,74 @@ var keyMappings = {
18: [164, 165] // Left Alt, Right Alt
};
-window.addEventListener(
- "keydown", function (evt) {
- evt.preventDefault();
- var keyCode = evt.keyCode;
- var codes = keyMappings[keyCode] || [keyCode];
-
- for (var i = 0; i < codes.length; i++) {
- var code = codes[i];
- if (Array.prototype.indexOf.call(heldKeys, code) === -1)
- heldKeys.push(code);
- }
- }, true
-);
-
-window.addEventListener(
- "keyup", function (evt) {
- evt.preventDefault();
- var keyCode = evt.keyCode;
- var codes = keyMappings[keyCode] || [keyCode];
-
- heldKeys = heldKeys.filter(function (element, index, array) {
- return codes.indexOf(element) === -1;
- });
- }, true
-);
-
-window.addEventListener(
- "mousemove", function (evt) {
- var canvas = document.getElementById("canvas");
- if ((typeof (canvas) !== "object") || (canvas === null))
- return;
-
- mousePosition[0] = evt.clientX - canvas.offsetLeft;
- mousePosition[1] = evt.clientY - canvas.offsetTop;
- }, true
-);
+(function () {
+ var canvas = document.getElementById("canvas");
+
+ window.addEventListener(
+ "keydown", function (evt) {
+ evt.preventDefault();
+ var keyCode = evt.keyCode;
+ var codes = keyMappings[keyCode] || [keyCode];
+
+ for (var i = 0; i < codes.length; i++) {
+ var code = codes[i];
+ if (Array.prototype.indexOf.call(heldKeys, code) === -1)
+ heldKeys.push(code);
+ }
+ }, true
+ );
+
+ window.addEventListener(
+ "keyup", function (evt) {
+ evt.preventDefault();
+ var keyCode = evt.keyCode;
+ var codes = keyMappings[keyCode] || [keyCode];
+
+ heldKeys = heldKeys.filter(function (element, index, array) {
+ return codes.indexOf(element) === -1;
+ });
+ }, true
+ );
+
+ canvas.addEventListener(
+ "mousedown", function (evt) {
+ mousePosition[0] = evt.clientX - canvas.offsetLeft;
+ mousePosition[1] = evt.clientY - canvas.offsetTop;
+
+ var button = evt.button;
+ if (Array.prototype.indexOf.call(heldButtons, button) === -1)
+ heldButtons.push(button);
+
+ evt.preventDefault();
+ evt.stopPropagation();
+ }, true
+ );
+
+ canvas.addEventListener(
+ "mouseup", function (evt) {
+ mousePosition[0] = evt.clientX - canvas.offsetLeft;
+ mousePosition[1] = evt.clientY - canvas.offsetTop;
+
+ var button = evt.button;
+ heldButtons = heldButtons.filter(function (element, index, array) {
+ (element !== button);
+ });
+
+ evt.preventDefault();
+ evt.stopPropagation();
+ }, true
+ );
+
+ canvas.addEventListener(
+ "mousemove", function (evt) {
+ mousePosition[0] = evt.clientX - canvas.offsetLeft;
+ mousePosition[1] = evt.clientY - canvas.offsetTop;
+
+ evt.preventDefault();
+ evt.stopPropagation();
+ }, true
+ );
+})();
function getAssetName (filename, preserveCase) {
var backslashRe = /\\/g;
View
8 Libraries/JSIL.XNACore.js
@@ -4843,7 +4843,8 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.SpriteFont", function
result.X = Math.max(lineWidth, result.X);
lineWidth = 0;
- if (i < (l - 1)) lineCount += 1;
+ if (i < (l - 1))
+ lineCount += 1;
continue;
}
@@ -4894,6 +4895,9 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.SpriteFont", function
scaleX, scaleY,
spriteEffects, layerDepth
) {
+ textblockPositionX -= (originX * scaleX);
+ textblockPositionY -= (originY * scaleY);
+
var tVector2 = Microsoft.Xna.Framework.Vector2;
var positionX = textblockPositionX;
var positionY = textblockPositionY;
@@ -4934,7 +4938,7 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.SpriteFont", function
this.textureValue, drawX, drawY, glyphRect.Width * scaleX, glyphRect.Height * scaleY,
glyphRect.X, glyphRect.Y, glyphRect.Width, glyphRect.Height,
color, rotation,
- originX, originY,
+ 0, 0,
1, 1,
spriteEffects, layerDepth
);
Please sign in to comment.
Something went wrong with that request. Please try again.