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

Author Topic: Event Problems  (Read 3325 times)

0 Members and 1 Guest are viewing this topic.

Reevesy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Event Problems
« on: August 28, 2013, 01:24:20 am »
I know you must be sick of people having trouble with events, but..

I'm trying to handle the MouseWheelMoved event but I cannot get it to fire.

Definitions and such:
        private RenderWindow SFMLWindow;
        private bool FormOpen = true;
        private BaseObject baseObj = new BaseObject();
        private Grid grid;
        public static Vector2f Offset = new Vector2f(150, 20);
        public static float Scale = 1;
        private Event mainEvent = new Event();

        private void Form1_Load(object sender, EventArgs e)
        {
            SFMLWindow = new RenderWindow(this.Handle);
            SFMLWindow.Size = new Vector2u((uint)ClientSize.Width, (uint)ClientSize.Height);
            SFMLWindow.MouseWheelMoved += new EventHandler<MouseWheelEventArgs>(window_MouseWheelMoved);
            baseObj.Load("Sprites/Base.png");
            grid = new Grid(SFMLWindow);
            MainLoop();
        }
 

Loop:
        private void MainLoop()
        {
            while (FormOpen)
            {            
                Application.DoEvents();
                SFMLWindow.DispatchEvents();
                SFMLWindow.Clear(SFML.Graphics.Color.Black);
                Input.Update();
                grid = new Grid(SFMLWindow);//TODO: Move stuff from constructor to Update().
                MWheelInput();
                //Draw
                baseObj.Draw(SFMLWindow);
                grid.Draw(SFMLWindow);
                //
                SFMLWindow.Display();        
            }
        }
 

How I tried to handle the event:
        private void window_MouseWheelMoved(object sender, MouseWheelEventArgs e)
        {
            //Tried this first.
            Console.WriteLine("roll");
        }

        private void MWheelInput()
        {
            if (mainEvent.Type == EventType.MouseWheelMoved)
            {
                Console.WriteLine("roll");
            }
        }

Neither seem to work, it's probably something stupid. Any help would be much appreciated.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Event Problems
« Reply #1 on: August 28, 2013, 02:28:20 am »
Since your hosting SFML inside a control (in this case the form) don't try to handle SFML's events, instead directly handle the control's events.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Reevesy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Event Problems
« Reply #2 on: August 28, 2013, 02:57:34 am »
        public Form1()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
            this.FormClosed += new FormClosedEventHandler(this.Form1_Closed);
            this.ResizeEnd += new EventHandler(this.Form1_ResizeEnd);
            this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
        }

        void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            Console.WriteLine("HI");
        }
 

Nothing, all the other events fire.
« Last Edit: August 28, 2013, 02:59:45 am by Reevesy »

Reevesy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Event Problems
« Reply #3 on: August 29, 2013, 05:41:33 am »
Any ideas?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Event Problems
« Reply #4 on: August 29, 2013, 04:13:51 pm »
        public Form1()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
            this.FormClosed += new FormClosedEventHandler(this.Form1_Closed);
            this.ResizeEnd += new EventHandler(this.Form1_ResizeEnd);
            this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
        }

        void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            Console.WriteLine("HI");
        }
 

Nothing, all the other events fire.

This works fine for me. I set a breakpoint on the Form1_MouseWheel and it was called when I scrolled the mouse wheel.
« Last Edit: August 29, 2013, 04:16:00 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything