mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-19 20:14:58 +00:00
Merge pull request #31 from WFBarnes/main
Framed accommodations for Screen 1. Tamed horizontal growth of qb-lang.js.
This commit is contained in:
commit
36c3bf9e5c
4 changed files with 69 additions and 19 deletions
|
@ -35,15 +35,27 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
// TODO: adjust for QB
|
||||
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
|
||||
|
||||
var builtinFuncsWords = ['_acos', '_acosh', '_alpha', '_alpha32', '_asin', '_asinh', '_atan2', '_atanh', '_autodisplay', '_blue', '_blue32', '_ceil', '_continue', '_copyimage', '_cosh', '_coth', '_csch', '_d2g', '_d2r', '_delay', '_dest',
|
||||
'_display', '_fontwidth', '_freeimage', '_fullscreen', '_g2d', '_g2r', '_green', '_green32', '_height', '_hypot', '_instrrev', '_limit', '_keyclear', '_keydown',
|
||||
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
|
||||
'_putimage', '_r2d', '_r2g', '_readbit', '_red', '_red32', '_resetbit', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
||||
'_screenexists', '_sech', '_setbit', '_shl', '_shr', '_sinh', '_source', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol', '_strcmp', '_stricmp', '_tanh',
|
||||
'_title', '_trim', '_togglebit', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'cdbl', 'cint', 'clng', 'csng', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'data', 'date', 'draw', 'exp',
|
||||
'fix', 'hex', 'input', 'inkey', 'instr', 'int', 'lbound', 'left', 'lcase', 'len', 'line', 'locate', 'log', 'ltrim', 'mid', 'mki', 'mkl',
|
||||
'oct', 'paint', 'point', 'preset', 'print', 'pset', 'right', 'rtrim', 'randomize', 'read', 'restore', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr',
|
||||
'str', 'swap', 'tan', 'time', 'timer', 'ubound', 'ucase', 'val', 'varptr', 'window',
|
||||
var builtinFuncsWords = ['_acos', '_acosh', '_alpha', '_alpha32', '_asin', '_asinh', '_atan2', '_atanh', '_autodisplay',
|
||||
'_blue', '_blue32', '_ceil', '_continue', '_copyimage', '_cosh', '_coth', '_csch', '_d2g',
|
||||
'_d2r', '_delay', '_dest', '_display', '_fontwidth', '_freeimage', '_fullscreen',
|
||||
'_g2d', '_g2r', '_green', '_green32', '_height', '_hypot',
|
||||
'_instrrev', '_limit', '_keyclear', '_keydown', '_keyhit', '_loadimage',
|
||||
'_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage',
|
||||
'_palettecolor', '_pi', '_printstring', '_printwidth', '_putimage',
|
||||
'_r2d', '_r2g', '_readbit', '_red', '_red32', '_resetbit', '_resize', '_resizewidth',
|
||||
'_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
||||
'_screenexists', '_sech', '_setbit', '_shl', '_shr', '_sinh', '_source', '_sndclose', '_sndopen',
|
||||
'_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol', '_strcmp', '_stricmp',
|
||||
'_tanh', '_title', '_trim', '_togglebit', '_width',
|
||||
'abs', 'asc', 'atn', 'beep',
|
||||
'chr', 'cdbl', 'cint', 'clng', 'csng', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl',
|
||||
'data', 'date', 'draw', 'exp', 'fix', 'hex', 'input', 'inkey', 'instr', 'int',
|
||||
'lbound', 'left', 'lcase', 'len', 'line', 'locate', 'log', 'ltrim', 'mid', 'mki', 'mkl',
|
||||
'oct', 'paint', 'point', 'preset', 'print', 'pset',
|
||||
'right', 'rtrim', 'randomize', 'read', 'restore', 'rnd',
|
||||
'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr',
|
||||
'str', 'swap', 'tan', 'time', 'timer', 'ubound', 'ucase',
|
||||
'val', 'varptr', 'window',
|
||||
// QBJS-specific
|
||||
'export', 'from', 'import', '_label']
|
||||
|
||||
|
|
52
qb.js
52
qb.js
|
@ -34,6 +34,7 @@ var QB = new function() {
|
|||
var _rndSeed;
|
||||
var _runningFlag = false;
|
||||
var _screenDiagInv;
|
||||
var _screenMode;
|
||||
var _sourceImage = 0;
|
||||
var _strokeDrawLength = null;
|
||||
var _strokeDrawAngle = null;
|
||||
|
@ -127,6 +128,7 @@ var QB = new function() {
|
|||
_rndSeed = 327680;
|
||||
_runningFlag = true;
|
||||
_sourceImage = 0;
|
||||
_initColorTable();
|
||||
GX._enableTouchMouse(true);
|
||||
GX.registerGameEvents(function(e){});
|
||||
QB.sub_Screen(0);
|
||||
|
@ -412,6 +414,10 @@ var QB = new function() {
|
|||
return tmpId;
|
||||
};
|
||||
|
||||
this.sub__PaletteColor = function(x, y) {
|
||||
_colormap[x] = _color(y);
|
||||
};
|
||||
|
||||
this.sub__PrintString = function(x, y, s) {
|
||||
// TODO: check the background opacity mode
|
||||
// Draw the text background
|
||||
|
@ -771,7 +777,11 @@ var QB = new function() {
|
|||
_images[_activeImage].dirty = true;
|
||||
ctx.beginPath();
|
||||
ctx.clearRect(0, 0, _width(), _height());
|
||||
//if (_screenMode == 1) { TODO: Finish implementing this.
|
||||
ctx.fillStyle = color.rgba();
|
||||
//} else {
|
||||
// ctx.fillStyle = color.rgba();
|
||||
//}
|
||||
ctx.fillRect(0, 0, _width(), _height());
|
||||
|
||||
// reset the text position
|
||||
|
@ -797,13 +807,24 @@ var QB = new function() {
|
|||
return _rgb(0,0,0);
|
||||
}
|
||||
|
||||
this.sub_Color = function(fg, bg) {
|
||||
if (fg != undefined) {
|
||||
_fgColor = _color(fg);
|
||||
this.sub_Color = function(x, y) {
|
||||
/*if (_screenMode == 1) { This code is fine.
|
||||
if (x == 0) { _bgColor = _rgb(0, 0, 0);
|
||||
} else if (x == 1) { _bgColor = _rgb(0, 0, 168);
|
||||
} else if (x == 2) { _bgColor = _rgb(0, 168, 0);
|
||||
} else if (x == 3) { _bgColor = _rgb(0, 168, 168); }
|
||||
ctx = _images[_activeImage].ctx;
|
||||
ctx.fillStyle = _bgColor.rgba();
|
||||
ctx.beginPath();
|
||||
ctx.fillRect(0, 0, _width(), _height());
|
||||
} else {*/
|
||||
if (x != undefined) {
|
||||
_fgColor = _color(x);
|
||||
}
|
||||
if (bg != undefined) {
|
||||
_bgColor = _color(bg);
|
||||
if (y != undefined) {
|
||||
_bgColor = _color(y);
|
||||
}
|
||||
//}
|
||||
};
|
||||
|
||||
this.func_Command = function() {
|
||||
|
@ -1335,7 +1356,7 @@ var QB = new function() {
|
|||
screen.lastY = y;
|
||||
|
||||
ctx.lineWidth = _strokeLineThickness;
|
||||
ctx.lineWidth += Math.tanh(8*radius*_screenDiagInv); // Adds some radius to compensate for antialiasing. The prefactor is arbitrary. //
|
||||
ctx.lineWidth += Math.tanh(8*radius*_screenDiagInv); // Adds some radius to compensate for antialiasing. The prefactor 8 is arbitrary. //
|
||||
ctx.strokeStyle = color.rgba();
|
||||
ctx.beginPath();
|
||||
if (aspect == undefined) {
|
||||
|
@ -1617,7 +1638,7 @@ var QB = new function() {
|
|||
var g = dat[p+1];
|
||||
var b = dat[p+2];
|
||||
//var a = dat[p+3]; // 0 < a < 255
|
||||
var thresh = 2;
|
||||
var thresh = 16; // usually 2
|
||||
if ((Math.abs(r - c1.r) < thresh) && (Math.abs(g - c1.g) < thresh) && (Math.abs(b - c1.b) < thresh)) { return false; }
|
||||
if ((Math.abs(r - c2.r) < thresh) && (Math.abs(g - c2.g) < thresh) && (Math.abs(b - c2.b) < thresh)) { return false; }
|
||||
return true;
|
||||
|
@ -1890,7 +1911,11 @@ var QB = new function() {
|
|||
if (mode == 0) {
|
||||
GX.sceneCreate(640, 400);
|
||||
}
|
||||
else if (mode < 2 || mode == 7 || mode == 13) {
|
||||
else if (mode == 1) {
|
||||
GX.sceneCreate(320, 200);
|
||||
_fgColor = _rgb(168, 168, 168);
|
||||
}
|
||||
else if (mode == 2 || mode == 7 || mode == 13) {
|
||||
GX.sceneCreate(320, 200);
|
||||
}
|
||||
else if (mode == 8) {
|
||||
|
@ -1916,13 +1941,14 @@ var QB = new function() {
|
|||
_images[mode] = _images[0];
|
||||
}
|
||||
}
|
||||
_images[0] = { canvas: GX.canvas(), ctx: GX.ctx(), lastX: 0, lastY: 0};
|
||||
_images[0] = { canvas: GX.canvas(), ctx: GX.ctx(), lastX: 0, lastY: 0 };
|
||||
_images[0].lastX = _images[0].canvas.width/2;
|
||||
_images[0].lastY = _images[0].canvas.height/2;
|
||||
|
||||
_screenDiagInv = 1/Math.sqrt(_images[0].canvas.width*_images[0].canvas.width + _images[0].canvas.height*_images[0].canvas.height);
|
||||
|
||||
// initialize the graphics
|
||||
_screenMode = mode;
|
||||
_fgColor = _color(7);
|
||||
_bgColor = _color(0);
|
||||
_locX = 0;
|
||||
|
@ -1939,6 +1965,14 @@ var QB = new function() {
|
|||
_keyHitBuffer = [];
|
||||
_keyDownMap = {};
|
||||
|
||||
/*
|
||||
if (mode == 1) {
|
||||
ctx = _images[_activeImage].ctx;
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = _bgColor.rgba();
|
||||
ctx.fillRect(0, 0, _width(), _height());
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
this.func_Sgn = function(value) {
|
||||
|
|
1
qb2js.js
1
qb2js.js
|
@ -2833,6 +2833,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "_MouseY", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_NewImage", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_Pi", False);
|
||||
await sub_AddQBMethod( "SUB", "_PaletteColor", False);
|
||||
await sub_AddQBMethod( "SUB", "_PrintString", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "_PrintWidth", False);
|
||||
await sub_AddQBMethod( "SUB", "_PutImage", False);
|
||||
|
|
|
@ -2,7 +2,9 @@ Option _Explicit
|
|||
$Console:Only
|
||||
'$ExeIcon:'./../gx/resource/gx.ico'
|
||||
|
||||
' In console, after creating qb2js.exe, run: qb2js qb2js.bas > ../qb2js.js
|
||||
'1) Edit this file as needed.
|
||||
'2) Compile to EXE only.
|
||||
'3) In console, run: qb2js qb2js.bas > ../qb2js.js
|
||||
|
||||
Const FILE = 1
|
||||
Const TEXT = 2
|
||||
|
@ -3015,6 +3017,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "_MouseY", False
|
||||
AddQBMethod "FUNCTION", "_NewImage", False
|
||||
AddQBMethod "FUNCTION", "_Pi", False
|
||||
AddQBMethod "SUB", "_PaletteColor", False
|
||||
AddQBMethod "SUB", "_PrintString", False
|
||||
AddQBMethod "FUNCTION", "_PrintWidth", False
|
||||
AddQBMethod "SUB", "_PutImage", False
|
||||
|
|
Loading…
Reference in a new issue