We have detected that cookies are not enabled on your browser. Please enable cookies to ensure the proper experience.
Results 1 to 8 of 8
  1. #1

    Question Turbine.UI.Lotro.TextBox and Mouse Events

    I'm an experience programmer but I'm new to Lua and LotRO plugin creation. I've delved into it because I'm not happy with a plugin I'm using. I have modified it in many ways and have learned much but I've run into a strange problem.

    I can't seem to catch most Mouse Events with Turbine.UI.Lotro.TextBox. I want to execute a function whenever I right-click the TextBox. Every version of the API documentation I've read lists the standard Mouse Events as members. The only ones that seem to actually work are Mouse Enter and Mouse Leave. Oddly, Mouse Enter also fires when I click the TextBox.

    The non-skinned version, Turbine.UI.TextBox, seems to fire all Mouse Events so I've switched to using that for now. I would prefer to use the skinned version, if possible, but mainly I'd like a better understanding of what is going on.

    Is the API documentation in error regarding Turbine.UI.Lotro.TextBox?

    Is Turbine.UI.Lotro.TextBox suppressing events in a way that can be overcome?

  2. #2
    Join Date
    Mar 2007
    Posts
    1,171
    This is a bug in the Turbine.UI.Lotro.TextBox class. Mouse events are being handled by the control and are not passed on to Lua. In fact, if you use SetMouseVisible(false) on a Turbine.UI.Lotro.TextBox, the mouse events do not pass through the control either making it impossible to handle mouse events other than MouseEnter and MouseLeave with a Turbine.UI.Lotro.TextBox. One possible workaround is to put a transparent text control (it has to be a textbox to get and pass on focus) in front of the textbox and use the :FocusGained event to set focus to the textbox effectively allowing you to catch mouse events.

    Consider the sample below with three textboxes, the standard Turbine.UI.TextBox, a Turbine.UI.Lotro.TextBox (demonstrating the bug) and a Turbine.UI.Lotro.TextBox with a mouse masking Turbine.UI.TextBox showing the work around. If you execute the code, you will see that the third textbox displays exactly as you desire as well as handling mouse events.
    Code:
    testWindow=Turbine.UI.Lotro.Window()
    testWindow:SetSize(300,175)
    testWindow:SetPosition(0,0)
    testWindow:SetZOrder(1)
    testWindow:SetVisible(true)
    
    label1=Turbine.UI.Label()
    label1:SetParent(testWindow)
    label1:SetSize(100,25)
    label1:SetPosition(10,45)
    label1:SetText("Box 1:")
    testBox1=Turbine.UI.TextBox()
    testBox1:SetParent(testWindow)
    testBox1:SetSize(175,25)
    testBox1:SetPosition(115,45)
    testBox1:SetText("test box 1")
    
    label2=Turbine.UI.Label()
    label2:SetParent(testWindow)
    label2:SetSize(100,25)
    label2:SetPosition(10,75)
    label2:SetText("Box 2:")
    testBox2=Turbine.UI.Lotro.TextBox()
    testBox2:SetParent(testWindow)
    testBox2:SetSize(175,25)
    testBox2:SetPosition(115,75)
    testBox2:SetText("test box 2")
    
    label3=Turbine.UI.Label()
    label3:SetParent(testWindow)
    label3:SetSize(100,25)
    label3:SetPosition(10,105)
    label3:SetText("Box 3:")
    testBox3=Turbine.UI.Lotro.TextBox()
    testBox3:SetParent(testWindow)
    testBox3:SetSize(175,25)
    testBox3:SetPosition(115,105)
    testBox3:SetText("test box 3")
    testBox3:SetMouseVisible(false)
    testBox3Mouse=Turbine.UI.TextBox()
    testBox3Mouse:SetParent(testWindow)
    testBox3Mouse:SetSize(175,25)
    testBox3Mouse:SetPosition(115,105)
    testBox3Mouse.FocusGained=function(sender,args)
        testBox3:Focus(testBox3,args)
    end
    
    -- box 1 mouse events
    testBox1.MouseEnter=function(sender,args)
        Turbine.Shell.WriteLine("test 1 mouse enter")
    end
    testBox1.MouseDown=function(sender,args)
        Turbine.Shell.WriteLine("test 1 mouse down")
    end
    testBox1.MouseUp=function(sender,args)
        Turbine.Shell.WriteLine("test 1 mouse up")
    end
    testBox1.MouseLeave=function()
        Turbine.Shell.WriteLine("test 1 mouse leave")
    end
    
    -- box 2 mouse events
    testBox2.MouseEnter=function(sender,args)
        Turbine.Shell.WriteLine("test 2 mouse enter")
    end
    testBox2.MouseDown=function(sender,args)
        Turbine.Shell.WriteLine("test 2 mouse down")
    end
    testBox2.MouseUp=function(sender,args)
        Turbine.Shell.WriteLine("test 2 mouse up")
    end
    testBox2.MouseLeave=function()
        Turbine.Shell.WriteLine("test 2 mouse leave")
    end
    testBox2.MouseMove=function()
        Turbine.Shell.WriteLine("test 2 mouse move")
    end
    
    -- box3mouse events that are then sent to box 3
    testBox3Mouse.MouseEnter=function(sender,args)
        testBox3.MouseEnter(testBox3,args)
    end
    testBox3Mouse.MouseDown=function(sender,args)
        testBox3.MouseDown(testBox3,args)
    end
    testBox3Mouse.MouseUp=function(sender,args)
        testBox3.MouseUp(testBox3,args)
    end
    testBox3Mouse.MouseLeave=function(sender,args)
        testBox3.MouseLeave(testBox3,args)
    end
    testBox3Mouse.MouseMove=function(sender,args)
        testBox3.MouseMove(testBox3,args)
    end
    -- actual box 3 events
    testBox3.MouseEnter=function(sender,args)
        Turbine.Shell.WriteLine("test 3 mouse enter")
    end
    testBox3.MouseDown=function(sender,args)
        Turbine.Shell.WriteLine("test 3 mouse down")
    end
    testBox3.MouseUp=function(sender,args)
        Turbine.Shell.WriteLine("test 3 mouse up")
    end
    testBox3.MouseLeave=function(sender,args)
        Turbine.Shell.WriteLine("test 3 mouse leave")
    end
    testBox3.MouseMove=function(sender,args)
        Turbine.Shell.WriteLine("test 3 mouse move (args.X:"..tostring(args.X)..")")
    end
    The testBox3Mouse control exists solely to handle mouse events and to pass focus to the underlying testBox3 control.

    When dissecting the code, pay close attention to how the mouse events are captured and passed on, specifically the difference in the "." and ":" calling conventions. For example, in the MouseDown handler for the masking textbox,
    Code:
    testBox3Mouse.MouseDown=function(sender,args)
        testBox3.MouseDown(testBox3,args)
    end
    the underlying control's MouseDown event is fired using the "." convention since we pass the underlying control as the "source" of the event to mask the fact that it is actually handled by our mask. You could simply handle the event in the mask without calling the underlying control's event handler but I wanted to show an example of how to make the underlying control function as it should.

    FWIW, the seemingly extraneous "MouseLeave" and "MouseEnter" events that occur on right clicking happen on both types of control and seem to be tied to the fact that while the right mouse is down, control reverts to moving the character so effectively the mouse has left your control and is interacting with the game UI and is then returned to your control once you lift the right mouse button.
    Last edited by Garan; Mar 13 2014 at 11:18 AM. Reason: clarification

  3. #3
    Thank you, Garan, for your prompt and very detailed reply. As always, your post is wealth of great information.

    Your proposed workaround is a tremendous help. I doubt I would have had the patience to ever find such a solution.

  4. #4
    Although your solution worked perfectly for what I wanted, now I've run into a snag.

    I cannot seem to find a way to handle text selection. While I've not exhausted all possibilities – in part because the API documentation is so lacking – I cannot see a likely solution.

    I'm happy to continue using the non-skinned version of the textbox control. If I desire to use the skinned textbox for its border, an option would be to place it in the background and put the active, non-skinned textbox on top with a transparent background (if possible – didn't work as expected) or with a background blend mode (screen works OK, but the active textbox should be inset by a few pixels). Less than ideal but better than nothing.

  5. #5
    Join Date
    Mar 2007
    Posts
    1,171
    I'm not sure what you meant by not being able to handle text selection. Could you be more specific in what part of text selection you are having trouble with?

    EDIT:
    Note, there is a function :SetSelectable(true) which you have to call on the Turbine.UI.TextBox before text is selectable. Turbine.UI.Lotro.Textbox has this set true by default.

  6. #6
    Sorry, I wasn't clear.

    I have text selection working with Turbine.UI.TextBox currently. Likewise it works fine with Turbine.UI.Lotro.TextBox.

    The problem is when I try to use Turbine.UI.Lotro.TextBox for my text entry, and an overlay Turbine.UI.TextBox to catch and pass mouse events (as you suggest above). I am unable to select text within Turbine.UI.Lotro.TextBox (using the mouse) if another control is on top of it.

  7. #7
    Join Date
    Mar 2007
    Posts
    1,171
    Ah, now I see what you meant. That does seem to be an insurmountable limit of the workaround. Keyboard text selection should work fine but mouse text selection will not since mouse events are handled by the overlayed control.

  8. #8
    This looks like the same problem I found with Lotro scrollbars.

    If I understand it correctly, this is what's happening:

    Mouse events (other than enter and leave) are passed directly to the first visible control under the mouse. In the case of a textbox, that can be the text field; in the case of a scroll-bar, that's the thumb or one of the buttons.

    The bug is that when one of these content controls is clicked, it captures and processes the mouse-click without informing the 'outside world' of the mouse event.

    And you cannot do some sort of capture-and-pass-on solution, because, once you've captured the mouse event, there's no way to say "no, I don't want this, you handle it" ... you can't get a mouse event *into* the lotro controls... that can only happen outside of the plugin's scope.


    So, without the lotro controls issuing the callback routines, there's simply no way to intercept or respond to the call: if you intercept it, the lotro control never gets the mouse command; if the lotro control gets the mouse command, you never see it. Either-or.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

This form's session has expired. You need to reload the page.

Reload