1
1
Fork 0
mirror of https://github.com/boxgaming/qbjs.git synced 2024-09-20 04:24:45 +00:00

Added support for character-based screen sizing

This commit is contained in:
boxgaming 2022-04-28 22:06:24 -05:00
parent 1d9e71147c
commit e151e935ea
4 changed files with 54 additions and 15 deletions

View file

@ -40,10 +40,10 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
'_putimage', '_r2d', '_red', '_red32', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
'_screenexists', '_sinh', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol',
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'exp',
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'csrlin', 'cvi', 'cvl', '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', 'timer', 'ubound', 'ucase', 'val',
'oct', 'paint', 'point', 'pos', 'preset', 'print', 'pset', 'right', 'rtrim', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space',
'sqr', 'str', 'swap', 'tan', 'timer', 'ubound', 'ucase', 'val',
// QBJS-specific
'export', 'from', 'import']

59
qb.js
View file

@ -233,9 +233,17 @@ var QB = new function() {
this.func__Height = function(imageId) {
if (imageId == undefined) { imageId = _activeImage; }
return _images[imageId].canvas.height;
if (_images[imageId].charSizeMode) {
return _height(imageId) / this.func__FontWidth();
}
return _height(imageId);
};
function _height(imageId) {
if (imageId == undefined) { imageId = _activeImage; }
return _images[imageId].canvas.height;
}
this.func__InStrRev = function(arg1, arg2, arg3) {
var startIndex = +Infinity;
var strSource = "";
@ -307,14 +315,20 @@ var QB = new function() {
return GX.mouseButton(button);
};
this.func__NewImage = function(iwidth, iheight) {
this.func__NewImage = function(iwidth, iheight, mode) {
var canvas = document.createElement("canvas");
canvas.id = "qb-canvas-" + _nextImageId;
canvas.width = iwidth;
canvas.height = iheight;
if (mode == 0) {
canvas.width = this.func__FontWidth() * iwidth;
canvas.height = this.func__FontHeight() * iheight;
}
else {
canvas.width = iwidth;
canvas.height = iheight;
}
ctx = canvas.getContext("2d");
_images[_nextImageId] = { canvas: canvas, ctx: ctx, lastX: 0, lastY: 0 };
_images[_nextImageId] = { canvas: canvas, ctx: ctx, lastX: 0, lastY: 0, charSizeMode: (mode == 0)};
var tmpId = _nextImageId;
_nextImageId++;
return tmpId;
@ -544,9 +558,17 @@ var QB = new function() {
this.func__Width = function(imageId) {
if (imageId == undefined) { imageId = _activeImage; }
return _images[imageId].canvas.width;
if (_images[imageId].charSizeMode) {
return _width(imageId) / this.func__FontWidth();
}
return _width(imageId);
};
function _width (imageId) {
if (imageId == undefined) { imageId = _activeImage; }
return _images[imageId].canvas.width;
}
// QB45 Keywords
// --------------------------------------------
@ -593,9 +615,9 @@ var QB = new function() {
ctx = _images[_activeImage].ctx;
ctx.beginPath();
ctx.clearRect(0, 0, QB.func__Width(), QB.func__Height());
ctx.clearRect(0, 0, _width(), _height());
ctx.fillStyle = color.rgba();
ctx.fillRect(0, 0, QB.func__Width(), QB.func__Height());
ctx.fillRect(0, 0, _width(), _height());
// reset the text position
_locX = 0;
@ -637,6 +659,10 @@ var QB = new function() {
return Math.cos(value);
};
this.func_Csrlin = function() {
return _locY + 1;
}
this.func_Cvi = function(numString) {
var result = 0;
numString = numString.split("").reverse().join("");
@ -669,11 +695,11 @@ var QB = new function() {
};
function _textColumns() {
return Math.floor(QB.func__Width() / QB.func__FontWidth());
return Math.floor(_width() / QB.func__FontWidth());
}
function _textRows() {
return Math.floor(QB.func__Height() / QB.func__FontHeight());
return Math.floor(_height() / QB.func__FontHeight());
}
this.func_Hex = function(n) {
@ -1019,6 +1045,10 @@ var QB = new function() {
return ret;
};
this.func_Pos = function() {
return _locX + 1;
};
this.sub_PReset = function(sstep, x, y, color) {
var screen = _images[_activeImage];
if (color == undefined) {
@ -1113,7 +1143,7 @@ var QB = new function() {
var ctx = _images[_activeImage].ctx;
ctx.beginPath();
ctx.fillStyle = _bgColor.rgba();
ctx.fillRect(0, 0, QB.func__Width(), QB.func__Height());
ctx.fillRect(0, 0, _width(), _height());
ctx.drawImage(img, 0, -QB.func__FontHeight());
}
@ -1158,6 +1188,7 @@ var QB = new function() {
this.sub_Screen = async function(mode) {
_activeImage = 0;
charSizeMode = false;
if (mode == 0) {
GX.sceneCreate(640, 400);
@ -1174,14 +1205,18 @@ var QB = new function() {
else if (mode == 11 || mode == 12) {
GX.sceneCreate(640, 480);
}
else if (mode == 13) {
GX.sceneCreate(320, 200);
}
else if (mode >= 1000) {
var img = _images[mode];
if (img && img.canvas) {
GX.sceneCreate(img.canvas.width, img.canvas.height);
this.sub__PutImage(undefined, undefined, undefined, undefined, undefined, undefined, mode);
charSizeMode = img.charSizeMode;
}
}
_images[0] = { canvas: GX.canvas(), ctx: GX.ctx(), lastX: 0, lastY: 0 };
_images[0] = { canvas: GX.canvas(), ctx: GX.ctx(), lastX: 0, lastY: 0, charSizeMode: charSizeMode };
// initialize the graphics
_fgColor = _color(7);

View file

@ -2593,6 +2593,7 @@ if (QB.halted()) { return; }
await sub_AddQBMethod( "SUB", "Color", False);
await sub_AddQBMethod( "FUNCTION", "Command$", False);
await sub_AddQBMethod( "FUNCTION", "Cos", False);
await sub_AddQBMethod( "FUNCTION", "Csrlin", False);
await sub_AddQBMethod( "FUNCTION", "Cvi", False);
await sub_AddQBMethod( "FUNCTION", "Cvl", False);
await sub_AddQBMethod( "FUNCTION", "Exp", False);
@ -2616,6 +2617,7 @@ if (QB.halted()) { return; }
await sub_AddQBMethod( "FUNCTION", "Oct$", False);
await sub_AddQBMethod( "SUB", "Paint", False);
await sub_AddQBMethod( "FUNCTION", "Point", False);
await sub_AddQBMethod( "FUNCTION", "Pos", False);
await sub_AddQBMethod( "SUB", "PReset", False);
await sub_AddQBMethod( "SUB", "Print", True);
await sub_AddQBMethod( "SUB", "PSet", False);

View file

@ -2750,6 +2750,7 @@ Sub InitQBMethods
AddQBMethod "SUB", "Color", False
AddQBMethod "FUNCTION", "Command$", False
AddQBMethod "FUNCTION", "Cos", False
AddQBMethod "FUNCTION", "Csrlin", False
AddQBMethod "FUNCTION", "Cvi", False
AddQBMethod "FUNCTION", "Cvl", False
AddQBMethod "FUNCTION", "Exp", False
@ -2773,6 +2774,7 @@ Sub InitQBMethods
AddQBMethod "FUNCTION", "Oct$", False
AddQBMethod "SUB", "Paint", False
AddQBMethod "FUNCTION", "Point", False
AddQBMethod "FUNCTION", "Pos", False
AddQBMethod "SUB", "PReset", False
AddQBMethod "SUB", "Print", True
AddQBMethod "SUB", "PSet", False