From 5c8193a8d9ef15b02ad907ab047ba61afe1737f1 Mon Sep 17 00:00:00 2001 From: boxgaming <75969133+boxgaming@users.noreply.github.com> Date: Tue, 15 Mar 2022 09:42:33 -0500 Subject: [PATCH] Added support for bgcolor parameter on Cls method. Added support for _autodisplay method. --- codemirror/qb-lang.js | 2 +- qb.js | 47 +++++++++++++++++++++++++++++++++++++++++-- qb2js.js | 30 +++++++++++++++++++++++++-- tools/qb2js.bas | 28 +++++++++++++++++++++++--- 4 files changed, 99 insertions(+), 8 deletions(-) diff --git a/codemirror/qb-lang.js b/codemirror/qb-lang.js index fc593d4..1804cdc 100644 --- a/codemirror/qb-lang.js +++ b/codemirror/qb-lang.js @@ -35,7 +35,7 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) { // TODO: adjust for QB var atomWords = ['true', 'false', 'nothing', 'empty', 'null']; - var builtinFuncsWords = ['_alpha', '_alpha32', '_atan2', '_blue', '_blue32', '_copyimage', '_delay', '_dest', '_dest', '_display', '_fontwidth', + var builtinFuncsWords = ['_alpha', '_alpha32', '_atan2', '_autodisplay', '_blue', '_blue32', '_copyimage', '_delay', '_dest', '_dest', '_display', '_fontwidth', '_freeimage', '_green', '_green32', '_height', '_instrrev', '_limit', '_keyclear', '_keydown', '_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth', '_putimage', '_red', '_red32', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round', '_screenexists', '_title', '_trim', '_width', 'abs', diff --git a/qb.js b/qb.js index 2dec0ca..c1c7eb6 100644 --- a/qb.js +++ b/qb.js @@ -21,6 +21,7 @@ var QB = new function() { var _images = {}; var _activeImage = 0; var _nextImageId = 1000; + var _lastLimitTime = 0; // Array handling methods // ---------------------------------------------------- @@ -124,6 +125,11 @@ var QB = new function() { return Math.atan2(y, x); }; + // the canvas handles the display for us, there is effectively no difference + // between _display and _autodisplay, included here for compatibility + this.func__AutoDisplay = function() { return -1; } + this.sub__AutoDisplay = function() {} + this.func__Blue = function(rgb, imageHandle) { // TODO: implement corresponding logic when an image handle is supplied (maybe) return _color(rgb).b; @@ -147,10 +153,18 @@ var QB = new function() { await GX.sleep(seconds*1000); }; + this.func__Dest = function() { + return _activeImage; + } + this.sub__Dest = function(imageId) { _activeImage = imageId; } + this.func__Display = function() { + return 0; + } + this.sub__Display = function() { // The canvas handles this for us, this method is included for compatibility }; @@ -309,6 +323,11 @@ var QB = new function() { dy1 = 0; dxu = true; } + else if (dstep1) { + dx1 = destImage.lastX + dx1; + dy1 = destImage.lastY + dy1; + } + if (dx2 == undefined) { if (dxu) { dw = destImage.canvas.width; @@ -320,6 +339,10 @@ var QB = new function() { } } else { + if (dstep2) { + dx2 = destImage.lastX + dx2; + dy2 = destImage.lastY + dy2; + } dw = dx2-dx1; dh = dy2-dy1; } @@ -328,15 +351,29 @@ var QB = new function() { sx1 = 0; sy1 = 0; } + else if (sstep1) { + sx1 = sourceImage.lastX + sx1; + sy1 = sourceImage.lastY + sy1; + } + if (sx2 == undefined) { sw = sourceImage.canvas.width; sh = sourceImage.canvas.height; } else { + if (sstep2) { + sx2 = sourceImage.lastX + sx2; + sy2 = sourceImage.lastY + sy2; + } sw = sx2-sx1; sh = sy2-sy1; } + destImage.lastX = dx1 + dw; + destImage.lastY = dy1 + dh; + sourceImage.lastX = sx1 + sw; + sourceImage.lastY = sy2 + sh; + destImage.ctx.drawImage(sourceImage.canvas, sx1, sy1, sw, sh, dx1, dy1, dw, dh); } @@ -443,11 +480,17 @@ var QB = new function() { return String.fromCharCode(charCode); }; - this.sub_Cls = function() { + this.sub_Cls = function(method, bgColor) { + // method parameter is ignored, there is no separate view port for text and graphics + + var color = _bgColor; + if (bgColor != undefined) { + color = _color(bgColor); + } // TODO: parameter variants ctx = _images[_activeImage].ctx; ctx.beginPath(); - ctx.fillStyle = _bgColor.rgba(); + ctx.fillStyle = color.rgba(); ctx.fillRect(0, 0, QB.func__Width() , QB.func__Height()); }; diff --git a/qb2js.js b/qb2js.js index c4d4f2b..8c2b002 100644 --- a/qb2js.js +++ b/qb2js.js @@ -407,6 +407,8 @@ var ConvertSub = null; js = (await func_ConvertInput( m, args)); } else if ( m.name == "Swap" ) { js = (await func_ConvertSwap( m, args)); + } else if ( m.name == "Cls" ) { + js = (await func_CallMethod( m)) +"(" +(await func_ConvertCls( args)) +");"; } else if ( m.name == "_PutImage" ) { js = (await func_CallMethod( m)) +"(" +(await func_ConvertPutImage( args)) +");"; } else { @@ -513,6 +515,27 @@ var doSmooth = ''; // STRING ConvertPutImage = startCoord +", " + sourceImage +", " + destImage +", " + destCoord +", " + doSmooth; return ConvertPutImage; } +async function func_ConvertCls(args/*STRING*/) { +if (QB.halted()) { return; } +var ConvertCls = null; + var argc = 0; // INTEGER + var parts = QB.initArray([{l:1,u:0}], ''); // STRING + argc = (await func_ListSplit( args, parts)); + var method = ''; // STRING +var bgcolor = ''; // STRING + method = "undefined"; + bgcolor = "undefined"; + if ( argc >= 1) { + if ((QB.func__Trim(QB.arrayValue(parts, [ 1]).value)) != "" ) { + method = (await func_ConvertExpression(QB.arrayValue(parts, [ 1]).value)); + } + } + if ( argc >= 2) { + bgcolor = (await func_ConvertExpression(QB.arrayValue(parts, [ 2]).value)); + } + ConvertCls = method +", " + bgcolor; +return ConvertCls; +} async function func_ConvertCoordParam(param/*STRING*/,hasEndCoord/*INTEGER*/) { if (QB.halted()) { return; } var ConvertCoordParam = null; @@ -2264,12 +2287,15 @@ if (QB.halted()) { return; } await sub_AddQBMethod("FUNCTION" , "_Alpha" , False); await sub_AddQBMethod("FUNCTION" , "_Alpha32" , False); await sub_AddQBMethod("FUNCTION" , "_Atan2" , False); + await sub_AddQBMethod("FUNCTION" , "_AutoDisplay" , False); + await sub_AddQBMethod("SUB" , "_AutoDisplay" , False); await sub_AddQBMethod("FUNCTION" , "_Blue" , False); await sub_AddQBMethod("FUNCTION" , "_Blue32" , False); await sub_AddQBMethod("FUNCTION" , "_CopyImage" , False); await sub_AddQBMethod("SUB" , "_Delay" , True); - await sub_AddQBMethod("FUNCTION" , "_Dest" , True); - await sub_AddQBMethod("SUB" , "_Dest" , True); + await sub_AddQBMethod("FUNCTION" , "_Dest" , False); + await sub_AddQBMethod("SUB" , "_Dest" , False); + await sub_AddQBMethod("FUNCTION" , "_Display" , False); await sub_AddQBMethod("SUB" , "_Display" , False); await sub_AddQBMethod("FUNCTION" , "_FontWidth" , False); await sub_AddQBMethod("FUNCTION" , "_FreeImage" , False); diff --git a/tools/qb2js.bas b/tools/qb2js.bas index 6ef344e..35a5943 100644 --- a/tools/qb2js.bas +++ b/tools/qb2js.bas @@ -488,6 +488,9 @@ Function ConvertSub$ (m As Method, args As String) ElseIf m.name = "Swap" Then js = ConvertSwap(m, args) + ElseIf m.name = "Cls" Then + js = CallMethod(m) + "(" + ConvertCls(args) + ");" + ElseIf m.name = "_PutImage" Then js = CallMethod(m) + "(" + ConvertPutImage(args) + ");" @@ -588,6 +591,23 @@ Function ConvertPutImage$ (args As String) ConvertPutImage = startCoord + ", " + sourceImage + ", " + destImage + ", " + destCoord + ", " + doSmooth End Function +Function ConvertCls$ (args As String) + Dim argc As Integer + ReDim parts(0) As String + argc = ListSplit(args, parts()) + + Dim As String method, bgcolor + method = "undefined" + bgcolor = "undefined" + + If argc >= 1 Then + If _Trim$(parts(1)) <> "" Then method = ConvertExpression(parts(1)) + End If + If argc >= 2 Then bgcolor = ConvertExpression(parts(2)) + + ConvertCls$ = method + ", " + bgcolor +End Function + Function ConvertCoordParam$ (param As String, hasEndCoord As Integer) If _Trim$(param) = "" Then If hasEndCoord Then @@ -2274,7 +2294,6 @@ Sub InitGX AddGXMethod "FUNCTION", "GXEntityType", False AddGXMethod "FUNCTION", "GXEntityUID$", False AddGXMethod "FUNCTION", "GXFontUID$", False - 'AddGXMethod "FUNCTION", "GX", False AddGXMethod "SUB", "GXEntityApplyGravity", False AddGXMethod "FUNCTION", "GXEntityApplyGravity", False AddGXMethod "SUB", "GXEntityCollisionOffset", False @@ -2403,12 +2422,15 @@ Sub InitQBMethods AddQBMethod "FUNCTION", "_Alpha", False AddQBMethod "FUNCTION", "_Alpha32", False AddQBMethod "FUNCTION", "_Atan2", False + AddQBMethod "FUNCTION", "_AutoDisplay", False + AddQBMethod "SUB", "_AutoDisplay", False AddQBMethod "FUNCTION", "_Blue", False AddQBMethod "FUNCTION", "_Blue32", False AddQBMethod "FUNCTION", "_CopyImage", False AddQBMethod "SUB", "_Delay", True - AddQBMethod "FUNCTION", "_Dest", True - AddQBMethod "SUB", "_Dest", True + AddQBMethod "FUNCTION", "_Dest", False + AddQBMethod "SUB", "_Dest", False + AddQBMethod "FUNCTION", "_Display", False AddQBMethod "SUB", "_Display", False AddQBMethod "FUNCTION", "_FontWidth", False AddQBMethod "FUNCTION", "_FreeImage", False