-
Hello all, I am currently building a Chip-8 Emulator in C#. I had an idea to create a GUI in the Console and found Terminal.Gui, which has basically everything that I need for that. The only thing that I can't find a reference for is a canvas-like component. The Chip-8 can display monochrome pixels in a 64 x 32-pixel display. I was hoping to find a canvas component where I could draw "Pixels" (characters) to an area that I define. Essentially I am looking for a way to do ASCII graphics like Dwarf Fortress or a Roguelike that are updateable. Did I miss this functionality? or is this something that I would have to cobble together on my own? Any help would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey that sounds like a fun project. The closest thing to a canvas currently is However if you have a map or world class that knows what it wants displayed as characters then it is very easy to subclass using Terminal.Gui;
Application.Init();
var myView = new MyView();
Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(1),
(l)=>{
myView.SetNeedsDisplay();
return true;
});
Application.Top.Add(myView);
Application.Run();
Application.Shutdown();
class MyView : View
{
public MyView()
{
Width = Dim.Fill();
Height = Dim.Fill();
}
public override void Redraw(Rect bounds)
{
AddRune(2,2,'F');
AddRune(2,3,'F');
AddRune(2,4,Driver.VLine);
AddRune(2,5,Driver.LLCorner);
var r = new Random();
AddRune(r.Next(Bounds.Width),r.Next(Bounds.Height),'X');
}
} I did something similar to this a while back, it might give you a head start although it is relatively simple and never really went anywhere: https://github.com/tznind/Wanderer/blob/master/TerminalGui/UI/MapView.cs |
Beta Was this translation helpful? Give feedback.
-
I think that there is value for a "Canvas" API where users do not need to keep track of what needs to be rendered, but rather just dump their runes in there, and they are recalled and redraw for them. This is to some extent what a Terminal emulator view does (except it implements what I consider a heavy-weight interface to position the content on the screen). |
Beta Was this translation helpful? Give feedback.
Hey that sounds like a fun project.
The closest thing to a canvas currently is
GraphView
which supports scrolling, zooming and drawing lines of fixed characters (for bar graphs, line graphs etc). It supports annotations and is designed to be expandable for newSeries
andAnnotations
.However if you have a map or world class that knows what it wants displayed as characters then it is very easy to subclass
View
and output them at the required locations in the view. For example: