Add flash.display.Stage, flash.ui.Keyboard, .Mouse stubs

This commit is contained in:
Yury Delendik 2012-06-05 12:09:28 -05:00
Родитель ed0a555c4b
Коммит a8c9026c86
8 изменённых файлов: 759 добавлений и 107 удалений

Просмотреть файл

@ -44,6 +44,18 @@
<script src="../../src/avm1/stream.js"></script> <script src="../../src/avm1/stream.js"></script>
<script src="../../src/avm1/interpreter.js"></script> <script src="../../src/avm1/interpreter.js"></script>
<script src="../../src/flash/util.js"></script>
<script src="../../src/flash/events/EventDispatcher.js"></script>
<script src="../../src/flash/display/DisplayObject.js"></script>
<script src="../../src/flash/display/InteractiveObject.js"></script>
<script src="../../src/flash/display/DisplayObjectContainer.js"></script>
<script src="../../src/flash/display/Graphics.js"></script>
<script src="../../src/flash/display/Sprite.js"></script>
<script src="../../src/flash/display/MovieClip.js"></script>
<script src="../../src/flash/display/Stage.js"></script>
<script src="../../src/flash/ui/Keyboard.js"></script>
<script src="../../src/flash/ui/Mouse.js"></script>
<script> <script>
SWF.embed("../../examples/racing/race.swf", document.getElementById("stage")); SWF.embed("../../examples/racing/race.swf", document.getElementById("stage"));
</script> </script>

Просмотреть файл

@ -92,6 +92,7 @@
}); });
</script> </script>
<script src="../src/flash/util.js"></script>
<script src="../src/flash/events/EventDispatcher.js"></script> <script src="../src/flash/events/EventDispatcher.js"></script>
<script src="../src/flash/display/DisplayObject.js"></script> <script src="../src/flash/display/DisplayObject.js"></script>
<script src="../src/flash/display/InteractiveObject.js"></script> <script src="../src/flash/display/InteractiveObject.js"></script>
@ -99,6 +100,9 @@
<script src="../src/flash/display/Graphics.js"></script> <script src="../src/flash/display/Graphics.js"></script>
<script src="../src/flash/display/Sprite.js"></script> <script src="../src/flash/display/Sprite.js"></script>
<script src="../src/flash/display/MovieClip.js"></script> <script src="../src/flash/display/MovieClip.js"></script>
<script src="../src/flash/display/Stage.js"></script>
<script src="../src/flash/ui/Keyboard.js"></script>
<script src="../src/flash/ui/Mouse.js"></script>
<div id="inputBar"> <div id="inputBar">
<span><a href="https://www.github.com/mozilla/shumway">shumway</a> inspector &nbsp;&nbsp;|&nbsp;&nbsp;</span> <span><a href="https://www.github.com/mozilla/shumway">shumway</a> inspector &nbsp;&nbsp;|&nbsp;&nbsp;</span>

Просмотреть файл

@ -1010,15 +1010,13 @@ defineObjectProperties(AS2Mouse, {
}, },
hide: { hide: {
value: function hide() { value: function hide() {
// flash.ui.Mouse.hide() Mouse.hide();
throw 'Not implemented: hide';
}, },
enumerable: false enumerable: false
}, },
show: { show: {
value: function show() { value: function show() {
// flash.ui.Mouse.show() Mouse.show();
throw 'Not implemented: show';
}, },
enumerable: false enumerable: false
} }
@ -1054,60 +1052,65 @@ AS2Broadcaster.initialize(AS2Mouse);
function AS2Stage() { function AS2Stage() {
} }
defineObjectProperties(AS2Stage, { defineObjectProperties(AS2Stage, {
$stage: {
get: function get$stage() {
return AS2Context.instance.stage;
}
},
align: { align: {
get: function get$align() { get: function get$align() {
throw 'Not implemented: get$align'; return this.$stage.align;
}, },
set: function set$align(value) { set: function set$align(value) {
throw 'Not implemented: set$align'; this.$stage.align = value;
}, },
enumerable: true enumerable: true
}, },
displayState: { displayState: {
get: function get$displayState() { get: function get$displayState() {
throw 'Not implemented: get$displayState'; return this.$stage.displayState;
}, },
set: function set$displayState(value) { set: function set$displayState(value) {
throw 'Not implemented: set$displayState'; this.$stage.displayState = value;
}, },
enumerable: true enumerable: true
}, },
fullScreenSourceRect: { fullScreenSourceRect: {
get: function get$fullScreenSourceRect() { get: function get$fullScreenSourceRect() {
throw 'Not implemented: get$fullScreenSourceRect'; return this.$stage.fullScreenSourceRect;
}, },
set: function set$fullScreenSourceRect(value) { set: function set$fullScreenSourceRect(value) {
throw 'Not implemented: set$fullScreenSourceRect'; this.$stage.fullScreenSourceRect = value;
}, },
enumerable: true enumerable: true
}, },
height: { height: {
get: function get$height() { get: function get$height() {
return AS2Context.instance.stage.height; return this.$stage.stageHeight;
}, },
enumerable: true enumerable: true
}, },
scaleMode: { scaleMode: {
get: function get$scaleMode() { get: function get$scaleMode() {
throw 'Not implemented: get$scaleMode'; return this.$stage.scaleMode;
}, },
set: function set$scaleMode(value) { set: function set$scaleMode(value) {
throw 'Not implemented: set$scaleMode'; this.$stage.scaleMode = value;
}, },
enumerable: true enumerable: true
}, },
showMenu: { showMenu: {
get: function get$showMenu() { get: function get$showMenu() {
throw 'Not implemented: get$showMenu'; return this.$stage.showDefaultContextMenu;
}, },
set: function set$showMenu(value) { set: function set$showMenu(value) {
throw 'Not implemented: set$showMenu'; this.$stage.showDefaultContextMenu = value;
}, },
enumerable: true enumerable: true
}, },
width: { width: {
get: function get$width() { get: function get$width() {
return AS2Context.instance.stage.width; return this.$stage.stageWidth;
}, },
enumerable: true enumerable: true
} }

Просмотреть файл

@ -0,0 +1,299 @@
function Stage() {
this._loaderInfo = null; // TODO
this._transform = [];
this._color = 0xFFFFFFFF;
}
Stage.prototype = Object.create(new DisplayObjectContainer, {
accessibilityProperties: descAccessor(function () {
return null; // read-only/default
}),
align: descAccessor(
function () {
return ''; // TODO
},
function (val) {
notImplemented();
}
),
allowsFullScreen: descAccessor(function () {
return false; // TODO
}),
alpha: descAccessor(function () {
return 1; // read-only/default
}),
blendMode: descAccessor(function () {
// TODO BlendMode.NORMAL
return 'normal'; // read-only/default
}),
cacheAsBitmap: descAccessor(function () {
return false; // read-only/default
}),
color: descAccessor(
function () {
return this._color;
},
function (val) {
this._color = val;
}
),
colorCorrection: descAccessor(
function () {
return 'default'; // TODO
},
function (val) {
notImplemented();
}
),
colorCorrectionSupport: descAccessor(function () {
return 'unsupported'; // TODO
}),
contextMenu: descAccessor(function () {
return null; // read-only/default
}),
displayState: descAccessor(
function () {
return null; // TODO
},
function (val) {
notImplemented();
}
),
filters: descAccessor(function () {
return []; // read-only/default
}),
focus: descAccessor(
function () {
return null; // TODO
},
function (val) {
notImplemented();
}
),
focusRect: descAccessor(function () {
return null; // read-only/default
}),
frameRate: descAccessor(
function () {
return this._frameRate;
},
function (val) {
if (val < 0.01 || val > 1000)
throw 'Invalid frame rate';
this._frameRate = val;
}
),
fullScreenHeight: descAccessor(function () {
notImplemented();
}),
fullScreenSourceRect: descAccessor(
function () {
return null; // TODO
},
function (val) {
notImplemented();
}
),
fullScreenWidth: descAccessor(function () {
notImplemented();
}),
invalidate: descMethod(function() {
notImplemented();
}),
isFocusInaccessible: descMethod(function() {
notImplemented();
}),
loaderInfo: descAccessor(function () {
return this._loaderInfo; // read-only/default
}),
mask: descAccessor(function () {
return null; // read-only/default
}),
mouseEnabled: descAccessor(function () {
return true; // read-only/default
}),
name: descAccessor(function () {
return null; // read-only/default
}),
nativeWindow: descAccessor(function () {
return null; // TODO
}),
opaqueBackground: descAccessor(function () {
return null; // read-only/default
}),
quality: descAccessor(
function () {
return 'HIGH'; // TODO
},
function (val) {
notImplemented();
}
),
rotation: descAccessor(function () {
return 0; // read-only/default
}),
scale9Grid: descAccessor(function () {
return null; // read-only/default
}),
scaleMode: descAccessor(
function () {
return 'noScale'; // TODO
},
function (val) {
notImplemented();
}
),
scaleX: descAccessor(function () {
return 1; // read-only/default
}),
scaleY: descAccessor(function () {
return 1; // read-only/default
}),
scrollRect: descAccessor(function () {
return null; // read-only/default
}),
showDefaultContextMenu: descAccessor(
function () {
return true; // TODO
},
function (val) {
notImplemented();
}
),
softKeyboardRect: descAccessor(function () {
notImplemented();
}),
stageFocusRect: descAccessor(
function () {
return false; // TODO
},
function (val) {
notImplemented();
}
),
stageHeight: descAccessor(
function () {
return this._stageHeight;
},
function (val) {
notImplemented();
}
),
stageWidth: descAccessor(
function () {
return this._stageWidth;
},
function (val) {
notImplemented();
}
),
tabEnabled: descAccessor(function () {
return false; // read-only/default
}),
tabIndex: descAccessor(function () {
return 1; // read-only/default
}),
transform: descAccessor(function () {
return this._transform; // read-only/default
}),
visible: descAccessor(function () {
return true; // read-only/default
}),
x: descAccessor(function () {
return 0; // read-only/default
}),
y: descAccessor(function () {
return 0; // read-only/default
}),
wmodeGPU: descAccessor(function () {
return false; // TODO
}),
_attachToCanvas: descMethod(function(parameters) {
var result;
var root;
var pframes = [];
var dictionary = parameters.dictionary;
var canvas = parameters.canvas;
var ctx = canvas.getContext('2d');
var frameRate, bounds;
var plays;
var as2Context = null;
var stage = this;
startWorking(parameters.file, function(obj) {
if (!root) {
bounds = obj.bounds;
stage._stageWidth = (bounds.xMax - bounds.xMin) / 20;
stage._stageHeight = (bounds.yMax - bounds.yMin) / 20
stage._frameRate = obj.frameRate;
// TODO disable AVM1 if AVM2 is enabled
as2Context = new AS2Context(obj.version, stage);
AS2Context.instance = as2Context;
var globals = as2Context.globals;
AS2Mouse.$bind(canvas);
AS2Key.$bind(canvas);
var proto = create(new MovieClipPrototype({
frameCount: obj.frameCount,
pframes: pframes
}, dictionary));
root = proto.constructor();
root.name = '_root';
globals._root = globals._level0 = root.$as2Object;
parameters.onstart(root, stage);
return;
}
AS2Context.instance = as2Context;
if (obj) {
if (obj.id) {
definePrototype(dictionary, obj);
} else if (obj.type === 'pframe') {
if (obj.bgcolor) {
stage._color = obj.bgcolor; // TODO convert to numeric
canvas.style.background = obj.bgcolor;
}
if (obj.abcBlocks) {
var blocks = obj.abcBlocks;
var i = 0;
var block;
while (block = blocks[i++]) {
var abc = new AbcFile(block);
executeAbc(abc, ALWAYS_INTERPRET);
}
}
if (obj.symbols) {
var symbols = obj.symbols;
var i = 0;
var sym;
while (sym = symbols[i++]) {
if (!sym.id) {
var mainTimeline = new (toplevel.getTypeByName(
Multiname.fromSimpleName(sym.name),
true
)).instance;
}
}
}
pframes.push(obj);
if (!plays) {
renderMovieClip(root, stage, ctx);
plays = true;
}
} else {
result = obj;
}
} else {
parameters.oncomplete(root, result);
}
});
})
});

372
src/flash/ui/Keyboard.js Normal file
Просмотреть файл

@ -0,0 +1,372 @@
function Keyboard() {
}
Object.defineProperties(Keyboard, {
capsLock: descAccessor(function () {
return Stage.instance.$keyboard.capsLock;
}),
hasVirtualKeyboard: descAccessor(function () {
return false; // TODO Stage.instance.$keyboard.hasVirtualKeyboard;
}),
numLock: descAccessor(function () {
return Stage.instance.$keyboard.numLock;
}),
physicalKeyboardType: descAccessor(function () {
return 'alphanumeric'; // TODO Stage.instance.$keyboard.physicalKeyboardType;
}),
isAccessible: descMethod(function () {
return true; // TODO
}),
A: descConst(65),
ALTERNATE: descConst(18),
AUDIO: descConst(0x01000017),
B: descConst(66),
BACK: descConst(0x01000016),
BACKQUOTE: descConst(192),
BACKSLASH: descConst(220),
BACKSPACE: descConst(8),
BLUE: descConst(0x01000003),
C: descConst(67),
CAPS_LOCK: descConst(20),
CHANNEL_DOWN: descConst(0x01000005),
CHANNEL_UP: descConst(0x01000004),
COMMA: descConst(188),
COMMAND: descConst(15),
CONTROL: descConst(17),
D: descConst(68),
DELETE: descConst(46),
DOWN: descConst(40),
DVR: descConst(0x01000019),
E: descConst(69),
END: descConst(35),
ENTER: descConst(13),
EQUAL: descConst(187),
ESCAPE: descConst(27),
EXIT: descConst(0x01000015),
F: descConst(70),
F1: descConst(112),
F10: descConst(121),
F11: descConst(122),
F12: descConst(123),
F13: descConst(124),
F14: descConst(125),
F15: descConst(126),
F2: descConst(113),
F3: descConst(114),
F4: descConst(115),
F5: descConst(116),
F6: descConst(117),
F7: descConst(118),
F8: descConst(119),
F9: descConst(120),
FAST_FORWARD: descConst(0x0100000A),
G: descConst(71),
GREEN: descConst(0x01000001),
GUIDE: descConst(0x01000014),
H: descConst(72),
HELP: descConst(0x0100001D),
HOME: descConst(36),
I: descConst(73),
INFO: descConst(0x01000013),
INPUT: descConst(0x0100001B),
INSERT: descConst(45),
J: descConst(74),
K: descConst(75),
KEYNAME_BEGIN: descConst('Begin'),
KEYNAME_BREAK: descConst('Break'),
KEYNAME_CLEARDISPLAY: descConst('ClrDsp'),
KEYNAME_CLEARLINE: descConst('ClrLn'),
KEYNAME_DELETE: descConst('Delete'),
KEYNAME_DELETECHAR: descConst('DelChr'),
KEYNAME_DELETELINE: descConst('DelLn'),
KEYNAME_DOWNARROW: descConst('Down'),
KEYNAME_END: descConst('End'),
KEYNAME_EXECUTE: descConst('Exec'),
KEYNAME_F1: descConst('F1'),
KEYNAME_F10: descConst('F10'),
KEYNAME_F11: descConst('F11'),
KEYNAME_F12: descConst('F12'),
KEYNAME_F13: descConst('F13'),
KEYNAME_F14: descConst('F14'),
KEYNAME_F15: descConst('F15'),
KEYNAME_F16: descConst('F16'),
KEYNAME_F17: descConst('F17'),
KEYNAME_F18: descConst('F18'),
KEYNAME_F19: descConst('F19'),
KEYNAME_F2: descConst('F2'),
KEYNAME_F20: descConst('F20'),
KEYNAME_F21: descConst('F21'),
KEYNAME_F22: descConst('F22'),
KEYNAME_F23: descConst('F23'),
KEYNAME_F24: descConst('F24'),
KEYNAME_F25: descConst('F25'),
KEYNAME_F26: descConst('F26'),
KEYNAME_F27: descConst('F27'),
KEYNAME_F28: descConst('F28'),
KEYNAME_F29: descConst('F29'),
KEYNAME_F3: descConst('F3'),
KEYNAME_F30: descConst('F30'),
KEYNAME_F31: descConst('F31'),
KEYNAME_F32: descConst('F32'),
KEYNAME_F33: descConst('F33'),
KEYNAME_F34: descConst('F34'),
KEYNAME_F35: descConst('F35'),
KEYNAME_F4: descConst('F4'),
KEYNAME_F5: descConst('F5'),
KEYNAME_F6: descConst('F6'),
KEYNAME_F7: descConst('F7'),
KEYNAME_F8: descConst('F8'),
KEYNAME_F9: descConst('F9'),
KEYNAME_FIND: descConst('Find'),
KEYNAME_HELP: descConst('Help'),
KEYNAME_HOME: descConst('Home'),
KEYNAME_INSERT: descConst('Insert'),
KEYNAME_INSERTCHAR: descConst('InsChr'),
KEYNAME_INSERTLINE: descConst('InsLn'),
KEYNAME_LEFTARROW: descConst('Left'),
KEYNAME_MENU: descConst('Menu'),
KEYNAME_MODESWITCH: descConst('ModeSw'),
KEYNAME_NEXT: descConst('Next'),
KEYNAME_PAGEDOWN: descConst('PgDn'),
KEYNAME_PAGEUP: descConst('PgUp'),
KEYNAME_PAUSE: descConst('Pause'),
KEYNAME_PREV: descConst('Prev'),
KEYNAME_PRINT: descConst('Print'),
KEYNAME_PRINTSCREEN: descConst('PrntScrn'),
KEYNAME_REDO: descConst('Redo'),
KEYNAME_RESET: descConst('Reset'),
KEYNAME_RIGHTARROW: descConst('Right'),
KEYNAME_SCROLLLOCK: descConst('ScrlLck'),
KEYNAME_SELECT: descConst('Select'),
KEYNAME_STOP: descConst('Stop'),
KEYNAME_SYSREQ: descConst('SysReq'),
KEYNAME_SYSTEM: descConst('Sys'),
KEYNAME_UNDO: descConst('Undo'),
KEYNAME_UPARROW: descConst('Up'),
KEYNAME_USER: descConst('User'),
L: descConst(76),
LAST: descConst(0x01000011),
LEFT: descConst(37),
LEFTBRACKET: descConst(219),
LIVE: descConst(0x01000010),
M: descConst(77),
MASTER_SHELL: descConst(0x0100001E),
MENU: descConst(0x01000012),
MINUS: descConst(189),
N: descConst(78),
NEXT: descConst(0x0100000E),
NUMBER_0: descConst(48),
NUMBER_1: descConst(49),
NUMBER_2: descConst(50),
NUMBER_3: descConst(51),
NUMBER_4: descConst(52),
NUMBER_5: descConst(53),
NUMBER_6: descConst(54),
NUMBER_7: descConst(55),
NUMBER_8: descConst(56),
NUMBER_9: descConst(57),
NUMPAD: descConst(21),
NUMPAD_0: descConst(96),
NUMPAD_1: descConst(97),
NUMPAD_2: descConst(98),
NUMPAD_3: descConst(99),
NUMPAD_4: descConst(100),
NUMPAD_5: descConst(101),
NUMPAD_6: descConst(102),
NUMPAD_7: descConst(103),
NUMPAD_8: descConst(104),
NUMPAD_9: descConst(105),
NUMPAD_ADD: descConst(107),
NUMPAD_DECIMAL: descConst(110),
NUMPAD_DIVIDE: descConst(111),
NUMPAD_ENTER: descConst(108),
NUMPAD_MULTIPLY: descConst(106),
NUMPAD_SUBTRACT: descConst(109),
O: descConst(79),
P: descConst(80),
PAGE_DOWN: descConst(34),
PAGE_UP: descConst(33),
PAUSE: descConst(0x01000008),
PERIOD: descConst(190),
PLAY: descConst(0x01000007),
PREVIOUS: descConst(0x0100000F),
Q: descConst(81),
QUOTE: descConst(222),
R: descConst(82),
RECORD: descConst(0x01000006),
RED: descConst(0x01000000),
REWIND: descConst(0x0100000B),
RIGHT: descConst(39),
RIGHTBRACKET: descConst(221),
S: descConst(83),
SEARCH: descConst(0x0100001F),
SEMICOLON: descConst(186),
SETUP: descConst(0x0100001C),
SHIFT: descConst(16),
SKIP_BACKWARD: descConst(0x0100000D),
SKIP_FORWARD: descConst(0x0100000C),
SLASH: descConst(191),
SPACE: descConst(32),
STOP: descConst(0x01000009),
STRING_BEGIN: descConst('\uF72A'),
STRING_BREAK: descConst('\uF732'),
STRING_CLEARDISPLAY: descConst('\uF73A'),
STRING_CLEARLINE: descConst('\uF739'),
STRING_DELETE: descConst('\uF728'),
STRING_DELETECHAR: descConst('\uF73E'),
STRING_DELETELINE: descConst('\uF73C'),
STRING_DOWNARROW: descConst('\uF701'),
STRING_END: descConst('\uF72B'),
STRING_EXECUTE: descConst('\uF742'),
STRING_F1: descConst('\uF704'),
STRING_F10: descConst('\uF70D'),
STRING_F11: descConst('\uF70E'),
STRING_F12: descConst('\uF70F'),
STRING_F13: descConst('\uF710'),
STRING_F14: descConst('\uF711'),
STRING_F15: descConst('\uF712'),
STRING_F16: descConst('\uF713'),
STRING_F17: descConst('\uF714'),
STRING_F18: descConst('\uF715'),
STRING_F19: descConst('\uF716'),
STRING_F2: descConst('\uF705'),
STRING_F20: descConst('\uF717'),
STRING_F21: descConst('\uF718'),
STRING_F22: descConst('\uF719'),
STRING_F23: descConst('\uF71A'),
STRING_F24: descConst('\uF71B'),
STRING_F25: descConst('\uF71C'),
STRING_F26: descConst('\uF71D'),
STRING_F27: descConst('\uF71E'),
STRING_F28: descConst('\uF71F'),
STRING_F29: descConst('\uF720'),
STRING_F3: descConst('\uF706'),
STRING_F30: descConst('\uF721'),
STRING_F31: descConst('\uF722'),
STRING_F32: descConst('\uF723'),
STRING_F33: descConst('\uF724'),
STRING_F34: descConst('\uF725'),
STRING_F35: descConst('\uF726'),
STRING_F4: descConst('\uF707'),
STRING_F5: descConst('\uF708'),
STRING_F6: descConst('\uF709'),
STRING_F7: descConst('\uF70A'),
STRING_F8: descConst('\uF70B'),
STRING_F9: descConst('\uF70C'),
STRING_FIND: descConst('\uF745'),
STRING_HELP: descConst('\uF746'),
STRING_HOME: descConst('\uF729'),
STRING_INSERT: descConst('\uF727'),
STRING_INSERTCHAR: descConst('\uF73D'),
STRING_INSERTLINE: descConst('\uF73B'),
STRING_LEFTARROW: descConst('\uF702'),
STRING_MENU: descConst('\uF735'),
STRING_MODESWITCH: descConst('\uF747'),
STRING_NEXT: descConst('\uF740'),
STRING_PAGEDOWN: descConst('\uF72D'),
STRING_PAGEUP: descConst('\uF72C'),
STRING_PAUSE: descConst('\uF730'),
STRING_PREV: descConst('\uF73F'),
STRING_PRINT: descConst('\uF738'),
STRING_PRINTSCREEN: descConst('\uF72E'),
STRING_REDO: descConst('\uF744'),
STRING_RESET: descConst('\uF733'),
STRING_RIGHTARROW: descConst('\uF703'),
STRING_SCROLLLOCK: descConst('\uF72F'),
STRING_SELECT: descConst('\uF741'),
STRING_STOP: descConst('\uF734'),
STRING_SYSREQ: descConst('\uF731'),
STRING_SYSTEM: descConst('\uF737'),
STRING_UNDO: descConst('\uF743'),
STRING_UPARROW: descConst('\uF700'),
STRING_USER: descConst('\uF736'),
SUBTITLE: descConst(0x01000018),
T: descConst(84),
TAB: descConst(9),
U: descConst(85),
UP: descConst(38),
V: descConst(86),
VOD: descConst(0x0100001A),
W: descConst(87),
X: descConst(88),
Y: descConst(89),
YELLOW: descConst(0x01000002),
Z: descConst(90),
});
Object.defineProperties(Keyboard, {
CharCodeStrings: descConst([
Keyboard.KEYNAME_BEGIN,
Keyboard.KEYNAME_BREAK,
Keyboard.KEYNAME_CLEARDISPLAY,
Keyboard.KEYNAME_CLEARLINE,
Keyboard.KEYNAME_DELETE,
Keyboard.KEYNAME_DELETECHAR,
Keyboard.KEYNAME_DELETELINE,
Keyboard.KEYNAME_DOWNARROW,
Keyboard.KEYNAME_END,
Keyboard.KEYNAME_EXECUTE,
Keyboard.KEYNAME_F1,
Keyboard.KEYNAME_F10,
Keyboard.KEYNAME_F11,
Keyboard.KEYNAME_F12,
Keyboard.KEYNAME_F13,
Keyboard.KEYNAME_F14,
Keyboard.KEYNAME_F15,
Keyboard.KEYNAME_F16,
Keyboard.KEYNAME_F17,
Keyboard.KEYNAME_F18,
Keyboard.KEYNAME_F19,
Keyboard.KEYNAME_F2,
Keyboard.KEYNAME_F20,
Keyboard.KEYNAME_F21,
Keyboard.KEYNAME_F22,
Keyboard.KEYNAME_F23,
Keyboard.KEYNAME_F24,
Keyboard.KEYNAME_F25,
Keyboard.KEYNAME_F26,
Keyboard.KEYNAME_F27,
Keyboard.KEYNAME_F28,
Keyboard.KEYNAME_F29,
Keyboard.KEYNAME_F3,
Keyboard.KEYNAME_F30,
Keyboard.KEYNAME_F31,
Keyboard.KEYNAME_F32,
Keyboard.KEYNAME_F33,
Keyboard.KEYNAME_F34,
Keyboard.KEYNAME_F35,
Keyboard.KEYNAME_F4,
Keyboard.KEYNAME_F5,
Keyboard.KEYNAME_F6,
Keyboard.KEYNAME_F7,
Keyboard.KEYNAME_F8,
Keyboard.KEYNAME_F9,
Keyboard.KEYNAME_FIND,
Keyboard.KEYNAME_HELP,
Keyboard.KEYNAME_HOME,
Keyboard.KEYNAME_INSERT,
Keyboard.KEYNAME_INSERTCHAR,
Keyboard.KEYNAME_INSERTLINE,
Keyboard.KEYNAME_LEFTARROW,
Keyboard.KEYNAME_MENU,
Keyboard.KEYNAME_MODESWITCH,
Keyboard.KEYNAME_NEXT,
Keyboard.KEYNAME_PAGEDOWN,
Keyboard.KEYNAME_PAGEUP,
Keyboard.KEYNAME_PAUSE,
Keyboard.KEYNAME_PREV,
Keyboard.KEYNAME_PRINT,
Keyboard.KEYNAME_PRINTSCREEN,
Keyboard.KEYNAME_REDO,
Keyboard.KEYNAME_RESET,
Keyboard.KEYNAME_RIGHTARROW,
Keyboard.KEYNAME_SCROLLLOCK,
Keyboard.KEYNAME_SELECT,
Keyboard.KEYNAME_STOP,
Keyboard.KEYNAME_SYSREQ,
Keyboard.KEYNAME_SYSTEM,
Keyboard.KEYNAME_UNDO,
Keyboard.KEYNAME_UPARROW,
Keyboard.KEYNAME_USER
])
});

31
src/flash/ui/Mouse.js Normal file
Просмотреть файл

@ -0,0 +1,31 @@
function Mouse() {
}
Object.defineProperties(Mouse, {
cursor: descAccessor(
function () {
return 'auto'; // TODO
},
function (val) {
notImplemented();
}
),
hide: descMethod(function () {
notImplemented();
}),
registerCursor: descMethod(function (name, cursor) {
notImplemented();
}),
show: descMethod(function () {
notImplemented();
}),
supportsCursor: descAccessor(function () {
return true; // TODO
}),
supportsNativeCursor: descAccessor(function () {
return true; // TODO
}),
unregisterCursor: descMethod(function (name) {
notImplemented();
})
});

Просмотреть файл

@ -95,103 +95,35 @@ SWF.embed = function(file, container, options) {
if (!options) if (!options)
options = { }; options = { };
var result;
var root;
var dictionary = new ObjDictionary();
var pframes = [];
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d'); var dictionary = new ObjDictionary();
var frameRate, bounds;
var plays;
var as2Context = null;
function resizeCanvas(container, canvas) { function resizeCanvas(container, canvas) {
canvas.width = container.clientWidth; canvas.width = container.clientWidth;
canvas.height = container.clientHeight; canvas.height = container.clientHeight;
} }
startWorking(file, function(obj) { var stage = new Stage();
if (!root) { stage._attachToCanvas({
bounds = obj.bounds; file: file,
canvas: canvas,
dictionary: dictionary,
onstart: function(root, stage) {
if (container.clientHeight) { if (container.clientHeight) {
resizeCanvas(container, canvas); resizeCanvas(container, canvas);
window.addEventListener('resize', window.addEventListener('resize',
resizeCanvas.bind(null, container, canvas), false); resizeCanvas.bind(null, container, canvas), false);
} else { } else {
canvas.width = (bounds.xMax - bounds.xMin) / 20; canvas.width = stage.stageWidth;
canvas.height = (bounds.yMax - bounds.yMin) / 20; canvas.height = stage.stageHeight;
} }
container.appendChild(canvas); container.appendChild(canvas);
frameRate = obj.frameRate;
// TODO disable AVM1 if AVM2 is enabled
as2Context = new AS2Context(obj.version, {
width: (bounds.xMax - bounds.xMin) / 20,
height: (bounds.yMax - bounds.yMin) / 20
});
AS2Context.instance = as2Context;
var globals = as2Context.globals;
AS2Mouse.$bind(canvas);
AS2Key.$bind(canvas);
var proto = create(new MovieClipPrototype({
frameCount: obj.frameCount,
pframes: pframes
}, dictionary));
root = proto.constructor();
root.name = '_root';
globals._root = globals._level0 = root.$as2Object;
if (options.onstart) if (options.onstart)
options.onstart(root); options.onstart(root);
return; },
} oncomplete: function(root, result) {
if (options.oncomplete)
AS2Context.instance = as2Context; options.oncomplete(root, result);
if (obj) {
if (obj.id) {
definePrototype(dictionary, obj);
} else if (obj.type === 'pframe') {
if (obj.bgcolor)
canvas.style.background = obj.bgcolor;
if (obj.abcBlocks) {
var blocks = obj.abcBlocks;
var i = 0;
var block;
while (block = blocks[i++]) {
var abc = new AbcFile(block);
executeAbc(abc, ALWAYS_INTERPRET);
}
}
if (obj.symbols) {
var symbols = obj.symbols;
var i = 0;
var sym;
while (sym = symbols[i++]) {
if (!sym.id) {
var mainTimeline = new (toplevel.getTypeByName(
Multiname.fromSimpleName(sym.name),
true
)).instance;
}
}
}
pframes.push(obj);
if (!plays) {
renderMovieClip(root, frameRate, bounds, ctx);
plays = true;
}
} else {
result = obj;
}
} else if (options.oncomplete) {
options.oncomplete(root, result);
} }
}); });
}; };

Просмотреть файл

@ -94,9 +94,9 @@ function renderShadowCanvas(character) {
ctx.restore(); ctx.restore();
} }
function renderMovieClip(mc, rate, bounds, ctx) { function renderMovieClip(mc, stage, ctx) {
var frameTime = 0; var frameTime = 0;
var maxDelay = 1000 / rate; var maxDelay = 1000 / stage.frameRate;
var frameWidth = ctx.canvas.width; var frameWidth = ctx.canvas.width;
var frameHeight = ctx.canvas.height; var frameHeight = ctx.canvas.height;
@ -109,22 +109,21 @@ function renderMovieClip(mc, rate, bounds, ctx) {
var frameWidth = ctx.canvas.width; var frameWidth = ctx.canvas.width;
var frameHeight = ctx.canvas.height; var frameHeight = ctx.canvas.height;
var scaleX = frameWidth / (bounds.xMax - bounds.xMin); var scaleX = frameWidth / stage.stageWidth;
var scaleY = frameHeight / (bounds.yMax - bounds.yMin); var scaleY = frameHeight / stage.stageHeight;
var scale = Math.min(scaleX, scaleY); var scale = Math.min(scaleX, scaleY);
var offsetX = (frameWidth - scale * (bounds.xMax - bounds.xMin)) / 2; var offsetX = (frameWidth - scale * stage.stageWidth) / 2;
var offsetY = (frameHeight - scale * (bounds.yMax - bounds.yMin)) / 2; var offsetY = (frameHeight - scale * stage.stageHeight) / 2;
ctx.clearRect(0, 0, frameWidth, frameHeight); ctx.clearRect(0, 0, frameWidth, frameHeight);
ctx.save(); ctx.save();
ctx.translate(offsetX, offsetY); ctx.translate(offsetX, offsetY);
ctx.scale(scale, scale); ctx.scale(scale / 20, scale / 20);
ctx.canvas.currentTransform = { ctx.canvas.currentTransform = {
scale: scale * 20, scale: scale,
offsetX: offsetX, offsetX: offsetX,
offsetY: offsetY, offsetY: offsetY
bounds: bounds
}; };
} }
this.depth++; this.depth++;