Joined: 8/24/2011(UTC) Posts: 7
|
When creating a windows form project (the template is outdated?) I get 4 errors Backgound color Code:Screen.BackgroundColor = Color.Grey;
// is now
WindowsApplication.BackgroundColor = Color.Grey;
Font drawing Code:Font.Default.DrawCentered("Mouse position=" + Input.Mouse.Position,
Point.Half);
// is now
Font.Default.Draw("Mouse position=" + Input.Mouse.Position, Rectangle.FromCenter(ScreenSpace.DrawArea.Center, Size.Half));
Start: Code:WindowsApplication.Start(form, form.viewportPanel, delegate
{
Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
Font.Default.Draw("Mouse position=" + Input.Mouse.Position, Rectangle.FromCenter(ScreenSpace.DrawArea.Center, Size.Half));
});
// is now?
WindowsApplication.SetEditorForm(form, form.viewportPanel);
WindowsApplication.Start(delegate
{
Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
Font.Default.Draw("Mouse position=" + Input.Mouse.Position, Rectangle.FromCenter(ScreenSpace.DrawArea.Center, Size.Half));
});
This seems to work except it changes BackgroundColor on the form to whatever WindowsApplication.BackgroundColor is set to. It also resizes the form to the resolution that is defines in Settings.xml Hack to fix this Code:using (ExampleForm form = new ExampleForm())
{
System.Drawing.Color color = form.BackColor;
System.Drawing.Size size = form.Size;
WindowsApplication.SetEditorForm(form, form.viewportPanel);
form.BackColor = color;
form.Size = size;
WindowsApplication.Start(delegate
{
Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
Font.Default.Draw("Mouse position=" + Input.Mouse.Position, Rectangle.FromCenter(ScreenSpace.DrawArea.Center, Size.Half));
});
};
Also I cant find any replacement for Code:Window.SetViewportControl(viewportPanel);
But that dont seems to be needed? The main problem I had is that Input.Keyboard dont work (as well as it should?). Code:Font.Default.Draw("Is a pressed: " + Input.Keyboard.IsPressed(InputButton.A), Rectangle.FromCenter(ScreenSpace.DrawArea.Center + Point.UnitY * Font.Default.LineHeight, Size.Half));
This text should say "Is A pressed: true" when I press A, but it does not. The WindowsKeyboard hooks to the owning form's KeyDown, KeyUp, KeyPress events. Hack to fix this Code:// this goes into the form constructor
CaptureKeyboard();
// and the code
private void CaptureKeyboard()
{
foreach (Control c in Controls)
{
c.KeyDown += new KeyEventHandler(delegate(object sender, KeyEventArgs e)
{
if (IsMouseOnControl(viewportPanel))
{
this.OnKeyDown(e);
e.Handled = true;
}
});
c.KeyUp += new KeyEventHandler(delegate(object sender, KeyEventArgs e)
{
if (IsMouseOnControl(viewportPanel))
{
this.OnKeyUp(e);
e.Handled = true;
}
});
c.KeyPress += new KeyPressEventHandler(delegate(object sender, KeyPressEventArgs e)
{
if (IsMouseOnControl(viewportPanel))
{
this.OnKeyPress(e);
e.Handled = true;
}
});
}
}
private bool IsMouseOnControl(Control c)
{
System.Drawing.Point mousePos = PointToClient(MousePosition);
if (mousePos.X > c.Left &&
mousePos.X < c.Right &&
mousePos.Y > c.Top &&
mousePos.Y < c.Bottom)
{
return true;
}
return false;
}
It works except for when I press a key inside the panel then leave with the key still pressed. (must release key inside panel) But it works good enough for me...
|