зеркало из https://github.com/mozilla/pluotsorbet.git
Refactor into sendNativeEvent function
This commit is contained in:
Родитель
9168be4ddb
Коммит
0e909d6639
51
midp.js
51
midp.js
|
@ -577,40 +577,19 @@ MIDP.Context2D = (function() {
|
|||
var mouse_is_down = false;
|
||||
|
||||
c.addEventListener("mousedown", function(ev) {
|
||||
console.log("mousedown", ev.layerX, ev.layerY);
|
||||
mouse_is_down = true;
|
||||
var obj = CLASSES.newObject(CLASSES.getClass("com/sun/midp/events/NativeEvent"));
|
||||
obj.class.getField("type", "I").set(obj, MIDP.PEN_EVENT);
|
||||
obj.class.getField("intParam1", "I").set(obj, 1); // PRESSED
|
||||
obj.class.getField("intParam2", "I").set(obj, ev.layerX);
|
||||
obj.class.getField("intParam3", "I").set(obj, ev.layerY);
|
||||
obj.class.getField("intParam4", "I").set(obj, 1); // displayID
|
||||
MIDP.sendEvent(obj);
|
||||
MIDP.sendNativeEvent(MIDP.PEN_EVENT, MIDP.PRESSED, ev.layerX, ev.layerY);
|
||||
});
|
||||
|
||||
c.addEventListener("mousemove", function(ev) {
|
||||
if (mouse_is_down) {
|
||||
//console.log("mousemove");
|
||||
var obj = CLASSES.newObject(CLASSES.getClass("com/sun/midp/events/NativeEvent"));
|
||||
obj.class.getField("type", "I").set(obj, MIDP.PEN_EVENT);
|
||||
obj.class.getField("intParam1", "I").set(obj, 3); // DRAGGED
|
||||
obj.class.getField("intParam2", "I").set(obj, ev.layerX);
|
||||
obj.class.getField("intParam3", "I").set(obj, ev.layerY);
|
||||
obj.class.getField("intParam4", "I").set(obj, 1); // displayID
|
||||
MIDP.sendEvent(obj);
|
||||
MIDP.sendNativeEvent(MIDP.PEN_EVENT, MIDP.DRAGGED, ev.layerX, ev.layerY)
|
||||
}
|
||||
});
|
||||
|
||||
c.addEventListener("mouseup", function(ev) {
|
||||
console.log("mouseup");
|
||||
mouse_is_down = false;
|
||||
var obj = CLASSES.newObject(CLASSES.getClass("com/sun/midp/events/NativeEvent"));
|
||||
obj.class.getField("type", "I").set(obj, MIDP.PEN_EVENT);
|
||||
obj.class.getField("intParam1", "I").set(obj, 2); // RELEASED
|
||||
obj.class.getField("intParam2", "I").set(obj, ev.layerX);
|
||||
obj.class.getField("intParam2", "I").set(obj, ev.layerY);
|
||||
obj.class.getField("intParam4", "I").set(obj, 1); // displayID
|
||||
MIDP.sendEvent(obj);
|
||||
MIDP.sendNativeEvent(MIDP.PEN_EVENT, MIDP.RELEASED, ev.layerX, ev.layerY);
|
||||
});
|
||||
|
||||
return c.getContext("2d");
|
||||
|
@ -789,19 +768,31 @@ MIDP.sendEvent = function(obj) {
|
|||
MIDP.waitingNativeEventContext = null;
|
||||
}
|
||||
|
||||
MIDP.sendNativeEvent = function(type, intParam1, intParam2, intParam3) {
|
||||
var obj = CLASSES.newObject(CLASSES.getClass("com/sun/midp/events/NativeEvent"));
|
||||
obj.class.getField("type", "I").set(obj, type);
|
||||
if (intParam1 !== undefined)
|
||||
obj.class.getField("intParam1", "I").set(obj, intParam1); // PRESSED
|
||||
if (intParam2 !== undefined)
|
||||
obj.class.getField("intParam2", "I").set(obj, intParam2);
|
||||
if (intParam3 !== undefined)
|
||||
obj.class.getField("intParam3", "I").set(obj, intParam3);
|
||||
|
||||
obj.class.getField("intParam4", "I").set(obj, 1); // displayID
|
||||
MIDP.sendEvent(obj);
|
||||
}
|
||||
|
||||
MIDP.KEY_EVENT = 1;
|
||||
MIDP.PEN_EVENT = 2;
|
||||
MIDP.PRESSED = 1;
|
||||
MIDP.RELEASED = 2;
|
||||
MIDP.DRAGGED = 3;
|
||||
MIDP.COMMAND_EVENT = 3;
|
||||
MIDP.EVENT_QUEUE_SHUTDOWN = 31;
|
||||
|
||||
window.addEventListener("keypress", function(ev) {
|
||||
ev.preventDefault();
|
||||
var obj = CLASSES.newObject(CLASSES.getClass("com/sun/midp/events/NativeEvent"));
|
||||
obj.class.getField("type", "I").set(obj, MIDP.KEY_EVENT);
|
||||
obj.class.getField("intParam1", "I").set(obj, 1); // PRESSED
|
||||
obj.class.getField("intParam2", "I").set(obj, ev.which);
|
||||
obj.class.getField("intParam4", "I").set(obj, 1); // displayID
|
||||
MIDP.sendEvent(obj);
|
||||
MIDP.sendNativeEvent(MIDP.KEY_EVENT, MIDP.PRESSED, ev.which);
|
||||
});
|
||||
|
||||
Native["com/sun/midp/events/NativeEventMonitor.waitForNativeEvent.(Lcom/sun/midp/events/NativeEvent;)I"] = function(ctx, stack) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче