Skip to content

Commit

Permalink
added pixelation menu, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ardean committed Mar 5, 2017
1 parent d81e01b commit 15b8bf9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
7 changes: 6 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ app
createMenuTemplate(mainWindowServer, {
openROMDialog,
openBatteryFileDialog,
saveBatteryFile
saveBatteryFile,
togglePixelation
})
)
);
Expand Down Expand Up @@ -101,3 +102,7 @@ function openBatteryFile(batteryFilePath) {
function saveBatteryFile() {
mainWindowServer.sendToClient("save-battery-file");
}

function togglePixelation(menuItem) {
mainWindowServer.sendToClient("toggle-pixelation", menuItem.checked);
}
5 changes: 5 additions & 0 deletions app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module.exports = function (mainWindowServer, options) {
{
label: "View",
submenu: [{
label: "Pixelated",
type: "checkbox",
checked: true,
click: options.togglePixelation
}, {
role: "reload"
},
{
Expand Down
8 changes: 4 additions & 4 deletions app/window-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class WindowServer extends EventEmitter {
this.window.on("enter-full-screen", () => {
this.window.setResizable(true);
if (this.isClientRequested) return this.isClientRequested = false;
this.sendToClient("requestFullscreen");
this.sendToClient("toggle-fullscreen", true);
}).on("leave-full-screen", () => {
this.window.setResizable(false);
if (this.isClientRequested) return this.isClientRequested = false;
this.sendToClient("cancelFullscreen");
this.sendToClient("toggle-fullscreen", false);
});
} else {
this.window.on("maximize", () => {
if (this.isClientRequested) return this.isClientRequested = false;
this.sendToClient("requestFullscreen");
this.sendToClient("toggle-fullscreen", true);
}).on("unmaximize", () => {
if (this.isClientRequested) return this.isClientRequested = false;
this.sendToClient("cancelFullscreen");
this.sendToClient("toggle-fullscreen", false);
});
}

Expand Down
18 changes: 13 additions & 5 deletions src/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Fullscreen from "./fullscreen.js";
export default function (gameboy, jsGBCui) {
if (require) {
const { ipcRenderer } = require("electron");
const $jsGBCui = $(jsGBCui);

const fullscreen = new Fullscreen();
let isServerRequested = false;
Expand Down Expand Up @@ -36,12 +37,19 @@ export default function (gameboy, jsGBCui) {
gameboy.loadBatteryFileArrayBuffer(batteryFile);
}).on("save-battery-file", () => {
util.downloadFile(gameboy.core.cartridgeSlot.cartridge.name + ".sav", gameboy.getBatteryFileArrayBuffer());
}).on("requestFullscreen", () => {
isServerRequested = true;
fullscreen.request();
}).on("cancelFullscreen", () => {
}).on("toggle-pixelation", (e, hasPixelation) => {
if (hasPixelation) {
$jsGBCui.removeAttr("no-pixelation");
} else {
$jsGBCui.attr("no-pixelation", true);
}
}).on("toggle-fullscreen", (e, isActive) => {
isServerRequested = true;
fullscreen.cancel();
if (isActive) {
fullscreen.request();
} else {
fullscreen.cancel();
}
});

ipcRenderer.send("ready");
Expand Down

0 comments on commit 15b8bf9

Please sign in to comment.