2018-02-22 09:44:55 -08:00
|
|
|
using System;
|
|
|
|
|
|
|
|
public class LifeWindow
|
|
|
|
{
|
|
|
|
private LifeBoard lifeBoard;
|
|
|
|
private LifeRender lifeRender;
|
|
|
|
|
2018-07-23 09:16:54 -07:00
|
|
|
void ResizeEvt(object sender, EventArgs ev)
|
2018-02-22 09:44:55 -08:00
|
|
|
{
|
2018-11-06 01:39:14 -08:00
|
|
|
lifeRender.RenderLayout((Efl.Ui.Win)sender);
|
2018-02-22 09:44:55 -08:00
|
|
|
}
|
|
|
|
|
2018-07-23 09:16:54 -07:00
|
|
|
void QuitEvt(object sender, EventArgs ev)
|
2018-02-22 09:44:55 -08:00
|
|
|
{
|
|
|
|
// quit the mainloop
|
2018-11-06 01:39:14 -08:00
|
|
|
Efl.Ui.Config.Exit();
|
2018-02-22 09:44:55 -08:00
|
|
|
}
|
|
|
|
|
2018-11-06 01:39:14 -08:00
|
|
|
void TouchEvt(object sender, Efl.Input.InterfacePointerDownEvt_Args ev)
|
2018-02-22 09:44:55 -08:00
|
|
|
{
|
|
|
|
int cellx, celly;
|
2018-11-06 01:39:14 -08:00
|
|
|
Efl.Ui.Win win = (Efl.Ui.Win)sender;
|
2018-07-23 09:16:54 -07:00
|
|
|
var position = ev.arg.GetPosition();
|
2018-02-22 09:44:55 -08:00
|
|
|
lifeRender.CellForCoords(win, position, out cellx, out celly);
|
|
|
|
|
2018-07-23 09:16:54 -07:00
|
|
|
int i = LifeBoard.IndexForPosition(cellx, celly);
|
2018-02-22 09:44:55 -08:00
|
|
|
lifeBoard.Cells[i] = !lifeBoard.Cells[i];
|
|
|
|
lifeRender.RenderCell(win, cellx, celly);
|
|
|
|
}
|
|
|
|
|
2018-11-06 01:39:14 -08:00
|
|
|
void KeyDownEvt(object sender, Efl.Input.InterfaceKeyDownEvt_Args ev)
|
2018-02-22 09:44:55 -08:00
|
|
|
{
|
2018-11-06 01:39:14 -08:00
|
|
|
Efl.Ui.Win win = (Efl.Ui.Win)sender;
|
2018-07-23 09:16:54 -07:00
|
|
|
if (ev.arg.GetKey() == "space")
|
2018-02-22 09:44:55 -08:00
|
|
|
lifeBoard.TogglePause(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
public LifeWindow()
|
|
|
|
{
|
2018-11-06 01:39:14 -08:00
|
|
|
Efl.Ui.Win win = new Efl.Ui.Win(null, (Efl.Ui.Win ewin) => {
|
|
|
|
ewin.SetWinType(Efl.Ui.WinType.Basic);
|
2018-02-22 09:44:55 -08:00
|
|
|
ewin.SetText("EFL Life");
|
|
|
|
ewin.SetAutohide(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when the user clicks "close" on a window there is a request to hide
|
2018-11-06 01:39:14 -08:00
|
|
|
((Efl.Gfx.Entity)win).HideEvt += QuitEvt;
|
2018-02-22 09:44:55 -08:00
|
|
|
|
2018-11-06 01:39:14 -08:00
|
|
|
Eina.Size2D sz;
|
2018-07-23 09:16:54 -07:00
|
|
|
sz.W = (int)(10 * LifeBoard.Width * win.GetScale());
|
|
|
|
sz.H = (int)(10 * LifeBoard.Height * win.GetScale());
|
2018-02-22 09:44:55 -08:00
|
|
|
|
|
|
|
lifeBoard = new LifeBoard();
|
|
|
|
lifeRender = new LifeRender(win, lifeBoard);
|
|
|
|
lifeRender.Refresh(win);
|
|
|
|
|
2018-11-06 01:39:14 -08:00
|
|
|
((Efl.Gfx.Entity)win).ResizeEvt += ResizeEvt;
|
|
|
|
((Efl.Input.Interface)win).PointerDownEvt += TouchEvt;
|
|
|
|
((Efl.Input.Interface)win).KeyDownEvt += KeyDownEvt;
|
2018-02-22 09:44:55 -08:00
|
|
|
|
|
|
|
win.SetSize(sz);
|
2018-07-23 09:16:54 -07:00
|
|
|
|
|
|
|
lifeBoard.Run(win);
|
2018-02-22 09:44:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Example
|
|
|
|
{
|
|
|
|
public static void Main()
|
|
|
|
{
|
2018-11-06 01:39:14 -08:00
|
|
|
Efl.All.Init(Efl.Components.Ui);
|
2018-02-22 09:44:55 -08:00
|
|
|
|
2018-07-23 09:16:54 -07:00
|
|
|
var lifeWin = new LifeWindow();
|
2018-02-22 09:44:55 -08:00
|
|
|
|
|
|
|
// start the mainloop
|
2018-11-06 01:39:14 -08:00
|
|
|
Efl.Ui.Config.Run();
|
2018-02-22 09:44:55 -08:00
|
|
|
|
2018-11-06 01:39:14 -08:00
|
|
|
Efl.All.Shutdown();
|
2018-02-22 09:44:55 -08:00
|
|
|
}
|
|
|
|
}
|