Fixed bug: removing mouse event listener causes mouse events stop working. Use hand cursor fixed.

This commit is contained in:
Yaski
2012-07-24 19:29:22 +06:00
parent 42aca415c2
commit bddeffa66a
2 changed files with 162 additions and 41 deletions

View File

@@ -172,26 +172,53 @@ package alternativa.engine3d.core {
*/ */
public class Object3D implements IEventDispatcher { public class Object3D implements IEventDispatcher {
// Mouse moving
private static const MOUSE_MOVE_BIT:uint = 1;
private static const MOUSE_OVER_BIT:uint = 2;
private static const MOUSE_OUT_BIT:uint = 4;
private static const ROLL_OVER_BIT:uint = 0x8;
private static const ROLL_OUT_BIT:uint = 0x10;
private static const USE_HAND_CURSOR_BIT:uint = 0x20;
// Mouse pressing
private static const MOUSE_DOWN_BIT:uint = 0x40;
private static const MOUSE_UP_BIT:uint = 0x80;
private static const CLICK_BIT:uint = 0x100;
private static const DOUBLE_CLICK_BIT:uint = 0x200;
// Mouse wheel
private static const MOUSE_WHEEL_BIT:uint = 0x400;
// Mouse middle button
private static const MIDDLE_CLICK_BIT:uint = 0x800;
private static const MIDDLE_MOUSE_DOWN_BIT:uint = 0x1000;
private static const MIDDLE_MOUSE_UP_BIT:uint = 0x2000;
// Mouse right button
private static const RIGHT_CLICK_BIT:uint = 0x4000;
private static const RIGHT_MOUSE_DOWN_BIT:uint = 0x8000;
private static const RIGHT_MOUSE_UP_BIT:uint = 0x10000;
/** /**
* @private * @private
*/ */
alternativa3d static const MOUSE_HANDLING_MOVING:uint = 1; alternativa3d static const MOUSE_HANDLING_MOVING:uint = MOUSE_MOVE_BIT | MOUSE_OVER_BIT | MOUSE_OUT_BIT | ROLL_OVER_BIT | ROLL_OUT_BIT | USE_HAND_CURSOR_BIT;
/** /**
* @private * @private
*/ */
alternativa3d static const MOUSE_HANDLING_PRESSING:uint = 2; alternativa3d static const MOUSE_HANDLING_PRESSING:uint = MOUSE_DOWN_BIT | MOUSE_UP_BIT | CLICK_BIT | DOUBLE_CLICK_BIT;
/** /**
* @private * @private
*/ */
alternativa3d static const MOUSE_HANDLING_WHEEL:uint = 4; alternativa3d static const MOUSE_HANDLING_WHEEL:uint = MOUSE_WHEEL_BIT;
/** /**
* @private * @private
*/ */
alternativa3d static const MOUSE_HANDLING_MIDDLE_BUTTON:uint = 8; alternativa3d static const MOUSE_HANDLING_MIDDLE_BUTTON:uint = MIDDLE_CLICK_BIT | MIDDLE_MOUSE_DOWN_BIT | MIDDLE_MOUSE_UP_BIT;
/** /**
* @private * @private
*/ */
alternativa3d static const MOUSE_HANDLING_RIGHT_BUTTON:uint = 16; alternativa3d static const MOUSE_HANDLING_RIGHT_BUTTON:uint = RIGHT_CLICK_BIT | RIGHT_MOUSE_DOWN_BIT | RIGHT_MOUSE_UP_BIT;
/** /**
* Custom data available to store within <code>Object3D</code> by user. * Custom data available to store within <code>Object3D</code> by user.
@@ -249,12 +276,6 @@ package alternativa.engine3d.core {
*/ */
public var doubleClickEnabled:Boolean = false; public var doubleClickEnabled:Boolean = false;
/**
* A Boolean value that indicates whether the pointing hand (hand cursor)
* appears when the pointer rolls over a <code>Object3D</code>.
*/
public var useHandCursor:Boolean = false;
/** /**
* Bounds of the object described as rectangular parallelepiped. * Bounds of the object described as rectangular parallelepiped.
*/ */
@@ -587,6 +608,25 @@ package alternativa.engine3d.core {
transformChanged = true; transformChanged = true;
} }
/**
* A Boolean value that indicates whether the pointing hand (hand cursor)
* appears when the pointer rolls over a <code>Object3D</code>.
*/
public function get useHandCursor():Boolean {
return (mouseHandlingType & USE_HAND_CURSOR_BIT) != 0;
}
/**
* @private
*/
public function set useHandCursor(value:Boolean):void {
if (value) {
mouseHandlingType |= USE_HAND_CURSOR_BIT;
} else {
mouseHandlingType &= ~USE_HAND_CURSOR_BIT;
}
}
/** /**
* Searches for the intersection of an <code>Object3D</code> and given ray, defined by <code>origin</code> and <code>direction</code>. * Searches for the intersection of an <code>Object3D</code> and given ray, defined by <code>origin</code> and <code>direction</code>.
* *
@@ -739,20 +779,56 @@ package alternativa.engine3d.core {
vector = new Vector.<Function>(); vector = new Vector.<Function>();
listeners[type] = vector; listeners[type] = vector;
if (type == MouseEvent3D.MOUSE_MOVE || type == MouseEvent3D.MOUSE_OVER || type == MouseEvent3D.MOUSE_OUT || type == MouseEvent3D.ROLL_OVER || type == MouseEvent3D.ROLL_OUT) { // update mouseHandlingType bits
mouseHandlingType |= MOUSE_HANDLING_MOVING; switch (type) {
} case MouseEvent3D.MOUSE_MOVE:
if (type == MouseEvent3D.MOUSE_DOWN || type == MouseEvent3D.MOUSE_UP || type == MouseEvent3D.CLICK || type == MouseEvent3D.DOUBLE_CLICK) { mouseHandlingType |= MOUSE_MOVE_BIT;
mouseHandlingType |= MOUSE_HANDLING_PRESSING; break;
} case MouseEvent3D.MOUSE_OVER:
if (type == MouseEvent3D.MOUSE_WHEEL) { mouseHandlingType |= MOUSE_OVER_BIT;
mouseHandlingType |= MOUSE_HANDLING_WHEEL; break;
} case MouseEvent3D.MOUSE_OUT:
if (type == MouseEvent3D.MIDDLE_CLICK || type == MouseEvent3D.MIDDLE_MOUSE_DOWN || type == MouseEvent3D.MIDDLE_MOUSE_UP) { mouseHandlingType |= MOUSE_OUT_BIT;
mouseHandlingType |= MOUSE_HANDLING_MIDDLE_BUTTON; break;
} case MouseEvent3D.ROLL_OVER:
if (type == MouseEvent3D.RIGHT_CLICK || type == MouseEvent3D.RIGHT_MOUSE_DOWN || type == MouseEvent3D.RIGHT_MOUSE_UP) { mouseHandlingType |= ROLL_OVER_BIT;
mouseHandlingType |= MOUSE_HANDLING_RIGHT_BUTTON; break;
case MouseEvent3D.ROLL_OUT:
mouseHandlingType |= ROLL_OUT_BIT;
break;
case MouseEvent3D.MOUSE_DOWN:
mouseHandlingType |= MOUSE_DOWN_BIT;
break;
case MouseEvent3D.MOUSE_UP:
mouseHandlingType |= MOUSE_UP_BIT;
break;
case MouseEvent3D.CLICK:
mouseHandlingType |= CLICK_BIT;
break;
case MouseEvent3D.DOUBLE_CLICK:
mouseHandlingType |= DOUBLE_CLICK_BIT;
break;
case MouseEvent3D.MOUSE_WHEEL:
mouseHandlingType |= MOUSE_WHEEL_BIT;
break;
case MouseEvent3D.MIDDLE_CLICK:
mouseHandlingType |= MIDDLE_CLICK_BIT;
break;
case MouseEvent3D.MIDDLE_MOUSE_DOWN:
mouseHandlingType |= MIDDLE_MOUSE_DOWN_BIT;
break;
case MouseEvent3D.MIDDLE_MOUSE_UP:
mouseHandlingType |= MIDDLE_MOUSE_UP_BIT;
break;
case MouseEvent3D.RIGHT_CLICK:
mouseHandlingType |= RIGHT_CLICK_BIT;
break;
case MouseEvent3D.RIGHT_MOUSE_DOWN:
mouseHandlingType |= RIGHT_MOUSE_DOWN_BIT;
break;
case MouseEvent3D.RIGHT_MOUSE_UP:
mouseHandlingType |= RIGHT_MOUSE_UP_BIT;
break;
} }
} }
if (vector.indexOf(listener) < 0) { if (vector.indexOf(listener) < 0) {
@@ -781,7 +857,68 @@ package alternativa.engine3d.core {
if (length > 1) { if (length > 1) {
vector.length = length - 1; vector.length = length - 1;
} else { } else {
// update mouseHandlingType bits
var noListeners:Boolean;
if (listeners == captureListeners) {
noListeners = (bubbleListeners == null || bubbleListeners[type] == null);
} else {
noListeners = (captureListeners == null || captureListeners[type] == null);
}
if (noListeners) {
switch (type) {
case MouseEvent3D.MOUSE_MOVE:
mouseHandlingType &= ~MOUSE_MOVE_BIT;
break;
case MouseEvent3D.MOUSE_OVER:
mouseHandlingType &= ~MOUSE_OVER_BIT;
break;
case MouseEvent3D.MOUSE_OUT:
mouseHandlingType &= ~MOUSE_OUT_BIT;
break;
case MouseEvent3D.ROLL_OVER:
mouseHandlingType &= ~ROLL_OVER_BIT;
break;
case MouseEvent3D.ROLL_OUT:
mouseHandlingType &= ~ROLL_OUT_BIT;
break;
case MouseEvent3D.MOUSE_DOWN:
mouseHandlingType &= ~MOUSE_DOWN_BIT;
break;
case MouseEvent3D.MOUSE_UP:
mouseHandlingType &= ~MOUSE_UP_BIT;
break;
case MouseEvent3D.CLICK:
mouseHandlingType &= ~CLICK_BIT;
break;
case MouseEvent3D.DOUBLE_CLICK:
mouseHandlingType &= ~DOUBLE_CLICK_BIT;
break;
case MouseEvent3D.MOUSE_WHEEL:
mouseHandlingType &= ~MOUSE_WHEEL_BIT;
break;
case MouseEvent3D.MIDDLE_CLICK:
mouseHandlingType &= ~MIDDLE_CLICK_BIT;
break;
case MouseEvent3D.MIDDLE_MOUSE_DOWN:
mouseHandlingType &= ~MIDDLE_MOUSE_DOWN_BIT;
break;
case MouseEvent3D.MIDDLE_MOUSE_UP:
mouseHandlingType &= ~MIDDLE_MOUSE_UP_BIT;
break;
case MouseEvent3D.RIGHT_CLICK:
mouseHandlingType &= ~RIGHT_CLICK_BIT;
break;
case MouseEvent3D.RIGHT_MOUSE_DOWN:
mouseHandlingType &= ~RIGHT_MOUSE_DOWN_BIT;
break;
case MouseEvent3D.RIGHT_MOUSE_UP:
mouseHandlingType &= ~RIGHT_MOUSE_UP_BIT;
break;
}
}
delete listeners[type]; delete listeners[type];
var key:*; var key:*;
for (key in listeners) break; for (key in listeners) break;
if (!key) { if (!key) {
@@ -791,21 +928,6 @@ package alternativa.engine3d.core {
bubbleListeners = null; bubbleListeners = null;
} }
} }
if (type == MouseEvent3D.MOUSE_MOVE || type == MouseEvent3D.MOUSE_OVER || type == MouseEvent3D.MOUSE_OUT || type == MouseEvent3D.ROLL_OVER || type == MouseEvent3D.ROLL_OUT) {
mouseHandlingType &= ~MOUSE_HANDLING_MOVING;
}
if (type == MouseEvent3D.MOUSE_DOWN || type == MouseEvent3D.MOUSE_UP || type == MouseEvent3D.CLICK || type == MouseEvent3D.DOUBLE_CLICK) {
mouseHandlingType &= ~MOUSE_HANDLING_PRESSING;
}
if (type == MouseEvent3D.MOUSE_WHEEL) {
mouseHandlingType &= ~MOUSE_HANDLING_WHEEL;
}
if (type == MouseEvent3D.MIDDLE_CLICK || type == MouseEvent3D.MIDDLE_MOUSE_DOWN || type == MouseEvent3D.MIDDLE_MOUSE_UP) {
mouseHandlingType &= ~MOUSE_HANDLING_MIDDLE_BUTTON;
}
if (type == MouseEvent3D.RIGHT_CLICK || type == MouseEvent3D.RIGHT_MOUSE_DOWN || type == MouseEvent3D.RIGHT_MOUSE_UP) {
mouseHandlingType &= ~MOUSE_HANDLING_RIGHT_BUTTON;
}
} }
} }
} }

View File

@@ -58,7 +58,6 @@ package alternativa.engine3d.resources {
if (data != null) { if (data != null) {
var source:BitmapData = data; var source:BitmapData = data;
if (resizeForGPU) { if (resizeForGPU) {
// TODO: test this
var wLog2Num:Number = Math.log(data.width)/Math.LN2; var wLog2Num:Number = Math.log(data.width)/Math.LN2;
var hLog2Num:Number = Math.log(data.height)/Math.LN2; var hLog2Num:Number = Math.log(data.height)/Math.LN2;
var wLog2:int = Math.ceil(wLog2Num); var wLog2:int = Math.ceil(wLog2Num);