Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unsigned integers and negative cursor positions  (Read 3064 times)

0 Members and 1 Guest are viewing this topic.

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Unsigned integers and negative cursor positions
« on: May 25, 2010, 05:26:23 am »
This is happening for me in .NET, but not sure if its from the SFML core. When the cursor is out of the screen to the left or top, the position relative to the window is negative. Normally, SFML won't even send these events since the cursor is out of the screen. However, when passing a manual handle and you click (and hold) on the form then move the cursor out of the form, these events will continue to be sent. Here is a minimalist example in C#:

Code: [Select]
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using SFML.Graphics;
using SFML.Window;
using Color = SFML.Graphics.Color;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            Application.Run(new Form1());
        }
    }

    public class Form1 : Form
    {
        readonly RenderWindow rw;

        string _displayText = string.Empty;

        public Form1()
        {
            InitializeComponent();

            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

            rw = new RenderWindow(Handle);

            rw.MouseMoved += rw_MouseMoved;

            Focus();
        }

        void InitializeComponent()
        {
            SuspendLayout();
            AutoScaleDimensions = new SizeF(6F, 13F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new Size(284, 262);
            ResumeLayout(false);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                rw.DispatchEvents();
                rw.Clear();

                using (var text = new Text { Color = Color.White, Font = SFML.Graphics.Font.DefaultFont, Size = 16 })
                {
                    text.DisplayedString = _displayText;
                    rw.Draw(text);
                }

                rw.Display();
            }
            finally
            {
                Invalidate();
            }
        }

        void rw_MouseMoved(object sender, MouseMoveEventArgs e)
        {
            _displayText = e.X + "," + e.Y;
        }
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unsigned integers and negative cursor positions
« Reply #1 on: May 25, 2010, 08:42:19 am »
Sorry, I don't understand the problem. Do you mean that:
- SFML should handle mouse coordinates outside the window when the mouse button is clicked
- SFML sometimes returns negative mouse coordinates, which is not supposed to happen
?
Laurent Gomila - SFML developer

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Unsigned integers and negative cursor positions
« Reply #2 on: May 25, 2010, 11:16:15 am »
The problem is that SFML is returning negative coordinates but in an unsigned number, so when it gets to the .NET bindings it contains an invalid value.

Put that demo code I gave into a C# winform application, click (and hold) on the screen, then move the cursor outside of the screen and you should see what I mean.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unsigned integers and negative cursor positions
« Reply #3 on: May 25, 2010, 07:44:18 pm »
It's fixed (in the sfml2 branch).

Thanks for your feedback :)
Laurent Gomila - SFML developer

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Unsigned integers and negative cursor positions
« Reply #4 on: May 25, 2010, 08:02:57 pm »
And thank you for the quick fix and understanding my gibberish when I'm tired. ;)

 

anything