Skip to content

Commit

Permalink
Added menu base.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Mc-kenzie committed Jul 12, 2020
1 parent 222366d commit 2c47d82
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CompactGraphics/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ public struct SmallRect
}
#endregion
/// <summary>
/// Initilise the virtual screen at the currrent cosole dimensions.
/// </summary>
public Graphics() : this(Console.WindowWidth, Console.WindowHeight)
{

}
/// <summary>
/// Initilises the Virtual screen.
/// </summary>
/// <param name="w">width of the screen</param>
Expand Down
57 changes: 57 additions & 0 deletions CompactGraphics/Menu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;

namespace CompactGraphics
{
/// <summary>
/// A base for Widget Based Menus
/// </summary>
public class Menu
{
/// <summary>
/// The graphics object to link to
/// </summary>
protected Graphics g;
/// <summary>
/// The list of widgets on page, in draw order.
/// </summary>
protected List<Widget> onPage;
/// <summary>
/// The numeric status of the menu, used for navigation.
/// </summary>
public int Status { get { return status; } }
protected int status;
public Menu()
{
g = new Graphics(Console.WindowWidth, Console.WindowHeight);
onPage = new List<Widget>();
}
public Menu(Graphics g)
{
this.g = g;
onPage = new List<Widget>();
}
/// <summary>
/// Steps to the next frame by adding all the widgets to the current frame.
/// DOES NOT PUSH
/// </summary>
public virtual void StepFrame()
{
foreach (Widget widget in onPage)
{
widget.Draw(g);
}
}
/// <summary>
/// Steps to the next frame by adding all the widgets to teh current frame, giving them the users input.
/// </summary>
/// <param name="keyinfo">The input to handle</param>
public virtual void StepFrame(ConsoleKeyInfo keyinfo)
{
foreach (Widget widget in onPage)
{
widget.Draw(g, keyinfo);
}
}
}
}
16 changes: 12 additions & 4 deletions TestApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


using CompactGraphics;
namespace TestApp
{
class Program
{
static void Main(string[] args)
{
Graphics graphics = new Graphics();

//Contunually draw frames
while (true)
{
//draw the frame counter at the top of the screen.
graphics.Draw($"Fps: {graphics.Fps}", ConsoleColor.White, 0, 0);
//now that all drawing is done, push the frame to the buffer.
graphics.pushFrame();
}
}
}
}
3 changes: 3 additions & 0 deletions TestApp/TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CompactGraphics">
<HintPath>..\CompactGraphics\bin\Debug\netstandard2.0\CompactGraphics.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down

0 comments on commit 2c47d82

Please sign in to comment.