1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2024-10-06 19:10:51 +01:00
cool-retro-term/qml/cool-old-term/main.qml

239 lines
8.9 KiB
QML
Raw Normal View History

/****************************************************************************
* This file is part of Terminal.
*
* Copyright (C) 2013 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
*
* Author(s):
* Pier Luigi Fiorini
*
* $BEGIN_LICENSE:GPL2+$
*
* This program 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 2 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/>.
*
* $END_LICENSE$
***************************************************************************/
import QtQuick 2.1
2013-11-25 15:46:10 +00:00
import QtQuick.Window 2.0
import QtQuick.Controls 1.0
import QtGraphicalEffects 1.0
ApplicationWindow{
id: mainwindow
2013-11-23 15:09:46 +00:00
width: 1024
height: 768
title: qsTr("Terminal")
2013-11-23 16:34:11 +00:00
2013-11-25 15:46:10 +00:00
menuBar: MenuBar {
id: menubar
2013-11-25 15:46:10 +00:00
Menu {
2013-11-25 18:05:31 +00:00
title: qsTr("File")
MenuItem { text: "Close"; onTriggered: mainwindow.close()}
2013-11-25 15:46:10 +00:00
}
2013-11-25 18:05:31 +00:00
Menu {
title: qsTr("Edit")
MenuItem {
text: qsTr("Settings")
onTriggered: {
var component = Qt.createComponent("SettingsWindow.qml");
component.createObject(mainwindow);
}
}
}
2013-11-25 15:46:10 +00:00
}
visible: true
Item{
id: maincontainer
anchors.fill: parent
anchors.top: menuBar.bottom
clip: true
ShaderSettings{
id: shadersettings
}
2013-11-23 15:09:46 +00:00
ShaderEffectSource{
id: theSource
sourceItem: terminal
2013-12-25 17:02:02 +00:00
sourceRect: frame.sourceRect
2013-11-26 18:10:15 +00:00
}
ShaderEffect {
id: shadercontainer
anchors.fill: terminal
blending: true
z: 2
property color font_color: shadersettings.font_color
property color background_color: shadersettings.background_color
property variant source: theSource
property size txt_Size: Qt.size(terminal.width, terminal.height)
property real time: 0
property real noise_strength: shadersettings.noise_strength
property real screen_distorsion: shadersettings.screen_distortion
property real glowing_line_strength: shadersettings.glowing_line_strength
property real brightness: 1.0
property real scanlines: shadersettings.scanlines ? 1.0 : 0.0
2013-12-25 20:04:10 +00:00
Behavior on brightness {
NumberAnimation{
duration: 250
onRunningChanged:
if(!running) shadercontainer.brightness = 1.0;
}
2013-12-25 20:04:10 +00:00
}
Loader{
active: shadersettings.brightness_flickering != 0
sourceComponent: Timer{
property real randval
id: flickertimer
interval: 500
onTriggered: {
console.log("Timer triggered")
randval = Math.random();
if(randval < shadersettings.brightness_flickering)
shadercontainer.brightness = Math.random() * 0.5 + 0.5;
}
repeat: true
running: true
2013-12-25 20:04:10 +00:00
}
}
2013-11-23 15:09:46 +00:00
property real deltay: 3 / terminal.height
property real deltax: 3 / terminal.width
//property real faulty_screen_prob: shadersettings.faulty_screen_prob
2013-11-23 16:34:11 +00:00
NumberAnimation on time{
from: -1
to: 100
duration: 5000
2013-11-23 15:09:46 +00:00
loops: Animation.Infinite
}
fragmentShader: "
2013-11-23 15:09:46 +00:00
uniform sampler2D source;
uniform highp float qt_Opacity;
uniform highp float time;
uniform highp vec2 txt_Size;
varying highp vec2 qt_TexCoord0;
uniform highp vec4 font_color;
uniform highp vec4 background_color;
2013-11-25 18:05:31 +00:00
2013-11-23 15:09:46 +00:00
uniform highp float noise_strength;
uniform highp float screen_distorsion;
uniform highp float glowing_line_strength;
2013-11-26 18:10:15 +00:00
uniform highp float brightness;
2013-11-25 18:05:31 +00:00
uniform highp float deltax;
uniform highp float deltay;
2013-11-23 15:09:46 +00:00
uniform highp float scanlines;
2013-11-23 15:09:46 +00:00
float rand(vec2 co, float time){
return fract(sin(dot(co.xy ,vec2(0.37898 * time ,0.78233))) * 437.5875453);
2013-11-23 15:09:46 +00:00
}
float stepNoise(vec2 p){
vec2 newP = p * txt_Size*0.25;
return rand(floor(newP), time);
}
float getScanlineIntensity(vec2 pos){
return abs(sin(pos.y * txt_Size.y)) * 0.5;
2013-11-23 15:09:46 +00:00
}
vec2 distortCoordinates(vec2 coords){
vec2 cc = coords - vec2(0.5);
float dist = dot(cc, cc) * screen_distorsion ;
2013-11-23 15:09:46 +00:00
return (coords + cc * (1.0 + dist) * dist);
}
float randomPass(vec2 coords){
return fract(smoothstep(-0.2, 0.0, coords.y - time * 0.03)) * glowing_line_strength;
}
vec4 blurredColor(sampler2D source, vec2 coords){
vec4 sum = vec4(0.0);
sum += texture2D(source, coords - vec2(-deltax, -deltay)) * 0.11;
sum += texture2D(source, coords - vec2(-deltax, 0.0)) * 0.11;
sum += texture2D(source, coords - vec2(-deltax, +deltay)) * 0.11;
sum += texture2D(source, coords - vec2(0.0, -deltay)) * 0.11;
sum += texture2D(source, coords - vec2(0.0, 0.0)) * 0.11;
sum += texture2D(source, coords - vec2(0.0, +deltay)) * 0.11;
sum += texture2D(source, coords - vec2(+deltax, -deltay)) * 0.11;
sum += texture2D(source, coords - vec2(+deltax, 0.0)) * 0.11;
sum += texture2D(source, coords - vec2(+deltax, +deltay)) * 0.11;
return sum;
}
2013-11-23 15:09:46 +00:00
void main() {
vec2 coords = distortCoordinates(qt_TexCoord0);
//Emulate faulty screen
//coords.x = coords.x + sin(coords.y * 5.0) * 0.05 * step(faulty_screen_prob, rand(txt_Size, floor(time)));
//vec4 color = texture2D(source, coords);
float color = (blurredColor(source, coords).r + texture2D(source, coords).r) * 0.5;
float scanline_alpha = getScanlineIntensity(coords) * scanlines;
2013-12-25 17:44:46 +00:00
//float inside = step(0.0, coords.x) * step(-1.0, -coords.x) * step(0.0, coords.y) * step(-1.0, -coords.y);
2013-11-23 15:09:46 +00:00
float noise = stepNoise(coords) * noise_strength;
float randomPass = randomPass(coords) * glowing_line_strength;
color += noise + randomPass;
vec3 finalColor = mix(background_color, font_color, color).rgb;
finalColor = mix(finalColor, vec3(0.0), scanline_alpha);
gl_FragColor = vec4(finalColor * brightness, 1.0);
2013-11-23 15:09:46 +00:00
}"
}
2013-11-23 15:09:46 +00:00
2013-12-25 17:44:46 +00:00
Loader{
property rect sourceRect: item.sourceRect
2013-12-25 17:44:46 +00:00
id: frame
anchors.fill: parent
2013-12-25 17:44:46 +00:00
z: 2.1
source: "./frames/WhiteSimpleFrame.qml"
}
TerminalScreen {
id: terminal
anchors.centerIn: parent
width: mainwindow.width
height: mainwindow.height
visible: false
//FIXME: Ugly forced clear terminal at the beginning
Component.onCompleted: terminal.screen.sendKey("l", 76, 67108864);
}
RadialGradient{
z: 4
anchors.fill: parent
cached: true
opacity: 0.1
gradient: Gradient{
GradientStop{position: 0.0; color: shadersettings.font_color}
GradientStop{position: 1.0; color: "#00000000"}
}
2013-11-25 15:46:10 +00:00
}
}
}