/******************************************************************************* * Copyright (c) 2013 "Filippo Scognamiglio" * https://github.com/Swordfish90/cool-retro-term * * This file is part of cool-retro-term. * * cool-retro-term is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . *******************************************************************************/ import QtQuick 2.2 import "utils.js" as Utils QtObject{ property string version: "0.9" // GENERAL SETTINGS /////////////////////////////////////////////////// property bool fullscreen: false property bool showMenubar: true property real windowOpacity: 1.0 property real ambientLight: 0.2 property real contrast: 0.85 property real brightness: 0.5 property bool showTerminalSize: true property real windowScaling: 1.0 property real fps: 24 property bool verbose: false onWindowScalingChanged: handleFontChanged(); // PROFILE SETTINGS /////////////////////////////////////////////////////// property string _backgroundColor: "#000000" property string _fontColor: "#ff8100" property string saturatedColor: Utils.mix(Utils.strToColor("#FFFFFF"), Utils.strToColor(_fontColor), saturationColor * 0.5) property color fontColor: Utils.mix(Utils.strToColor(saturatedColor), Utils.strToColor(_backgroundColor), 0.7 + (contrast * 0.3)) property color backgroundColor: Utils.mix(Utils.strToColor(_backgroundColor), Utils.strToColor(saturatedColor), 0.7 + (contrast * 0.3)) property real staticNoise: 0.1 property real screenCurvature: 0.1 property real glowingLine: 0.2 property real burnIn: 0.40 property real bloom: 0.65 property real bloomQuality: 0.5 property real burnInQuality: 0.5 property real chromaColor: 0.0 property real saturationColor: 0.0 property real jitter: 0.18 property real horizontalSync: 0.08 property real flickering: 0.1 property real rbgShift: 0.0 readonly property int no_rasterization: 0 readonly property int scanline_rasterization: 1 readonly property int pixel_rasterization: 2 property int rasterization: no_rasterization // FONTS ////////////////////////////////////////////////////////////////// property real fontScaling: 1.0 property real fontWidth: 1.0 property var fontNames: ["HERMIT", "COMMODORE_PET", "COMMODORE_PET"] property var fontlist: fontManager.item.fontlist signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, real screenScaling, real fontWidth) property Loader fontManager: Loader{ states: [ State { when: rasterization == no_rasterization PropertyChanges {target: fontManager; source: "Fonts.qml" } }, State { when: rasterization == scanline_rasterization PropertyChanges {target: fontManager; source: "FontScanlines.qml" } }, State { when: rasterization == pixel_rasterization; PropertyChanges {target: fontManager; source: "FontPixels.qml" } } ] onLoaded: handleFontChanged() } onFontScalingChanged: handleFontChanged(); onFontWidthChanged: handleFontChanged(); function getIndexByName(name) { for (var i = 0; i < fontlist.count; i++) { if (name === fontlist.get(i).name) return i; } return 0; // If the font is not available default to 0. } function incrementScaling(){ fontScaling = Math.min(fontScaling + 0.05, 2.50); handleFontChanged(); } function decrementScaling(){ fontScaling = Math.max(fontScaling - 0.05, 0.50); handleFontChanged(); } function handleFontChanged(){ if (!fontManager.item) return; var index = getIndexByName(fontNames[rasterization]); if (index === undefined) return; fontManager.item.selectedFontIndex = index; fontManager.item.scaling = fontScaling * windowScaling; var fontSource = fontManager.item.source; var pixelSize = fontManager.item.pixelSize; var lineSpacing = fontManager.item.lineSpacing; var screenScaling = fontManager.item.screenScaling; var fontWidth = fontManager.item.defaultFontWidth * appSettings.fontWidth; terminalFontChanged(fontSource, pixelSize, lineSpacing, screenScaling, fontWidth); } // FRAMES ///////////////////////////////////////////////////////////////// property ListModel framesList: ListModel{ ListElement{ name: "NO_FRAME" text: "No frame" source: "" reflections: false } ListElement{ name: "SIMPLE_WHITE_FRAME" text: "Simple white frame" source: "./frames/WhiteSimpleFrame.qml" reflections: true } ListElement{ name: "ROUGH_BLACK_FRAME" text: "Rough black frame" source: "./frames/BlackRoughFrame.qml" reflections: true } } function getFrameIndexByName(name) { for (var i = 0; i < framesList.count; i++) { if (name === framesList.get(i).name) return i; } return 0; // If the frame is not available default to 0. } property string frameSource: "./frames/WhiteSimpleFrame.qml" property string frameName: "SIMPLE_WHITE_FRAME" property bool _frameReflections: false property bool reflectionsAllowed: true property bool frameReflections: _frameReflections && reflectionsAllowed onFrameNameChanged: { var index = getFrameIndexByName(frameName); frameSource = framesList.get(index).source; reflectionsAllowed = framesList.get(index).reflections; } // DB STORAGE ///////////////////////////////////////////////////////////// property Storage storage: Storage{ } function stringify(obj) { var replacer = function(key, val) { return val.toFixed ? Number(val.toFixed(4)) : val; } return JSON.stringify(obj, replacer, 2); } function composeSettingsString(){ var settings = { fps: fps, windowScaling: windowScaling, showTerminalSize: showTerminalSize, fontScaling: fontScaling, fontNames: fontNames, frameReflections: _frameReflections, showMenubar: showMenubar, bloomQuality: bloomQuality, burnInQuality: burnInQuality } return stringify(settings); } function composeProfileObject(){ var settings = { backgroundColor: _backgroundColor, fontColor: _fontColor, flickering: flickering, horizontalSync: horizontalSync, staticNoise: staticNoise, chromaColor: chromaColor, saturationColor: saturationColor, screenCurvature: screenCurvature, glowingLine: glowingLine, frameName: frameName, burnIn: burnIn, bloom: bloom, rasterization: rasterization, jitter: jitter, rbgShift: rbgShift, brightness: brightness, contrast: contrast, ambientLight: ambientLight, windowOpacity: windowOpacity, fontName: fontNames[rasterization], fontWidth: fontWidth } return settings; } function composeProfileString() { return stringify(composeProfileObject()); } function loadSettings(){ var settingsString = storage.getSetting("_CURRENT_SETTINGS"); var profileString = storage.getSetting("_CURRENT_PROFILE"); if(!settingsString) return; if(!profileString) return; loadSettingsString(settingsString); loadProfileString(profileString); if (verbose) console.log("Loading settings: " + settingsString + profileString); } function storeSettings(){ var settingsString = composeSettingsString(); var profileString = composeProfileString(); storage.setSetting("_CURRENT_SETTINGS", settingsString); storage.setSetting("_CURRENT_PROFILE", profileString); if (verbose) { console.log("Storing settings: " + settingsString); console.log("Storing profile: " + profileString); } } function loadSettingsString(settingsString){ var settings = JSON.parse(settingsString); showTerminalSize = settings.showTerminalSize !== undefined ? settings.showTerminalSize : showTerminalSize fps = settings.fps !== undefined ? settings.fps: fps windowScaling = settings.windowScaling !== undefined ? settings.windowScaling : windowScaling fontNames = settings.fontNames !== undefined ? settings.fontNames : fontNames fontScaling = settings.fontScaling !== undefined ? settings.fontScaling : fontScaling _frameReflections = settings.frameReflections !== undefined ? settings.frameReflections : _frameReflections; showMenubar = settings.showMenubar !== undefined ? settings.showMenubar : showMenubar; bloomQuality = settings.bloomQuality !== undefined ? settings.bloomQuality : bloomQuality; burnInQuality = settings.burnInQuality !== undefined ? settings.burnInQuality : burnInQuality; } function loadProfileString(profileString){ var settings = JSON.parse(profileString); _backgroundColor = settings.backgroundColor !== undefined ? settings.backgroundColor : _backgroundColor; _fontColor = settings.fontColor !== undefined ? settings.fontColor : _fontColor; horizontalSync = settings.horizontalSync !== undefined ? settings.horizontalSync : horizontalSync flickering = settings.flickering !== undefined ? settings.flickering : flickering; staticNoise = settings.staticNoise !== undefined ? settings.staticNoise : staticNoise; chromaColor = settings.chromaColor !== undefined ? settings.chromaColor : chromaColor; saturationColor = settings.saturationColor !== undefined ? settings.saturationColor : saturationColor; screenCurvature = settings.screenCurvature !== undefined ? settings.screenCurvature : screenCurvature; glowingLine = settings.glowingLine !== undefined ? settings.glowingLine : glowingLine; burnIn = settings.burnIn !== undefined ? settings.burnIn : burnIn bloom = settings.bloom !== undefined ? settings.bloom : bloom frameName = settings.frameName !== undefined ? settings.frameName : frameName; rasterization = settings.rasterization !== undefined ? settings.rasterization : rasterization; jitter = settings.jitter !== undefined ? settings.jitter : jitter; rbgShift = settings.rbgShift !== undefined ? settings.rbgShift : rbgShift; ambientLight = settings.ambientLight !== undefined ? settings.ambientLight : ambientLight; contrast = settings.contrast !== undefined ? settings.contrast : contrast; brightness = settings.brightness !== undefined ? settings.brightness : brightness; windowOpacity = settings.windowOpacity !== undefined ? settings.windowOpacity : windowOpacity; fontNames[rasterization] = settings.fontName !== undefined ? settings.fontName : fontNames[rasterization]; fontWidth = settings.fontWidth !== undefined ? settings.fontWidth : fontWidth; handleFontChanged(); } function storeCustomProfiles(){ storage.setSetting("_CUSTOM_PROFILES", composeCustomProfilesString()); } function loadCustomProfiles(){ var customProfileString = storage.getSetting("_CUSTOM_PROFILES"); if(customProfileString === undefined) customProfileString = "[]"; loadCustomProfilesString(customProfileString); } function loadCustomProfilesString(customProfilesString){ var customProfiles = JSON.parse(customProfilesString); for (var i=0; i