Announcement

Collapse
No announcement yet.

OnMouseEnter behavior buttons

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    New issue came up after integrating above code, for some reason there is something going wrong with the translations.

    i have 2 buttonrows, each row containing 10 buttons. When i tap and hold the button on the top row i see that its being held since the button changes, however the button below it also changes even though its not being hit by the mouse button..

    Comment


    • #17
      For the sake of making my new issue clearer i've recorded it:

      https://www.youtube.com/watch?v=eYPc3VhLiQY


      On the video you can see that the actual positioning is right(The first button gets hit which results in the text fading a bit), however the actually OnEnter happens below the tapped button, any idea???

      Comment


      • #18
        I do not fully understand the problem. Any button should fade if the cursor is above it.
        Did you try to do the same thing with the mouse cursor instead of touching it?

        Comment


        • #19
          Originally posted by yhplr View Post
          I do not fully understand the problem. Any button should fade if the cursor is above it.
          Did you try to do the same thing with the mouse cursor instead of touching it?
          Yep same behavior. and not any button should fade, there is a limit on the amount of buttons that can have the checkmark(10 buttons can have checkmark) when the limit is reached others buttons being interacted should just fade

          Comment


          • #20
            Hello there Maxdg !

            It would help a lot if you were to provide some of the application code so we can test it and provide further help. Thanks!

            Comment


            • #21
              Hey Minolo ,

              I can provide some, but not alot since the project is quite big. Ill post the essentials below.


              To create the buttons:

              Code:
              public class TopTable : Grid
                      {
                          public TopTable()
                              : base()
                          {
                              this.SetTopGrid();
                              this.CreateButtons();
              
                              this.IsVisible = true;
                          }
              
                          private void SetTopGrid()
                          {                
                              this.Margin = new Thickness(75, 100, 500, 0);
                              this.Width = 50;
                              this.Height = 450;
                              this.IsBorder = false;
                              //Sets all RowDefenitions
                              for (int i = 0; i <= 4; i++)
                              {
                                  this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(i, GridUnitType.Auto) });
                              }
                              for (int i = 0; i <= 10; i++)
                              {
                                  this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(i, GridUnitType.Auto) });
                              }
                          }
              
                          private void CreateButtons()
                          {
              
                              for (int i = 0; i < 40; i++)
                              {
                                  int d = i + 1;
                                  ToggleButton cancelButton = new ToggleButton()
                                  {
                                      FontPath = WaveContent.Art.Font.Eurostile_24_ttf,
                                      Margin = new Thickness(2f),
                                      IsBorder = false,
                                      BackgroundImage = WaveContent.Art.Buttons.game_button_normal_png,
                                      ID = d,
                                      Foreground = WaveEngine.Common.Graphics.Color.Red,
                                      Text = d.ToString(),
                                      HorizontalAlignment = HorizontalAlignment.Center,
                                      VerticalAlignment = VerticalAlignment.Center,
                                      Width = 82,
                                      Height = 67,
                                  };
                                  cancelButton.Entity.AddComponent(new AnimationUI());
              
                                  //cancelButton.Entity.AddComponent (new MouseEventBehavior ());
                                  cancelButton.state = ToggleButton.ToggleState.uncheck;
                                  cancelButton.previousState = cancelButton.state;
              
              
              
                                  Transform2D transform = cancelButton.Entity.FindComponent<Transform2D>();
                                  var animComponent = cancelButton.Entity.FindComponent<AnimationUI>();
                                  Vector2 originScale = transform.LocalScale;
                                  cancelButton.Entity.AddComponent (new NewMouseEnterBehavior ());
                                  NewMouseEnterBehavior mouse = cancelButton.Entity.FindComponent<NewMouseEnterBehavior> ();
                                  //touch.TouchTap += (sender, args) =>
                                  mouse.MouseEnter += (sender, args) =>
                                  {             
                                      if (cancelButton.state == ToggleButton.ToggleState.uncheck)
                                      {
                                          if (DataHandler.selected <= maxvalue)
                                          {
                                              cancelButton.BackgroundImage = WaveContent.Art.Buttons.game_button_selected_png;
                                              cancelButton.state = ToggleButton.ToggleState.check;
                                              cancelButton.previousState = cancelButton.state;
                                              cancelButton.selected = true;
                                              DataHandler.selected++;
                                          }                                       
                                      }
                                      else
                                      {
                                          cancelButton.BackgroundImage = WaveContent.Art.Buttons.game_button_normal_png;
                                          cancelButton.state = ToggleButton.ToggleState.uncheck;
                                          cancelButton.previousState = cancelButton.state;
                                          cancelButton.selected = false;
                                          DataHandler.selected--;
                                      }
                                      DataHandler.CheckStates();
              
              
                                  };
                                  cancelButton.Hit += (sender, EventArgs) =>
                                  {
              
                                      cancelButton.BackgroundImage = WaveContent.Art.Buttons.game_button_selectedhit_png;
                                      cancelButton.state = ToggleButton.ToggleState.selecthit;
              
              
                                  };
                                  if (i >= 10)
                                  {
              
                                      int r;
                                      int c;
                                      r = i / 10;
                                      c = i % 10;                        
                                      if (c < 0)
                                          c = 0;
                                      cancelButton.SetValue(GridControl.RowProperty, r);
                                      cancelButton.SetValue(GridControl.ColumnProperty, c);
                                  }
                                  else
                                  {
                                      cancelButton.SetValue(GridControl.RowProperty, 0);
                                      cancelButton.SetValue(GridControl.ColumnProperty, i);
                                  }
              
              
                                  this.Add(cancelButton);
                                  DataHandler.toggles.Add(cancelButton);
              
                              }
              
                          }
              
                      }
              The NewMouseEnter given by yhplr and altered to attempt any fixes:

              Code:
              using System.Runtime.Serialization;
              using WaveEngine.Framework;
              using WaveEngine.Framework.Graphics;
              using System;
              using WaveEngine.Framework.Services;
              using WaveEngine.Common.Math;
              using Keno_Linux;
              using Keno.UI;
              using WaveEngine.Components.Gestures;
              using WaveEngine.Framework.Diagnostic;
              
              [DataContract]
              public class NewMouseEnterBehavior : Behavior
              {
                  [RequiredComponent]
                  private Transform2D _transform2D;
                  [RequiredComponent]
                  private TouchGestures _touchGestures;
                  private bool isHovering = false;
                  private Vector2 offset;
                  protected override void Initialize()
                  {
                      _transform2D = Owner.FindComponent<Transform2D>();
                      Labels.Add (Owner.Name, _transform2D.Rectangle.Location);
              
                      //offset = new Vector2( -50, -20 );
                  }
              
                  Vector2 pos = WaveServices.Input.MouseState.Position;
                  public delegate void MouseEnterEventHandler(Object sender, EventArgs e);
              
                  public event MouseEnterEventHandler MouseEnter;
              
                  protected override void Update(TimeSpan gameTime)
                  {
                      //pos = WaveServices.Input.MouseState.Position + offset;
                      pos = EntityManager.Find("TouchManager").FindComponent<TouchManager>().currentTouch;
              
                      // Mouse Over Button
                      if (_transform2D.Rectangle.Contains(pos) && pos != Vector2.Zero && !isHovering)
                      {
                          isHovering = true;
                          MouseEnter (null, null);
                      }
                      else if(!_transform2D.Rectangle.Contains(pos) && isHovering)
                      {
                          isHovering = false;
                      }
                  }
                  protected Vector2 Offset()
                  {
                      Vector2 mouseVec = WaveServices.Input.MouseState.Position;
                      Vector2 touchVec = _touchGestures.ReadGesture ().Position;
                      float xDif = Math.Abs (mouseVec.X - touchVec.X);
                      float yDif = Math.Abs (mouseVec.Y - touchVec.Y);
                      Vector2 diffVec = new Vector2 (xDif, yDif);
                      Console.WriteLine ("Difference is: " + diffVec);
                      return diffVec;
              
                  }
              
              }
              And the TouchManager(i've been trying some fixes already, like now i'm trying to 'calibrate' it by adding to the X and Y.

              Code:
              using System;
              using WaveEngine.Framework;
              using WaveEngine.Components.Gestures;
              using WaveEngine.Common.Math;
              using WaveEngine.Framework.Services;
              using WaveEngine.Framework.Diagnostic;
              
              namespace Keno_Linux
              {
                  public class TouchManager : Behavior
                  {
                      TouchGestures touch;
                      public Vector2 currentTouch = new Vector2();
                      protected override void Initialize()
                      {
                          touch = Owner.FindComponent<TouchGestures>();
              
                          WaveServices.ScreenContextManager.SetDiagnosticsActive(true);
                      }
              
                      protected override void Update(TimeSpan gameTime)
                      {
                          Labels.Add ("Mouse Position", WaveServices.Input.MouseState.Position);
              
              //            currentTouch = touch.ReadGesture ().Position;
                          float VecX = WaveServices.Input.MouseState.Position.X + -150f;
                          float VecY = WaveServices.Input.MouseState.Position.Y + -50f;
                          Vector2 calibrated = new Vector2 (VecX, VecY);
                          currentTouch = calibrated;
                          if (WaveServices.Input.MouseState.Position.X <= 0)
                          {
                              Debugger.WriteLine("Mouse went negative to: "+ (VecX+150f).ToString());
                          }
                          Labels.Add ("Mouse + Correction", calibrated);
                          //Debugger.WriteLine ("TM: CT: " + currentTouch);
                      }
                  }
              }

              Comment


              • #22
                bumping thread

                Comment


                • #23
                  Hi Maxdg,

                  Reviewing the code you have posted, the only thing that I think can be related is the VirtualScreenManager. ¿Do you have enabled the VirtualScreenManager?

                  Also, if you can post a simple project that reproduce the issue we will can help you better.

                  Greetings,
                  Daniel.

                  Comment


                  • #24
                    Originally posted by DanielCaceres View Post
                    Hi Maxdg,

                    Reviewing the code you have posted, the only thing that I think can be related is the VirtualScreenManager. ¿Do you have enabled the VirtualScreenManager?

                    Also, if you can post a simple project that reproduce the issue we will can help you better.

                    Greetings,
                    Daniel.
                    Yes after i disabled the VirtualScreenManager(VSM) it worked perfectly, however i had to completely recode the UI to fit the new screen again. But without the VSM its not multi resolution anymore right?

                    Comment


                    • #25
                      Hello there!

                      It looks like you are mixing both mouse and touch events. The TouchGestures component takes the VirtualScreenManager into account, so any touches reported by it are correct in Virtual Screen space. However, the MouseState position does not, so you have to manually transform the mouse position events to Virtual Screen space. This can be done with the following piece of code:

                      Code:
                      var click = WaveServices.Input.MouseState.Position;
                      camera2D.UsedVirtualScreen.ToVirtualPosition(ref click);
                      I hope this helps. Cheers!

                      Comment


                      • #26
                        Originally posted by Minolo View Post
                        Hello there!

                        It looks like you are mixing both mouse and touch events. The TouchGestures component takes the VirtualScreenManager into account, so any touches reported by it are correct in Virtual Screen space. However, the MouseState position does not, so you have to manually transform the mouse position events to Virtual Screen space. This can be done with the following piece of code:

                        Code:
                        var click = WaveServices.Input.MouseState.Position;
                        camera2D.UsedVirtualScreen.ToVirtualPosition(ref click);
                        I hope this helps. Cheers!
                        Hey Minolo, i'll try to implement this later once i'm done with current product. deadline is near so no time to experiment it.

                        Comment


                        • #27
                          Great! Please report back to us when you test it

                          Comment

                          Working...
                          X