I’m trying to use a MessageBox as a dialog box in which the user can enter a password. It’s no problem to add buttons to the MessageBox, but when I add a TextBox its coordinates are relative to the underlying screen instead of the MesaageBox as expected. Furthermore it’s not possible to update the text of the TextBox using Invalidate().
Is the MessageBox able to have other children than buttons?
MessageBox serves a specific purpose. Invalidate doesn’t work because Glide itself is paused while the box is up, as it’s waiting for a response from the user (to return so the code can continue). What you’re trying to do is best implemented by other means.
You’d have to write your own DisplayObjectContainer.
namespace MyNamespace
{
public class DialogBox : DisplayObjectContainer
{
public DialogBox(string name, ushort alpha, int x, int y, int width, int height)
{
Name = name;
Alpha = alpha;
X = x;
Y = y;
Width = width;
Height = height;
}
public override void Render()
{
int x = Parent.X + X;
int y = Parent.Y + Y;
// Draw the DialogBox background here.
// ...
// ...
// Render this DialogBox's children.
base.Render();
}
}
}
Then you’d do something like this:
void Open()
{
// Disable interactivity on all children
for (int i = 0; i < window.NumChildren; i++)
window[i].Interactive = false;
window.AddChild(canvas); // This canvas draws a rectangle that acts as the mask.
window.AddChild(dialogBox); // Then you add your DialogBox.
window.Invalidate(); // Then you redraw everything.
}