mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
Merge pull request #20 from WFBarnes/main
Window mostly implemented, updated draw.
This commit is contained in:
commit
81ecb485b2
4 changed files with 200 additions and 15 deletions
|
@ -43,7 +43,7 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', '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', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr',
|
||||
'str', 'swap', 'tan', 'time', 'timer', 'ubound', 'ucase', 'val', 'varptr',
|
||||
'str', 'swap', 'tan', 'time', 'timer', 'ubound', 'ucase', 'val', 'varptr', 'window',
|
||||
// QBJS-specific
|
||||
'export', 'from', 'import']
|
||||
|
||||
|
|
97
qb.js
97
qb.js
|
@ -6,9 +6,13 @@ var QB = new function() {
|
|||
this.SQUAREPIXELS = Symbol("SQUAREPIXELS");
|
||||
this.OFF = Symbol("OFF");
|
||||
|
||||
var _strokeLineThickness = 2;
|
||||
var _strokeDrawLength = 4;
|
||||
var _strokeDrawAngle = -Math.PI/2;
|
||||
var _windowDef = [];
|
||||
var _windowAspectR;
|
||||
var _windowAspectX;
|
||||
var _windowAspectY;
|
||||
var _strokeLineThickness;
|
||||
var _strokeDrawLength;
|
||||
var _strokeDrawAngle;
|
||||
var _strokeDrawColor;
|
||||
var _fgColor = null;
|
||||
var _bgColor = null;
|
||||
|
@ -686,8 +690,8 @@ var QB = new function() {
|
|||
|
||||
// Turn input string into array of characters.
|
||||
var u = t.toString();
|
||||
u = u.replace(" ","");
|
||||
u = u.replace("=","");
|
||||
u = u.replace(/\s+/g, '');
|
||||
u = u.replace(/=/g, '');
|
||||
u = u.toUpperCase();
|
||||
u = u.split("");
|
||||
|
||||
|
@ -730,8 +734,11 @@ var QB = new function() {
|
|||
}
|
||||
v.push([elem,flag]);
|
||||
|
||||
// Compatibility factors.
|
||||
var compatFactorM = 1.30;
|
||||
var compatFactorT = 0.75;
|
||||
|
||||
// Draw-specific variables.
|
||||
var fudgeFactor = 1.30;
|
||||
var cursX, cursY;
|
||||
var cursX0, cursY0;
|
||||
var cursXt, cursYt;
|
||||
|
@ -785,7 +792,7 @@ var QB = new function() {
|
|||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok1 = v.shift();
|
||||
_strokeDrawLength = (tok1[0]) * (fudgeFactor);
|
||||
_strokeDrawLength = (tok1[0]) * (compatFactorM);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -811,16 +818,14 @@ var QB = new function() {
|
|||
if (tok1[0] == "A") {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
multiplier = 1;
|
||||
if (tmp[1] == -1) {
|
||||
if (tmp[0] == "-") {
|
||||
multiplier = -1;
|
||||
} else if (tmp[0] == "+") {
|
||||
multiplier = 1;
|
||||
}
|
||||
tmp = v.shift();
|
||||
tmp = v[0];
|
||||
} else {
|
||||
multiplier = 1;
|
||||
tok1 = v.shift();
|
||||
}
|
||||
}
|
||||
if (v.length) {
|
||||
|
@ -898,17 +903,22 @@ var QB = new function() {
|
|||
ang = (_strokeDrawAngle + Math.PI/2);
|
||||
uxx = ux * Math.cos(ang) - uy * Math.sin(ang);
|
||||
uyy = ux * Math.sin(ang) + uy * Math.cos(ang);
|
||||
uxx *= (_strokeDrawLength/4) / (fudgeFactor);
|
||||
uyy *= (_strokeDrawLength/4) / (fudgeFactor);
|
||||
uxx *= (_strokeDrawLength/4) / (compatFactorM);
|
||||
uyy *= (_strokeDrawLength/4) / (compatFactorM);
|
||||
} else {
|
||||
uxx = ux;
|
||||
uyy = uy;
|
||||
}
|
||||
if (_windowAspectR != false) {
|
||||
uxx *= _windowAspectX;
|
||||
uyy *= _windowAspectY;
|
||||
}
|
||||
cursXt = ux0 + uxx;
|
||||
cursYt = uy0 + uyy;
|
||||
}
|
||||
}
|
||||
if (cursSkipdraw == false) {
|
||||
ctx.lineWidth = _strokeLineThickness;
|
||||
ctx.strokeStyle = _color(_strokeDrawColor).rgba();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cursX, cursY);
|
||||
|
@ -957,9 +967,14 @@ var QB = new function() {
|
|||
}
|
||||
dx = dlen * Math.cos(_strokeDrawAngle + lines[i][1]);
|
||||
dy = dlen * Math.sin(_strokeDrawAngle + lines[i][1]);
|
||||
if (_windowAspectR != false) {
|
||||
dx *= _windowAspectX * (compatFactorT);
|
||||
dy *= _windowAspectY * (compatFactorT);
|
||||
}
|
||||
cursXt = (cursX)*1.0 + dx;
|
||||
cursYt = (cursY)*1.0 + dy;
|
||||
if (cursSkipdraw == false) {
|
||||
ctx.lineWidth = _strokeLineThickness;
|
||||
ctx.strokeStyle = _color(_strokeDrawColor).rgba();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cursX, cursY);
|
||||
|
@ -1127,6 +1142,11 @@ var QB = new function() {
|
|||
screen.lastX = x;
|
||||
screen.lastY = y;
|
||||
|
||||
if (_windowAspectR != false) {
|
||||
aspect = _windowAspectR;
|
||||
radius *= _windowAspectR;
|
||||
}
|
||||
|
||||
var ctx = screen.ctx;
|
||||
ctx.lineWidth = _strokeLineThickness;
|
||||
ctx.strokeStyle = color.rgba();
|
||||
|
@ -1472,7 +1492,11 @@ var QB = new function() {
|
|||
var ctx = screen.ctx;
|
||||
ctx.fillStyle = color.rgba();
|
||||
ctx.beginPath();
|
||||
if (_windowAspectR == false) {
|
||||
ctx.fillRect(x, y, 1, 1);
|
||||
} else {
|
||||
ctx.fillRect(x, y, _windowAspectX, _windowAspectY);
|
||||
}
|
||||
_strokeDrawColor = _color(color);
|
||||
};
|
||||
|
||||
|
@ -1532,6 +1556,11 @@ var QB = new function() {
|
|||
_bgColor = _color(0);
|
||||
_locX = 0;
|
||||
_locY = 0;
|
||||
|
||||
_windowAspectR = false;
|
||||
_strokeLineThickness = 2;
|
||||
_strokeDrawLength = 4;
|
||||
_strokeDrawAngle = -Math.PI/2;
|
||||
_strokeDrawColor = _color(15);
|
||||
|
||||
_lastKey = null;
|
||||
|
@ -1539,6 +1568,7 @@ var QB = new function() {
|
|||
_inkeyBuffer = [];
|
||||
_keyHitBuffer = [];
|
||||
_keyDownMap = {};
|
||||
|
||||
};
|
||||
|
||||
this.func_Sgn = function(value) {
|
||||
|
@ -1643,6 +1673,47 @@ var QB = new function() {
|
|||
return String(value);
|
||||
};
|
||||
|
||||
this.sub_Window = function(screenSwitch, x0, y0, x1, y1) {
|
||||
var screen = _images[_activeImage];
|
||||
var ctx = screen.ctx;
|
||||
var orientY, factorX, factorY;
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
if (_windowAspectR != false) { // convert cursor position to native
|
||||
screen.lastX = screen.canvas.width * (screen.lastX - _windowDef[0]) / (_windowDef[2] - _windowDef[0]);
|
||||
screen.lastY = screen.canvas.height * (screen.lastY - _windowDef[1]) / (_windowDef[3] - _windowDef[1]);
|
||||
}
|
||||
if ((screenSwitch == false) && (x0 == undefined) && (y0 == undefined) && (x1 == undefined) && (y1 == undefined)) {
|
||||
_windowAspectR = false;
|
||||
_strokeLineThickness = 2;
|
||||
///
|
||||
_strokeDrawLength = 4;//
|
||||
_strokeDrawAngle = -Math.PI/2;//
|
||||
_strokeDrawColor = _color(15);//
|
||||
//
|
||||
} else {
|
||||
if (screenSwitch == false) {
|
||||
orientY = -1;
|
||||
ctx.translate(0, screen.canvas.height);
|
||||
} else {
|
||||
orientY = 1;
|
||||
}
|
||||
factorX = Math.abs(x1-x0) / screen.canvas.width;
|
||||
factorY = Math.abs(y1-y0) / screen.canvas.height;
|
||||
_windowAspectR = factorY/factorX;
|
||||
_windowAspectX = factorX;
|
||||
_windowAspectY = orientY*factorY;
|
||||
ctx.scale(1/factorX, orientY/factorY);
|
||||
ctx.translate(-x0, -y0);
|
||||
_strokeLineThickness = Math.sqrt(factorX*factorX + factorY*factorY) / Math.sqrt(2);
|
||||
screen.lastX = screen.lastX * factorX + x0;
|
||||
screen.lastY = (screen.canvas.height - screen.lastY) * factorY + y0;
|
||||
_windowDef[0] = x0;
|
||||
_windowDef[1] = y0;
|
||||
_windowDef[2] = x1;
|
||||
_windowDef[3] = y1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// QBJS-only methods
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
|
55
qb2js.js
55
qb2js.js
|
@ -517,6 +517,8 @@ var ConvertSub = null;
|
|||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertCls( args)) +");";
|
||||
} else if ( m.name == "_PutImage" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertPutImage( args)) +");";
|
||||
} else if ( m.name == "Window" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertWindow( args)) +");";
|
||||
} else if ( m.name == "_FullScreen" ) {
|
||||
js = (await func_CallMethod( m)) +"(" +(await func_ConvertFullScreen( args)) +");";
|
||||
} else {
|
||||
|
@ -652,6 +654,58 @@ var doSmooth = ''; // STRING
|
|||
ConvertPutImage = startCoord +", " + sourceImage +", " + destImage +", " + destCoord +", " + doSmooth;
|
||||
return ConvertPutImage;
|
||||
}
|
||||
async function func_ConvertWindow(args/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var ConvertWindow = null;
|
||||
var invertFlag = ''; // STRING
|
||||
var firstParam = ''; // STRING
|
||||
var theRest = ''; // STRING
|
||||
var idx = 0; // INTEGER
|
||||
var sstep = ''; // STRING
|
||||
var estep = ''; // STRING
|
||||
invertFlag = "false";
|
||||
var kwd = ''; // STRING
|
||||
kwd = "SCREEN";
|
||||
if (((QB.func_UCase( (QB.func_Left( args, (QB.func_Len( kwd)))))) == kwd) ) {
|
||||
args = (QB.func_Right( args, (QB.func_Len( args)) -(QB.func_Len( kwd))));
|
||||
invertFlag = "true";
|
||||
}
|
||||
args = (QB.func__Trim( args));
|
||||
sstep = "false";
|
||||
estep = "false";
|
||||
idx = (await func_FindParamChar( args, ","));
|
||||
if ( idx == -1) {
|
||||
firstParam = args;
|
||||
theRest = "";
|
||||
} else {
|
||||
firstParam = (QB.func_Left( args, idx - 1));
|
||||
theRest = (QB.func_Right( args, (QB.func_Len( args)) - idx));
|
||||
}
|
||||
idx = (await func_FindParamChar( firstParam, "-"));
|
||||
var startCord = ''; // STRING
|
||||
var endCord = ''; // STRING
|
||||
if ( idx == -1) {
|
||||
endCord = firstParam;
|
||||
} else {
|
||||
startCord = (QB.func_Left( firstParam, idx - 1));
|
||||
endCord = (QB.func_Right( firstParam, (QB.func_Len( firstParam)) - idx));
|
||||
}
|
||||
idx = (QB.func_InStr( startCord, "("));
|
||||
startCord = (QB.func_Right( startCord, (QB.func_Len( startCord)) - idx));
|
||||
idx = (QB.func__InStrRev( startCord, ")"));
|
||||
startCord = (QB.func_Left( startCord, idx - 1));
|
||||
startCord = (await func_ConvertExpression( startCord));
|
||||
if (((QB.func__Trim( startCord)) == "") ) {
|
||||
startCord = "undefined, undefined";
|
||||
}
|
||||
idx = (QB.func_InStr( endCord, "("));
|
||||
endCord = (QB.func_Right( endCord, (QB.func_Len( endCord)) - idx));
|
||||
idx = (QB.func__InStrRev( endCord, ")"));
|
||||
endCord = (QB.func_Left( endCord, idx - 1));
|
||||
endCord = (await func_ConvertExpression( endCord));
|
||||
ConvertWindow = invertFlag +", " + startCord +", " + endCord;
|
||||
return ConvertWindow;
|
||||
}
|
||||
async function func_ConvertCls(args/*STRING*/) {
|
||||
if (QB.halted()) { return; }
|
||||
var ConvertCls = null;
|
||||
|
@ -2721,6 +2775,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "UCase$", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Val", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Varptr", False);
|
||||
await sub_AddQBMethod( "SUB", "Window", False);
|
||||
await sub_AddQBMethod( "SUB", "IncludeJS", True);
|
||||
await sub_AddSystemType( "FETCHRESPONSE", "ok:INTEGER,status:INTEGER,statusText:STRING,text:STRING");
|
||||
await sub_AddQBMethod( "FUNCTION", "Fetch", True);
|
||||
|
|
|
@ -610,6 +610,9 @@ Function ConvertSub$ (m As Method, args As String)
|
|||
ElseIf m.name = "_PutImage" Then
|
||||
js = CallMethod(m) + "(" + ConvertPutImage(args) + ");"
|
||||
|
||||
ElseIf m.name = "Window" Then
|
||||
js = CallMethod(m) + "(" + ConvertWindow(args) + ");"
|
||||
|
||||
ElseIf m.name = "_FullScreen" Then
|
||||
js = CallMethod(m) + "(" + ConvertFullScreen(args) + ");"
|
||||
Else
|
||||
|
@ -735,6 +738,61 @@ Function ConvertPutImage$ (args As String)
|
|||
ConvertPutImage = startCoord + ", " + sourceImage + ", " + destImage + ", " + destCoord + ", " + doSmooth
|
||||
End Function
|
||||
|
||||
Function ConvertWindow$ (args As String)
|
||||
Dim As String invertFlag
|
||||
Dim firstParam As String
|
||||
Dim theRest As String
|
||||
Dim idx As Integer
|
||||
Dim sstep As String
|
||||
Dim estep As String
|
||||
invertFlag = "false"
|
||||
|
||||
Dim kwd As String
|
||||
kwd = "SCREEN"
|
||||
If (UCase$(Left$(args, Len(kwd))) = kwd) Then
|
||||
args = Right$(args, Len(args) - Len(kwd))
|
||||
invertFlag = "true"
|
||||
End If
|
||||
args = _Trim$(args)
|
||||
|
||||
sstep = "false"
|
||||
estep = "false"
|
||||
|
||||
idx = FindParamChar(args, ",")
|
||||
If idx = -1 Then
|
||||
firstParam = args
|
||||
theRest = ""
|
||||
Else
|
||||
firstParam = Left$(args, idx - 1)
|
||||
theRest = Right$(args, Len(args) - idx)
|
||||
End If
|
||||
|
||||
idx = FindParamChar(firstParam, "-")
|
||||
Dim startCord As String
|
||||
Dim endCord As String
|
||||
If idx = -1 Then
|
||||
endCord = firstParam
|
||||
Else
|
||||
startCord = Left$(firstParam, idx - 1)
|
||||
endCord = Right$(firstParam, Len(firstParam) - idx)
|
||||
End If
|
||||
|
||||
idx = InStr(startCord, "(")
|
||||
startCord = Right$(startCord, Len(startCord) - idx)
|
||||
idx = _InStrRev(startCord, ")")
|
||||
startCord = Left$(startCord, idx - 1)
|
||||
startCord = ConvertExpression(startCord)
|
||||
If (_Trim$(startCord) = "") Then startCord = "undefined, undefined"
|
||||
|
||||
idx = InStr(endCord, "(")
|
||||
endCord = Right$(endCord, Len(endCord) - idx)
|
||||
idx = _InStrRev(endCord, ")")
|
||||
endCord = Left$(endCord, idx - 1)
|
||||
endCord = ConvertExpression(endCord)
|
||||
|
||||
ConvertWindow = invertFlag + ", " + startCord + ", " + endCord
|
||||
End Function
|
||||
|
||||
Function ConvertCls$ (args As String)
|
||||
Dim argc As Integer
|
||||
ReDim parts(0) As String
|
||||
|
@ -2855,6 +2913,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "UCase$", False
|
||||
AddQBMethod "FUNCTION", "Val", False
|
||||
AddQBMethod "FUNCTION", "Varptr", False
|
||||
AddQBMethod "SUB", "Window", False
|
||||
|
||||
|
||||
' QBJS-only language features
|
||||
|
|
Loading…
Reference in a new issue