2023-01-02 19:08:46 +03:00
|
|
|
|
using Gtk;
|
|
|
|
|
using CairoObjective;
|
|
|
|
|
using GLib;
|
|
|
|
|
using FractalTreeGtk.Draw;
|
|
|
|
|
|
|
|
|
|
namespace FractalTreeGtk
|
|
|
|
|
{
|
|
|
|
|
internal class CairoWindow : Window
|
|
|
|
|
{
|
2023-01-03 00:17:18 +03:00
|
|
|
|
static int fractallevels = 2;
|
2023-01-02 19:08:46 +03:00
|
|
|
|
DrawingArea drawing = new DrawingArea();
|
2023-01-03 00:17:18 +03:00
|
|
|
|
Fractal fractal = new Fractal(fractallevels);
|
2023-01-02 19:08:46 +03:00
|
|
|
|
public CairoWindow(string title) : base(title) {
|
|
|
|
|
Fullscreen();
|
|
|
|
|
drawing.Drawn += Drawing_Drawn;
|
|
|
|
|
Add(drawing);
|
|
|
|
|
ShowAll();
|
2023-01-03 00:17:18 +03:00
|
|
|
|
KeyPressEvent += CairoWindow_KeyPressEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CairoWindow_KeyPressEvent(object o, KeyPressEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if(args.Event.Key == Gdk.Key.equal)
|
|
|
|
|
{
|
|
|
|
|
fractal = new Fractal(++fractallevels);
|
|
|
|
|
QueueDraw();
|
|
|
|
|
}
|
|
|
|
|
if (args.Event.Key == Gdk.Key.minus && fractallevels > 1)
|
|
|
|
|
{
|
|
|
|
|
fractal = new Fractal(--fractallevels);
|
|
|
|
|
QueueDraw();
|
|
|
|
|
}
|
2023-01-02 19:08:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Drawing_Drawn(object o, DrawnArgs args)
|
|
|
|
|
{
|
2023-01-03 18:32:30 +03:00
|
|
|
|
long branches = 0;
|
|
|
|
|
Text.CenterText = false;
|
2023-01-02 19:08:46 +03:00
|
|
|
|
args.Cr.Translate(AllocatedWidth / 2, AllocatedHeight);
|
|
|
|
|
Set.Context = args.Cr;
|
|
|
|
|
Set.Background(new Cairo.Color(0, 0, 0));
|
2023-01-03 18:32:30 +03:00
|
|
|
|
foreach (CairoObjective.DrawObjects.Line[] lines in (CairoObjective.DrawObjects.Line[][])fractal.Fractallines)
|
2023-01-02 19:08:46 +03:00
|
|
|
|
{
|
2023-01-03 18:32:30 +03:00
|
|
|
|
foreach (CairoObjective.DrawObjects.Line line in lines) {
|
|
|
|
|
branches++;
|
2023-01-02 19:08:46 +03:00
|
|
|
|
Line.Make(line);
|
2023-01-03 18:32:30 +03:00
|
|
|
|
}
|
2023-01-02 19:08:46 +03:00
|
|
|
|
}
|
2023-01-03 18:32:30 +03:00
|
|
|
|
Text.Make($"Total Branches: {branches}", -(AllocatedWidth / 2), -30, new Cairo.Color(1, 1, 1));
|
|
|
|
|
Text.Make($"Levels: {fractallevels}", -(AllocatedWidth / 2), -5, new Cairo.Color(1,1,1));
|
2023-01-02 19:08:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|