Thread Tools Display Modes
06-14-15, 12:42 PM   #1
Niatue
A Defias Bandit
Join Date: Jun 2015
Posts: 3
Right mouse button clicks on menu buttons

Hello, I have an EasyMenu DropDownMenu and I want to be able to both right and left click on the buttons and handle each button click differently. However, right button clicks are not registered at all and there's no way to even tell the left button has been clicked.

My code is:
Code:
local menuFrame = CreateFrame("Frame", "MenuFrame", DropDownButton, "UIDropDownMenuTemplate")

local menuList = {	
	{ text = "Menu 1", hasArrow = true, notCheckable = true,
        menuList = {
            { text = "First option", notCheckable = true, 
		func = function() print("1st option clicked") end },
			
	    { text = "Second option", notCheckable = true, 
		func = function() print("2nd option clicked") end }
        } 
    }
}

local function ShowMenu(self, button)
	EasyMenu(menuList, menuFrame, "cursor", 0, 0, "MENU")
end

local button = CreateFrame("Button", "DropDownButton", UIParent, "UIPanelButtonTemplate")
button:SetSize(100, 50) 
button:SetText("Menu")
button:SetPoint("CENTER")
button:RegisterForClicks("RightButtonDown", "LeftButtonDown")
button:SetScript("OnClick", ShowMenu)
button:Show()

Is there any way to register both buttons and distinguish between the two via one of the 2 custom arguments menuList takes? Other than having to implement my own DropDownMenu. Is there perhaps a function than can be hooked to "force" it to recognize both buttons?

I'd like to do something like this:

Code:
local menuList = {	
     { text = "Menu 1", hasArrow = true, notCheckable = true,
        menuList = {
          { text = "First option", arg1 = "1st option clicked", arg2 = button, 
	     notCheckable = true, func = function() 
	        if button == "RightButton" then
		     print(arg1)
		else
		     print("Left button clicked!")
		end 
	   end},			
          } 
     }
}
  Reply With Quote
06-14-15, 04:29 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Try this to see if any arguments are passed through to your function maybe?
Lua Code:
  1. func = function(...) print(...) end
If there are, and one of them is which button was used, then it's easy. Otherwise, not so much.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-14-15, 11:31 PM   #3
Niatue
A Defias Bandit
Join Date: Jun 2015
Posts: 3
The signature of the function is func(self, arg1, arg2, checked). Arg1 and arg2 are user defined variables and can be literally anything but unlike most OnClick functions, the button state is not passed!

In fact, right button clicks are not recognized at all, meaning, when I right-click a button nothing happens. It only recognizes left-clicks and I'm trying to change that.

Each menuList table has a specific signature more on which can be found here: UI Object UIDropDownMenu and EasyMenu
  Reply With Quote
06-16-15, 06:47 AM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
It can be done, but it's a bit hacky.

First hook the function that creates menu buttons to make sure they're registered for right clicks. (unless you have a reason to use *Down, I'd use *Up instead, as that's what the rest of the UI uses)
Code:
local function createFramesHook(numLevels, numButtons)
	for level = 1, numLevels do
		for i = 1, numButtons do
			_G["DropDownList"..level.."Button"..i]:RegisterForClicks("LeftButtonUp", "RightButtonUp")
		end
	end
end

createFramesHook(UIDROPDOWNMENU_MAXLEVELS, UIDROPDOWNMENU_MAXBUTTONS)
hooksecurefunc("UIDropDownMenu_CreateFrames", createFramesHook)
Then use GetMouseButtonClicked() in func to determine which button was clicked.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-16-15, 02:59 PM   #5
Niatue
A Defias Bandit
Join Date: Jun 2015
Posts: 3
That's exactly what I wanted! Thank you, Lombra.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Right mouse button clicks on menu buttons

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off