Skip to content

Commit

Permalink
New QML-based GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
David Haller committed May 1, 2021
1 parent 61f0106 commit 6f983de
Show file tree
Hide file tree
Showing 45 changed files with 2,385 additions and 3,043 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/*
doc/*
*.pro.user
53 changes: 53 additions & 0 deletions AboutDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import QtQuick 2.9
import QtQuick.Controls 2.2

Dialog
{
property alias instance: instance

id: instance
width: parent.width
height: parent.height
modal: true
title: qsTr("About Headway")

ScrollView
{
anchors.fill: parent

TextArea
{
readOnly: true
selectByMouse: true

wrapMode: TextEdit.WordWrap
textFormat: TextEdit.RichText

font.pointSize: 14
text: "<h1>Headway 4.0.2</h1>"
+ "<p>David Haller (<a href=\"mailto:[email protected]\">[email protected]</a>)<br/>"
+ "Copyright © 2017 David Haller</p>"
+ "<p>Licensed under the terms and conditions of the<br/>Apache License, Version 2.0.</p>"
+ "<h2>Description</h2>"
+ "<p>In 1970, the British mathematician John Conway invented a cellular automaton called *Game Of Life*. The simulation takes place in a two-dimensional grid of cells represented as rectangles. A cell can either be *alive* or *dead*. This state can change from one generation to another, depending on the amount of neighbor cells. If a cell has two neighbors, it keeps its state, three neighbors means that the cell will be revived when it was dead before. A cell dies when it has zero, one or more than four neighbors. Therefore, life is threatened by overpopulation and aloneness.</p>"
+ "<p>At every generation transition, the neighbors of each cell are counted and, depending on the result, the rules mentioned before are applied to each cell. There are several possible simulation outcomes which can occur, e.g:</p>"
+ "<p><ul><li>death of all cells</li><li>all cells turn stable, so in every future generation no cell dies or gets revived</li><li>periodic movement patterns</li><li>chaotic fluctuation, no recognizable pattern</li></ul></p>"
+ "<p>Although the simulation may appear to be chaotic, it's actually deterministic, so the same starting parameters will always lead to the same simulation progress.</p>"
}
}

footer: DialogButtonBox
{
Button
{
text: qsTr("Open Website")
onClicked: Qt.openUrlExternally("https://davidhaller.github.io/headway")
}

Button
{
text: qsTr("Close")
onClicked: instance.accept()
}
}
}
60 changes: 0 additions & 60 deletions CMakeLists.txt

This file was deleted.

26 changes: 26 additions & 0 deletions Cell.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import QtQuick 2.9

Rectangle
{
function move(newX, newY)
{
x = newX;
y = newY;
}

function resize(newWidth, newHeight)
{
width = newWidth;
height = newHeight;
}

function setAlive(value)
{
if (value === true)
color = "black";
else
color = "white";
}

border.color: "lightgray"
}
66 changes: 66 additions & 0 deletions CellCanvas.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import QtQuick 2.9

Item
{
id: canvas
width: parent.width
height: parent.height

property int columns: 0
property int rows: 0
property var cellArray: []

function redraw(biotope)
{
const Cell = Qt.createComponent("Cell.qml");
children = []; // remove all cells from canvas

columns = biotope.width;
rows = biotope.height;
cellArray = new Array(columns * rows); // keep references of cells to modify them later

const boxWidth = canvas.width / columns;
const boxHeight = canvas.height / rows;

for (var y = 0; y < rows; y++)
{
for (var x = 0; x < columns; x++)
{
var cell = Cell.createObject(canvas);

cell.move(boxWidth * x, boxHeight * y);
cell.resize(boxWidth, boxHeight);

cellArray[offset(x, y)] = cell;
}
}

refreshAll(biotope);
}

function refreshAll(biotope)
{
canvas.visible = false;

for (var y = 0; y < rows; y++)
{
for (var x = 0; x < columns; x++)
{
refreshCell(biotope, x, y);
}
}

canvas.visible = true;
}

function refreshCell(biotope, x, y)
{
var cell = cellArray[offset(x, y)];
cell.setAlive(biotope.isAlive(x, y));
}

function offset(x, y)
{
return y * columns + x;
}
}
Loading

0 comments on commit 6f983de

Please sign in to comment.