Добавьте файлы проекта.

This commit is contained in:
Савелій Савёнак
2023-01-02 19:08:46 +03:00
parent 08c0b31845
commit b16a3b1adc
14 changed files with 539 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
using Gtk;
using CairoObjective;
using System.Linq;
using System.Diagnostics;
namespace FractalTree
{
class CairoWindow : Window
{
DrawingArea drawing = new DrawingArea();
DrawObjects.Grid grid;
int Scaler = 50;
int offsetX = 0;
int offsetY = 0;
public CairoWindow(string title) : base(title)
{
Fullscreen();
DeleteEvent += delegate { Application.Quit(); };
drawing.Drawn += OnDrawn;
KeyPressEvent += CairoWindow_KeyPressEvent;
Add(drawing);
ShowAll();
Line.DefaultSize = 2;
}
private void CairoWindow_KeyPressEvent(object o, KeyPressEventArgs args)
{
if(args.Event.Key == Gdk.Key.equal)
{
Trace.WriteLine("+");
Scaler++;
QueueDraw();
}
if (args.Event.Key == Gdk.Key.minus && Scaler > 1)
{
Trace.WriteLine("-");
Scaler--;
QueueDraw();
}
if (args.Event.Key == Gdk.Key.a)
{
Trace.WriteLine("←");
offsetX-=10;
QueueDraw();
}
if (args.Event.Key == Gdk.Key.d)
{
Trace.WriteLine("→");
offsetX+=10;
QueueDraw();
}
if (args.Event.Key == Gdk.Key.w)
{
Trace.WriteLine("↑");
offsetY += 10;
QueueDraw();
}
if (args.Event.Key == Gdk.Key.s)
{
Trace.WriteLine("↓");
offsetY -= 10;
QueueDraw();
}
}
private void OnDrawn(object sender, DrawnArgs args)
{
MainDrawer();
}
private void MainDrawer()
{
grid = new(AllocatedWidth, AllocatedHeight, Scaler, offsetX, offsetY);
Set.Context = Gdk.CairoHelper.Create(drawing.GdkWindow);
Set.Background(new Cairo.Color(0, 0, 0));
foreach(CairoObjective.DrawObjects.Line gridline in grid.LinesHorizontal)
{
Line.Make(gridline, new Cairo.Color(1,1,1));
}
foreach (CairoObjective.DrawObjects.Line gridline in grid.LinesVertical)
{
Line.Make(gridline, new Cairo.Color(1, 1, 1));
}
}
}
}

View File

@@ -0,0 +1,49 @@
using CairoObjective.DrawObjects;
using System;
using System.Diagnostics;
namespace FractalTree.DrawObjects
{
internal class Grid
{
public Line[] LinesHorizontal;
public Line[] LinesVertical;
int Scaler;
int Width;
int Height;
int offsetX;
int offsetY;
/// <summary>
/// Make Grid Array of lines
/// </summary>
/// <param name="Width">Width of Window</param>
/// <param name="Height">Height of Window</param>
/// <param name="Scaler">Pixels Per Lines</param>
public Grid(int Width, int Height, int Scaler, int offsetX, int offsetY)
{
this.Width = Width;
this.Height = Height;
this.Scaler = Scaler;
this.offsetX = offsetX;
this.offsetY = offsetY;
LinesHorizontal = new Line[this.Width / Scaler + 1];
LinesVertical = new Line[this.Height / Scaler + 1];
MakeHorizontal();
MakeVertical();
}
private void MakeHorizontal()
{
for(int i = 0; i < Width / Scaler + 1; i++)
{
LinesHorizontal[i] = new Line(i * Scaler + offsetX, 0, i * Scaler, Height);
}
}
private void MakeVertical()
{
for (int i = 0; i < Height / Scaler + 1; i++)
{
LinesVertical[i] = new Line(0, i * Scaler, Width, i * Scaler);
}
}
}
}

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CairoSharp" Version="3.24.24.38" />
<PackageReference Include="GtkSharp" Version="3.24.24.38" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CairoObjective\CairoObjective.csproj" />
</ItemGroup>
</Project>

15
FractalTree/Program.cs Normal file
View File

@@ -0,0 +1,15 @@
using Gtk;
namespace FractalTree
{
internal class Program
{
static void Main()
{
Application.Init();
//Create the Window
new CairoWindow("Window");
Application.Run();
}
}
}