From 6a8ce430755db6ce5a75d9fc404663274592034f Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Wed, 25 Dec 2013 03:57:57 +0100 Subject: [PATCH] refactored frames so that it will be easier to add others --- cool-old-term.pro | 5 +- qml/cool-old-term/NoFrameShader.qml | 23 +++++++ qml/cool-old-term/TerminalFrame.qml | 58 +++++++++++++++++ qml/cool-old-term/WhiteFrameShader.qml | 40 ++++++++++++ qml/cool-old-term/main.qml | 90 ++++---------------------- 5 files changed, 137 insertions(+), 79 deletions(-) create mode 100644 qml/cool-old-term/NoFrameShader.qml create mode 100644 qml/cool-old-term/TerminalFrame.qml create mode 100644 qml/cool-old-term/WhiteFrameShader.qml diff --git a/cool-old-term.pro b/cool-old-term.pro index a551f57..536ebad 100644 --- a/cool-old-term.pro +++ b/cool-old-term.pro @@ -23,4 +23,7 @@ OTHER_FILES += \ $$PWD/qml/images/frame.png \ qml/cool-old-term/SettingsWindow.qml \ qml/cool-old-term/SettingComponent.qml \ - qml/cool-old-term/ColorButton.qml + qml/cool-old-term/ColorButton.qml \ + qml/cool-old-term/TerminalFrame.qml \ + qml/cool-old-term/WhiteFrameShader.qml \ + qml/cool-old-term/NoFrameShader.qml diff --git a/qml/cool-old-term/NoFrameShader.qml b/qml/cool-old-term/NoFrameShader.qml new file mode 100644 index 0000000..a59a874 --- /dev/null +++ b/qml/cool-old-term/NoFrameShader.qml @@ -0,0 +1,23 @@ +import QtQuick 2.1 + +ShaderEffect{ + property variant source: framesource + property real screen_distorsion: shadersettings.screen_distortion + + fragmentShader: " + uniform sampler2D source; + uniform highp float screen_distorsion; + varying highp vec2 qt_TexCoord0; + + vec2 distortCoordinates(vec2 coords){ + vec2 cc = coords - vec2(0.5); + float dist = dot(cc, cc) * screen_distorsion; + return (coords + cc * (1.0 + dist) * dist); + } + + void main(){ + vec2 coords = distortCoordinates(qt_TexCoord0); + float inside = texture2D(source, coords).a; + gl_FragColor = vec4(vec3(0.0), inside); + }" +} diff --git a/qml/cool-old-term/TerminalFrame.qml b/qml/cool-old-term/TerminalFrame.qml new file mode 100644 index 0000000..326e179 --- /dev/null +++ b/qml/cool-old-term/TerminalFrame.qml @@ -0,0 +1,58 @@ +import QtQuick 2.1 + +Item{ + id: framecontainer + property int addedWidth + property int addedHeight + property int borderLeft + property int borderRight + property int borderTop + property int borderBottom + property string imageSource + property string normalsSource + property Component shader + property string shaderString + + BorderImage{ + id: frameimage + anchors.centerIn: parent + width: parent.width + addedWidth + height: parent.height + addedHeight + + border.bottom: borderBottom + border.top: borderTop + border.left: borderLeft + border.right: borderRight + + source: imageSource + horizontalTileMode: BorderImage.Stretch + verticalTileMode: BorderImage.Stretch + } + BorderImage{ + id: framenormals + anchors.fill: frameimage + + border.bottom: borderBottom + border.top: borderTop + border.left: borderLeft + border.right: borderRight + + source: normalsSource + horizontalTileMode: BorderImage.Stretch + verticalTileMode: BorderImage.Stretch + } + ShaderEffectSource{ + id: framesource + sourceItem: frameimage + hideSource: true + } + ShaderEffectSource{ + id: framesourcenormals + sourceItem: framenormals + hideSource: true + } + Loader{ + anchors.fill: frameimage + source: shaderString + } +} diff --git a/qml/cool-old-term/WhiteFrameShader.qml b/qml/cool-old-term/WhiteFrameShader.qml new file mode 100644 index 0000000..9c8bddf --- /dev/null +++ b/qml/cool-old-term/WhiteFrameShader.qml @@ -0,0 +1,40 @@ +import QtQuick 2.1 + +ShaderEffect{ + property variant source: framesource + property variant normals: framesourcenormals + property real screen_distorsion: shadersettings.screen_distortion + property real ambient_light: shadersettings.ambient_light + property color font_color: shadersettings.font_color + property color background_color: shadersettings.background_color + property real brightness: shadercontainer.brightness + + fragmentShader: " + uniform sampler2D source; + uniform sampler2D normals; + uniform highp float screen_distorsion; + uniform highp float ambient_light; + + uniform highp vec4 font_color; + uniform highp vec4 background_color; + uniform highp float brightness; + + varying highp vec2 qt_TexCoord0; + + vec2 distortCoordinates(vec2 coords){ + vec2 cc = coords - vec2(0.5); + float dist = dot(cc, cc) * screen_distorsion; + return (coords + cc * (1.0 + dist) * dist); + } + + void main(){ + vec2 coords = distortCoordinates(qt_TexCoord0); + vec4 txt_color = texture2D(source, coords); + vec4 normala = texture2D(normals, coords); + vec3 normal = normalize(normala.rgb) * txt_color.a; + float reflection = dot(normal, vec3(1.0, 1.0, 0.0)) * 0.3 * brightness; + vec3 reflection_color = mix(font_color, background_color, 0.7).rgb * reflection; + vec3 final_color = mix(txt_color.rgb, reflection_color, 1.0 - ambient_light); + gl_FragColor = vec4(final_color, txt_color.a); + }" +} diff --git a/qml/cool-old-term/main.qml b/qml/cool-old-term/main.qml index 8e0ebb4..3735936 100644 --- a/qml/cool-old-term/main.qml +++ b/qml/cool-old-term/main.qml @@ -190,86 +190,20 @@ ApplicationWindow{ }" } - ShaderEffect{ - z: 2.1 - anchors.centerIn: parent - anchors.fill: frame - clip: true - blending: true - - property variant source: framesource - property variant normals: framesourcenormals - property real screen_distorsion: shadersettings.screen_distortion - property real ambient_light: shadersettings.ambient_light - property color font_color: shadersettings.font_color - property color background_color: shadersettings.background_color - property real brightness: shadercontainer.brightness - - fragmentShader: " - uniform sampler2D source; - uniform sampler2D normals; - uniform highp float screen_distorsion; - uniform highp float ambient_light; - - uniform highp vec4 font_color; - uniform highp vec4 background_color; - uniform highp float brightness; - - varying highp vec2 qt_TexCoord0; - - vec2 distortCoordinates(vec2 coords){ - vec2 cc = coords - vec2(0.5); - float dist = dot(cc, cc) * screen_distorsion; - return (coords + cc * (1.0 + dist) * dist); - } - - void main(){ - vec2 coords = distortCoordinates(qt_TexCoord0); - vec4 txt_color = texture2D(source, coords); - vec4 normala = texture2D(normals, coords); - vec3 normal = normalize(normala.rgb) * txt_color.a; - float reflection = dot(normal, vec3(1.0, 1.0, 0.0)) * 0.3 * brightness; - vec3 reflection_color = mix(font_color, background_color, 0.7).rgb * reflection; - vec3 final_color = mix(txt_color.rgb, reflection_color, 1.0 - ambient_light); - gl_FragColor = vec4(final_color, txt_color.a); - }" - } - - ShaderEffectSource{ - id: framesource - sourceItem: frame - hideSource: true - } - - ShaderEffectSource{ - id: framesourcenormals - sourceItem: framenormals - hideSource: true - } - - BorderImage{ + TerminalFrame{ id: frame - width: parent.width + 140 - height: parent.height + 140 - anchors.centerIn: parent - source: "../images/screen-frame.png" - border {left: 116; right: 116; top: 116; bottom: 116} - horizontalTileMode: BorderImage.Stretch - verticalTileMode: BorderImage.Stretch - visible: false - } + z: 2.1 + anchors.fill: parent + addedWidth: 140 + addedHeight: 140 + borderLeft: 116 + borderRight: 116 + borderTop: 116 + borderBottom: 116 + imageSource: "../images/screen-frame.png" + normalsSource: "../images/screen-frame-normals.png" - BorderImage{ - id: framenormals - anchors.fill: frame - source: "../images/screen-frame-normals.png" - border.bottom: frame.border.bottom - border.top: frame.border.top - border.left: frame.border.left - border.right: frame.border.right - horizontalTileMode: BorderImage.Stretch - verticalTileMode: BorderImage.Stretch - visible: false + shaderString: "WhiteFrameShader.qml" } TerminalScreen {