The plant to imprint ascii into a bitmap was quite easy, although using C#'s internal Color values is bit strange, because DarkGray value is actually brighter than Gray, for some reason. I think I need to create my own set of colors.
public Gui(ref Graphics g)
{
//assign form's drawing surface for gui class
this.g = g;
const int amt = sizeof(Glyphs) - 1;
//tile data of glyphs
tiles = new Glyph[amt]
{
new Glyph ( ' ', Color.Black, Color.Black, "Darkness" ),
new Glyph ( '#', Color.Green, Color.DarkGray, "Wall" ),
new Glyph ( '.', Color.Gray, Color.Black, "Floor" )
};
//create glyph tiles source image
glyphs = new Bitmap(
fontSize.Width*fontGrid.Width,
fontSize.Height*fontGrid.Height);
Graphics bm = Graphics.FromImage(glyphs);
bm.Clear(Color.Blue);
Font fnt = new Font("Consolas", 16);
Point source = new Point(0, 0);
StringFormat drawFormat = new StringFormat();
for (int t=0; t<amt; t++)
{
//draw background slab
SolidBrush bgBrush = new SolidBrush(tiles[t].backgroundColor);
Rectangle rect = new Rectangle(source.X, source.Y, fontSize.Width, fontSize.Height);
bm.FillRectangle(bgBrush, rect);
//draw letter
string str = tiles[t].ascii.ToString();
SolidBrush letterBrush = new SolidBrush(tiles[t].color);
bm.DrawString(str, fnt, letterBrush, source.X, source.Y, drawFormat);
//move to next source location
source.X += fontSize.Width;
if (source.X>=glyphs.Width)
{
source.X = 0;
source.Y += fontSize.Height;
}
}
fnt.Dispose();
}
Two new observations I made were that enum isn't auto-converted into int even it's declared using int internal type. And also that even if you have a struct, you need to declare each variable 'public' if you want to use them outside the struct, even if the struct itself is declared public. I guess it makes sense, but it's a bit different from C++.