Stuck on a right click

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Damlimey
Posts: 31
Joined: Sun May 31, 2009 10:56 am

Stuck on a right click

Post by Damlimey » Sat Jul 11, 2009 11:42 am

First of all, my thanks to jansschenkel and shadowslash for their help with this but I've come unstuck. Here's an example of how I've tried to set up a player start/stop button with a right click menu option, maybe someone can tell me where I've gone wrong...

Code: Select all

start/stop button code:
on mouseUp
   if pMouseButton is 1 then  -- left-button click
     do your normal thing
  else
   popup button "rightclick"
 end if
   if the filename of player "p1" is "" then exit mouseUp
   put the label of me into myLabel 
 if myLabel is not "STOP" then 
    set the label of me to "STOP"
    start player "p1" 
   else 
   set the label of me to "START" 
   stop player "p1" 
   # this resets the player to the beginning 
   set the currenttime of player "p1" to 0 
end if

end mouseUp
And here is the right click pop up menu code:

Code: Select all

on menuPick pMenuItem
  answer pMenuItem
end menuPick 
Thank you in advance,
geoff
So, it's a big Salami... Just take it one slice at a time.

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Sat Jul 11, 2009 12:48 pm

Hi,

you do not pass the parameter in mouseUp

should read

on mouseUp pMouseButton

Hth,

Malte

Damlimey
Posts: 31
Joined: Sun May 31, 2009 10:56 am

Thank you Malte

Post by Damlimey » Sun Jul 12, 2009 10:24 am

I have found another approach which is shown here...

Code: Select all

on mouseUp mouseButtonNumber 
 if mouseButtonNumber = 1 then do leftclickstuff 
 if mouseButtonNumber = 3 then do rightclickstuff 
end mouseUp
This looks like a more elegant way to proceed but I do have another question...

Now that I have a pop up menu on my right-click, I am finding it hard to find out how to use the menu items command. If for example I want to have a 'load' option in the menu item list, how do I write the command line to action that menu item?

Thank in advance,
D
So, it's a big Salami... Just take it one slice at a time.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sun Jul 12, 2009 10:37 am

Hi D,

let me first say that context menus that appear on right/control click are supposed to appear "on mousedown". This is at least my observation.

Sou you should script this:

Code: Select all

## Only hanlde right clicks!
on mousedown tButton
  if tButton = 3 then
    popup btn "my context menu" at the mouseloc
  end if
end mousedown

## Handle "normal" clicks with the left mousebutton
on mouseup tButton
  if tButton <> 1 then
    exit mouseup
  end if
  ## do your mouseup stuff here..
end mouseup
To handle the choosen menutitems from the popup you need to do it in the
"menupick" handler of the popup button like this:

Code: Select all

on menupick tItem
  switch tItem
    case "Load"
       ### do your "load" stuff
    break
   case "Another choosen menu item"
     ### do other stuff etc...
   break
   case "Yet another choosen menu item"
     ### do other stuff etc...
   break
  end switch
end menupick
Hope that helps.


Best

Klaus

Damlimey
Posts: 31
Joined: Sun May 31, 2009 10:56 am

Thank you Klaus

Post by Damlimey » Sun Jul 12, 2009 9:18 pm

Once again, you've cleared my confusion as well as putting me on the right path!

That all works really well.

D
So, it's a big Salami... Just take it one slice at a time.

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Mon Jul 13, 2009 12:05 pm

Klaus wrote:

Code: Select all

on mousedown tButton
  if tButton = 3 then
    popup btn "my context menu" at the mouseloc
  end if
end mousedown
Lollllllllllllll this was one of the RunRev mysteries that I can't seem to find an answer of and that I'm too shy to ask about... Thanks a lot! Image
Parañaque, Philippines
Image
Image

!Jerry!
Posts: 16
Joined: Tue Apr 07, 2009 3:49 pm

Post by !Jerry! » Mon Jul 13, 2009 12:45 pm

shadowslash wrote:
Klaus wrote:

Code: Select all

on mousedown tButton
  if tButton = 3 then
    popup btn "my context menu" at the mouseloc
  end if
end mousedown
Lollllllllllllll this was one of the RunRev mysteries that I can't seem to find an answer of and that I'm too shy to ask about... Thanks a lot! Image
Hi shadowslash!

These mysteries are old enough :-):

Posted: Thu Apr 27, 2006 5:11 pm Post subject: Re: pop-up menu on mouse right button click
Janschenkel wrote:A better option is to put your opup menu button somewhere off-screen, and then use a script like:

Code: Select all

on mouseUp pMouseButton
  if pMouseButton = 3 then 
    popup button "MyPopupButton" at the clickLoc
  else
    -- do other stuff here
  end if
end mouseUp
The popup menu button will receive the 'menuPick' message when the user picks one of the items, so you'll have to move some of your logic into that menu button as well:

Code: Select all

on menuPick pItem
  switch pItem
    case "Hello world"
      answer "Hello, world!"
      break
    case "Foo"
      answer "Bar" with "Cancel"
      break
    -- more case statements here
  end switch
end menuPick
Hope this helped,

Jan Schenkel.
Jerry

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Mon Jul 13, 2009 12:47 pm

Yah well, I just started Revving last month Image and I kinda missed that topic... Image
Parañaque, Philippines
Image
Image

!Jerry!
Posts: 16
Joined: Tue Apr 07, 2009 3:49 pm

Post by !Jerry! » Mon Jul 13, 2009 12:59 pm

Don't cry! It is too late! This is a good lesson for the next time!

:lol: :lol:
Jerry

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Mon Jul 13, 2009 1:03 pm

!Jerry! wrote:Don't cry! It is too late! This is a good lesson for the next time!

:lol: :lol:
Jerry
Lol ofcourse...
-------
Follow me now on Twitter -> http://Twitter.com/shadowslash
Image
Parañaque, Philippines
Image
Image

Post Reply