mirror of
https://github.com/felixrieseberg/macintosh.js.git
synced 2024-09-27 08:54:26 +00:00
Merge pull request #118 from kipdec/scaling
Added basic window resizing
This commit is contained in:
commit
e5b24cc04a
@ -61,9 +61,9 @@ function createWindow() {
|
||||
width: 900,
|
||||
height: 730,
|
||||
useContentSize: true,
|
||||
frame: false,
|
||||
frame: true,
|
||||
transparent: true,
|
||||
resizable: false,
|
||||
resizable: true,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
nativeWindowOpen: true,
|
||||
@ -89,5 +89,5 @@ function createWindow() {
|
||||
|
||||
module.exports = {
|
||||
createWindow,
|
||||
getMainWindow,
|
||||
getMainWindow
|
||||
};
|
||||
|
@ -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++) {
|
||||
for (var i = 0; i < SCREEN_HEIGHT; i++) {
|
||||
for (var j = 0; j < SCREEN_WIDTH; j++){
|
||||
// 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
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user