From 3a133d85d918e772caf0a813035abfc455aca9f9 Mon Sep 17 00:00:00 2001 From: William Barnes Date: Sat, 18 Jun 2022 02:02:52 -0400 Subject: [PATCH 1/4] Tweaked threshold value in Paint. --- qb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qb.js b/qb.js index 5c3a25f..126520e 100644 --- a/qb.js +++ b/qb.js @@ -1335,7 +1335,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 +1617,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; From 62153b8001413cbafff0b0756525a0d68397d8af Mon Sep 17 00:00:00 2001 From: William Barnes Date: Sun, 19 Jun 2022 14:11:53 -0400 Subject: [PATCH 2/4] Tamed the horizontal growth of qb-lang.js. --- codemirror/qb-lang.js | 30 +++++++++++++++++++++--------- qb.js | 5 +++++ qb2js.js | 1 + tools/qb2js.bas | 5 ++++- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/codemirror/qb-lang.js b/codemirror/qb-lang.js index b1e15d7..5564736 100644 --- a/codemirror/qb-lang.js +++ b/codemirror/qb-lang.js @@ -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'] diff --git a/qb.js b/qb.js index 126520e..1b1717d 100644 --- a/qb.js +++ b/qb.js @@ -127,6 +127,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 +413,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 diff --git a/qb2js.js b/qb2js.js index 8f046a4..cc3a265 100644 --- a/qb2js.js +++ b/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); diff --git a/tools/qb2js.bas b/tools/qb2js.bas index ca6e0f5..6307582 100644 --- a/tools/qb2js.bas +++ b/tools/qb2js.bas @@ -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 From a7a0fbedbbde175418ae7887e15c582e01fef0f8 Mon Sep 17 00:00:00 2001 From: William Barnes Date: Wed, 22 Jun 2022 00:41:47 -0400 Subject: [PATCH 3/4] Framed accommodations for Screen 1. --- qb.js | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/qb.js b/qb.js index 1b1717d..50b7df9 100644 --- a/qb.js +++ b/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; @@ -776,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 @@ -802,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); + _bgColor = _color(y); } + //} }; this.func_Command = function() { @@ -1895,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) { @@ -1921,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; @@ -1944,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) { From 8c4e324cb40cae75a593f52634aec2ed98f45e5d Mon Sep 17 00:00:00 2001 From: William Barnes Date: Wed, 22 Jun 2022 01:14:10 -0400 Subject: [PATCH 4/4] Fixed spacing issue. --- qb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qb.js b/qb.js index 50b7df9..a649b79 100644 --- a/qb.js +++ b/qb.js @@ -821,8 +821,8 @@ var QB = new function() { if (x != undefined) { _fgColor = _color(x); } - if (bg != undefined) { - _bgColor = _color(y); + if (y != undefined) { + _bgColor = _color(y); } //} };