1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-01-18 20:20:45 +00:00

Various riorganizations and fixes.

This commit is contained in:
Filippo Scognamiglio 2014-06-07 02:19:37 +02:00
parent 947b355c29
commit bd0938610f
4 changed files with 83 additions and 92 deletions

View File

@ -127,7 +127,7 @@ Item{
ListElement{pixelSize: 18; virtualWidth: 0; virtualHeight: 6}, ListElement{pixelSize: 18; virtualWidth: 0; virtualHeight: 6},
ListElement{pixelSize: 24; virtualWidth: 0; virtualHeight: 8}, ListElement{pixelSize: 24; virtualWidth: 0; virtualHeight: 8},
ListElement{pixelSize: 35; virtualWidth: 5; virtualHeight: 12}, ListElement{pixelSize: 35; virtualWidth: 5; virtualHeight: 12},
ListElement{pixelSize: 47; virtualWidth: 6; virtualHeight: 11}, ListElement{pixelSize: 43; virtualWidth: 6; virtualHeight: 11},
ListElement{pixelSize: 54; virtualWidth: 7; virtualHeight: 11}, ListElement{pixelSize: 54; virtualWidth: 7; virtualHeight: 11},
ListElement{pixelSize: 64; virtualWidth: 8; virtualHeight: 11}, ListElement{pixelSize: 64; virtualWidth: 8; virtualHeight: 11},
ListElement{pixelSize: 75; virtualWidth: 8; virtualHeight: 11}] ListElement{pixelSize: 75; virtualWidth: 8; virtualHeight: 11}]

View File

@ -47,7 +47,7 @@ Item{
property int mScanlines: shadersettings.rasterization property int mScanlines: shadersettings.rasterization
onMScanlinesChanged: restartBlurredSource() onMScanlinesChanged: restartBlurredSource()
property size terminalSize property size terminalSize: kterminal.terminalSize
property size paintedTextSize property size paintedTextSize
onPaintedTextSizeChanged: console.log(paintedTextSize) onPaintedTextSizeChanged: console.log(paintedTextSize)
@ -60,79 +60,64 @@ Item{
blurredSource.live = true; blurredSource.live = true;
livetimer.restart() livetimer.restart()
} }
function loadKTerminal(){
kterminal.active = true;
}
function unloadKTerminal(){
kterminal.active = false;
}
function pasteClipboard(){ function pasteClipboard(){
kterminal.item.pasteClipboard(); kterminal.pasteClipboard();
} }
function copyClipboard(){ function copyClipboard(){
kterminal.item.copyClipboard(); kterminal.copyClipboard();
} }
Loader{
KTerminal {
id: kterminal id: kterminal
active: false
anchors.fill: parent anchors.fill: parent
font.pixelSize: shadersettings.font.pixelSize
font.family: shadersettings.font.name
sourceComponent: KTerminal { colorScheme: "MyWhiteOnBlack"
id: ktermitem
font.pixelSize: shadersettings.font.pixelSize
font.family: shadersettings.font.name
colorScheme: "MyWhiteOnBlack" session: KSession {
id: ksession
kbScheme: "linux"
onTerminalSizeChanged: terminalContainer.terminalSize = ktermitem.terminalSize onFinished: {
Qt.quit()
session: KSession {
id: ksession
kbScheme: "linux"
onFinished: {
Qt.quit()
}
} }
}
Text{id: fontMetrics; text: "B"; visible: false} Text{id: fontMetrics; text: "B"; visible: false}
function handleFontChange(){ function handleFontChange(){
var scaling_factor = shadersettings.window_scaling; var scaling_factor = shadersettings.window_scaling;
var font_size = shadersettings.font.pixelSize * scaling_factor; var font_size = shadersettings.font.pixelSize * scaling_factor;
font.pixelSize = font_size; font.pixelSize = font_size;
font.family = shadersettings.font.name; font.family = shadersettings.font.name;
fontMetrics.font = font; fontMetrics.font = font;
var vertical_density = shadersettings.font.virtualResolution.height; var vertical_density = shadersettings.font.virtualResolution.height;
var horizontal_density = shadersettings.font.virtualResolution.width; var horizontal_density = shadersettings.font.virtualResolution.width;
var scanline_height = fontMetrics.paintedHeight / vertical_density; var scanline_height = fontMetrics.paintedHeight / vertical_density;
var scanline_width = fontMetrics.paintedWidth / horizontal_density; var scanline_width = fontMetrics.paintedWidth / horizontal_density;
console.log("Font height: " + fontMetrics.paintedHeight) var scanline_spacing = shadersettings.font.lineSpacing;
var line_spacing = Math.round(scanline_spacing * scanline_height);
var scanline_spacing = shadersettings.font.lineSpacing; // console.log("Font height: " + fontMetrics.paintedHeight)
var line_spacing = Math.round(scanline_spacing * scanline_height); // console.log("Scanline Height: " + scanline_height)
// console.log("Line Spacing: " + line_spacing)
console.log("Scanline Height: " + scanline_height) terminalContainer.scanlineHeight = scanline_height;
console.log("Line Spacing: " + line_spacing) terminalContainer.scanlineWidth = scanline_width;
terminalContainer.scanlineHeight = scanline_height; setLineSpacing(line_spacing);
terminalContainer.scanlineWidth = scanline_width; restartBlurredSource();
}
setLineSpacing(line_spacing); Component.onCompleted: {
restartBlurredSource(); shadersettings.terminalFontChanged.connect(handleFontChange);
} handleFontChange();
forceActiveFocus();
onUpdatedImage: {blurredSource.live = true;livetimer.restart();}
Component.onCompleted: {
shadersettings.terminalFontChanged.connect(handleFontChange);
handleFontChange();
forceActiveFocus();
}
} }
} }
Menu{ Menu{
@ -146,33 +131,33 @@ Item{
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
anchors.fill: parent anchors.fill: parent
onWheel: onWheel:
wheel.angleDelta.y > 0 ? kterminal.item.scrollUp() : kterminal.item.scrollDown() wheel.angleDelta.y > 0 ? kterminal.scrollUp() : kterminal.scrollDown()
onClicked: { onClicked: {
if (mouse.button == Qt.RightButton){ if (mouse.button == Qt.RightButton){
contextmenu.popup(); contextmenu.popup();
} else if (mouse.button == Qt.MiddleButton){ } else if (mouse.button == Qt.MiddleButton){
kterminal.item.pasteSelection(); kterminal.pasteSelection();
} }
} }
onDoubleClicked: { onDoubleClicked: {
if (mouse.button == Qt.LeftButton){ if (mouse.button == Qt.LeftButton){
var coord = correctDistortion(mouse.x, mouse.y); var coord = correctDistortion(mouse.x, mouse.y);
kterminal.item.mouseDoubleClick(coord.width, coord.height); kterminal.mouseDoubleClick(coord.width, coord.height);
} }
} }
onPositionChanged: { onPositionChanged: {
var coord = correctDistortion(mouse.x, mouse.y); var coord = correctDistortion(mouse.x, mouse.y);
kterminal.item.mouseMove(coord.width, coord.height); kterminal.mouseMove(coord.width, coord.height);
} }
onPressed: { onPressed: {
if (mouse.button == Qt.LeftButton){ if (mouse.button == Qt.LeftButton){
var coord = correctDistortion(mouse.x, mouse.y); var coord = correctDistortion(mouse.x, mouse.y);
kterminal.item.mousePress(coord.width, coord.height); kterminal.mousePress(coord.width, coord.height);
} }
} }
onReleased: { onReleased: {
if (mouse.button == Qt.LeftButton){ if (mouse.button == Qt.LeftButton){
kterminal.item.mouseRelease(mouse.x, mouse.y); kterminal.mouseRelease(mouse.x, mouse.y);
} }
} }
@ -206,6 +191,12 @@ Item{
id: livetimer id: livetimer
running: true running: true
onTriggered: parent.live = false; onTriggered: parent.live = false;
function updateImageHandler(){
livetimer.restart();
blurredSource.live = true;
}
Component.onCompleted: kterminal.updatedImage.connect(updateImageHandler);
} }
} }
ShaderEffectSource{ ShaderEffectSource{
@ -220,7 +211,7 @@ Item{
property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined property variant blurredSource: (mBlur !== 0) ? blurredSource : undefined
property size virtual_resolution: parent.virtual_resolution property size virtual_resolution: parent.virtual_resolution
property size delta: Qt.size((mScanlines == shadersettings.pixel_rasterization ? deltax : 0), property size delta: Qt.size((mScanlines == shadersettings.pixel_rasterization ? deltax : 0),
mScanlines != shadersettings.no_rasterization ? deltay : 0) mScanlines != shadersettings.no_rasterization ? deltay : 0)
z: 2 z: 2
fragmentShader: fragmentShader:
@ -232,28 +223,28 @@ Item{
uniform highp vec2 virtual_resolution;" + uniform highp vec2 virtual_resolution;" +
(mBlur !== 0 ? (mBlur !== 0 ?
"uniform lowp sampler2D blurredSource;" "uniform lowp sampler2D blurredSource;"
: "") + : "") +
"void main() {" + "void main() {" +
"vec2 coords = qt_TexCoord0;" + "vec2 coords = qt_TexCoord0;" +
(mScanlines != shadersettings.no_rasterization ? " (mScanlines != shadersettings.no_rasterization ? "
coords.y = floor(virtual_resolution.y * coords.y) / virtual_resolution.y;" + coords.y = floor(virtual_resolution.y * coords.y) / virtual_resolution.y;" +
(mScanlines == shadersettings.pixel_rasterization ? " (mScanlines == shadersettings.pixel_rasterization ? "
coords.x = floor(virtual_resolution.x * coords.x) / virtual_resolution.x;" : "") coords.x = floor(virtual_resolution.x * coords.x) / virtual_resolution.x;" : "")
: "") + : "") +
"float color = texture2D(source, coords + delta).r * 256.0;" + "float color = texture2D(source, coords + delta).r * 256.0;" +
(mBlur !== 0 ? (mBlur !== 0 ?
"float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 256.0;" + "float blurredSourceColor = texture2D(blurredSource, qt_TexCoord0).r * 256.0;" +
"blurredSourceColor = blurredSourceColor - blurredSourceColor * " + (1.0 - motionBlurCoefficient) * fpsAttenuation+ ";" + "blurredSourceColor = blurredSourceColor - blurredSourceColor * " + (1.0 - motionBlurCoefficient) * fpsAttenuation+ ";" +
"color = step(1.0, color) * color + step(color, 1.0) * blurredSourceColor;" "color = step(1.0, color) * color + step(color, 1.0) * blurredSourceColor;"
: "") + : "") +
"gl_FragColor = vec4(vec3(floor(color) / 256.0), 1.0);" + "gl_FragColor = vec4(vec3(floor(color) / 256.0), 1.0);" +
"}" "}"
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//EFFECTS //EFFECTS
@ -296,14 +287,14 @@ Item{
float getScanlineIntensity(vec2 coords) { float getScanlineIntensity(vec2 coords) {
float result = abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" + float result = abs(sin(coords.y * virtual_resolution.y * "+Math.PI+"));" +
(mScanlines == shadersettings.pixel_rasterization ? (mScanlines == shadersettings.pixel_rasterization ?
"result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + " "result *= abs(sin(coords.x * virtual_resolution.x * "+Math.PI+"));" : "") + "
return result; return result;
}" + }" +
"void main() {" + "void main() {" +
"gl_FragColor = vec4(getScanlineIntensity(qt_TexCoord0));" + "gl_FragColor = vec4(getScanlineIntensity(qt_TexCoord0));" +
"}" "}"
} }
} }
Loader{ Loader{

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-06-06T20:31:03. --> <!-- Written by QtCreator 3.0.1, 2014-06-07T01:48:03. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -74,7 +74,10 @@
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/> <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="int" key="PE.EnvironmentAspect.Base">0</value> <value type="int" key="PE.EnvironmentAspect.Base">0</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes">
<value type="QString">QML_DISABLE_OPTIMIZER=1</value>
<value type="QString">&lt;VARIABLE&gt;=&lt;VALUE&gt;</value>
</valuelist>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">QML Scene</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">QML Scene</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmlProjectManager.QmlRunConfiguration.QmlScene</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmlProjectManager.QmlRunConfiguration.QmlScene</value>

View File

@ -88,6 +88,10 @@ ApplicationWindow{
} }
} }
ShaderSettings{
id: shadersettings
}
Loader{ Loader{
id: frame id: frame
property rect sourceRect: Qt.rect(-item.rectX * shadersettings.window_scaling, property rect sourceRect: Qt.rect(-item.rectX * shadersettings.window_scaling,
@ -142,9 +146,6 @@ ApplicationWindow{
z: 1.9 z: 1.9
} }
} }
ShaderSettings{
id: shadersettings
}
SettingsWindow{ SettingsWindow{
id: settingswindow id: settingswindow
visible: false visible: false
@ -158,8 +159,4 @@ ApplicationWindow{
terminalSize: terminal.terminalSize terminalSize: terminal.terminalSize
} }
} }
Component.onCompleted: {
terminal.loadKTerminal();
}
} }