Added basic window resizing to the application

This commit is contained in:
Kip DeCastro 2021-07-27 23:32:18 -04:00
parent ede11165a9
commit 4d57fc494c
3 changed files with 43 additions and 19 deletions

View File

@ -6,6 +6,9 @@ const { getIsDevMode } = require("./devmode");
const windowList = {};
let mainWindow;
function getMainWindow() {
return mainWindow;
}
@ -61,9 +64,9 @@ function createWindow() {
width: 900,
height: 730,
useContentSize: true,
frame: false,
frame: true,
transparent: true,
resizable: false,
resizable: true,
webPreferences: {
nodeIntegration: true,
nativeWindowOpen: true,
@ -73,6 +76,7 @@ function createWindow() {
},
});
// and load the index.html of the app.
mainWindow.loadFile(path.join(__dirname, "../renderer/index.html"));
@ -82,6 +86,7 @@ function createWindow() {
// Ensure we create child windows with the correct settings
mainWindow.webContents.on("new-window", handleNewWindow);
if (getIsDevMode()) {
mainWindow.webContents.toggleDevTools();
}
@ -89,5 +94,5 @@ function createWindow() {
module.exports = {
createWindow,
getMainWindow,
getMainWindow
};

View File

@ -98,6 +98,8 @@ window.addEventListener("keyup", function (event) {
inputQueue.push({ type: "keyup", keyCode: event.keyCode });
});
module.exports = {
INPUT_BUFFER_SIZE,
inputBuffer,

View File

@ -1,9 +1,9 @@
const { videoModeBufferView } = require("./video");
const { audioContext } = require("./audio");
var SCREEN_WIDTH = 800;
var SCREEN_HEIGHT = 600;
const BITS = 4;
const SCREEN_BUFFER_SIZE = 800 * 600 * BITS; // 32bpp;
const SCREEN_WIDTH = 800;
const SCREEN_HEIGHT = 600;
const SCREEN_BUFFER_SIZE = SCREEN_WIDTH * SCREEN_HEIGHT * 4; // 32bpp;
const screenBuffer = new SharedArrayBuffer(SCREEN_BUFFER_SIZE);
const screenBufferView = new Uint8Array(screenBuffer);
@ -12,7 +12,19 @@ canvas.width = SCREEN_WIDTH;
canvas.height = SCREEN_HEIGHT;
const canvasCtx = canvas.getContext("2d");
const imageData = canvasCtx.createImageData(SCREEN_WIDTH, SCREEN_HEIGHT);
var imageData = canvasCtx.createImageData(SCREEN_WIDTH, SCREEN_HEIGHT);
window.addEventListener('resize', () => {
SCREEN_HEIGHT = window.innerHeight -35;
SCREEN_WIDTH = Math.floor(SCREEN_HEIGHT * (4 / 3))
if(window.innerWidth < SCREEN_WIDTH){
SCREEN_WIDTH = window.innerWidth;
SCREEN_HEIGHT = Math.floor(SCREEN_WIDTH * 0.75);
}
canvas.width = SCREEN_WIDTH;
canvas.height = SCREEN_HEIGHT;
imageData = canvasCtx.createImageData(SCREEN_WIDTH, SCREEN_HEIGHT);
});
let stopDrawing = false;
@ -21,23 +33,28 @@ function drawScreen() {
const pixelsRGBA = imageData.data;
const numPixels = SCREEN_WIDTH * SCREEN_HEIGHT;
const expandedFromPalettedMode = videoModeBufferView[3];
const start = audioContext.currentTime;
if (expandedFromPalettedMode) {
for (var i = 0; i < numPixels; i++) {
// palette
pixelsRGBA[i * 4 + 0] = screenBufferView[i * 4 + 0];
pixelsRGBA[i * 4 + 1] = screenBufferView[i * 4 + 1];
pixelsRGBA[i * 4 + 2] = screenBufferView[i * 4 + 2];
pixelsRGBA[i * 4 + 3] = 255; // full opacity
pixelsRGBA[i * BITS + 0] = screenBufferView[i * BITS + 0];
pixelsRGBA[i * BITS + 1] = screenBufferView[i * BITS + 1];
pixelsRGBA[i * BITS + 2] = screenBufferView[i * BITS + 2];
pixelsRGBA[i * BITS + 3] = 255; // full opacity
}
} else {
for (var i = 0; i < numPixels; i++) {
// ARGB
pixelsRGBA[i * 4 + 0] = screenBufferView[i * 4 + 1];
pixelsRGBA[i * 4 + 1] = screenBufferView[i * 4 + 2];
pixelsRGBA[i * 4 + 2] = screenBufferView[i * 4 + 3];
pixelsRGBA[i * 4 + 3] = 255; // full opacity
for (var i = 0; i < SCREEN_HEIGHT; i++) {
for (var j = 0; j < SCREEN_WIDTH; j++){
// ARGB
const xRatio = 800 / SCREEN_WIDTH;
const yRatio = 600 / SCREEN_HEIGHT;
const px = Math.floor(j * xRatio);
const py = Math.floor(i * yRatio);
pixelsRGBA[((i * SCREEN_WIDTH) + j) * 4 + 0] = screenBufferView[((py*800) +px) * 4 + 1];//- lineMult];
pixelsRGBA[((i * SCREEN_WIDTH) + j) * 4 + 1] = screenBufferView[((py*800) +px) * 4 + 2];//- lineMult];
pixelsRGBA[((i * SCREEN_WIDTH) + j) * 4 + 2] = screenBufferView[((py*800) +px) * 4 + 3];//- lineMult];
pixelsRGBA[((i * SCREEN_WIDTH) + j) * 4 + 3] = 255; // full opacity
}
}
}