Added rudiments of graphics mode.
This commit is contained in:
@ -27,17 +27,63 @@ r|
|
||||
| 1 jseval!
|
||||
: jseval ( a n -- ) 1 call ;
|
||||
|
||||
r"
|
||||
context.inbuffer = [];
|
||||
if (!globalObj.write) {
|
||||
r|
|
||||
context.inbuffer = [];
|
||||
context.outbuffer = '';
|
||||
if (!globalObj.write) {
|
||||
context.screen = document.getElementById('ueforth');
|
||||
if (context.screen === null) {
|
||||
context.screen = document.createElement('div');
|
||||
document.body.appendChild(context.screen);
|
||||
}
|
||||
context.filler = document.createElement('div');
|
||||
document.body.insertBefore(context.filler, document.body.firstChild);
|
||||
context.canvas = document.createElement('canvas');
|
||||
context.canvas.style.top = 0;
|
||||
context.canvas.style.left = 0;
|
||||
context.canvas.style.position = 'fixed';
|
||||
context.canvas.style.backgroundColor = '#000';
|
||||
context.screen.appendChild(context.canvas);
|
||||
context.ctx = context.canvas.getContext('2d');
|
||||
context.terminal = document.createElement('pre');
|
||||
context.screen.appendChild(context.terminal);
|
||||
context.outbuffer = '';
|
||||
context.mode = 1;
|
||||
function setMode(mode) {
|
||||
if (context.mode === mode) {
|
||||
return ;
|
||||
}
|
||||
if (mode) {
|
||||
context.filler.style.display = '';
|
||||
context.canvas.style.display = '';
|
||||
} else {
|
||||
context.filler.style.display = 'none';
|
||||
context.canvas.style.display = 'none';
|
||||
}
|
||||
context.mode = mode;
|
||||
}
|
||||
context.setMode = setMode;
|
||||
function Resize() {
|
||||
var width = window.innerWidth;
|
||||
var theight = Math.max(120, Math.floor(window.innerHeight / 6));
|
||||
var height = window.innerHeight - theight;
|
||||
if (width == context.width && height == context.height) {
|
||||
return;
|
||||
}
|
||||
context.canvas.width = width;
|
||||
context.canvas.height = height;
|
||||
context.filler.style.width = '1px';
|
||||
context.filler.style.height = height + 'px';
|
||||
context.width = width;
|
||||
context.height = height;
|
||||
}
|
||||
function Draw() {
|
||||
Resize();
|
||||
context.ctx.fillStyle = '#000';
|
||||
context.ctx.fillRect(0, 0, context.canvas.width, context.canvas.height);
|
||||
}
|
||||
window.onresize = function(e) {
|
||||
Draw();
|
||||
};
|
||||
window.onkeypress = function(e) {
|
||||
context.inbuffer.push(e.keyCode);
|
||||
};
|
||||
@ -46,8 +92,10 @@ r"
|
||||
context.inbuffer.push(e.keyCode);
|
||||
}
|
||||
};
|
||||
}
|
||||
" jseval
|
||||
setMode(0);
|
||||
Draw();
|
||||
}
|
||||
| jseval
|
||||
|
||||
r|
|
||||
(function(sp) {
|
||||
@ -134,9 +182,22 @@ r|
|
||||
})
|
||||
| 6 jseval! 6 call echo !
|
||||
|
||||
r|
|
||||
(function(sp) {
|
||||
var mode = i32[sp>>2]; sp -= 4;
|
||||
if (globalObj.write) {
|
||||
return sp;
|
||||
}
|
||||
context.setMode(mode);
|
||||
return sp;
|
||||
})
|
||||
| 7 jseval!
|
||||
|
||||
forth definitions web
|
||||
|
||||
: bye 0 terminate ;
|
||||
: page 12 emit ;
|
||||
: gr 1 7 call ;
|
||||
: text 0 7 call ;
|
||||
|
||||
forth definitions
|
||||
|
||||
Reference in New Issue
Block a user