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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - zeroFLAMES

Pages: [1]
1
DotNet / Re: Subscribing for input events went wrong
« 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

2
DotNet / 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.

Pages: [1]