mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 07:04:20 +00:00 
			
		
		
		
	Move constants to a separate qml file.
This commit is contained in:
		
							
								
								
									
										39
									
								
								app/qml/ApplicationConstants.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								app/qml/ApplicationConstants.qml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | |||||||
|  | /******************************************************************************* | ||||||
|  | * Copyright (c) 2013-2021 "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 <http://www.gnu.org/licenses/>. | ||||||
|  | *******************************************************************************/ | ||||||
|  | import QtQuick 2.2 | ||||||
|  |  | ||||||
|  | QtObject { | ||||||
|  |     readonly property string version: appVersion | ||||||
|  |     readonly property int profileVersion: 2 | ||||||
|  |  | ||||||
|  |     readonly property real screenCurvatureSize: 0.4 | ||||||
|  |     readonly property real minimumFontScaling: 0.25 | ||||||
|  |     readonly property real maximumFontScaling: 2.50 | ||||||
|  |  | ||||||
|  |     readonly property real minBurnInFadeTime: 160 | ||||||
|  |     readonly property real maxBurnInFadeTime: 1600 | ||||||
|  |  | ||||||
|  |     readonly property int no_rasterization: 0 | ||||||
|  |     readonly property int scanline_rasterization: 1 | ||||||
|  |     readonly property int pixel_rasterization: 2 | ||||||
|  |     readonly property int subpixel_rasterization: 3 | ||||||
|  |  | ||||||
|  |     readonly property real baseFontScaling: 0.75 | ||||||
|  | } | ||||||
| @@ -23,18 +23,8 @@ import QtQuick.Controls 2.0 | |||||||
| import "utils.js" as Utils | import "utils.js" as Utils | ||||||
|  |  | ||||||
| QtObject { | QtObject { | ||||||
|     readonly property string version: appVersion |  | ||||||
|     readonly property int profileVersion: 2 |  | ||||||
|  |  | ||||||
|     // STATIC CONSTANTS //////////////////////////////////////////////////////// |     // APPLICATION SETTINGS /////////////////////////////////////////////////////// | ||||||
|     readonly property real screenCurvatureSize: 0.4 |  | ||||||
|     readonly property real minimumFontScaling: 0.25 |  | ||||||
|     readonly property real maximumFontScaling: 2.50 |  | ||||||
|  |  | ||||||
|     readonly property real minBurnInFadeTime: 160 |  | ||||||
|     readonly property real maxBurnInFadeTime: 1600 |  | ||||||
|  |  | ||||||
|     // GENERAL SETTINGS /////////////////////////////////////////////////////// |  | ||||||
|     property int x: 100 |     property int x: 100 | ||||||
|     property int y: 100 |     property int y: 100 | ||||||
|     property int width: 1024 |     property int width: 1024 | ||||||
| @@ -56,8 +46,6 @@ QtObject { | |||||||
|     property real burnInQuality: 0.5 |     property real burnInQuality: 0.5 | ||||||
|     property bool useFastBurnIn: Qt.platform.os === "osx" ? false : true |     property bool useFastBurnIn: Qt.platform.os === "osx" ? false : true | ||||||
|  |  | ||||||
|     property bool blinkingCursor: false |  | ||||||
|  |  | ||||||
|     onWindowScalingChanged: handleFontChanged() |     onWindowScalingChanged: handleFontChanged() | ||||||
|  |  | ||||||
|     // PROFILE SETTINGS /////////////////////////////////////////////////////// |     // PROFILE SETTINGS /////////////////////////////////////////////////////// | ||||||
| @@ -106,17 +94,13 @@ QtObject { | |||||||
|  |  | ||||||
|     property real totalMargin: frameMargin + margin |     property real totalMargin: frameMargin + margin | ||||||
|  |  | ||||||
|     readonly property int no_rasterization: 0 |  | ||||||
|     readonly property int scanline_rasterization: 1 |  | ||||||
|     readonly property int pixel_rasterization: 2 |  | ||||||
|     readonly property int subpixel_rasterization: 3 |  | ||||||
|  |  | ||||||
|     property int rasterization: no_rasterization |     property int rasterization: no_rasterization | ||||||
|  |  | ||||||
|  |     property bool blinkingCursor: false | ||||||
|  |  | ||||||
|     // FONTS ////////////////////////////////////////////////////////////////// |     // FONTS ////////////////////////////////////////////////////////////////// | ||||||
|     readonly property real baseFontScaling: 0.75 |  | ||||||
|     property real fontScaling: 1.0 |     property real fontScaling: 1.0 | ||||||
|     property real totalFontScaling: baseFontScaling * fontScaling |     property real totalFontScaling: appConstants.baseFontScaling * fontScaling | ||||||
|  |  | ||||||
|     property real fontWidth: 1.0 |     property real fontWidth: 1.0 | ||||||
|  |  | ||||||
| @@ -132,28 +116,28 @@ QtObject { | |||||||
|     property Loader fontManager: Loader { |     property Loader fontManager: Loader { | ||||||
|         states: [ |         states: [ | ||||||
|             State { |             State { | ||||||
|                 when: rasterization == no_rasterization |                 when: rasterization == appConstants.no_rasterization | ||||||
|                 PropertyChanges { |                 PropertyChanges { | ||||||
|                     target: fontManager |                     target: fontManager | ||||||
|                     source: "Fonts.qml" |                     source: "Fonts.qml" | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|             State { |             State { | ||||||
|                 when: rasterization == scanline_rasterization |                 when: rasterization == appConstants.scanline_rasterization | ||||||
|                 PropertyChanges { |                 PropertyChanges { | ||||||
|                     target: fontManager |                     target: fontManager | ||||||
|                     source: "FontScanlines.qml" |                     source: "FontScanlines.qml" | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|             State { |             State { | ||||||
|                 when: rasterization == pixel_rasterization |                 when: rasterization == appConstants.pixel_rasterization | ||||||
|                 PropertyChanges { |                 PropertyChanges { | ||||||
|                     target: fontManager |                     target: fontManager | ||||||
|                     source: "FontPixels.qml" |                     source: "FontPixels.qml" | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|             State { |             State { | ||||||
|                 when: rasterization == subpixel_rasterization |                 when: rasterization == appConstants.subpixel_rasterization | ||||||
|                 PropertyChanges { |                 PropertyChanges { | ||||||
|                     target: fontManager |                     target: fontManager | ||||||
|                     source: "FontPixels.qml" |                     source: "FontPixels.qml" | ||||||
| @@ -179,12 +163,12 @@ QtObject { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     function incrementScaling() { |     function incrementScaling() { | ||||||
|         fontScaling = Math.min(fontScaling + 0.05, maximumFontScaling) |         fontScaling = Math.min(fontScaling + 0.05, appConstants.maximumFontScaling) | ||||||
|         handleFontChanged() |         handleFontChanged() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function decrementScaling() { |     function decrementScaling() { | ||||||
|         fontScaling = Math.max(fontScaling - 0.05, minimumFontScaling) |         fontScaling = Math.max(fontScaling - 0.05, appConstants.minimumFontScaling) | ||||||
|         handleFontChanged() |         handleFontChanged() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,8 +32,8 @@ Loader { | |||||||
|     property real delay: (1.0 / appSettings.fps) * 1000 |     property real delay: (1.0 / appSettings.fps) * 1000 | ||||||
|     property real burnIn: appSettings.burnIn |     property real burnIn: appSettings.burnIn | ||||||
|     property real burnInFadeTime: 1 / Utils.lint(_minBurnInFadeTime, _maxBurnInFadeTime, burnIn) |     property real burnInFadeTime: 1 / Utils.lint(_minBurnInFadeTime, _maxBurnInFadeTime, burnIn) | ||||||
|     property real _minBurnInFadeTime: appSettings.minBurnInFadeTime |     property real _minBurnInFadeTime: appConstants.minBurnInFadeTime | ||||||
|     property real _maxBurnInFadeTime: appSettings.maxBurnInFadeTime |     property real _maxBurnInFadeTime: appConstants.maxBurnInFadeTime | ||||||
|  |  | ||||||
|     active: appSettings.useFastBurnIn && appSettings.burnIn !== 0 |     active: appSettings.useFastBurnIn && appSettings.burnIn !== 0 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -217,7 +217,7 @@ Item{ | |||||||
|             y = (y - margin) / height; |             y = (y - margin) / height; | ||||||
|  |  | ||||||
|             var cc = Qt.size(0.5 - x, 0.5 - y); |             var cc = Qt.size(0.5 - x, 0.5 - y); | ||||||
|             var distortion = (cc.height * cc.height + cc.width * cc.width) * appSettings.screenCurvature * appSettings.screenCurvatureSize; |             var distortion = (cc.height * cc.height + cc.width * cc.width) * appSettings.screenCurvature * appConstants.screenCurvatureSize; | ||||||
|  |  | ||||||
|             return Qt.point((x - cc.width  * (1+distortion) * distortion) * (kterminal.totalWidth), |             return Qt.point((x - cc.width  * (1+distortion) * distortion) * (kterminal.totalWidth), | ||||||
|                            (y - cc.height * (1+distortion) * distortion) * (kterminal.totalHeight)) |                            (y - cc.height * (1+distortion) * distortion) * (kterminal.totalHeight)) | ||||||
|   | |||||||
| @@ -156,7 +156,7 @@ ColumnLayout { | |||||||
|             } |             } | ||||||
|             CheckBox { |             CheckBox { | ||||||
|                 Layout.columnSpan: 2 |                 Layout.columnSpan: 2 | ||||||
|                 text: qsTr("Burnin optimization (Might display timing artifacts)") |                 text: qsTr("Burnin optimization (might display timing artifacts)") | ||||||
|                 checked: appSettings.useFastBurnIn |                 checked: appSettings.useFastBurnIn | ||||||
|                 onCheckedChanged: appSettings.useFastBurnIn = checked |                 onCheckedChanged: appSettings.useFastBurnIn = checked | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -113,7 +113,7 @@ ColumnLayout { | |||||||
|  |  | ||||||
|                             var version = profileObject.version |                             var version = profileObject.version | ||||||
|                                     !== undefined ? profileObject.version : 1 |                                     !== undefined ? profileObject.version : 1 | ||||||
|                             if (version !== appSettings.profileVersion) |                             if (version !== appConstants.profileVersion) | ||||||
|                                 throw "This profile is not supported on this version of CRT." |                                 throw "This profile is not supported on this version of CRT." | ||||||
|  |  | ||||||
|                             delete profileObject.name |                             delete profileObject.name | ||||||
| @@ -160,7 +160,7 @@ ColumnLayout { | |||||||
|                             var profileSettings = JSON.parse( |                             var profileSettings = JSON.parse( | ||||||
|                                         profileObject.obj_string) |                                         profileObject.obj_string) | ||||||
|                             profileSettings["name"] = profileObject.text |                             profileSettings["name"] = profileObject.text | ||||||
|                             profileSettings["version"] = appSettings.profileVersion |                             profileSettings["version"] = appConstants.profileVersion | ||||||
|  |  | ||||||
|                             var result = fileIO.write(url, JSON.stringify( |                             var result = fileIO.write(url, JSON.stringify( | ||||||
|                                                           profileSettings, |                                                           profileSettings, | ||||||
|   | |||||||
| @@ -83,8 +83,8 @@ ColumnLayout { | |||||||
|                     onValueChanged: appSettings.fontScaling = value |                     onValueChanged: appSettings.fontScaling = value | ||||||
|                     value: appSettings.fontScaling |                     value: appSettings.fontScaling | ||||||
|                     stepSize: 0.05 |                     stepSize: 0.05 | ||||||
|                     from: appSettings.minimumFontScaling |                     from: appConstants.minimumFontScaling | ||||||
|                     to: appSettings.maximumFontScaling |                     to: appConstants.maximumFontScaling | ||||||
|                 } |                 } | ||||||
|                 SizedLabel { |                 SizedLabel { | ||||||
|                     text: Math.round(fontScalingChanger.value * 100) + "%" |                     text: Math.round(fontScalingChanger.value * 100) + "%" | ||||||
|   | |||||||
| @@ -2,12 +2,12 @@ import QtQuick 2.0 | |||||||
|  |  | ||||||
| QtObject { | QtObject { | ||||||
|     property string rasterizationShader: |     property string rasterizationShader: | ||||||
|         (appSettings.rasterization === appSettings.no_rasterization ? " |         (appSettings.rasterization === appConstants.no_rasterization ? " | ||||||
|             lowp vec3 applyRasterization(vec2 screenCoords, lowp vec3 texel, vec2 virtualResolution, float intensity) { |             lowp vec3 applyRasterization(vec2 screenCoords, lowp vec3 texel, vec2 virtualResolution, float intensity) { | ||||||
|                 return texel; |                 return texel; | ||||||
|             }" : "") + |             }" : "") + | ||||||
|  |  | ||||||
|         (appSettings.rasterization === appSettings.scanline_rasterization ? " |         (appSettings.rasterization === appConstants.scanline_rasterization ? " | ||||||
|             #define INTENSITY 0.30 |             #define INTENSITY 0.30 | ||||||
|             #define BRIGHTBOOST 0.30 |             #define BRIGHTBOOST 0.30 | ||||||
|  |  | ||||||
| @@ -22,7 +22,7 @@ QtObject { | |||||||
|                 return mix(texel, rasterizationColor, intensity); |                 return mix(texel, rasterizationColor, intensity); | ||||||
|             }" : "") + |             }" : "") + | ||||||
|  |  | ||||||
|         (appSettings.rasterization === appSettings.pixel_rasterization ? " |         (appSettings.rasterization === appConstants.pixel_rasterization ? " | ||||||
|             #define INTENSITY 0.30 |             #define INTENSITY 0.30 | ||||||
|             #define BRIGHTBOOST 0.30 |             #define BRIGHTBOOST 0.30 | ||||||
|  |  | ||||||
| @@ -40,7 +40,7 @@ QtObject { | |||||||
|                 return mix(texel, rasterizationColor, intensity); |                 return mix(texel, rasterizationColor, intensity); | ||||||
|             }" : "") + |             }" : "") + | ||||||
|  |  | ||||||
|         (appSettings.rasterization === appSettings.subpixel_rasterization ? " |         (appSettings.rasterization === appConstants.subpixel_rasterization ? " | ||||||
|             #define INTENSITY 0.30 |             #define INTENSITY 0.30 | ||||||
|             #define BRIGHTBOOST 0.30 |             #define BRIGHTBOOST 0.30 | ||||||
|             #define SUBPIXELS 3.0 |             #define SUBPIXELS 3.0 | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ Item { | |||||||
|     property color fontColor: appSettings.fontColor |     property color fontColor: appSettings.fontColor | ||||||
|     property color backgroundColor: appSettings.backgroundColor |     property color backgroundColor: appSettings.backgroundColor | ||||||
|  |  | ||||||
|     property real screenCurvature: appSettings.screenCurvature * appSettings.screenCurvatureSize |     property real screenCurvature: appSettings.screenCurvature * appConstants.screenCurvatureSize | ||||||
|  |  | ||||||
|     property real chromaColor: appSettings.chromaColor |     property real chromaColor: appSettings.chromaColor | ||||||
|  |  | ||||||
|   | |||||||
| @@ -38,8 +38,8 @@ Loader { | |||||||
|             property real fps: appSettings.fps !== 0 ? appSettings.fps : 60 |             property real fps: appSettings.fps !== 0 ? appSettings.fps : 60 | ||||||
|             property real burnInFadeTime: Utils.lint(minBurnInFadeTime, maxBurnInFadeTime, burnIn) |             property real burnInFadeTime: Utils.lint(minBurnInFadeTime, maxBurnInFadeTime, burnIn) | ||||||
|             property real burnInCoefficient: 1000 / (fps * burnInFadeTime) |             property real burnInCoefficient: 1000 / (fps * burnInFadeTime) | ||||||
|             property real minBurnInFadeTime: appSettings.minBurnInFadeTime |             property real minBurnInFadeTime: appConstants.minBurnInFadeTime | ||||||
|             property real maxBurnInFadeTime: appSettings.maxBurnInFadeTime |             property real maxBurnInFadeTime: appConstants.maxBurnInFadeTime | ||||||
|  |  | ||||||
|             id: burnInSourceEffect |             id: burnInSourceEffect | ||||||
|  |  | ||||||
|   | |||||||
| @@ -29,7 +29,7 @@ ShaderEffect { | |||||||
|     property real _ambientLight: Utils.lint(0.2, 0.8, appSettings.ambientLight) |     property real _ambientLight: Utils.lint(0.2, 0.8, appSettings.ambientLight) | ||||||
|  |  | ||||||
|     property color frameColor: Utils.mix(_staticFrameColor, _lightColor, _ambientLight) |     property color frameColor: Utils.mix(_staticFrameColor, _lightColor, _ambientLight) | ||||||
|     property real screenCurvature: appSettings.screenCurvature * appSettings.screenCurvatureSize |     property real screenCurvature: appSettings.screenCurvature * appConstants.screenCurvatureSize | ||||||
|  |  | ||||||
|     // Coefficient of the log curve used to approximate shadowing |     // Coefficient of the log curve used to approximate shadowing | ||||||
|     property real screenShadowCoeff: Utils.lint(20.0, 10.0, _ambientLight) |     property real screenShadowCoeff: Utils.lint(20.0, 10.0, _ambientLight) | ||||||
|   | |||||||
| @@ -127,6 +127,9 @@ ApplicationWindow { | |||||||
|             aboutDialog.raise() |             aboutDialog.raise() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |     ApplicationConstants { | ||||||
|  |         id: appConstants | ||||||
|  |     } | ||||||
|     ApplicationSettings { |     ApplicationSettings { | ||||||
|         id: appSettings |         id: appSettings | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -46,5 +46,6 @@ | |||||||
|         <file>menus/FullContextMenu.qml</file> |         <file>menus/FullContextMenu.qml</file> | ||||||
|         <file>menus/ShortContextMenu.qml</file> |         <file>menus/ShortContextMenu.qml</file> | ||||||
|         <file>ShaderLibrary.qml</file> |         <file>ShaderLibrary.qml</file> | ||||||
|  |         <file>ApplicationConstants.qml</file> | ||||||
|     </qresource> |     </qresource> | ||||||
| </RCC> | </RCC> | ||||||
|   | |||||||
 Submodule qmltermwidget updated: 5c47d1f494...65e75bc6ea
									
								
							
		Reference in New Issue
	
	Block a user