Skip to content

Commit

Permalink
Minor fixes for GKLifePlugin (fix #571)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Jun 17, 2024
1 parent dcc134d commit 0aa7b4a
Showing 7 changed files with 47 additions and 72 deletions.
14 changes: 4 additions & 10 deletions projects/plugins/GKLifePlugin/ConwayLife/LifeForm.cs
Original file line number Diff line number Diff line change
@@ -16,10 +16,6 @@ namespace GKLifePlugin.ConwayLife
{
public partial class LifeForm : Form, ILocalizable
{
private static string PatternStabilisedTitle = "Стабильность образца";
private static string RepeatingPattern = "Образец повторяется через каждые {0} поколений!";
private static string StaticPattern = "Образец статичен!";

private bool fIsMinimised;
private ILangMan fLangMan;

@@ -74,8 +70,8 @@ private void tmrNextGeneration_Tick(object sender, EventArgs e)

private void cmpLife_Change(object sender)
{
stlGeneration.Text = "Поколений: " + cmpLife.Generation.ToString();
stlLivingCells.Text = "Живых клеток: " + cmpLife.LiveCellCount.ToString();
stlGeneration.Text = string.Format(fLangMan.LS(PLS.Generation), cmpLife.Generation);
stlLivingCells.Text = string.Format(fLangMan.LS(PLS.LivingCells), cmpLife.LiveCellCount);
}

private void UpdateMenusAndButtons()
@@ -86,11 +82,9 @@ private void UpdateMenusAndButtons()
if (tbStart.Checked) {
cmpLife.OnChange += cmpLife_Change;
tbStart.Text = fLangMan.LS(PLS.Stop);
tbStart.ToolTipText = "Остановка хода поколений";
} else {
cmpLife.OnChange -= cmpLife_Change;
tbStart.Text = fLangMan.LS(PLS.Start);
tbStart.ToolTipText = "Автоматическое прохождение поколений";
}

btnSetCells.Enabled = !tbStart.Checked;
@@ -101,8 +95,8 @@ private void UpdateMenusAndButtons()

private void PatternStabilised(int periodicity)
{
string msg = (periodicity == 1) ? StaticPattern : string.Format(RepeatingPattern, periodicity);
MessageBox.Show(msg, PatternStabilisedTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
string msg = (periodicity == 1) ? fLangMan.LS(PLS.StaticPattern) : string.Format(fLangMan.LS(PLS.RepeatingPattern), periodicity);
MessageBox.Show(msg, fLangMan.LS(PLS.PatternStabilisedTitle), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}

private void tbStep_Click(object sender, EventArgs e)
14 changes: 4 additions & 10 deletions projects/plugins/GKLifePlugin/ConwayLife/LifeForm.net.cs
Original file line number Diff line number Diff line change
@@ -18,10 +18,6 @@ namespace GKLifePlugin.ConwayLife
{
public partial class LifeForm : Form, ILocalizable
{
private static string PatternStabilisedTitle = "Стабильность образца";
private static string RepeatingPattern = "Образец повторяется через каждые {0} поколений!";
private static string StaticPattern = "Образец статичен!";

#region Design components
#pragma warning disable CS0169, CS0649, IDE0044, IDE0051

@@ -104,8 +100,8 @@ private void tmrNextGeneration_Tick(object sender, EventArgs e)

private void cmpLife_Change(object sender)
{
stlGeneration.Text = "Поколений: " + cmpLife.Generation.ToString();
stlLivingCells.Text = "Живых клеток: " + cmpLife.LiveCellCount.ToString();
stlGeneration.Text = string.Format(fLangMan.LS(PLS.Generation), cmpLife.Generation);
stlLivingCells.Text = string.Format(fLangMan.LS(PLS.LivingCells), cmpLife.LiveCellCount);
}

private void UpdateMenusAndButtons()
@@ -116,11 +112,9 @@ private void UpdateMenusAndButtons()
if (tbStart.Checked) {
cmpLife.OnChange += cmpLife_Change;
tbStart.Text = fLangMan.LS(PLS.Stop);
tbStart.ToolTip = "Остановка хода поколений";
} else {
cmpLife.OnChange -= cmpLife_Change;
tbStart.Text = fLangMan.LS(PLS.Start);
tbStart.ToolTip = "Автоматическое прохождение поколений";
}

btnSetCells.Enabled = !tbStart.Checked;
@@ -131,8 +125,8 @@ private void UpdateMenusAndButtons()

private void PatternStabilised(int periodicity)
{
string msg = (periodicity == 1) ? StaticPattern : string.Format(RepeatingPattern, periodicity);
AppHost.StdDialogs.ShowWarning(msg, PatternStabilisedTitle);
string msg = (periodicity == 1) ? fLangMan.LS(PLS.StaticPattern) : string.Format(fLangMan.LS(PLS.RepeatingPattern), periodicity);
AppHost.StdDialogs.ShowWarning(msg, fLangMan.LS(PLS.PatternStabilisedTitle));
}

private void tbStep_Click(object sender, EventArgs e)
36 changes: 11 additions & 25 deletions projects/plugins/GKLifePlugin/ConwayLife/LifeViewer.cs
Original file line number Diff line number Diff line change
@@ -116,35 +116,21 @@ protected override void Dispose(bool disposing)

protected Point CellAtPos(int X, int Y)
{
int ClientWidth = Width;
int ClientHeight = Height;
int clientWidth = Width;
int clientHeight = Height;

if ((X < 0) || (X >= ClientWidth))
if (X < 0 || X >= clientWidth)
throw new IndexOutOfRangeException("X coordinate is outside the control's bounds");
if ((Y < 0) || (Y >= ClientHeight))
if (Y < 0 || Y >= clientHeight)
throw new IndexOutOfRangeException("Y coordinate is outside the control's bounds");

Point result = new Point();

int cellWidth = ClientWidth / GridWidth;
int offsetX = (ClientWidth % GridWidth) / 2;
int cellWidth = clientWidth / GridWidth;
int offsetX = (clientWidth % GridWidth) / 2;

if (X <= offsetX * (cellWidth + 1)) {
result.X = X / (cellWidth + 1);
} else {
result.X = offsetX + (X - offsetX * (cellWidth + 1)) / cellWidth;
}

int cellHeight = ClientHeight / GridHeight;
int offsetY = (ClientHeight % GridHeight) / 2;
int cellHeight = clientHeight / GridHeight;
int offsetY = (clientHeight % GridHeight) / 2;

if (Y <= offsetY * (cellHeight + 1)) {
result.Y = Y / (cellHeight + 1);
} else {
result.Y = offsetY + (Y - offsetY * (cellHeight + 1)) / cellHeight;
}

return result;
return new Point((X - offsetX) / cellWidth, (Y - offsetY) / cellHeight);
}

private int CellEdge(int coordinate, int fieldSize, int divisions)
@@ -185,15 +171,15 @@ protected void Change()
if (fOnChange != null) fOnChange(this);
}

protected override void OnMouseUp(MouseEventArgs e)
protected override void OnMouseMove(MouseEventArgs e)
{
if (AcceptMouseClicks && (e.Button == MouseButtons.Left)) {
Point pt = CellAtPos(e.X, e.Y);
byte val = this[pt.X, pt.Y];
this[pt.X, pt.Y] = (byte)((val > 0) ? 0 : 1);
}

base.OnMouseUp(e);
base.OnMouseMove(e);
}

private void DrawGridLines(Graphics gfx, Pen pen)
36 changes: 11 additions & 25 deletions projects/plugins/GKLifePlugin/ConwayLife/LifeViewer.net.cs
Original file line number Diff line number Diff line change
@@ -116,35 +116,21 @@ protected override void Dispose(bool disposing)

protected Point CellAtPos(int X, int Y)
{
int ClientWidth = Width;
int ClientHeight = Height;
int clientWidth = Width;
int clientHeight = Height;

if ((X < 0) || (X >= ClientWidth))
if (X < 0 || X >= clientWidth)
throw new IndexOutOfRangeException("X coordinate is outside the control's bounds");
if ((Y < 0) || (Y >= ClientHeight))
if (Y < 0 || Y >= clientHeight)
throw new IndexOutOfRangeException("Y coordinate is outside the control's bounds");

Point result = new Point();

int cellWidth = ClientWidth / GridWidth;
int offsetX = (ClientWidth % GridWidth) / 2;
int cellWidth = clientWidth / GridWidth;
int offsetX = (clientWidth % GridWidth) / 2;

if (X <= offsetX * (cellWidth + 1)) {
result.X = X / (cellWidth + 1);
} else {
result.X = offsetX + (X - offsetX * (cellWidth + 1)) / cellWidth;
}

int cellHeight = ClientHeight / GridHeight;
int offsetY = (ClientHeight % GridHeight) / 2;
int cellHeight = clientHeight / GridHeight;
int offsetY = (clientHeight % GridHeight) / 2;

if (Y <= offsetY * (cellHeight + 1)) {
result.Y = Y / (cellHeight + 1);
} else {
result.Y = offsetY + (Y - offsetY * (cellHeight + 1)) / cellHeight;
}

return result;
return new Point((X - offsetX) / cellWidth, (Y - offsetY) / cellHeight);
}

private int CellEdge(int coordinate, int fieldSize, int divisions)
@@ -185,15 +171,15 @@ protected void Change()
if (fOnChange != null) fOnChange(this);
}

protected override void OnMouseUp(MouseEventArgs e)
protected override void OnMouseMove(MouseEventArgs e)
{
if (AcceptMouseClicks && (e.Buttons == MouseButtons.Primary)) {
Point pt = CellAtPos((int)e.Location.X, (int)e.Location.Y);
byte val = this[pt.X, pt.Y];
this[pt.X, pt.Y] = (byte)((val > 0) ? 0 : 1);
}

base.OnMouseUp(e);
base.OnMouseMove(e);
}

private void DrawGridLines(Graphics gfx, Pen pen)
9 changes: 7 additions & 2 deletions projects/plugins/GKLifePlugin/GKLifePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
@@ -29,7 +29,7 @@
[assembly: AssemblyTitle("GKLifePlugin")]
[assembly: AssemblyDescription("GEDKeeper Conway's Game of Life plugin")]
[assembly: AssemblyProduct("GEDKeeper")]
[assembly: AssemblyCopyright("Copyright © 2011-2023 by Sergey V. Zhdanovskih")]
[assembly: AssemblyCopyright("Copyright © 2011-2024 by Sergey V. Zhdanovskih")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyCulture("")]

@@ -51,6 +51,11 @@ public enum PLS
Clear,
Random,
Options,
PatternStabilisedTitle,
RepeatingPattern,
StaticPattern,
Generation,
LivingCells,
}

public class Plugin : OrdinaryPlugin
5 changes: 5 additions & 0 deletions projects/plugins/GKLifePlugin/GKLifePlugin.enu
Original file line number Diff line number Diff line change
@@ -7,3 +7,8 @@
06=Clear
07=Random
08=Options
09=Pattern stability
10=The pattern repeats itself every {0} generations!
11=The pattern is static!
12=Generation: {0}
13=Living cells: {0}
5 changes: 5 additions & 0 deletions projects/plugins/GKLifePlugin/GKLifePlugin.rus
Original file line number Diff line number Diff line change
@@ -7,3 +7,8 @@
06=Очистить
07=Случайное заполнение
08=Настройки
09=Стабильность образца
10=Образец повторяется через каждые {0} поколений!
11=Образец статичен!
12=Поколение: {0}
13=Живые клетки: {0}

0 comments on commit 0aa7b4a

Please sign in to comment.