So I'm back to make yet another attempt on creating a GUI library for DarkGDK .NET. I know at this point this is mostly to my benefit, but I want to do this and I'm pretty far along! I have a working event system and proper mouse / keyboard I/O. The problem I am having is in rendering, and there are actually two problem areas for me.
The first is this. Right now I am rendering similar to the following:
class Component {
private DarkGDK.Basic2D.Bitmap my_bmp;
// ...
protected override void Draw () {
// preserve the bitmap
DarkGDK.Basic2D.Bitmap save = DarkGDK.Basic2D.Bitmap.Current;
// set my window's bitmap as the current bitmap
my_bmp.SetCurrent ();
// render the window to the bitmap
// a bunch of drawing routines, omitted for brevity
Render ();
// render the child controls of this window
foreach (Component c in children)
c.Draw ();
// switch back to the screen if save is null
// otherwise switch back to the upper level bitmap
if (save == null) {
DarkGDK.Basic2D.ScreenBitmap.SetCurrent ();
DarkGDK.Basic2D.ScreenBitmap.CopyFrom (my_bmp, 0, 0, size.Width, size.Height, location.X, location.Y, location.X+size.Width, location.Y+size.Height);
}
else {
save.SetCurrent ();
my_bmp.CopyTo (0, 0, size.Width, size.Height, save, location.X, location.Y, location.X+size.Width, location.Y+size.Y);
}
}
}
This code, no matter how hard I try, will not correctly render the bitmap to the screen. Here is why I designed it this way. A window may be contained in another window, and this code attempts to solve the problem of the window overrunning it's parent window. I switched to a bitmap approach for this reason. Originally I was drawing to the bitmap, converting it to an image, then pasting to the screen. Obviously my frame rates dropped like a lead brick. The next solution was to direct-draw everything, but the problem was the controls would overrun the bounds of the parent. Even if I solved the problem of the drawing staying in-bounds of the parent's client area (enforce bounds-checking on each child against the parent, breaks encapsulation) I couldn't hope to use a routine like ShowText() to place text in a control, as there is no way to avoid an overrun without tons of extra processing (framerate issue.) So I switched to this approach, hoping to simply nest the bitmaps instead to improve frame rate.
So the question is, how can I fix the code I have for it to work (since right now I just get blank output), or how can I better draw my UI objects to avoid this problem entirely? Even with each widget using pure drawing commands to update itself, the frame rate drops significantly for each additional UI component. I am testing on a low-quality machine, but I feel like a UI should be lightweight enough to not hamper game performance. Any ideas?