mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 15:12:28 +00:00 
			
		
		
		
	Merge pull request #118 from Swordfish90/simplifyimprove
Many simplifications and optimizations of the underlying structure. cool-retro-term is now faster, it has better rasterizations and pixel perfect mouse events.
This commit is contained in:
		| @@ -99,7 +99,7 @@ Item{ | ||||
|  | ||||
|     // FONTS ////////////////////////////////////////////////////////////////// | ||||
|  | ||||
|     signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, size virtualCharSize) | ||||
|     signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, real screenScaling) | ||||
|  | ||||
|     Loader{ | ||||
|         id: fontManager | ||||
| @@ -117,17 +117,17 @@ Item{ | ||||
|     } | ||||
|  | ||||
|     signal fontScalingChanged | ||||
|     property var fontScalingList: fontManager.item.fontScalingList | ||||
|     property var fontScalingIndexes: [5,1,1] | ||||
|     property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] | ||||
|     property int fontScalingIndex: 5 | ||||
|  | ||||
|     function setScalingIndex(newScaling){ | ||||
|         fontScalingIndexes[rasterization] = newScaling; | ||||
|         fontScalingIndex = newScaling; | ||||
|         fontScalingChanged(); | ||||
|         handleFontChanged(); | ||||
|     } | ||||
|  | ||||
|     function getScalingIndex(){ | ||||
|         return fontScalingIndexes[rasterization]; | ||||
|         return fontScalingIndex; | ||||
|     } | ||||
|  | ||||
|     property var fontIndexes: [0,0,0] | ||||
| @@ -136,14 +136,14 @@ Item{ | ||||
|     function handleFontChanged(){ | ||||
|         if(!fontManager.item) return; | ||||
|         fontManager.item.selectedFontIndex = fontIndexes[rasterization]; | ||||
|         fontManager.item.selectedScalingIndex = fontScalingIndexes[rasterization]; | ||||
|         fontManager.item.scaling = fontScalingList[fontScalingIndex]; | ||||
|  | ||||
|         var fontSource = fontManager.item.source; | ||||
|         var pixelSize = fontManager.item.pixelSize; | ||||
|         var lineSpacing = fontManager.item.lineSpacing; | ||||
|         var virtualCharSize = fontManager.item.virtualCharSize; | ||||
|         var screenScaling = fontManager.item.screenScaling; | ||||
|  | ||||
|         terminalFontChanged(fontSource, pixelSize, lineSpacing, virtualCharSize); | ||||
|         terminalFontChanged(fontSource, pixelSize, lineSpacing, screenScaling); | ||||
|     } | ||||
|  | ||||
|     // FRAMES ///////////////////////////////////////////////////////////////// | ||||
| @@ -164,7 +164,7 @@ Item{ | ||||
|             fps: fps, | ||||
|             window_scaling: window_scaling, | ||||
|             show_terminal_size: show_terminal_size, | ||||
|             fontScalingIndexes: fontScalingIndexes, | ||||
|             fontScalingIndex: fontScalingIndex, | ||||
|             fontIndexes: fontIndexes, | ||||
|             frameReflections: _frameReflections, | ||||
|             showMenubar: showMenubar | ||||
| @@ -231,7 +231,7 @@ Item{ | ||||
|         window_scaling = settings.window_scaling !== undefined ? settings.window_scaling : window_scaling | ||||
|  | ||||
|         fontIndexes = settings.fontIndexes !== undefined ? settings.fontIndexes : fontIndexes | ||||
|         fontScalingIndexes = settings.fontScalingIndexes !== undefined ? settings.fontScalingIndexes : fontScalingIndexes | ||||
|         fontScalingIndex = settings.fontScalingIndex !== undefined ? settings.fontScalingIndex : fontScalingIndex | ||||
|  | ||||
|         _frameReflections = settings.frameReflections !== undefined ? settings.frameReflections : _frameReflections; | ||||
|  | ||||
|   | ||||
| @@ -22,50 +22,50 @@ import QtQuick 2.2 | ||||
|  | ||||
| Item{ | ||||
|     property int selectedFontIndex | ||||
|     property int selectedScalingIndex | ||||
|     property real scaling | ||||
|     property alias fontlist: fontlist | ||||
|     property var _font: fontlist.get(selectedFontIndex) | ||||
|     property var _scaling: fontScalingList[selectedScalingIndex] | ||||
|     property var source: _font.source | ||||
|     property var fontScalingList: [0.75, 1.0, 1.25, 1.50, 1.75, 2.0, 2.25, 2.5] | ||||
|     property int pixelSize: _font.pixelSize * _scaling | ||||
|     property int lineSpacing: (_font.pixelSize / _font.virtualCharHeight) * _font.lineSpacing | ||||
|     property size virtualCharSize: Qt.size(_font.virtualCharWidth, | ||||
|                                            _font.virtualCharHeight) | ||||
|     property int pixelSize: _font.pixelSize | ||||
|     property int lineSpacing: _font.lineSpacing | ||||
|     property real screenScaling: scaling * _font.baseScaling | ||||
|  | ||||
|     ListModel{ | ||||
|         id: fontlist | ||||
|         ListElement{ | ||||
|             text: "Commodore PET 2Y (1977)" | ||||
|             source: "fonts/1977-commodore-pet/COMMODORE_PET_2y.ttf" | ||||
|             lineSpacing: 2 | ||||
|             pixelSize: 16 | ||||
|             baseScaling: 3.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Commodore PET (1977)" | ||||
|             source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" | ||||
|             lineSpacing: 2 | ||||
|             virtualCharWidth: 8 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Apple ][ (1977)" | ||||
|             source: "fonts/1977-apple2/PrintChar21.ttf" | ||||
|             lineSpacing: 2 | ||||
|             virtualCharWidth: 7 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Atari 400-800 (1979)" | ||||
|             source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" | ||||
|             lineSpacing: 3 | ||||
|             virtualCharWidth: 8 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Commodore 64 (1982)" | ||||
|             source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" | ||||
|             lineSpacing: 3 | ||||
|             virtualCharWidth: 8 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -22,16 +22,13 @@ import QtQuick 2.2 | ||||
|  | ||||
| Item{ | ||||
|     property int selectedFontIndex | ||||
|     property int selectedScalingIndex | ||||
|     property real scaling | ||||
|     property alias fontlist: fontlist | ||||
|     property var _font: fontlist.get(selectedFontIndex) | ||||
|     property var _scaling: fontScalingList[selectedScalingIndex] | ||||
|     property var source: _font.source | ||||
|     property var fontScalingList: [0.75, 1.0, 1.25, 1.50, 1.75, 2.0, 2.25, 2.50] | ||||
|     property int pixelSize: _font.pixelSize * _scaling | ||||
|     property int lineSpacing: (_font.pixelSize / _font.virtualCharHeight) * _font.lineSpacing | ||||
|     property size virtualCharSize: Qt.size(_font.virtualCharWidth, | ||||
|                                            _font.virtualCharHeight) | ||||
|     property int pixelSize: _font.pixelSize | ||||
|     property int lineSpacing: _font.lineSpacing | ||||
|     property real screenScaling: scaling * _font.baseScaling | ||||
|  | ||||
|     ListModel{ | ||||
|         id: fontlist | ||||
| @@ -39,41 +36,36 @@ Item{ | ||||
|             text: "Commodore PET 2Y (1977)" | ||||
|             source: "fonts/1977-commodore-pet/COMMODORE_PET_2y.ttf" | ||||
|             lineSpacing: 2 | ||||
|             virtualCharWidth: 4 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 16 | ||||
|             baseScaling: 3.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Commodore PET (1977)" | ||||
|             source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" | ||||
|             lineSpacing: 2 | ||||
|             virtualCharWidth: 8 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Apple ][ (1977)" | ||||
|             source: "fonts/1977-apple2/PrintChar21.ttf" | ||||
|             lineSpacing: 2 | ||||
|             virtualCharWidth: 8 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Atari 400-800 (1979)" | ||||
|             source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" | ||||
|             lineSpacing: 3 | ||||
|             virtualCharWidth: 8 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|         ListElement{ | ||||
|             text: "Commodore 64 (1982)" | ||||
|             source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" | ||||
|             lineSpacing: 3 | ||||
|             virtualCharWidth: 8 | ||||
|             virtualCharHeight: 8 | ||||
|             pixelSize: 32 | ||||
|             pixelSize: 8 | ||||
|             baseScaling: 4.0 | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -22,14 +22,13 @@ import QtQuick 2.2 | ||||
|  | ||||
| Item{ | ||||
|     property int selectedFontIndex | ||||
|     property int selectedScalingIndex | ||||
|     property real scaling | ||||
|     property alias fontlist: fontlist | ||||
|     property var source: fontlist.get(selectedFontIndex).source | ||||
|     property var _font: fontlist.get(selectedFontIndex) | ||||
|     property var _scaling: fontScalingList[selectedScalingIndex] | ||||
|     property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5] | ||||
|     property int pixelSize: _font.pixelSize * _scaling | ||||
|     property int pixelSize: _font.pixelSize * scaling | ||||
|     property int lineSpacing: pixelSize * _font.lineSpacing | ||||
|     property real screenScaling: 1.0 | ||||
|  | ||||
|     //In this configuration lineSpacing is proportional to pixelSize. | ||||
|  | ||||
|   | ||||
| @@ -26,7 +26,19 @@ import org.crt.konsole 0.1 | ||||
|  | ||||
| Item{ | ||||
|     id: terminalContainer | ||||
|     property variant theSource: finalSource | ||||
|  | ||||
|     //Frame displacement properties. This makes the terminal the same size of the texture. | ||||
|     property real dtop: frame.item.displacementTop | ||||
|     property real dleft:frame.item.displacementLeft | ||||
|     property real dright: frame.item.displacementRight | ||||
|     property real dbottom: frame.item.displacementBottom | ||||
|  | ||||
|     anchors.leftMargin: dleft | ||||
|     anchors.rightMargin: dright | ||||
|     anchors.topMargin: dtop | ||||
|     anchors.bottomMargin: dbottom | ||||
|  | ||||
|     property variant theSource: mBlur !== 0 ? blurredSourceLoader.item : kterminalSource | ||||
|     property variant bloomSource: bloomSourceLoader.item | ||||
|     property variant rasterizationSource: rasterizationEffectSource | ||||
|     property variant staticNoiseSource: staticNoiseSource | ||||
| @@ -45,11 +57,6 @@ Item{ | ||||
|     property real _minBlurCoefficient: 0.70 | ||||
|     property real _maxBlurCoefficient: 0.90 | ||||
|  | ||||
|     property size virtualPxSize: Qt.size(1,1) | ||||
|     property size virtual_resolution: Qt.size(width / virtualPxSize.width, height / virtualPxSize.height) | ||||
|     property real deltay: 0.5 / virtual_resolution.height | ||||
|     property real deltax: 0.5 / virtual_resolution.width | ||||
|  | ||||
|     property real mBloom: shadersettings.bloom_strength | ||||
|     property int mScanlines: shadersettings.rasterization | ||||
|     onMScanlinesChanged: restartBlurredSource() | ||||
| @@ -60,9 +67,8 @@ Item{ | ||||
|     onMBlurChanged: restartBlurredSource() | ||||
|  | ||||
|     function restartBlurredSource(){ | ||||
|         if(!blurredSource) return; | ||||
|         blurredSource.live = true; | ||||
|         livetimer.restart() | ||||
|         if(!blurredSourceLoader.item) return; | ||||
|         blurredSourceLoader.item.restartBlurSource(); | ||||
|     } | ||||
|     function pasteClipboard(){ | ||||
|         kterminal.pasteClipboard(); | ||||
| @@ -73,7 +79,8 @@ Item{ | ||||
|  | ||||
|     KTerminal { | ||||
|         id: kterminal | ||||
|         anchors.fill: parent | ||||
|         width: parent.width | ||||
|         height: parent.height | ||||
|  | ||||
|         colorScheme: "cool-retro-term" | ||||
|  | ||||
| @@ -89,30 +96,15 @@ Item{ | ||||
|         FontLoader{ id: fontLoader } | ||||
|         Text{id: fontMetrics; text: "B"; visible: false} | ||||
|  | ||||
|         function getPaintedSize(pixelSize){ | ||||
|             fontMetrics.font.family = fontLoader.name; | ||||
|             fontMetrics.font.pixelSize = pixelSize; | ||||
|             return Qt.size(fontMetrics.paintedWidth, fontMetrics.paintedHeight); | ||||
|         } | ||||
|         function isValid(size){ | ||||
|             return size.width >= 0 && size.height >= 0; | ||||
|         } | ||||
|         function handleFontChange(fontSource, pixelSize, lineSpacing, virtualCharSize){ | ||||
|         function handleFontChange(fontSource, pixelSize, lineSpacing, screenScaling){ | ||||
|             fontLoader.source = fontSource; | ||||
|             font.pixelSize = pixelSize * shadersettings.window_scaling; | ||||
|             font.pixelSize = pixelSize; | ||||
|             font.family = fontLoader.name; | ||||
|  | ||||
|             var paintedSize = getPaintedSize(pixelSize); | ||||
|             var charSize = isValid(virtualCharSize) | ||||
|                     ? virtualCharSize | ||||
|                     : Qt.size(paintedSize.width / 2, paintedSize.height / 2); | ||||
|             width = Qt.binding(function() {return Math.floor(terminalContainer.width / screenScaling);}); | ||||
|             height = Qt.binding(function() {return Math.floor(terminalContainer.height / screenScaling);}); | ||||
|  | ||||
|             var virtualPxSize = Qt.size((paintedSize.width  / charSize.width) * shadersettings.window_scaling, | ||||
|                                         (paintedSize.height / charSize.height) * shadersettings.window_scaling) | ||||
|  | ||||
|             terminalContainer.virtualPxSize = virtualPxSize; | ||||
|  | ||||
|             setLineSpacing(lineSpacing * shadersettings.window_scaling); | ||||
|             setLineSpacing(lineSpacing); | ||||
|             restartBlurredSource(); | ||||
|         } | ||||
|         Component.onCompleted: { | ||||
| @@ -162,83 +154,98 @@ Item{ | ||||
|             kterminal.mouseMoveEvent(coord, mouse.button, mouse.buttons, mouse.modifiers); | ||||
|         } | ||||
|  | ||||
|         //Frame displacement properties | ||||
|         property real dtop: frame.item.displacementTop | ||||
|         property real dleft:frame.item.displacementLeft | ||||
|         property real dright: frame.item.displacementRight | ||||
|         property real dbottom: frame.item.displacementBottom | ||||
|  | ||||
|         function correctDistortion(x, y){ | ||||
|             x = x / width; | ||||
|             y = y / height; | ||||
|  | ||||
|             x = (-dleft + x * (width + dleft + dright)) / width | ||||
|             y = (-dtop  + y * (height + dtop + dbottom)) / height | ||||
|  | ||||
|             var cc = Qt.size(0.5 - x, 0.5 - y); | ||||
|             var distortion = (cc.height * cc.height + cc.width * cc.width) * shadersettings.screen_distortion; | ||||
|  | ||||
|             return Qt.point((x - cc.width  * (1+distortion) * distortion) * width, | ||||
|                            (y - cc.height * (1+distortion) * distortion) * height) | ||||
|             return Qt.point((x - cc.width  * (1+distortion) * distortion) * kterminal.width, | ||||
|                            (y - cc.height * (1+distortion) * distortion) * kterminal.height) | ||||
|         } | ||||
|     } | ||||
|     ShaderEffectSource{ | ||||
|         id: source | ||||
|         id: kterminalSource | ||||
|         sourceItem: kterminal | ||||
|         hideSource: true | ||||
|         smooth: false | ||||
|     } | ||||
|     ShaderEffectSource{ | ||||
|         id: blurredSource | ||||
|         sourceItem: blurredterminal | ||||
|         recursive: true | ||||
|         smooth: mScanlines == shadersettings.no_rasterization | ||||
|         wrapMode: ShaderEffectSource.ClampToEdge | ||||
|         live: false | ||||
|  | ||||
|         hideSource: true | ||||
|         signal sourceUpdate | ||||
|  | ||||
|         smooth: false | ||||
|         antialiasing: false | ||||
|         Connections{ | ||||
|             target: kterminal | ||||
|             onUpdatedImage:{ | ||||
|                 kterminalSource.scheduleUpdate(); | ||||
|                 kterminalSource.sourceUpdate(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     Loader{ | ||||
|         id: blurredSourceLoader | ||||
|         active: mBlur !== 0 | ||||
|  | ||||
|         sourceComponent: ShaderEffectSource{ | ||||
|             id: _blurredSourceEffect | ||||
|             sourceItem: blurredTerminalLoader.item | ||||
|             recursive: true | ||||
|             live: false | ||||
|             hideSource: true | ||||
|             wrapMode: kterminalSource.wrapMode | ||||
|  | ||||
|             smooth: mScanlines == shadersettings.no_rasterization | ||||
|  | ||||
|             function restartBlurSource(){ | ||||
|                 livetimer.restart(); | ||||
|             } | ||||
|  | ||||
|             Timer{ | ||||
|                 id: livetimer | ||||
|                 running: true | ||||
|             onRunningChanged: running ? | ||||
|                                   timeManager.onTimeChanged.connect(blurredSource.scheduleUpdate) : | ||||
|                                   timeManager.onTimeChanged.disconnect(blurredSource.scheduleUpdate) | ||||
|                 onRunningChanged: { | ||||
|                     running ? | ||||
|                         timeBinding.target = timeManager : | ||||
|                         timeBinding.target = null | ||||
|                 } | ||||
|             } | ||||
|             Connections{ | ||||
|                 id: timeBinding | ||||
|                 target: timeManager | ||||
|                 onTimeChanged: { | ||||
|                     _blurredSourceEffect.scheduleUpdate(); | ||||
|                 } | ||||
|             } | ||||
|             Connections{ | ||||
|                 target: kterminalSource | ||||
|                 onSourceUpdate:{ | ||||
|                     livetimer.restart(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|             Component.onCompleted: kterminal.updatedImage.connect(restart); | ||||
|         } | ||||
|     } | ||||
|     ShaderEffectSource{ | ||||
|         id: finalSource | ||||
|         sourceItem: blurredterminal | ||||
|         sourceRect: frame.sourceRect | ||||
|         hideSource: true | ||||
|     } | ||||
|     ShaderEffect { | ||||
|         id: blurredterminal | ||||
|         anchors.fill: parent | ||||
|         property variant source: source | ||||
|         property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined | ||||
|     Loader{ | ||||
|         id: blurredTerminalLoader | ||||
|         anchors.fill: kterminal | ||||
|         active: mBlur !== 0 | ||||
|  | ||||
|         sourceComponent: ShaderEffect { | ||||
|             property variant txt_source: kterminalSource | ||||
|             property variant blurredSource: blurredSourceLoader.item | ||||
|             property real blurCoefficient: (1.0 - motionBlurCoefficient) * fpsAttenuation | ||||
|         property size virtual_resolution: parent.virtual_resolution | ||||
|         property size delta: Qt.size((mScanlines == shadersettings.pixel_rasterization ? deltax : 0), | ||||
|                                      mScanlines != shadersettings.no_rasterization ? deltay : 0) | ||||
|  | ||||
|             blending: false | ||||
|  | ||||
|             fragmentShader: | ||||
|                 "uniform lowp float qt_Opacity;" + | ||||
|             "uniform lowp sampler2D source;" + | ||||
|             "uniform highp vec2 delta;" + | ||||
|                 "uniform lowp sampler2D txt_source;" + | ||||
|  | ||||
|                 "varying highp vec2 qt_TexCoord0; | ||||
|  | ||||
|              uniform highp vec2 virtual_resolution;" + | ||||
|  | ||||
|             (mBlur !== 0 ? | ||||
|                 "uniform lowp sampler2D blurredSource; | ||||
|                  uniform lowp float blurCoefficient;" | ||||
|             : "") + | ||||
|                  uniform lowp sampler2D blurredSource; | ||||
|                  uniform highp float blurCoefficient;" + | ||||
|  | ||||
|                 "float rgb2grey(vec3 v){ | ||||
|                     return dot(v, vec3(0.21, 0.72, 0.04)); | ||||
| @@ -246,28 +253,18 @@ Item{ | ||||
|  | ||||
|                 "void main() {" + | ||||
|                     "vec2 coords = qt_TexCoord0;" + | ||||
|                 (mScanlines != shadersettings.no_rasterization ? " | ||||
|                             coords.y = floor(virtual_resolution.y * coords.y) / virtual_resolution.y;" + | ||||
|                 (mScanlines == shadersettings.pixel_rasterization ? " | ||||
|                             coords.x = floor(virtual_resolution.x * coords.x) / virtual_resolution.x;" : "") | ||||
|                 : "") + | ||||
|                 "coords = coords + delta;" + | ||||
|                     "vec3 color = texture2D(txt_source, coords).rgb * 256.0;" + | ||||
|  | ||||
|                 "vec4 color = texture2D(source, coords) * 256.0; | ||||
|                  color.a = rgb2grey(color.rgb);" + | ||||
|                     "vec3 blur_color = texture2D(blurredSource, coords).rgb * 256.0;" + | ||||
|                     "blur_color = blur_color - blur_color * blurCoefficient;" + | ||||
|                     "color = step(vec3(1.0), color) * color + step(color, vec3(1.0)) * blur_color;" + | ||||
|  | ||||
|                 (mBlur !== 0 ? | ||||
|                     "vec4 blur_color = texture2D(blurredSource, coords) * 256.0;" + | ||||
|                     "blur_color.a = blur_color.a - blur_color.a * blurCoefficient;" + | ||||
|                     "color = step(1.0, color.a) * color + step(color.a, 1.0) * blur_color;" | ||||
|                 : "") + | ||||
|  | ||||
|  | ||||
|                 "gl_FragColor = floor(color) / 256.0;" + | ||||
|                     "gl_FragColor = vec4(floor(color) / 256.0, 1.0);" + | ||||
|                 "}" | ||||
|  | ||||
|             onStatusChanged: if (log) console.log(log) //Print warning messages | ||||
|         } | ||||
|     } | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
|     //  EFFECTS  ////////////////////////////////////////////////////////////// | ||||
|     /////////////////////////////////////////////////////////////////////////// | ||||
| @@ -291,7 +288,6 @@ Item{ | ||||
|         sourceComponent: ShaderEffectSource{ | ||||
|             sourceItem: bloomEffectLoader.item | ||||
|             hideSource: true | ||||
|             sourceRect: frame.sourceRect | ||||
|             smooth: false | ||||
|         } | ||||
|     } | ||||
| @@ -301,7 +297,8 @@ Item{ | ||||
|     ShaderEffect { | ||||
|         id: staticNoiseEffect | ||||
|         anchors.fill: parent | ||||
|         property size virtual_resolution: terminalContainer.virtual_resolution | ||||
|         property real element_size: shadersettings.rasterization == shadersettings.no_rasterization ? 2 : 1 | ||||
|         property size virtual_resolution: Qt.size(kterminal.width / element_size, kterminal.height / element_size) | ||||
|  | ||||
|         blending: false | ||||
|  | ||||
| @@ -345,46 +342,15 @@ Item{ | ||||
|         wrapMode: ShaderEffectSource.Repeat | ||||
|         smooth: true | ||||
|         hideSource: true | ||||
|         //format: ShaderEffectSource.Alpha | ||||
|     } | ||||
|  | ||||
|     // RASTERIZATION ////////////////////////////////////////////////////////// | ||||
|  | ||||
|     ShaderEffect{ | ||||
|         id: rasterizationContainer | ||||
|         width: frame.sourceRect.width | ||||
|         height: frame.sourceRect.height | ||||
|         property size offset: Qt.size(width - rasterizationEffect.width, height - rasterizationEffect.height) | ||||
|         property size txtRes: Qt.size(width, height) | ||||
|  | ||||
|         blending: false | ||||
|  | ||||
|         fragmentShader: | ||||
|             "uniform lowp float qt_Opacity; | ||||
|              uniform highp vec2 offset; | ||||
|              uniform highp vec2 txtRes;" + | ||||
|  | ||||
|             "varying highp vec2 qt_TexCoord0;" + | ||||
|  | ||||
|             "void main() {" + | ||||
|                 "float color = 1.0; | ||||
|                  color *= smoothstep(0.0, offset.x / txtRes.x, qt_TexCoord0.x); | ||||
|                  color *= smoothstep(0.0, offset.y / txtRes.y, qt_TexCoord0.y); | ||||
|                  color *= smoothstep(0.0, offset.x / txtRes.x, 1.0 - qt_TexCoord0.x); | ||||
|                  color *= smoothstep(0.0, offset.y / txtRes.y, 1.0 - qt_TexCoord0.y);" + | ||||
|  | ||||
|                 "float distance = length(vec2(0.5) - qt_TexCoord0);" + | ||||
|                 "color = mix(color, 0.0, 1.2 * distance * distance);" + | ||||
|  | ||||
|                 "gl_FragColor.a = color;" + | ||||
|             "}" | ||||
|  | ||||
|     ShaderEffect { | ||||
|         id: rasterizationEffect | ||||
|             width: terminalContainer.width | ||||
|             height: terminalContainer.height | ||||
|             anchors.centerIn: parent | ||||
|             property size virtual_resolution: terminalContainer.virtual_resolution | ||||
|         width: parent.width | ||||
|         height: parent.height | ||||
|         property size virtual_resolution: Qt.size(kterminal.width, kterminal.height) | ||||
|  | ||||
|         blending: false | ||||
|  | ||||
| @@ -394,17 +360,19 @@ Item{ | ||||
|             "varying highp vec2 qt_TexCoord0; | ||||
|              uniform highp vec2 virtual_resolution; | ||||
|  | ||||
|                      float getScanlineIntensity(vec2 coords) { | ||||
|                         float result = 1.0;" + | ||||
|              highp float getScanlineIntensity(vec2 coords) { | ||||
|                  highp float result = 1.0;" + | ||||
|  | ||||
|                 (mScanlines != shadersettings.no_rasterization ? | ||||
|                     "result *= abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" : "") + | ||||
|                 (mScanlines == shadersettings.pixel_rasterization ? | ||||
|                     "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " | ||||
|  | ||||
|                 return result; | ||||
|              }" + | ||||
|  | ||||
|             "void main() {" + | ||||
|                 "float color = getScanlineIntensity(qt_TexCoord0);" + | ||||
|                 "highp float color = getScanlineIntensity(qt_TexCoord0);" + | ||||
|  | ||||
|                 "float distance = length(vec2(0.5) - qt_TexCoord0);" + | ||||
|                 "color = mix(color, 0.0, 1.2 * distance * distance);" + | ||||
| @@ -414,13 +382,11 @@ Item{ | ||||
|  | ||||
|         onStatusChanged: if (log) console.log(log) //Print warning messages | ||||
|     } | ||||
|         onStatusChanged: if (log) console.log(log) //Print warning messages | ||||
|     } | ||||
|     ShaderEffectSource{ | ||||
|         id: rasterizationEffectSource | ||||
|         sourceItem: rasterizationContainer | ||||
|         sourceItem: rasterizationEffect | ||||
|         hideSource: true | ||||
|         smooth: true | ||||
|         //format: ShaderEffectSource.Alpha | ||||
|         wrapMode: ShaderEffectSource.Repeat | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -21,6 +21,7 @@ | ||||
| import QtQuick 2.2 | ||||
| import QtGraphicalEffects 1.0 | ||||
|  | ||||
|  | ||||
| ShaderEffect { | ||||
|     property color font_color: shadersettings.font_color | ||||
|     property color background_color: shadersettings.background_color | ||||
| @@ -28,11 +29,8 @@ ShaderEffect { | ||||
|     property variant bloomSource: terminal.bloomSource | ||||
|     property variant rasterizationSource: terminal.rasterizationSource | ||||
|     property variant noiseSource: terminal.staticNoiseSource | ||||
|     property size txt_Size: Qt.size(frame.sourceRect.width, frame.sourceRect.height) | ||||
|     property real bloom_strength: shadersettings.bloom_strength * 2.5 | ||||
|  | ||||
|     property int rasterization: shadersettings.rasterization | ||||
|  | ||||
|     property real jitter: shadersettings.jitter * 0.007 | ||||
|  | ||||
|     property real noise_strength: shadersettings.noise_strength | ||||
| @@ -40,7 +38,6 @@ ShaderEffect { | ||||
|     property real glowing_line_strength: shadersettings.glowing_line_strength | ||||
|  | ||||
|     property real chroma_color: shadersettings.chroma_color; | ||||
|     property real saturation_color: shadersettings.saturation_color; | ||||
|  | ||||
|     property real rgb_shift: shadersettings.rgb_shift * 0.2 | ||||
|  | ||||
| @@ -49,10 +46,10 @@ ShaderEffect { | ||||
|  | ||||
|     property bool frameReflections: shadersettings.frameReflections | ||||
|  | ||||
|     property real disp_top: frame.item.displacementTop * shadersettings.window_scaling | ||||
|     property real disp_bottom: frame.item.displacementBottom * shadersettings.window_scaling | ||||
|     property real disp_left: frame.item.displacementLeft * shadersettings.window_scaling | ||||
|     property real disp_right: frame.item.displacementRight * shadersettings.window_scaling | ||||
|     property real disp_top: frame.item.displacementTop / height | ||||
|     property real disp_bottom: frame.item.displacementBottom / height | ||||
|     property real disp_left: frame.item.displacementLeft / width | ||||
|     property real disp_right: frame.item.displacementRight / width | ||||
|  | ||||
|     property real screen_brightness: shadersettings.brightness * 1.5 + 0.5 | ||||
|  | ||||
| @@ -88,7 +85,11 @@ ShaderEffect { | ||||
|         uniform highp mat4 qt_Matrix; | ||||
|         uniform highp float time; | ||||
|         uniform sampler2D randomFunctionSource; | ||||
|         uniform highp vec2 txt_Size; | ||||
|  | ||||
|         uniform highp float disp_left; | ||||
|         uniform highp float disp_right; | ||||
|         uniform highp float disp_top; | ||||
|         uniform highp float disp_bottom; | ||||
|  | ||||
|         attribute highp vec4 qt_Vertex; | ||||
|         attribute highp vec2 qt_MultiTexCoord0; | ||||
| @@ -103,8 +104,8 @@ ShaderEffect { | ||||
|             uniform lowp float horizontal_sincronization;" : "") + | ||||
|         " | ||||
|         void main() { | ||||
|             qt_TexCoord0.x = -"+str(disp_left)+"/txt_Size.x + qt_MultiTexCoord0.x / ((txt_Size.x -("+str(disp_left+disp_right)+")) / txt_Size.x);" + " | ||||
|             qt_TexCoord0.y = -"+str(disp_top)+"/txt_Size.y + qt_MultiTexCoord0.y / ((txt_Size.y -("+str(disp_top+disp_bottom)+")) / txt_Size.y);" + " | ||||
|             qt_TexCoord0.x = (qt_MultiTexCoord0.x - disp_left) / (1.0 - disp_left - disp_right); | ||||
|             qt_TexCoord0.y = (qt_MultiTexCoord0.y - disp_top) / (1.0 - disp_top - disp_bottom); | ||||
|             vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + | ||||
|             (brightness_flickering !== 0.0 ? " | ||||
|                 brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;" | ||||
| @@ -123,7 +124,6 @@ ShaderEffect { | ||||
|         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; | ||||
| @@ -136,7 +136,7 @@ ShaderEffect { | ||||
|             uniform lowp float bloom_strength;" : "") + | ||||
|         (noise_strength !== 0 ? " | ||||
|             uniform highp float noise_strength;" : "") + | ||||
|         (noise_strength !== 0 || jitter !== 0 ? " | ||||
|         (noise_strength !== 0 || jitter !== 0 || rgb_shift ? " | ||||
|             uniform lowp sampler2D noiseSource;" : "") + | ||||
|         (screen_distorsion !== 0 ? " | ||||
|             uniform highp float screen_distorsion;" : "") + | ||||
| @@ -175,10 +175,6 @@ ShaderEffect { | ||||
|             :" | ||||
|                 vec2 coords = qt_TexCoord0;") + | ||||
|  | ||||
|             (frameReflections ? " | ||||
|                 vec2 inside = step(0.0, coords) - step(1.0, coords); | ||||
|                 coords = abs(mod(floor(coords), 2.0) - fract(coords)) * clamp(inside.x + inside.y, 0.0, 1.0);" : "") + | ||||
|  | ||||
|             (horizontal_sincronization !== 0 ? " | ||||
|                 float h_distortion = 0.5 * sin(time*0.001 + coords.y*10.0*fract(time/10.0)); | ||||
|                 h_distortion += 0.5 * cos(time*0.04 + 0.03 + coords.y*50.0*fract(time/10.0 + 0.4)); | ||||
| @@ -202,36 +198,38 @@ ShaderEffect { | ||||
|             (glowing_line_strength !== 0 ? " | ||||
|                 color += randomPass(coords) * glowing_line_strength;" : "") + | ||||
|  | ||||
|  | ||||
|             "vec3 txt_color = texture2D(source, txt_coords).rgb; | ||||
|              float greyscale_color = rgb2grey(txt_color) + color;" + | ||||
|  | ||||
|             (chroma_color !== 0 ? | ||||
|                 (rgb_shift !== 0 ? " | ||||
|                     float rgb_noise = abs(texture2D(noiseSource, vec2(fract(time/(1024.0 * 256.0)), fract(time/(1024.0*1024.0)))).a - 0.5); | ||||
|                     vec4 realBackColor = texture2D(source, txt_coords); | ||||
|                     vec2 rcolor = texture2D(source, txt_coords + vec2(0.1, 0.0) * rgb_shift * rgb_noise).ra; | ||||
|                     vec2 bcolor = texture2D(source, txt_coords - vec2(0.1, 0.0) * rgb_shift * rgb_noise).ba; | ||||
|                     realBackColor.r = rcolor.x; | ||||
|                     realBackColor.b = bcolor.x; | ||||
|                     realBackColor.a = 0.33 * (realBackColor.a + rcolor.y + bcolor.y);" | ||||
|                 : | ||||
|                     "vec4 realBackColor = texture2D(source, txt_coords);") + | ||||
|                     float rcolor = texture2D(source, txt_coords + vec2(0.1, 0.0) * rgb_shift * rgb_noise).r; | ||||
|                     float bcolor = texture2D(source, txt_coords - vec2(0.1, 0.0) * rgb_shift * rgb_noise).b; | ||||
|                     txt_color.r = rcolor; | ||||
|                     txt_color.b = bcolor; | ||||
|                     greyscale_color = 0.33 * (rcolor + bcolor);" : "") + | ||||
|  | ||||
|                 "vec4 mixedColor = mix(font_color, realBackColor * font_color, chroma_color);" + | ||||
|  | ||||
|                 "vec4 finalBackColor = mix(background_color, mixedColor, realBackColor.a);" + | ||||
|                 "vec3 finalColor = mix(finalBackColor, font_color, color).rgb;" | ||||
|                 "vec3 mixedColor = mix(font_color.rgb, txt_color * font_color.rgb, chroma_color); | ||||
|                  vec3 finalBackColor = mix(background_color.rgb, mixedColor, greyscale_color); | ||||
|                  vec3 finalColor = mix(finalBackColor, font_color.rgb, color).rgb;" | ||||
|             : | ||||
|                 "color += texture2D(source, txt_coords).a;" + | ||||
|                 "vec3 finalColor = mix(background_color, font_color, color).rgb;" | ||||
|             ) + | ||||
|                 "vec3 finalColor = mix(background_color.rgb, font_color.rgb, greyscale_color);") + | ||||
|  | ||||
|             "finalColor *= texture2D(rasterizationSource, coords).a;" + | ||||
|  | ||||
|             (bloom_strength !== 0 ? | ||||
|                 "vec3 bloomColor = texture2D(bloomSource, coords).rgb;" + | ||||
|                 "vec4 bloomFullColor = texture2D(bloomSource, coords); | ||||
|                  vec3 bloomColor = bloomFullColor.rgb; | ||||
|                  vec2 minBound = step(vec2(0.0), coords); | ||||
|                  vec2 maxBound = step(coords, vec2(1.0)); | ||||
|                  float bloomAlpha = bloomFullColor.a * minBound.x * minBound.y * maxBound.x * maxBound.y;" + | ||||
|                 (chroma_color !== 0 ? | ||||
|                     "bloomColor = font_color.rgb * mix(vec3(rgb2grey(bloomColor)), bloomColor, chroma_color);" | ||||
|                 : | ||||
|                     "bloomColor = font_color.rgb * rgb2grey(bloomColor);") + | ||||
|                 "finalColor += bloomColor * bloom_strength;" | ||||
|                 "finalColor += bloomColor * bloom_strength * bloomAlpha;" | ||||
|             : "") + | ||||
|  | ||||
|             (brightness_flickering !== 0 ? " | ||||
|   | ||||
| @@ -7,22 +7,19 @@ TerminalFrame{ | ||||
|     anchors.fill: parent | ||||
|     addedWidth: 200 | ||||
|     addedHeight: 370 | ||||
|     borderLeft: 148 | ||||
|     borderRight: 148 | ||||
|     borderTop: 232 | ||||
|     borderBottom: 232 | ||||
|     borderLeft: 170 | ||||
|     borderRight: 170 | ||||
|     borderTop: 250 | ||||
|     borderBottom: 250 | ||||
|     imageSource: "../images/black-frame.png" | ||||
|     normalsSource: "../images/black-frame-normals.png" | ||||
|  | ||||
|     rectX: 20 | ||||
|     rectY: 20 | ||||
|  | ||||
|     distortionCoefficient: 1.9 | ||||
|  | ||||
|     displacementLeft: 70.0 | ||||
|     displacementTop: 55.0 | ||||
|     displacementRight: 50.0 | ||||
|     displacementBottom: 38.0 | ||||
|     displacementLeft: 80.0 | ||||
|     displacementTop: 65.0 | ||||
|     displacementRight: 80.0 | ||||
|     displacementBottom: 65.0 | ||||
|  | ||||
|     shaderString: "FrameShader.qml" | ||||
| } | ||||
|   | ||||
| @@ -12,9 +12,6 @@ TerminalFrame{ | ||||
|     borderTop: 0 | ||||
|     borderBottom: 0 | ||||
|  | ||||
|     rectX: 15 | ||||
|     rectY: 15 | ||||
|  | ||||
|     displacementLeft: 0 | ||||
|     displacementTop: 0 | ||||
|     displacementRight: 0 | ||||
|   | ||||
| @@ -14,15 +14,12 @@ TerminalFrame{ | ||||
|     imageSource: "../images/screen-frame.png" | ||||
|     normalsSource: "../images/screen-frame-normals.png" | ||||
|  | ||||
|     rectX: 15 | ||||
|     rectY: 15 | ||||
|  | ||||
|     distortionCoefficient: 1.5 | ||||
|  | ||||
|     displacementLeft: 45 | ||||
|     displacementTop: 40 | ||||
|     displacementRight: 38.0 | ||||
|     displacementBottom: 28.0 | ||||
|     displacementLeft: 55 | ||||
|     displacementTop: 50 | ||||
|     displacementRight: 55 | ||||
|     displacementBottom: 50 | ||||
|  | ||||
|     shaderString: "FrameShader.qml" | ||||
| } | ||||
|   | ||||
| @@ -15,10 +15,6 @@ Item{ | ||||
|     property string normalsSource | ||||
|     property string shaderString | ||||
|  | ||||
|     //Value used to create the rect used to add the border to the texture | ||||
|     property real rectX | ||||
|     property real rectY | ||||
|  | ||||
|     //Values used to displace the texture in the screen. Used to make reflections correct. | ||||
|     property real displacementLeft | ||||
|     property real displacementTop | ||||
| @@ -27,11 +23,6 @@ Item{ | ||||
|  | ||||
|     property real distortionCoefficient | ||||
|  | ||||
|     property rect sourceRect: Qt.rect(-rectX * shadersettings.window_scaling, | ||||
|                                       -rectY * shadersettings.window_scaling, | ||||
|                                       terminal.width + 2*rectX * shadersettings.window_scaling, | ||||
|                                       terminal.height + 2*rectY * shadersettings.window_scaling) | ||||
|  | ||||
|     BorderImage{ | ||||
|         id: frameimage | ||||
|         anchors.centerIn: parent | ||||
|   | ||||
| @@ -83,7 +83,7 @@ ApplicationWindow{ | ||||
|         text: qsTr("Zoom In") | ||||
|         shortcut: "Ctrl++" | ||||
|         onTriggered: { | ||||
|             var oldScaling = shadersettings.fontScalingIndexes[shadersettings.rasterization]; | ||||
|             var oldScaling = shadersettings.fontScalingIndex; | ||||
|             var maxScalingIndex = shadersettings.fontScalingList.length - 1; | ||||
|             shadersettings.setScalingIndex(Math.min(oldScaling + 1, maxScalingIndex)); | ||||
|         } | ||||
| @@ -93,7 +93,7 @@ ApplicationWindow{ | ||||
|         text: qsTr("Zoom Out") | ||||
|         shortcut: "Ctrl+-" | ||||
|         onTriggered: { | ||||
|             var oldScaling = shadersettings.fontScalingIndexes[shadersettings.rasterization]; | ||||
|             var oldScaling = shadersettings.fontScalingIndex; | ||||
|             shadersettings.setScalingIndex(Math.max(oldScaling - 1, 0)); | ||||
|         } | ||||
|     } | ||||
| @@ -148,23 +148,17 @@ ApplicationWindow{ | ||||
|         width: parent.width * shadersettings.window_scaling | ||||
|         height: parent.height * shadersettings.window_scaling | ||||
|         scale: 1.0 / shadersettings.window_scaling | ||||
|         smooth: false | ||||
|         antialiasing: false | ||||
|         opacity: shadersettings.windowOpacity * 0.3 + 0.7 | ||||
|  | ||||
|         Loader{ | ||||
|             id: frame | ||||
|             anchors.fill: parent | ||||
|  | ||||
|             property rect sourceRect: item.sourceRect | ||||
|  | ||||
|             z: 2.1 | ||||
|             source: shadersettings.frame_source | ||||
|         } | ||||
|         PreprocessedTerminal{ | ||||
|             id: terminal | ||||
|             anchors.fill: parent | ||||
|             anchors.margins: 30 | ||||
|         } | ||||
|         ShaderTerminal{ | ||||
|             id: shadercontainer | ||||
|   | ||||
| @@ -1996,7 +1996,7 @@ void KTerminalDisplay::calcGeometry() | ||||
|     _contentHeight = height() - 2 * DEFAULT_TOP_MARGIN + /* mysterious */ 1; | ||||
|  | ||||
|     // ensure that display is always at least one column wide | ||||
|     _columns     = qMax(1, qRound(_contentWidth / _fontWidth)); | ||||
|     _columns     = qMax(1, qFloor(_contentWidth / _fontWidth)); | ||||
|     _usedColumns = qMin(_usedColumns,_columns); | ||||
|  | ||||
|     // ensure that display is always at least one line high | ||||
| @@ -2265,7 +2265,7 @@ void KTerminalDisplay::drawCursor(QPainter* painter, | ||||
|                                   bool& invertCharacterColor) | ||||
| { | ||||
|     QRectF cursorRect = rect; | ||||
|     cursorRect.setHeight(_fontHeight - _lineSpacing - 1); | ||||
|     cursorRect.setHeight(_fontHeight - _lineSpacing); | ||||
|  | ||||
|     if (!_cursorBlinking) | ||||
|     { | ||||
| @@ -2280,8 +2280,8 @@ void KTerminalDisplay::drawCursor(QPainter* painter, | ||||
|             // it is draw entirely inside 'rect' | ||||
|             int penWidth = qMax(1,painter->pen().width()); | ||||
|  | ||||
|             painter->drawRect(cursorRect.adjusted( penWidth/2, | ||||
|                                                    penWidth/2, | ||||
|             painter->drawRect(cursorRect.adjusted( penWidth/2 + penWidth%2, | ||||
|                                                    penWidth/2 + penWidth%2, | ||||
|                                                    - penWidth/2 - penWidth%2, | ||||
|                                                    - penWidth/2 - penWidth%2)); | ||||
|             if ( hasFocus() ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user