1
1
Fork 0
mirror of https://github.com/boxgaming/qbjs.git synced 2024-09-19 20:14:58 +00:00

Added support for bgcolor parameter on Cls method. Added support for _autodisplay method.

This commit is contained in:
boxgaming 2022-03-15 09:42:33 -05:00
parent 2497e09a96
commit 5c8193a8d9
4 changed files with 99 additions and 8 deletions

View file

@ -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',

47
qb.js
View file

@ -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());
};

View file

@ -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);

View file

@ -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