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

Author Topic: Subscribing for input events went wrong  (Read 2606 times)

0 Members and 2 Guests are viewing this topic.

zeroFLAMES

  • Newbie
  • *
  • Posts: 2
    • View Profile
Subscribing for input events went wrong
« on: June 17, 2017, 05:16:32 pm »
I have started new project in VS2017 sfml.net with simple test of subscribing for MouseMove and MouseButtonPressed. Here are key files:

using SFML.Graphics;
using SFML.Window;
using System;
using UnforgottenRealms.Core.Input;
using UnforgottenRealms.Window;

namespace UnforgottenRealms
{
    class Program
    {
        static void Main(string[] args)
        {
            var settings = new ContextSettings
            {
                AntialiasingLevel = 8
            };

            var window = new GameWindow(new VideoMode(640, 480), settings);
            var inputProcessor = new InputProcessor(window, 1);
            inputProcessor.Layers[0].Handles.Add(new Test(0, 100));
            inputProcessor.Layers[0].Handles.Add(new Test(500, 600));
            while (window.IsOpen())
            {
                window.DispatchEvents();
                window.Clear(new Color(100, 100, 200));
                window.Display();
            }
        }

        class Test : InputHandle
        {
            private int x, y;

            public Test(int x, int y)
            {
                this.x = x;
                this.y = y;
            }

            public override bool ContainsMouse(int x, int y)
            {
                return (x > this.x && x < this.y);
            }

            public override void Trigger()
            {
                Console.WriteLine("Triggered!");
            }
        }
    }
}
 

using SFML.Graphics;
using SFML.Window;
using System.Threading.Tasks;

namespace UnforgottenRealms.Core.Input
{
    public class InputProcessor
    {
        public LayerCollection Layers { get; }

        private RenderWindow window;

        public InputProcessor(RenderWindow window, int layersCount = 0)
        {
            this.window = window;
            Layers = new LayerCollection(layersCount);

            window.MouseButtonPressed += ProcessMouseButtonPress;
            window.MouseMoved += ProcessMouseMovement;
        }

        private void ProcessMouseButtonPress(object sender, MouseButtonEventArgs e)
        {
        }

        private void ProcessMouseMovement(object sender, MouseMoveEventArgs e)
        {
            var h = Layers.MatchHandle(e.X, e.Y);
            if (h != null)
            {
                h.Trigger();
            }
        }
    }
}
 

GameWindow derives from RenderWindow and there is nothing special about it.
I noticed that my Console.WriteLines does not trigger, after debugging with breakpoint I found out that `ProcessMouseMovement` is triggered on mouse button release and `ProcessMouseButtonPress` on mouse wheel movement. Moreover property `MouseMoveEventArgs.X` is always equal to zero.
It confuses me because I have already done some stuff in SFML.Net and I am rather familiar with it.
What do I do?

SFML.Net downloaded from NuGet and CSFML from website.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Subscribing for input events went wrong
« Reply #1 on: June 17, 2017, 05:42:31 pm »
Your versions of SFML.Net and CSFML probably don't match.
Laurent Gomila - SFML developer

zeroFLAMES

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Subscribing for input events went wrong
« Reply #2 on: June 17, 2017, 05:55:24 pm »
I see CSFML is 2.4 and SFML.Net 2.1.5, so NuGet distribution isn't maintained?
Ah, I see SFML.Net is behind C binding, however 2.2 version of .net is available on website
« Last Edit: June 17, 2017, 06:01:17 pm by zeroFLAMES »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Subscribing for input events went wrong
« Reply #3 on: June 17, 2017, 06:34:40 pm »
NuGet distributions are not maintained by the team.

SFML.Net 2.2 is available, yes, and the current sources on github are 2.4 and should work fine.
Laurent Gomila - SFML developer

 

anything