From 2bc88768b6951ce4fd4b3b1a634919b02f03ded6 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Tue, 20 Jan 2015 00:57:23 +0100 Subject: [PATCH] Reduce minimum scaling value and fix aliasing issues with small fonts and rasterization. --- app/qml/ApplicationSettings.qml | 11 ++++++++--- app/qml/SettingsTerminalTab.qml | 4 ++-- app/qml/ShaderTerminal.qml | 15 +++++++++++++-- app/qml/utils.js | 8 +++++++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/qml/ApplicationSettings.qml b/app/qml/ApplicationSettings.qml index c3d4583..1b4fd8b 100644 --- a/app/qml/ApplicationSettings.qml +++ b/app/qml/ApplicationSettings.qml @@ -26,7 +26,12 @@ import "utils.js" as Utils QtObject{ property string version: "1.0.0 RC1" - // GENERAL SETTINGS /////////////////////////////////////////////////// + // STATIC CONSTANTS //////////////////////////////////////////////////////// + + readonly property real minimumFontScaling: 0.25 + readonly property real maximumFontScaling: 2.50 + + // GENERAL SETTINGS /////////////////////////////////////////////////////// property bool fullscreen: false property bool showMenubar: true @@ -114,12 +119,12 @@ QtObject{ } function incrementScaling(){ - fontScaling = Math.min(fontScaling + 0.05, 2.50); + fontScaling = Math.min(fontScaling + 0.05, maximumFontScaling); handleFontChanged(); } function decrementScaling(){ - fontScaling = Math.max(fontScaling - 0.05, 0.50); + fontScaling = Math.max(fontScaling - 0.05, minimumFontScaling); handleFontChanged(); } diff --git a/app/qml/SettingsTerminalTab.qml b/app/qml/SettingsTerminalTab.qml index ae0e719..32f458f 100644 --- a/app/qml/SettingsTerminalTab.qml +++ b/app/qml/SettingsTerminalTab.qml @@ -66,8 +66,8 @@ Tab{ stepSize: 0.05 enabled: false // Another trick to fix initial bad behavior. Component.onCompleted: { - minimumValue = 0.5; - maximumValue = 2.5; + minimumValue = appSettings.minimumFontScaling; + maximumValue = appSettings.maximumFontScaling; value = appSettings.fontScaling; enabled = true; } diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index aa024b0..f3478e2 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -21,6 +21,8 @@ import QtQuick 2.2 import QtGraphicalEffects 1.0 +import "utils.js" as Utils + ShaderEffect { property ShaderEffectSource source property ShaderEffectSource blurredSource @@ -56,6 +58,12 @@ ShaderEffect { property real screen_brightness: appSettings.brightness * 1.5 + 0.5 + // This is the average value of the abs(sin) function. Needed to avoid aliasing. + readonly property real absSinAvg: 0.63661828335466886 + property size rasterizationSmooth: Qt.size( + Utils.clamp(2.0 * virtual_resolution.width / width, 0.0, 1.0), + Utils.clamp(2.0 * virtual_resolution.height / height, 0.0, 1.0)) + property real dispX property real dispY property size virtual_resolution @@ -153,6 +161,7 @@ ShaderEffect { uniform lowp float screen_brightness; uniform highp vec2 virtual_resolution; + uniform highp vec2 rasterizationSmooth; uniform highp float dispX; uniform highp float dispY;" + @@ -198,9 +207,11 @@ ShaderEffect { highp float result = 1.0;" + (appSettings.rasterization != appSettings.no_rasterization ? - "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + + "float val = abs(sin(coords.y * virtual_resolution.y * "+Math.PI+")); + result *= mix(val, " + absSinAvg + ", rasterizationSmooth.y);" : "") + (appSettings.rasterization == appSettings.pixel_rasterization ? - "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " + "val = abs(sin(coords.x * virtual_resolution.x * "+Math.PI+")); + result *= mix(val, " + absSinAvg + ", rasterizationSmooth.x);" : "") + " return result; } diff --git a/app/qml/utils.js b/app/qml/utils.js index b7daf2d..ba8ae04 100644 --- a/app/qml/utils.js +++ b/app/qml/utils.js @@ -1,5 +1,11 @@ .pragma library - +function clamp(x, min, max) { + if (x <= min) + return min; + if (x >= max) + return max; + return x; +} function lint(a, b, t) { return (1 - t) * a + (t) * b; }