Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline s990we  
#1 Posted : Wednesday, February 15, 2012 4:58:04 PM(UTC)
s990we

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...

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Benjamin  
#2 Posted : Wednesday, February 15, 2012 5:21:24 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
The samples themselves are updated. I guess something broke that generates the templates from the samples. Please use the sample directly in the \Samples folder!

The Font change makes sense because the overloads have changed a few weeks back to solve problems people had reusing the same font and changing colors. The rest of the changes are really old. Strange that those problems are in the Windows Form Template.

I will fix it for the next nightly release. Thanks for the bug report!
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.049 seconds.